diff --git a/backend/server/middleware.go b/backend/server/middleware.go deleted file mode 100644 index e51c700..0000000 --- a/backend/server/middleware.go +++ /dev/null @@ -1,18 +0,0 @@ -package server - -import ( - "net/http" - "strings" -) - -// DisableDirectoryListings intercepts and responds with 404 to HTTP requests -// which would otherwise be served with a directory listing by http.FileServer. -func DisableDirectoryListings(next http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if strings.HasSuffix(r.URL.Path, "/") { - http.NotFound(w, r) - return - } - next.ServeHTTP(w, r) - }) -} diff --git a/backend/server/middleware_test.go b/backend/server/middleware_test.go deleted file mode 100644 index c8ad361..0000000 --- a/backend/server/middleware_test.go +++ /dev/null @@ -1,66 +0,0 @@ -package server_test - -import ( - "fmt" - "net/http" - "net/http/httptest" - "testing" - - "git.netflux.io/rob/clipper/server" - "github.com/stretchr/testify/assert" -) - -func TestDisableDirectoryListings(t *testing.T) { - testCases := []struct { - path string - wantStatus int - }{ - { - path: "/", - wantStatus: http.StatusNotFound, - }, - { - path: "/index.html", - wantStatus: http.StatusOK, - }, - { - path: "/foo", - wantStatus: http.StatusOK, - }, - { - path: "/foo/", - wantStatus: http.StatusNotFound, - }, - { - path: "/foo/bar", - wantStatus: http.StatusOK, - }, - { - path: "/foo/bar/", - wantStatus: http.StatusNotFound, - }, - { - path: "/foo/bar/baz", - wantStatus: http.StatusOK, - }, - { - path: "/foo/bar/baz/index.html", - wantStatus: http.StatusOK, - }, - } - - for _, tc := range testCases { - t.Run("path="+tc.path, func(t *testing.T) { - req := httptest.NewRequest("GET", tc.path, nil) - rec := httptest.NewRecorder() - - handler := server.DisableDirectoryListings(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { - fmt.Fprintf(w, "Hello world") - })) - handler.ServeHTTP(rec, req) - - resp := rec.Result() - assert.Equal(t, tc.wantStatus, resp.StatusCode) - }) - } -} diff --git a/backend/server/server.go b/backend/server/server.go index d3112a0..a305d73 100644 --- a/backend/server/server.go +++ b/backend/server/server.go @@ -307,9 +307,6 @@ func Start(options Options) error { fileHandler = http.FileServer(http.Dir(options.Config.FileStoreHTTPRoot)) } - // Ensure http.FileServer does not serve directory listings. - fileHandler = DisableDirectoryListings(fileHandler) - httpServer := http.Server{ Addr: options.Config.BindAddr, ReadTimeout: options.Timeout,