Add canonical_uris to file server

Matt Holt 2019-09-09 08:29:58 -06:00
parent 7c005f6ca8
commit 9d36e8d510

@ -81,6 +81,7 @@ Features which are available in Caddy Enterprise are indicated with   🏢
- [http.handlers.reverse_proxy](#httphandlersreverse_proxy) - [http.handlers.reverse_proxy](#httphandlersreverse_proxy)
- [http.handlers.subroute](#httphandlerssubroute) - [http.handlers.subroute](#httphandlerssubroute)
- [http.handlers.error](#httphandlerserror) - [http.handlers.error](#httphandlerserror)
- [http.handlers.vars](#httphandlersvars)
- [http/servers/errors](#httpserverserrors) - [http/servers/errors](#httpserverserrors)
- [http/servers/tls_connection_policies](#httpserverstls_connection_policies) - [http/servers/tls_connection_policies](#httpserverstls_connection_policies)
- [tls.certificate_selection.enterprise](#tlscertificate_selectionenterprise) - [tls.certificate_selection.enterprise](#tlscertificate_selectionenterprise)
@ -418,17 +419,17 @@ See the [Caddyfile directives](#caddyfile-directives) below for more details abo
The Caddyfile is supposed to be easy to write, so it also provides shorter placeholder variable names for you to use. Instead of `{http.request.uri.path}` for example, you could just write `{path}`. Again, this loses some of the flexibility of the full JSON config because these shorthand variables are not properly namespaced. They are optional, however, so you are welcome to use the full name. The Caddyfile is supposed to be easy to write, so it also provides shorter placeholder variable names for you to use. Instead of `{http.request.uri.path}` for example, you could just write `{path}`. Again, this loses some of the flexibility of the full JSON config because these shorthand variables are not properly namespaced. They are optional, however, so you are welcome to use the full name.
| Shorthand | Replaces | | Shorthand | Replaces |
|------------|------------------------------| |------------|---------------------------------|
| {uri} | {http.request.uri} | | {uri} | {http.request.uri} |
| {path} | {http.request.uri.path} | | {path} | {http.request.uri.path} |
| {host} | {http.request.host} | | {host} | {http.request.host} |
| {hostport} | {http.request.hostport} | | {hostport} | {http.request.hostport} |
| {method} | {http.request.method} | | {method} | {http.request.method} |
| {scheme} | {http.request.scheme} | | {scheme} | {http.request.scheme} |
| {file} | {http.request.uri.path.file} | | {file} | {http.request.uri.path.file} |
| {dir} | {http.request.uri.path.dir} | | {dir} | {http.request.uri.path.dir} |
| {query} | {http.request.uri.query} | | {query} | {http.request.uri.query_string} |
#### Global config #### Global config
@ -873,7 +874,7 @@ Matches requests by request path using a regular expression.
} }
``` ```
- `name`: A name for the regular expression so you can access its capture groups in placeholders. - `name`: A name for the regular expression so you can access its capture groups in placeholders. Optional.
- `pattern`: The regular expression in [Go's regexp syntax](https://golang.org/pkg/regexp/). - `pattern`: The regular expression in [Go's regexp syntax](https://golang.org/pkg/regexp/).
@ -910,7 +911,7 @@ Matches requests by request headers.
} }
``` ```
The object keys should be header field names, with the values to match in an array. The object keys should be header field names, with the values to match in an array. If the values array is present but empty, it will accept any value and match merely on the presence of the header field.
##### http.matchers.header_regexp ##### http.matchers.header_regexp
@ -927,7 +928,7 @@ Matches requests by request headers using a regular expression.
The object keys should be header fields, then: The object keys should be header fields, then:
- `name`: A name for the regular expression so you can access its capture groups in placeholders. - `name`: A name for the regular expression so you can access its capture groups in placeholders. Optional.
- `pattern`: The regular expression in [Go's regexp syntax](https://golang.org/pkg/regexp/). - `pattern`: The regular expression in [Go's regexp syntax](https://golang.org/pkg/regexp/).
##### http.matchers.protocol ##### http.matchers.protocol
@ -985,7 +986,7 @@ Matches requests based on files on disk.
} }
``` ```
- `root`: The base path with which relative paths will be rooted. Default is current working directory. - `root`: The base path with which relative paths will be rooted. Default is `{http.vars.root}` if set, or current working directory.
- `try_files`: A list of root-relative file paths to "try" matching (similar to nginx's try_files). A file will be selected based on try_policy. - `try_files`: A list of root-relative file paths to "try" matching (similar to nginx's try_files). A file will be selected based on try_policy.
- `try_policy`: When trying files listed in `try_files`, use this policy to choose one. - `try_policy`: When trying files listed in `try_files`, use this policy to choose one.
- `first_exist` (default): Choose the first file that exists. - `first_exist` (default): Choose the first file that exists.
@ -1171,7 +1172,7 @@ Interprets the response as a template body, then executes the template and write
} }
``` ```
- `include_root`: The root path from which to load files. Required if template functions accessing the file system are used (such as .Include). - `include_root`: The root path from which to load files. Required if template functions accessing the file system are used (such as .Include). Default is `{http.vars.root}` if set, or current working directory.
- `mime_types`: The MIME types for which to render templates. It is important to use this if the route matchers do not exclude images or other binary files. - `mime_types`: The MIME types for which to render templates. It is important to use this if the route matchers do not exclude images or other binary files.
- `delimiters`: The template action delimiters. - `delimiters`: The template action delimiters.
@ -1218,15 +1219,17 @@ This module executes placeholders in most of its properties. It does not call th
"index_names": [], "index_names": [],
"browse": { "browse": {
"template_file": "" "template_file": ""
} },
"canonical_uris": true
} }
``` ```
- `root`: The path to the root of the site. - `root`: The path to the root of the site. Default is `{http.vars.root}` if set, or current working directory.
- `hide`: A list of files or folders to hide; the file server will pretend as if they don't exist. Accepts globular patterns like "\*.hidden" or "/foo/*/bar". - `hide`: A list of files or folders to hide; the file server will pretend as if they don't exist. Accepts globular patterns like "\*.hidden" or "/foo/*/bar".
- `index_names`: The names of files to try as index files if a folder is requested. - `index_names`: The names of files to try as index files if a folder is requested.
- `browse`: Enables browsing if a directory was requested. - `browse`: Enables browsing if a directory was requested.
- `browse.template_file`: Use this template file instead of the default browse template. - `browse.template_file`: Use this template file instead of the default browse template.
- `canonical_uris`: Use redirects to enforce trailing slash appended to URIs for directories, or to remove trailing slash from URIs for files. Default is true.
@ -1269,7 +1272,7 @@ Example:
##### http.handlers.subroute ##### http.handlers.subroute
Creates a group of routes that are compiled and executed when this handler is invoked. This is useful if the evaluation of matchers needs to be deferred, like if they depend on placeholders created by other matchers that need to be evaluated first. Creates a group of routes that are compiled and executed when this handler is invoked. This is useful if the evaluation of matchers needs to be deferred, like if they depend on placeholders created by other matchers or handlers that need to be evaluated first.
This handler does not invoke the next handler in the chain. Instead, it compiles and executes the chain defined in `routes`. This handler does not invoke the next handler in the chain. Instead, it compiles and executes the chain defined in `routes`.
@ -1301,6 +1304,17 @@ Since this handler does not write a response, the error information is for use b
- `error`: The error message. Optional. Default is no error message. - `error`: The error message. Optional. Default is no error message.
##### http.handlers.vars
Sets variables associated with the request that can be used later with placeholders: `{http.vars.variable_name}`
```json
{
"handler": "vars",
"variable_name": "value"
}
```
#### http/servers/errors #### http/servers/errors