@@ -274,13 +274,33 @@ func getStatusByErr(err error) int {
274
274
}
275
275
}
276
276
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 ) {
278
278
if baseItem == nil || ! baseItem .IsDir () || h .emptyRoot || len (h .dirIndexes ) == 0 {
279
279
return
280
280
}
281
281
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
+
282
299
for _ , index := range h .dirIndexes {
283
300
file , item , err = stat (baseDir + "/" + index , true )
301
+ if err != nil && file != nil {
302
+ file .Close ()
303
+ }
284
304
if err != nil && os .IsNotExist (err ) {
285
305
continue
286
306
} else {
@@ -320,7 +340,7 @@ func (h *handler) getResponseData(r *http.Request) (data *responseData) {
320
340
status = getStatusByErr (_statErr )
321
341
}
322
342
323
- indexFile , indexItem , _statIdxErr := h .stateIndexFile (item , reqFsPath )
343
+ indexFile , indexItem , _statIdxErr := h .stateIndexFile (rawReqPath , reqFsPath , item )
324
344
if _statIdxErr != nil {
325
345
errs = append (errs , _statIdxErr )
326
346
status = getStatusByErr (_statIdxErr )
0 commit comments