{"record":{"id":"6197353712713512","repo":"biomejs/biome","slug":"invalid-value-for-content-type-expected-mime-js","errorCode":null,"errorMessage":"invalid value for Content-Type expected \"${MIME_JSONRPC}\", got \"${headerValue}\"","messagePattern":"invalid value for Content-Type expected \"(.+?)\", got \"(.+?)\"","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/@biomejs/backend-jsonrpc/src/transport.ts","lineNumber":242,"sourceCode":"\t\t}\n\n\t\tconst colonIndex = line.indexOf(\":\");\n\t\tif (colonIndex < 0) {\n\t\t\tthrow new Error(`could not find colon token in \"${line}\"`);\n\t\t}\n\n\t\tconst headerName = line.substring(0, colonIndex);\n\t\tconst headerValue = line.substring(colonIndex + 1).trim();\n\n\t\tswitch (headerName) {\n\t\t\tcase \"Content-Length\": {\n\t\t\t\tconst value = Number.parseInt(headerValue, 10);\n\t\t\t\treaderState.contentLength = value;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"Content-Type\": {\n\t\t\t\tif (!headerValue.startsWith(MIME_JSONRPC)) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`invalid value for Content-Type expected \"${MIME_JSONRPC}\", got \"${headerValue}\"`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\treaderState.contentType = headerValue;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\tconsole.warn(`ignoring unknown header \"${headerName}\"`);\n\t\t}\n\t}\n\n\tprivate processIncomingBody(buffer: Buffer) {\n\t\tconst data = buffer.toString(\"utf-8\");\n\t\tconst body = JSON.parse(data);\n\n\t\tif (isJsonRpcMessage(body)) {\n\t\t\tif (isJsonRpcRequest(body)) {","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/biomejs/biome/blob/7529811358079edb5a2a9d4a5f67a9f639a63f3a/packages/@biomejs/backend-jsonrpc/src/transport.ts#L224-L260","documentation":"The framer accepts an optional Content-Type header, but if present its value must start with the constant MIME_JSONRPC = \"application/vscode-jsonrpc\" (transport.ts:99, 240-245). Any other Content-Type aborts parsing immediately, because the peer is demonstrably not speaking the expected JSON-RPC dialect.","triggerScenarios":"The peer replies with 'Content-Type: application/json', 'text/html', or similar; typically an HTTP server, proxy error page, or custom implementation answering on the socket instead of the Biome daemon. The startsWith check also rejects truncated or rewritten values injected by intermediaries.","commonSituations":"An HTTP/JSON service or reverse proxy answering on the port the Transport is connected to; a mock daemon in tests that sets a generic application/json content type; middleware that rewrites header values.","solutions":["Confirm the socket endpoint belongs to the Biome daemon and that no HTTP proxy sits in between.","If you implement the peer, send exactly 'Content-Type: application/vscode-jsonrpc;charset=utf-8' as sendMessage does (transport.ts:167) or omit the Content-Type header entirely (it is optional).","Capture the first bytes of the stream and compare them against the expected header block to identify what is actually answering."],"exampleFix":"// before: peer sends a generic content type\nsocket.write(`Content-Length: ${body.length}\\r\\nContent-Type: application/json\\r\\n\\r\\n`);\n\n// after: peer sends the expected vscode-jsonrpc content type\nsocket.write(`Content-Length: ${body.length}\\r\\nContent-Type: application/vscode-jsonrpc;charset=utf-8\\r\\n\\r\\n`);","handlingStrategy":"validation","validationCode":"// Peek the Content-Type line before handing the socket to Transport\nsocket.once(\"data\", (chunk) => {\n\tconst text = chunk.toString(\"utf-8\", 0, 512);\n\tconst m = text.match(/^Content-Type:\\s*(.+?)\\r?$/m);\n\tif (m && !m[1].startsWith(\"application/vscode-jsonrpc\")) {\n\t\tsocket.destroy();\n\t\tthrow new Error(`unexpected peer Content-Type: ${m[1]}`);\n\t}\n});","typeGuard":null,"tryCatchPattern":"process.on(\"uncaughtException\", (err) => {\n\tif (err.message.includes(\"invalid value for Content-Type\")) {\n\t\t// The endpoint is not a vscode-jsonrpc peer; do not retry the same address.\n\t\ttransport.destroy();\n\t\tthrow new Error(\"connected to a non-JSON-RPC endpoint; check host/port\");\n\t} else {\n\t\tthrow err;\n\t}\n});","preventionTips":["Connect only to the Biome daemon's socket; keep HTTP servers, proxies, and health-check endpoints off that address.","If you implement the peer, copy the exact Content-Type string sendMessage uses, or omit the header (it is optional).","In test doubles, reuse the same framing helper as production code instead of hand-writing headers."],"tags":["jsonrpc","transport","content-type","protocol","headers"],"backgroundTag":"jsonrpc-header-framing","analyzedSha":"7529811358079edb5a2a9d4a5f67a9f639a63f3a","analyzedAt":"2026-08-16T22:13:27.842Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}