MCPcopy Create free account
hub / github.com/conforma/cli / contentTypeFrom

Function contentTypeFrom

acceptance/wiremock/wiremock.go:121–136  ·  view source on GitHub ↗

contentTypeFrom returns the content-type based on the "Accept" HTTP header of a HTTP request, given that HTTP headers can be multivalued it either returns the single value or the first value of many "<unknown>" is returned when the "Accept" HTTP header is not present, or it contains no values

(u unmatchedRequest)

Source from the content-addressed store, hash-verified

119// "<unknown>" is returned when the "Accept" HTTP header is not
120// present, or it contains no values
121func contentTypeFrom(u unmatchedRequest) string {
122 for key, value := range u.Headers {
123 if strings.ToLower(key) == "accept" {
124 switch v := value.(type) {
125 case string:
126 return contentTypeFromString(v)
127 case []interface{}:
128 if len(v) >= 1 {
129 return contentTypeFromString(fmt.Sprintf("%s", v[0]))
130 }
131 }
132 }
133 }
134
135 return "<unknown>"
136}
137
138// String formats the unmatched request and generates a snippet to help
139// stub the request, useful when reporting unmatched requests i.e. those

Callers 1

StringMethod · 0.85

Calls 1

contentTypeFromStringFunction · 0.85

Tested by

no test coverage detected