@@ -274,13 +274,33 @@ func getStatusByErr(err error) int {
274274 }
275275}
276276
277- func (h * handler ) stateIndexFile (baseItem os. FileInfo , baseDir string ) (file * os.File , item os.FileInfo , err error ) {
277+ func (h * handler ) stateIndexFile (rawReqPath , baseDir string , baseItem os. FileInfo ) (file * os.File , item os.FileInfo , err error ) {
278278 if baseItem == nil || ! baseItem .IsDir () || h .emptyRoot || len (h .dirIndexes ) == 0 {
279279 return
280280 }
281281
282+ for _ , index := range h .dirIndexes {
283+ for _ , alias := range h .aliases {
284+ if rawReqPath + "/" + index != alias .urlPath {
285+ continue
286+ }
287+ file , item , err = stat (alias .fsPath , true )
288+ if err != nil && file != nil {
289+ file .Close ()
290+ }
291+ if err != nil && os .IsNotExist (err ) {
292+ continue
293+ } else {
294+ return
295+ }
296+ }
297+ }
298+
282299 for _ , index := range h .dirIndexes {
283300 file , item , err = stat (baseDir + "/" + index , true )
301+ if err != nil && file != nil {
302+ file .Close ()
303+ }
284304 if err != nil && os .IsNotExist (err ) {
285305 continue
286306 } else {
@@ -320,7 +340,7 @@ func (h *handler) getResponseData(r *http.Request) (data *responseData) {
320340 status = getStatusByErr (_statErr )
321341 }
322342
323- indexFile , indexItem , _statIdxErr := h .stateIndexFile (item , reqFsPath )
343+ indexFile , indexItem , _statIdxErr := h .stateIndexFile (rawReqPath , reqFsPath , item )
324344 if _statIdxErr != nil {
325345 errs = append (errs , _statIdxErr )
326346 status = getStatusByErr (_statIdxErr )
0 commit comments