From a31fd9eb0996acd3f68d0caa8790232d381a5c71 Mon Sep 17 00:00:00 2001 From: Chase Hutchins Date: Fri, 19 Jun 2015 17:39:05 -0700 Subject: [PATCH] subdirectory index functionality --- echo.go | 2 +- echo_test.go | 8 +++++++- examples/website/public/folder/index.html | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 examples/website/public/folder/index.html diff --git a/echo.go b/echo.go index 8b0c0d98..474d7ba8 100644 --- a/echo.go +++ b/echo.go @@ -338,7 +338,7 @@ func serveFile(dir, file string, c *Context) error { fi, _ := f.Stat() if fi.IsDir() { - f, err = fs.Open("index.html") + f, err = fs.Open(file + "/index.html") if err != nil { return NewHTTPError(http.StatusForbidden) } diff --git a/echo_test.go b/echo_test.go index 09495d1c..8e5b3d9e 100644 --- a/echo_test.go +++ b/echo_test.go @@ -78,8 +78,14 @@ func TestEchoStatic(t *testing.T) { // Directory with index.html e.Static("/", "examples/website/public") - c, _ = request(GET, "/", e) + c, r := request(GET, "/", e) assert.Equal(t, http.StatusOK, c) + assert.Equal(t, true, strings.HasPrefix(r, "")) + + // Sub-directory with index.html + c, r = request(GET, "/folder", e) + assert.Equal(t, http.StatusOK, c) + assert.Equal(t, "sub directory", r) } func TestEchoMiddleware(t *testing.T) { diff --git a/examples/website/public/folder/index.html b/examples/website/public/folder/index.html new file mode 100644 index 00000000..36b3a421 --- /dev/null +++ b/examples/website/public/folder/index.html @@ -0,0 +1 @@ +sub directory \ No newline at end of file