IsJSONContentType reports whether contentType is application/json or a +json type.
(contentType string)
| 82 | |
| 83 | // IsJSONContentType reports whether contentType is application/json or a +json type. |
| 84 | func IsJSONContentType(contentType string) bool { |
| 85 | mediaType, _, errParse := mime.ParseMediaType(strings.TrimSpace(contentType)) |
| 86 | if errParse != nil { |
| 87 | mediaType = strings.TrimSpace(contentType) |
| 88 | } |
| 89 | mediaType = strings.ToLower(mediaType) |
| 90 | return mediaType == "application/json" || strings.HasSuffix(mediaType, "+json") |
| 91 | } |
| 92 | |
| 93 | // LooksLikeJSON reports whether body starts with an object or array JSON marker. |
| 94 | func LooksLikeJSON(body []byte) bool { |