MCPcopy
hub / github.com/caddyserver/caddy / UnmarshalCaddyfile

Method UnmarshalCaddyfile

modules/caddyhttp/matchers.go:948–987  ·  view source on GitHub ↗

UnmarshalCaddyfile implements caddyfile.Unmarshaler.

(d *caddyfile.Dispenser)

Source from the content-addressed store, hash-verified

946
947// UnmarshalCaddyfile implements caddyfile.Unmarshaler.
948func (m *MatchHeader) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
949 if *m == nil {
950 *m = make(map[string][]string)
951 }
952 // iterate to merge multiple matchers into one
953 for d.Next() {
954 var field, val string
955 if !d.Args(&field) {
956 return d.Errf("malformed header matcher: expected field")
957 }
958
959 if strings.HasPrefix(field, "!") {
960 if len(field) == 1 {
961 return d.Errf("malformed header matcher: must have field name following ! character")
962 }
963
964 field = field[1:]
965 headers := *m
966 headers[field] = nil
967 m = &headers
968 if d.NextArg() {
969 return d.Errf("malformed header matcher: null matching headers cannot have a field value")
970 }
971 } else {
972 if !d.NextArg() {
973 return d.Errf("malformed header matcher: expected both field and value")
974 }
975
976 // If multiple header matchers with the same header field are defined,
977 // we want to add the existing to the list of headers (will be OR'ed)
978 val = d.Val()
979 http.Header(*m).Add(field, val)
980 }
981
982 if d.NextBlock(0) {
983 return d.Err("malformed header matcher: blocks are not supported")
984 }
985 }
986 return nil
987}
988
989// Match returns true if r matches m.
990func (m MatchHeader) Match(r *http.Request) bool {

Callers

nothing calls this directly

Calls 9

ArgsMethod · 0.80
ErrfMethod · 0.80
NextArgMethod · 0.80
ValMethod · 0.80
NextBlockMethod · 0.80
ErrMethod · 0.80
NextMethod · 0.65
AddMethod · 0.45
HeaderMethod · 0.45

Tested by

no test coverage detected