@marcel91200 / caddy Mirror · read-only / commits / d810637a
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: Update directive docs; put root after rewrite

Matthew Holt committed Jan 22, 2020 at 09:32 UTC d810637a9fe2d2015b1f5ad701fdc23f26dda66a
4 files changed +27 -9
caddyconfig/httpcaddyfile/builtins.go
+18 -3
@@ -30,7 +30,7 @@ import (
30
31 func init() {
32 RegisterDirective("bind", parseBind)
33 - RegisterDirective("root", parseRoot)
33 + RegisterDirective("root", parseRoot) // TODO: isn't this a handler directive?
34 RegisterDirective("tls", parseTLS)
35 RegisterHandlerDirective("redir", parseRedir)
36 RegisterHandlerDirective("respond", parseRespond)
@@ -38,6 +38,10 @@ func init() {
38 RegisterHandlerDirective("handle", parseHandle)
39 }
40
41 +// parseBind parses the bind directive. Syntax:
42 +//
43 +// bind <addresses...>
44 +//
45 func parseBind(h Helper) ([]ConfigValue, error) {
46 var lnHosts []string
47 for h.Next() {
@@ -46,6 +50,10 @@ func parseBind(h Helper) ([]ConfigValue, error) {
50 return h.NewBindAddresses(lnHosts), nil
51 }
52
53 +// parseRoot parses the root directive. Syntax:
54 +//
55 +// root [<matcher>] <path>
56 +//
57 func parseRoot(h Helper) ([]ConfigValue, error) {
58 if !h.Next() {
59 return nil, h.ArgErr()
@@ -251,6 +259,10 @@ func parseTLS(h Helper) ([]ConfigValue, error) {
259 return configVals, nil
260 }
261
262 +// parseRedir parses the redir directive. Syntax:
263 +//
264 +// redir [<matcher>] <to> [<code>]
265 +//
266 func parseRedir(h Helper) (caddyhttp.MiddlewareHandler, error) {
267 if !h.Next() {
268 return nil, h.ArgErr()
@@ -269,10 +281,10 @@ func parseRedir(h Helper) (caddyhttp.MiddlewareHandler, error) {
281 code = "301"
282 }
283 if code == "temporary" || code == "" {
272 - code = "307"
284 + code = "302"
285 }
286 var body string
275 - if code == "meta" {
287 + if code == "html" {
288 // Script tag comes first since that will better imitate a redirect in the browser's
289 // history, but the meta tag is a fallback for most non-JS clients.
290 const metaRedir = `<!DOCTYPE html>
@@ -296,6 +308,7 @@ func parseRedir(h Helper) (caddyhttp.MiddlewareHandler, error) {
308 }, nil
309 }
310
311 +// parseRespond parses the respond directive.
312 func parseRespond(h Helper) (caddyhttp.MiddlewareHandler, error) {
313 sr := new(caddyhttp.StaticResponse)
314 err := sr.UnmarshalCaddyfile(h.Dispenser)
@@ -305,6 +318,7 @@ func parseRespond(h Helper) (caddyhttp.MiddlewareHandler, error) {
318 return sr, nil
319 }
320
321 +// parseRoute parses the route directive.
322 func parseRoute(h Helper) (caddyhttp.MiddlewareHandler, error) {
323 sr := new(caddyhttp.Subroute)
324
@@ -337,6 +351,7 @@ func parseRoute(h Helper) (caddyhttp.MiddlewareHandler, error) {
351 return sr, nil
352 }
353
354 +// parseHandle parses the route directive.
355 func parseHandle(h Helper) (caddyhttp.MiddlewareHandler, error) {
356 var allResults []ConfigValue
357
caddyconfig/httpcaddyfile/directives.go
+2 -2
@@ -27,11 +27,11 @@ import (
27 // directiveOrder specifies the order
28 // to apply directives in HTTP routes.
29 var directiveOrder = []string{
30 - "root",
31 -
30 "redir",
31 "rewrite",
32
33 + "root",
34 +
35 "strip_prefix",
36 "strip_suffix",
37 "uri_replace",
modules/caddyhttp/fileserver/matcher.go
+6 -3
@@ -51,9 +51,12 @@ type MatchFile struct {
51 Root string `json:"root,omitempty"`
52
53 // The list of files to try. Each path here is
54 - // considered relatice to Root. If nil, the
55 - // request URL's path will be assumed. Accepts
56 - // placeholders.
54 + // considered relatice to Root. If nil, the request
55 + // URL's path will be assumed. Files and
56 + // directories are treated distinctly, so to match
57 + // a directory, the filepath MUST end in a forward
58 + // slash `/`. To match a regular file, there must
59 + // be no trailing slash. Accepts placeholders.
60 TryFiles []string `json:"try_files,omitempty"`
61
62 // How to choose a file in TryFiles. Can be:
modules/caddyhttp/staticresp.go
+1 -1
@@ -54,7 +54,7 @@ func (StaticResponse) CaddyModule() caddy.ModuleInfo {
54
55 // UnmarshalCaddyfile sets up the handler from Caddyfile tokens. Syntax:
56 //
57 -// respond [<matcher>] [<status>|[<body> [<status>]] {
57 +// respond [<matcher>] <status>|<body> [<status>] {
58 // body <text>
59 // close
60 // }