{"record":{"id":"fe755b697b100e15","repo":"hashicorp/terraform","slug":"response-has-invalid-content-type-s","errorCode":null,"errorMessage":"response has invalid Content-Type: %s","messagePattern":"response has invalid Content-Type: (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/getproviders/http_mirror_source.go","lineNumber":377,"sourceCode":"\tdefer func() {\n\t\t// If we're not returning the body then we'll close it\n\t\t// before we return.\n\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","sourceCodeStart":359,"sourceCodeEnd":395,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/getproviders/http_mirror_source.go#L359-L395","documentation":"On a 200 response, get() reads the Content-Type header and runs mime.ParseMediaType on it. If the header value is structurally malformed (unparseable by the MIME parser) this error is returned directly (not wrapped in ErrQueryFailed). It indicates the mirror sent a broken Content-Type header on a successful response.","triggerScenarios":"Mirror responds 200 with a Content-Type header that fails mime.ParseMediaType — e.g. unquoted parameters, stray characters, or an otherwise malformed media-type string. Browsers tolerate it; Go's MIME parser does not.","commonSituations":"Custom mirror server sets Content-Type by string concatenation without quoting parameter values; legacy server sending non-standard media type syntax.","solutions":["Check the response headers with curl -i and inspect Content-Type.","Set Content-Type to exactly application/json with no malformed parameters.","If a charset parameter is needed, ensure it is properly formatted (charset=utf-8)."],"exampleFix":"# before\nContent-Type: application/json; charset=\"utf-8\"; oops\n\n# after\nContent-Type: application/json","handlingStrategy":"try-catch","validationCode":"// Preflight: confirm the mirror returns a parseable Content-Type.\nct := resp.Header.Get(\"Content-Type\")\nif _, _, err := mime.ParseMediaType(ct); err != nil {\n    return fmt.Errorf(\"bad Content-Type %q: %w\", ct, err)\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"invalid Content-Type\") {\n    // raw error from get(); surface mirror misconfiguration, not retryable\n}","preventionTips":["Serve .json as exactly application/json with no malformed parameters.","Quote any Content-Type parameters you do send.","curl -i the mirror to inspect headers before relying on it."],"tags":["protocol","http","content-type","mirror"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T20:17:04.800Z"}