{"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":"http","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/c9def3e214014c1188faabfc4a5bde5095139765/internal/getproviders/http_mirror_source.go#L362-L398","documentation":"After successfully parsing the Content-Type media type, get() requires it to be exactly application/json. Any other media type (text/html, application/octet-stream, etc.) on a 200 response yields this error. Typically means an error/landing page was served with status 200 instead of the JSON index.","triggerScenarios":"Mirror or an intermediary returns 200 with a non-JSON body: a generic HTML page, a directory listing, or a binary. Common when a static file server doesn't set .json Content-Type or a proxy serves a fallback page.","commonSituations":"Mirror directory served by a web server without the .json MIME mapping; catch-all route returning an HTML SPA page with 200; wrong base URL path landing on a listing page.","solutions":["Configure the mirror server to serve .json files as application/json.","Point the base URL at the exact directory containing index.json and the version files.","Remove catch-all routes that return HTML with 200 for missing paths."],"exampleFix":"# before: nginx default type for unknown ext\nhttp {\n  default_type application/octet-stream;\n}\n\n# after\nhttp {\n  types {\n    application/json json;\n  }\n  default_type application/octet-stream;\n}","handlingStrategy":"try-catch","validationCode":"// Preflight: require a JSON media type from the mirror.\nmt, _, _ := mime.ParseMediaType(resp.Header.Get(\"Content-Type\"))\nif mt != \"application/json\" {\n    return fmt.Errorf(\"expected application/json, got %q\", mt)\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"must be application/json\") {\n    // mirror served a non-JSON 200; report, do not retry\n}","preventionTips":["Map the .json extension to application/json on the mirror web server.","Disable catch-all routes that return HTML with 200.","Point the base URL at the directory holding index.json."],"tags":["protocol","http","content-type","mirror"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}