Browse Source
file_server: Accept files args in one-liner of Caddyfile matcher (#3298 )
Previously, matching by trying files other than the actual path of the
URI was:
file {
try_files <files...>
}
Now, the same can be done in one line:
file <files...>
As before, an empty file matcher:
file
still matches if the request URI exists as a file in the site root.
master
Matt Holt
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
3 additions and
2 deletions
modules/caddyhttp/fileserver/matcher.go
@ -91,7 +91,7 @@ func (MatchFile) CaddyModule() caddy.ModuleInfo {
// UnmarshalCaddyfile sets up the matcher from Caddyfile tokens. Syntax:
// UnmarshalCaddyfile sets up the matcher from Caddyfile tokens. Syntax:
//
//
// file {
// file <files...> {
// root <path>
// root <path>
// try_files <files...>
// try_files <files...>
// try_policy first_exist|smallest_size|largest_size|most_recently_modified
// try_policy first_exist|smallest_size|largest_size|most_recently_modified
@ -99,6 +99,7 @@ func (MatchFile) CaddyModule() caddy.ModuleInfo {
//
//
func ( m * MatchFile ) UnmarshalCaddyfile ( d * caddyfile . Dispenser ) error {
func ( m * MatchFile ) UnmarshalCaddyfile ( d * caddyfile . Dispenser ) error {
for d . Next ( ) {
for d . Next ( ) {
m . TryFiles = append ( m . TryFiles , d . RemainingArgs ( ) ... )
for d . NextBlock ( 0 ) {
for d . NextBlock ( 0 ) {
switch d . Val ( ) {
switch d . Val ( ) {
case "root" :
case "root" :
@ -107,7 +108,7 @@ func (m *MatchFile) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
}
}
m . Root = d . Val ( )
m . Root = d . Val ( )
case "try_files" :
case "try_files" :
m . TryFiles = d . RemainingArgs ( )
m . TryFiles = append ( m . TryFiles , d . RemainingArgs ( ) ... )
if len ( m . TryFiles ) == 0 {
if len ( m . TryFiles ) == 0 {
return d . ArgErr ( )
return d . ArgErr ( )
}
}