@marcel91200 / caddy Mirror · read-only / commits / 178ba024
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 14, 05:15 UTC

httpcaddyfile: Put root directive first, before redir and rewrite

See https://caddy.community/t/v2-match-any-path-but-files/7326/8?u=matt If rewrites (or redirects, for that matter) match on file existence, the file matcher would need to know the root of the site. Making this change implies that root directives that depend on rewritten URIs will not work as expected. However, I think this is very uncommon, and am not sure I have ever seen that. Usually, dynamic roots are based on host, not paths or query strings. I suspect that rewrites based on file existence will be more common than roots based on rewritten URIs, so I am moving root to be the first in the list. Users can always override this ordering with the 'order' global option.

Matthew Holt committed Mar 28, 2020 at 19:07 UTC 178ba024fea4db2b91fd159da629f0a8588f119a
2 files changed +11 -2
caddyconfig/httpcaddyfile/directives.go
+9 -2
@@ -27,14 +27,21 @@ import (
27
28 // directiveOrder specifies the order
29 // to apply directives in HTTP routes.
30 +//
31 +// The root directive goes first in case rewrites or
32 +// redirects depend on existence of files, i.e. the
33 +// file matcher, which must know the root first.
34 +//
35 +// The header directive goes second so that headers
36 +// can be manipulated before doing redirects.
37 var directiveOrder = []string{
38 + "root",
39 +
40 "header",
41
42 "redir",
43 "rewrite",
44
36 - "root",
37 -
45 // URI manipulation
46 "uri",
47 "try_files",
modules/caddyhttp/caddyhttp.go
+2
@@ -199,6 +199,8 @@ func StatusCodeMatches(actual, configured int) bool {
199
200 // tlsPlaceholderWrapper is a no-op listener wrapper that marks
201 // where the TLS listener should be in a chain of listener wrappers.
202 +// It should only be used if another listener wrapper must be placed
203 +// in front of the TLS handshake.
204 type tlsPlaceholderWrapper struct{}
205
206 func (tlsPlaceholderWrapper) CaddyModule() caddy.ModuleInfo {