MCPcopy Create free account
hub / github.com/danielmiessler/Fabric / isTextContent

Method isTextContent

internal/plugins/template/fetch.go:48–68  ·  view source on GitHub ↗

isTextContent checks if the content type is text-based

(contentType string)

Source from the content-addressed store, hash-verified

46
47// isTextContent checks if the content type is text-based
48func (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
71func (p *FetchPlugin) validateTextContent(content []byte) error {

Callers 1

fetchMethod · 0.95

Calls 1

debugfFunction · 0.85

Tested by

no test coverage detected