diff options
author | Matthew Holt <mholt@users.noreply.github.com> | 2020-01-22 09:32:38 -0700 |
---|---|---|
committer | Matthew Holt <mholt@users.noreply.github.com> | 2020-01-22 09:32:38 -0700 |
commit | d810637a9fe2d2015b1f5ad701fdc23f26dda66a (patch) | |
tree | 10c402a69a10b17a19d50f971caa78f835930852 | |
parent | 5d3ccf1eb79c47c1da37836b60903f26693b8018 (diff) |
httpcaddyfile: Update directive docs; put root after rewrite
-rw-r--r-- | caddyconfig/httpcaddyfile/builtins.go | 21 | ||||
-rw-r--r-- | caddyconfig/httpcaddyfile/directives.go | 4 | ||||
-rw-r--r-- | modules/caddyhttp/fileserver/matcher.go | 9 | ||||
-rw-r--r-- | modules/caddyhttp/staticresp.go | 2 |
4 files changed, 27 insertions, 9 deletions
diff --git a/caddyconfig/httpcaddyfile/builtins.go b/caddyconfig/httpcaddyfile/builtins.go index 81f9302..3fc78a1 100644 --- a/caddyconfig/httpcaddyfile/builtins.go +++ b/caddyconfig/httpcaddyfile/builtins.go @@ -30,7 +30,7 @@ import ( func init() { RegisterDirective("bind", parseBind) - RegisterDirective("root", parseRoot) + RegisterDirective("root", parseRoot) // TODO: isn't this a handler directive? RegisterDirective("tls", parseTLS) RegisterHandlerDirective("redir", parseRedir) RegisterHandlerDirective("respond", parseRespond) @@ -38,6 +38,10 @@ func init() { RegisterHandlerDirective("handle", parseHandle) } +// parseBind parses the bind directive. Syntax: +// +// bind <addresses...> +// func parseBind(h Helper) ([]ConfigValue, error) { var lnHosts []string for h.Next() { @@ -46,6 +50,10 @@ func parseBind(h Helper) ([]ConfigValue, error) { return h.NewBindAddresses(lnHosts), nil } +// parseRoot parses the root directive. Syntax: +// +// root [<matcher>] <path> +// func parseRoot(h Helper) ([]ConfigValue, error) { if !h.Next() { return nil, h.ArgErr() @@ -251,6 +259,10 @@ func parseTLS(h Helper) ([]ConfigValue, error) { return configVals, nil } +// parseRedir parses the redir directive. Syntax: +// +// redir [<matcher>] <to> [<code>] +// func parseRedir(h Helper) (caddyhttp.MiddlewareHandler, error) { if !h.Next() { return nil, h.ArgErr() @@ -269,10 +281,10 @@ func parseRedir(h Helper) (caddyhttp.MiddlewareHandler, error) { code = "301" } if code == "temporary" || code == "" { - code = "307" + code = "302" } var body string - if code == "meta" { + if code == "html" { // Script tag comes first since that will better imitate a redirect in the browser's // history, but the meta tag is a fallback for most non-JS clients. const metaRedir = `<!DOCTYPE html> @@ -296,6 +308,7 @@ func parseRedir(h Helper) (caddyhttp.MiddlewareHandler, error) { }, nil } +// parseRespond parses the respond directive. func parseRespond(h Helper) (caddyhttp.MiddlewareHandler, error) { sr := new(caddyhttp.StaticResponse) err := sr.UnmarshalCaddyfile(h.Dispenser) @@ -305,6 +318,7 @@ func parseRespond(h Helper) (caddyhttp.MiddlewareHandler, error) { return sr, nil } +// parseRoute parses the route directive. func parseRoute(h Helper) (caddyhttp.MiddlewareHandler, error) { sr := new(caddyhttp.Subroute) @@ -337,6 +351,7 @@ func parseRoute(h Helper) (caddyhttp.MiddlewareHandler, error) { return sr, nil } +// parseHandle parses the route directive. func parseHandle(h Helper) (caddyhttp.MiddlewareHandler, error) { var allResults []ConfigValue diff --git a/caddyconfig/httpcaddyfile/directives.go b/caddyconfig/httpcaddyfile/directives.go index 7acdb8c..94dac21 100644 --- a/caddyconfig/httpcaddyfile/directives.go +++ b/caddyconfig/httpcaddyfile/directives.go @@ -27,11 +27,11 @@ import ( // directiveOrder specifies the order // to apply directives in HTTP routes. var directiveOrder = []string{ - "root", - "redir", "rewrite", + "root", + "strip_prefix", "strip_suffix", "uri_replace", diff --git a/modules/caddyhttp/fileserver/matcher.go b/modules/caddyhttp/fileserver/matcher.go index c119865..ed5c102 100644 --- a/modules/caddyhttp/fileserver/matcher.go +++ b/modules/caddyhttp/fileserver/matcher.go @@ -51,9 +51,12 @@ type MatchFile struct { Root string `json:"root,omitempty"` // The list of files to try. Each path here is - // considered relatice to Root. If nil, the - // request URL's path will be assumed. Accepts - // placeholders. + // considered relatice to Root. If nil, the request + // URL's path will be assumed. Files and + // directories are treated distinctly, so to match + // a directory, the filepath MUST end in a forward + // slash `/`. To match a regular file, there must + // be no trailing slash. Accepts placeholders. TryFiles []string `json:"try_files,omitempty"` // How to choose a file in TryFiles. Can be: diff --git a/modules/caddyhttp/staticresp.go b/modules/caddyhttp/staticresp.go index 777ecb2..3841a26 100644 --- a/modules/caddyhttp/staticresp.go +++ b/modules/caddyhttp/staticresp.go @@ -54,7 +54,7 @@ func (StaticResponse) CaddyModule() caddy.ModuleInfo { // UnmarshalCaddyfile sets up the handler from Caddyfile tokens. Syntax: // -// respond [<matcher>] [<status>|[<body> [<status>]] { +// respond [<matcher>] <status>|<body> [<status>] { // body <text> // close // } |