Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fileserver: Fix file matcher with empty try_files #4147

Merged
merged 2 commits into from
May 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions modules/caddyhttp/fileserver/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ func (m *MatchFile) Provision(_ caddy.Context) error {
if m.Root == "" {
m.Root = "{http.vars.root}"
}
// if list of files to try was omitted entirely, assume URL path
francislavoie marked this conversation as resolved.
Show resolved Hide resolved
// (use placeholder instead of r.URL.Path; see issue #4146)
if m.TryFiles == nil {
m.TryFiles = []string{"{http.request.uri.path}"}
}
return nil
}

Expand Down Expand Up @@ -174,13 +179,6 @@ func (m MatchFile) selectFile(r *http.Request) (matched bool) {

root := repl.ReplaceAll(m.Root, ".")

// if list of files to try was omitted entirely,
// assume URL path
if m.TryFiles == nil {
// m is not a pointer, so this is safe
m.TryFiles = []string{r.URL.Path}
}

// common preparation of the file into parts
prepareFilePath := func(file string) (suffix, fullpath, remainder string) {
suffix, remainder = m.firstSplit(path.Clean(repl.ReplaceAll(file, "")))
Expand Down