isTextContent checks if the content type is text-based
(contentType string)
| 46 | |
| 47 | // isTextContent checks if the content type is text-based |
| 48 | func (p *FetchPlugin) isTextContent(contentType string) bool { |
| 49 | debugf("Fetch: checking content type %q", contentType) |
| 50 | |
| 51 | mediaType, _, err := mime.ParseMediaType(contentType) |
| 52 | if err != nil { |
| 53 | debugf("Fetch: error parsing media type: %v", err) |
| 54 | return false |
| 55 | } |
| 56 | |
| 57 | isText := strings.HasPrefix(mediaType, "text/") || |
| 58 | mediaType == "application/json" || |
| 59 | mediaType == "application/xml" || |
| 60 | mediaType == "application/yaml" || |
| 61 | mediaType == "application/x-yaml" || |
| 62 | strings.HasSuffix(mediaType, "+json") || |
| 63 | strings.HasSuffix(mediaType, "+xml") || |
| 64 | strings.HasSuffix(mediaType, "+yaml") |
| 65 | |
| 66 | debugf("Fetch: content type %q is text: %v", mediaType, isText) |
| 67 | return isText |
| 68 | } |
| 69 | |
| 70 | // validateTextContent ensures content is valid UTF-8 without null bytes |
| 71 | func (p *FetchPlugin) validateTextContent(content []byte) error { |