UnmarshalCaddyfile sets up the handler from Caddyfile tokens. Syntax: error [<matcher>] <status>|<message> [<status>] { message <text> } If there is just one argument (other than the matcher), it is considered to be a status code if it's a valid positive integer of 3 digits.
(d *caddyfile.Dispenser)
| 60 | // If there is just one argument (other than the matcher), it is considered |
| 61 | // to be a status code if it's a valid positive integer of 3 digits. |
| 62 | func (e *StaticError) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { |
| 63 | d.Next() // consume directive name |
| 64 | args := d.RemainingArgs() |
| 65 | switch len(args) { |
| 66 | case 1: |
| 67 | if len(args[0]) == 3 { |
| 68 | if num, err := strconv.Atoi(args[0]); err == nil && num > 0 { |
| 69 | e.StatusCode = WeakString(args[0]) |
| 70 | break |
| 71 | } |
| 72 | } |
| 73 | e.Error = args[0] |
| 74 | case 2: |
| 75 | e.Error = args[0] |
| 76 | e.StatusCode = WeakString(args[1]) |
| 77 | default: |
| 78 | return d.ArgErr() |
| 79 | } |
| 80 | |
| 81 | for d.NextBlock(0) { |
| 82 | switch d.Val() { |
| 83 | case "message": |
| 84 | if e.Error != "" { |
| 85 | return d.Err("message already specified") |
| 86 | } |
| 87 | if !d.AllArgs(&e.Error) { |
| 88 | return d.ArgErr() |
| 89 | } |
| 90 | default: |
| 91 | return d.Errf("unrecognized subdirective '%s'", d.Val()) |
| 92 | } |
| 93 | } |
| 94 | return nil |
| 95 | } |
| 96 | |
| 97 | func (e StaticError) ServeHTTP(w http.ResponseWriter, r *http.Request, _ Handler) error { |
| 98 | repl := r.Context().Value(caddy.ReplacerCtxKey).(*caddy.Replacer) |
nothing calls this directly
no test coverage detected