parseReqHdrCaddyfile sets up the handler for request headers from Caddyfile tokens. Syntax: request_header [<matcher>] [[+|-]<field> [<value|regexp>] [<replacement>]]
(h httpcaddyfile.Helper)
| 161 | // |
| 162 | // request_header [<matcher>] [[+|-]<field> [<value|regexp>] [<replacement>]] |
| 163 | func parseReqHdrCaddyfile(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error) { |
| 164 | h.Next() // consume directive name |
| 165 | matcherSet, err := h.ExtractMatcherSet() |
| 166 | if err != nil { |
| 167 | return nil, err |
| 168 | } |
| 169 | h.Next() // consume the directive name again (matcher parsing resets) |
| 170 | |
| 171 | if !h.NextArg() { |
| 172 | return nil, h.ArgErr() |
| 173 | } |
| 174 | field := h.Val() |
| 175 | |
| 176 | hdr := Handler{ |
| 177 | Request: &HeaderOps{}, |
| 178 | } |
| 179 | |
| 180 | // sometimes it is habitual for users to suffix a field name with a colon, |
| 181 | // as if they were writing a curl command or something; see |
| 182 | // https://caddy.community/t/v2-reverse-proxy-please-add-cors-example-to-the-docs/7349/19 |
| 183 | field = strings.TrimSuffix(field, ":") |
| 184 | |
| 185 | var value string |
| 186 | var replacement *string |
| 187 | if h.NextArg() { |
| 188 | value = h.Val() |
| 189 | } |
| 190 | if h.NextArg() { |
| 191 | arg := h.Val() |
| 192 | replacement = &arg |
| 193 | if h.NextArg() { |
| 194 | return nil, h.ArgErr() |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | if hdr.Request == nil { |
| 199 | hdr.Request = new(HeaderOps) |
| 200 | } |
| 201 | if err := CaddyfileHeaderOp(hdr.Request, field, value, replacement); err != nil { |
| 202 | return nil, h.Err(err.Error()) |
| 203 | } |
| 204 | |
| 205 | configValues := h.NewRoute(matcherSet, hdr) |
| 206 | |
| 207 | if h.NextArg() { |
| 208 | return nil, h.ArgErr() |
| 209 | } |
| 210 | return configValues, nil |
| 211 | } |
| 212 | |
| 213 | // CaddyfileHeaderOp applies a new header operation according to |
| 214 | // field, value, and replacement. The field can be prefixed with |
nothing calls this directly
no test coverage detected