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)
| 119 | // "<unknown>" is returned when the "Accept" HTTP header is not |
| 120 | // present, or it contains no values |
| 121 | func 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 |
no test coverage detected