MCPcopy
hub / github.com/gorilla/mux / Headers

Method Headers

route.go:249–256  ·  view source on GitHub ↗

Headers adds a matcher for request header values. It accepts a sequence of key/value pairs to be matched. For example: r := mux.NewRouter().NewRoute() r.Headers("Content-Type", "application/json", "X-Requested-With", "XMLHttpRequest") The above route will only match if both request he

(pairs ...string)

Source from the content-addressed store, hash-verified

247// The above route will only match if both request header values match.
248// If the value is an empty string, it will match any value if the key is set.
249func (r *Route) Headers(pairs ...string) *Route {
250 if r.err == nil {
251 var headers map[string]string
252 headers, r.err = mapFromPairsToString(pairs...)
253 return r.addMatcher(headerMatcher(headers))
254 }
255 return r
256}
257
258// headerRegexMatcher matches the request against the route given a regex for the header
259type headerRegexMatcher map[string]*regexp.Regexp

Callers

nothing calls this directly

Calls 3

addMatcherMethod · 0.95
mapFromPairsToStringFunction · 0.85
headerMatcherTypeAlias · 0.85

Tested by

no test coverage detected