{"record":{"id":"f07139a1519c964c","repo":"prestodb/presto","slug":"bad-content-type-from-remote-presto-server-conte","errorCode":null,"errorMessage":"Bad Content-Type from remote Presto server:${contentType}","messagePattern":"Bad Content-Type from remote Presto server:(.+?)","errorType":"exception","errorClass":"ProxyException","httpStatus":502,"severity":"error","filePath":"presto-proxy/src/main/java/com/facebook/presto/proxy/ProxyResponseHandler.java","lineNumber":61,"sourceCode":"    }\n\n    @Override\n    public ProxyResponse handle(Request request, Response response)\n    {\n        if (response.getStatusCode() == NO_CONTENT.code()) {\n            return new ProxyResponse(response.getHeaders(), new byte[0]);\n        }\n\n        if (response.getStatusCode() != OK.code()) {\n            throw new ProxyException(format(\"Bad status code from remote Presto server: %s: %s\", response.getStatusCode(), readBody(response)));\n        }\n\n        String contentType = response.getHeader(CONTENT_TYPE);\n        if (contentType == null) {\n            throw new ProxyException(\"No Content-Type set in response from remote Presto server\");\n        }\n        if (!MediaType.parse(contentType).is(MEDIA_TYPE_JSON)) {\n            throw new ProxyException(\"Bad Content-Type from remote Presto server:\" + contentType);\n        }\n\n        try {\n            return new ProxyResponse(response.getHeaders(), toByteArray(response.getInputStream()));\n        }\n        catch (IOException e) {\n            throw new ProxyException(\"Failed reading response from remote Presto server\", e);\n        }\n    }\n\n    private static String readBody(Response response)\n    {\n        try {\n            return new String(toByteArray(response.getInputStream()), US_ASCII);\n        }\n        catch (IOException e) {\n            return \"\";\n        }","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-proxy/src/main/java/com/facebook/presto/proxy/ProxyResponseHandler.java#L43-L79","documentation":"After confirming a Content-Type exists, the proxy requires it to be application/json. Any other media type (text/html, text/plain, etc.) triggers this ProxyException with the offending type appended. It means the 200 response body is not the JSON the proxy expects.","triggerScenarios":"Remote server returned 200 with a non-JSON Content-Type, e.g. an HTML login/error page from an auth gateway, or text/plain from a misconfigured endpoint.","commonSituations":"Reverse proxy or SSO layer intercepting requests and returning an HTML page with 200; hitting the wrong backend path; Presto version/endpoint mismatch.","solutions":["Check the reported Content-Type in the message to identify what answered.","Curl the remote endpoint directly and inspect the body (likely HTML from an auth page or LB).","Bypass/fix the intercepting layer or supply credentials so the real JSON API answers.","Confirm the remote server URI points at the Presto coordinator API."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// assert the remote endpoint speaks JSON before proxying\nconst probe = await fetch(backendUri + path, { headers });\nconst ct = (probe.headers.get(\"content-type\") || \"\");\nif (!ct.startsWith(\"application/json\")) throw new Error(\"Non-JSON backend response: \" + ct + \" — check for SSO/LB interception\");","typeGuard":null,"tryCatchPattern":"try {\n  return await proxyCall(req);\n} catch (e) {\n  if (String(e.message).startsWith(\"Bad Content-Type\")) {\n    // likely an HTML auth page; re-authenticate or fix routing\n  } else throw e;\n}","preventionTips":["Exclude Presto API paths from SSO/HTML login interception","Never route the coordinator API through HTML-generating middlewares","Version-check backend endpoints after upgrades","Monitor content-type of sampled backend responses"],"tags":["http","content-type","json","proxy"],"backgroundTag":"bad-content-type","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}