@@ -28,6 +28,10 @@ type responseData struct {
2828 rawReqPath string
2929 handlerReqPath string
3030
31+ NeedAuth bool
32+ AuthUserName string
33+ AuthSuccess bool
34+
3135 errors []error
3236 Status int
3337
@@ -51,8 +55,6 @@ type responseData struct {
5155 HasDeletable bool
5256 CanArchive bool
5357 CanCors bool
54- NeedAuth bool
55- AuthUserName string
5658
5759 IsDownload bool
5860 IsUpload bool
@@ -269,10 +271,18 @@ func (h *handler) getResponseData(r *http.Request) *responseData {
269271
270272 rawReqPath := util .CleanUrlPath (requestUri )
271273 reqPath := util .CleanUrlPath (rawReqPath [len (h .urlPrefix ):]) // strip url prefix path
274+ reqFsPath , _ := util .NormalizeFsPath (h .root + reqPath )
275+
276+ needAuth := h .getNeedAuth (rawReqPath , reqFsPath )
277+ authUserName := ""
278+ authSuccess := true
279+ if needAuth {
280+ authUserName , authSuccess = h .verifyAuth (r )
281+ }
282+
272283 errs := []error {}
273284 status := http .StatusOK
274285 isRoot := rawReqPath == "/"
275-
276286 rawQuery := r .URL .RawQuery
277287
278288 pathEntries := getPathEntries (rawReqPath , tailSlash )
@@ -283,9 +293,7 @@ func (h *handler) getResponseData(r *http.Request) *responseData {
283293 rootRelPath = "./"
284294 }
285295
286- reqFsPath , _ := util .NormalizeFsPath (h .root + reqPath )
287-
288- file , item , _statErr := stat (reqFsPath , ! h .emptyRoot )
296+ file , item , _statErr := stat (reqFsPath , authSuccess && ! h .emptyRoot )
289297 if _statErr != nil {
290298 errs = append (errs , _statErr )
291299 status = getStatusByErr (_statErr )
@@ -307,7 +315,7 @@ func (h *handler) getResponseData(r *http.Request) *responseData {
307315
308316 itemName := getItemName (item , r )
309317
310- subItems , _readdirErr := readdir (file , item , needResponseBody (r .Method ))
318+ subItems , _readdirErr := readdir (file , item , authSuccess && needResponseBody (r .Method ))
311319 if _readdirErr != nil {
312320 errs = append (errs , _readdirErr )
313321 status = http .StatusInternalServerError
@@ -334,7 +342,6 @@ func (h *handler) getResponseData(r *http.Request) *responseData {
334342 hasDeletable := canDelete && len (subItems ) > len (aliasSubItems )
335343 canArchive := h .getCanArchive (subItems , rawReqPath , reqFsPath )
336344 canCors := h .getCanCors (rawReqPath , reqFsPath )
337- needAuth := h .getNeedAuth (rawReqPath , reqFsPath )
338345
339346 isDownload := false
340347 isUpload := false
@@ -366,6 +373,10 @@ func (h *handler) getResponseData(r *http.Request) *responseData {
366373 rawReqPath : rawReqPath ,
367374 handlerReqPath : reqPath ,
368375
376+ NeedAuth : needAuth ,
377+ AuthUserName : authUserName ,
378+ AuthSuccess : authSuccess ,
379+
369380 errors : errs ,
370381 Status : status ,
371382
@@ -389,7 +400,6 @@ func (h *handler) getResponseData(r *http.Request) *responseData {
389400 HasDeletable : hasDeletable ,
390401 CanArchive : canArchive ,
391402 CanCors : canCors ,
392- NeedAuth : needAuth ,
393403
394404 IsDownload : isDownload ,
395405 IsUpload : isUpload ,
0 commit comments