contentTypeFromString returns the content-type part of a MIME media type for example given "type/subtype;parameter=value;..." returns "type/subtype"
(s string)
| 100 | // contentTypeFromString returns the content-type part of a MIME media type |
| 101 | // for example given "type/subtype;parameter=value;..." returns "type/subtype" |
| 102 | func contentTypeFromString(s string) string { |
| 103 | for _, part := range strings.Split(s, ",") { |
| 104 | contentType, _, err := mime.ParseMediaType(part) |
| 105 | if err != nil { |
| 106 | continue |
| 107 | } |
| 108 | |
| 109 | // first that parses without error |
| 110 | return contentType |
| 111 | } |
| 112 | |
| 113 | return "unknown/unknown" |
| 114 | } |
| 115 | |
| 116 | // contentTypeFrom returns the content-type based on the "Accept" HTTP |
| 117 | // header of a HTTP request, given that HTTP headers can be multivalued |