summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDusty Doris <[email protected]>2017-08-07 17:10:47 -0700
committerMatt Holt <[email protected]>2017-08-07 18:10:47 -0600
commit4e52b3fe8ad4afdf6d8c83287d59c8aa377d6eb7 (patch)
tree11353b90a4bf42c19fb8303b5e670ca5cfd1c284
parentbd67ec99f01797931a0787b9c2de0f04fa0e5980 (diff)
downloadcaddy-4e52b3fe8ad4afdf6d8c83287d59c8aa377d6eb7.tar.gz
caddy-4e52b3fe8ad4afdf6d8c83287d59c8aa377d6eb7.zip
staticfiles: fix handling of filenames that end with index file names (#1812)
* static files ending with an index were redirected improperly * optimize requestPage
-rw-r--r--caddyhttp/staticfiles/fileserver.go3
-rw-r--r--caddyhttp/staticfiles/fileserver_test.go9
2 files changed, 11 insertions, 1 deletions
diff --git a/caddyhttp/staticfiles/fileserver.go b/caddyhttp/staticfiles/fileserver.go
index d5cca1d3a..a66e1b136 100644
--- a/caddyhttp/staticfiles/fileserver.go
+++ b/caddyhttp/staticfiles/fileserver.go
@@ -106,8 +106,9 @@ func (fs FileServer) serveFile(w http.ResponseWriter, r *http.Request) (int, err
// if an index file was explicitly requested, strip file name from the request
// ("/foo/index.html" -> "/foo/")
+ var requestPage = path.Base(urlCopy.Path)
for _, indexPage := range IndexPages {
- if strings.HasSuffix(urlCopy.Path, indexPage) {
+ if requestPage == indexPage {
urlCopy.Path = urlCopy.Path[:len(urlCopy.Path)-len(indexPage)]
redir = true
break
diff --git a/caddyhttp/staticfiles/fileserver_test.go b/caddyhttp/staticfiles/fileserver_test.go
index a71998a76..715915b3c 100644
--- a/caddyhttp/staticfiles/fileserver_test.go
+++ b/caddyhttp/staticfiles/fileserver_test.go
@@ -219,6 +219,13 @@ func TestServeHTTP(t *testing.T) {
expectedLocation: "https://foo/bar/file1.html",
expectedBodyContent: movedPermanently,
},
+ {
+ url: "https://foo/notindex.html",
+ expectedStatus: http.StatusOK,
+ expectedBodyContent: testFiles[webrootNotIndexHTML],
+ expectedEtag: `"2n9cm"`,
+ expectedContentLength: strconv.Itoa(len(testFiles[webrootNotIndexHTML])),
+ },
}
for i, test := range tests {
@@ -493,6 +500,7 @@ func TestServeHTTPFailingStat(t *testing.T) {
// Paths for the fake site used temporarily during testing.
var (
webrootFile1HTML = filepath.Join(webrootName, "file1.html")
+ webrootNotIndexHTML = filepath.Join(webrootName, "notindex.html")
webrootDirFile2HTML = filepath.Join(webrootName, "dir", "file2.html")
webrootDirHiddenHTML = filepath.Join(webrootName, "dir", "hidden.html")
webrootDirwithindexIndeHTML = filepath.Join(webrootName, "dirwithindex", "index.html")
@@ -519,6 +527,7 @@ var (
var testFiles = map[string]string{
"unreachable.html": "<h1>must not leak</h1>",
webrootFile1HTML: "<h1>file1.html</h1>",
+ webrootNotIndexHTML: "<h1>notindex.html</h1>",
webrootDirFile2HTML: "<h1>dir/file2.html</h1>",
webrootDirwithindexIndeHTML: "<h1>dirwithindex/index.html</h1>",
webrootDirHiddenHTML: "<h1>dir/hidden.html</h1>",