{"record":{"id":"3090137606c60b2f","repo":"hashicorp/terraform","slug":"response-has-invalid-content-type-must-be-applica","errorCode":null,"errorMessage":"response has invalid Content-Type: must be application/json","messagePattern":"response has invalid Content-Type: must be application/json","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/getproviders/http_mirror_source.go","lineNumber":380,"sourceCode":"\t\tif body == nil {\n\t\t\tresp.Body.Close()\n\t\t}\n\t}()\n\t// After this point, our final URL return value should always be the\n\t// one from resp.Request, because that takes into account any redirects\n\t// we followed along the way.\n\tfinalURL = resp.Request.URL\n\n\tif resp.StatusCode == http.StatusOK {\n\t\t// If and only if we get an OK response, we'll check that the response\n\t\t// type is JSON and return the body reader.\n\t\tct := resp.Header.Get(\"Content-Type\")\n\t\tmt, params, err := mime.ParseMediaType(ct)\n\t\tif err != nil {\n\t\t\treturn 0, nil, finalURL, fmt.Errorf(\"response has invalid Content-Type: %s\", err)\n\t\t}\n\t\tif mt != \"application/json\" {\n\t\t\treturn 0, nil, finalURL, fmt.Errorf(\"response has invalid Content-Type: must be application/json\")\n\t\t}\n\t\tfor name := range params {\n\t\t\t// The application/json content-type has no defined parameters,\n\t\t\t// but some servers are configured to include a redundant \"charset\"\n\t\t\t// parameter anyway, presumably out of a sense of completeness.\n\t\t\t// We'll ignore them but warn that we're ignoring them in case the\n\t\t\t// subsequent parsing fails due to the server trying to use an\n\t\t\t// unsupported character encoding. (RFC 7159 defines its own\n\t\t\t// JSON-specific character encoding rules.)\n\t\t\tlog.Printf(\"[WARN] Network mirror returned %q as part of its JSON content type, which is not defined. Ignoring.\", name)\n\t\t}\n\t\tbody = resp.Body\n\t}\n\n\treturn resp.StatusCode, body, finalURL, nil\n}\n\nfunc (s *HTTPMirrorSource) errQueryFailed(provider addrs.Provider, err error) error {","sourceCodeStart":362,"sourceCodeEnd":398,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/getproviders/http_mirror_source.go#L362-L398","documentation":"After successfully parsing the `Content-Type`, the client asserts the parsed media type is exactly `application/json`. Any other media type (e.g. `text/html`, `application/octet-stream`) on a 200 response triggers this error.","triggerScenarios":"`mime.ParseMediaType` succeeds but `mt != \"application/json\"`; error at http_mirror_source.go:380.","commonSituations":"Mirror serves an HTML page with status 200; mirror serves JSON as `text/plain`; CDN/default fallback returns a generic page; misconfigured reverse proxy default type.","solutions":["Configure the mirror to send `Content-Type: application/json` for index responses.","Check for default-catch-all pages served by the mirror host.","`curl -i` the URL and confirm the header."],"exampleFix":"// before\nContent-Type: text/html\n...<html>...\n// after\nContent-Type: application/json\n{\"versions\":{...}}","handlingStrategy":"validation","validationCode":"// Verify the served media type\nmt, _, _ := mime.ParseMediaType(resp.Header.Get(\"Content-Type\"))\nif mt != \"application/json\" {\n    return fmt.Errorf(\"mirror content type %q is not application/json\", mt)\n}","typeGuard":"// isJSONMediaType narrows to application/json responses\nfunc isJSONMediaType(ct string) bool {\n    mt, _, err := mime.ParseMediaType(ct)\n    return err == nil && mt == \"application/json\"\n}","tryCatchPattern":null,"preventionTips":["Always set `Content-Type: application/json` on the mirror.","Don't serve HTML error pages with status 200.","Test with `curl -i`.","Default server fallbacks should return non-200, not 200+HTML."],"tags":["network","mirror","http-headers","content-type"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}