diff --git a/caddyhttp/staticfiles/fileserver.go b/caddyhttp/staticfiles/fileserver.go index 5690ceb93..65ae322b3 100644 --- a/caddyhttp/staticfiles/fileserver.go +++ b/caddyhttp/staticfiles/fileserver.go @@ -116,7 +116,7 @@ func (fs FileServer) serveFile(w http.ResponseWriter, r *http.Request) (int, err } urlCopy.Path += "/" http.Redirect(w, r, urlCopy.String(), http.StatusMovedPermanently) - return http.StatusMovedPermanently, nil + return 0, nil } } else { // ensure no trailing slash @@ -143,7 +143,7 @@ func (fs FileServer) serveFile(w http.ResponseWriter, r *http.Request) (int, err urlCopy.Path = strings.TrimPrefix(urlCopy.Path, "/") } http.Redirect(w, r, urlCopy.String(), http.StatusMovedPermanently) - return http.StatusMovedPermanently, nil + return 0, nil } } diff --git a/caddyhttp/staticfiles/fileserver_test.go b/caddyhttp/staticfiles/fileserver_test.go index a534d8c85..8425c2020 100644 --- a/caddyhttp/staticfiles/fileserver_test.go +++ b/caddyhttp/staticfiles/fileserver_test.go @@ -301,6 +301,9 @@ func TestServeHTTP(t *testing.T) { // perform the test status, err := fileServer.ServeHTTP(responseRecorder, request) + if status == 0 { + status = responseRecorder.Code + } etag := responseRecorder.Header().Get("Etag") body := responseRecorder.Body.String() vary := responseRecorder.Header().Get("Vary")