Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 13, 20:30 UTC
staticfiles: Expand placeholder for index files (#4679)
Y.Horie committed
Apr 8, 2022 at 06:01 UTC
afca2421112eb89e435888f50f8146364a3c60a4
3 files changed
+25
caddytest/integration/caddyfile_test.go
+24
@@ -101,3 +101,27 @@ func TestReadCookie(t *testing.T) {
101
// act and assert
102
tester.AssertGetResponse("http://localhost:9080/cookie.html", 200, "<h2>Cookie.ClientName caddytest</h2>")
103
}
104
+
105
+func TestReplIndex(t *testing.T) {
106
+
107
+ tester := caddytest.NewTester(t)
108
+ tester.InitServer(`
109
+ {
110
+ http_port 9080
111
+ https_port 9443
112
+ }
113
+
114
+ localhost:9080 {
115
+ templates {
116
+ root testdata
117
+ }
118
+ file_server {
119
+ root testdata
120
+ index "index.{host}.html"
121
+ }
122
+ }
123
+ `, "caddyfile")
124
+
125
+ // act and assert
126
+ tester.AssertGetResponse("http://localhost:9080/", 200, "")
127
+}
caddytest/integration/testdata/index.localhost.html
modules/caddyhttp/fileserver/staticfiles.go
+1
@@ -200,6 +200,7 @@ func (fsrv *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request, next c
200
var implicitIndexFile bool
201
if info.IsDir() && len(fsrv.IndexNames) > 0 {
202
for _, indexPage := range fsrv.IndexNames {
203
+ indexPage := repl.ReplaceAll(indexPage, "")
204
indexPath := caddyhttp.SanitizedPathJoin(filename, indexPage)
205
if fileHidden(indexPath, filesToHide) {
206
// pretend this file doesn't exist