Repository navigation
Description
What version of Bun is running?
1.4.3-canary.1+b52d51348 (also main at fd8422c)
What platform is your computer?
Linux x64 (the code path is the same on every platform)
What steps can reproduce the bug?
A node:http server with an 'upgrade' listener receives a request that llhttp does not flag as an upgrade. Run the script with node and with bun.
import http from "node:http";
import net from "node:net";
import { once } from "node:events";
const heads = {
"Upgrade: (empty)": "Connection: Upgrade\r\nUpgrade:\r\n",
"Connection: upgrade-x": "Connection: upgrade-x\r\nUpgrade: x\r\n",
"Connection: foo upgrade": "Connection: foo upgrade\r\nUpgrade: x\r\n",
"Connection: Upgrade<HTAB>": "Connection: Upgrade\t\r\nUpgrade: x\r\n",
"control: Connection: Upgrade": "Connection: Upgrade\r\nUpgrade: x\r\n",
};
for (const [name, headers] of Object.entries(heads)) {
const events = [];
const server = http.createServer((req, res) => {
events.push(`request (req.upgrade=${req.upgrade})`);
res.end("ok");
});
server.on("upgrade", (req, socket) => {
events.push("upgrade");
socket.end("HTTP/1.1 101 Switching Protocols\r\nConnection: Upgrade\r\nUpgrade: x\r\n\r\n");
});
await once(server.listen(0, "127.0.0.1"), "listening");
const client = net.connect(server.address().port, "127.0.0.1");
client.on("error", () => {});
client.write(`GET / HTTP/1.1\r\nHost: x\r\n${headers}Connection: close\r\n\r\n`);
client.resume();
await once(client, "close");
console.log(name.padEnd(30), JSON.stringify(events));
server.close();
server.closeAllConnections();
}
process.exit(0);What is the expected behavior?
Node v26.3.0 emits 'upgrade' only for the control:
Upgrade: (empty) ["request (req.upgrade=false)"]
Connection: upgrade-x ["request (req.upgrade=false)"]
Connection: foo upgrade ["request (req.upgrade=false)"]
Connection: Upgrade<HTAB> ["request (req.upgrade=false)"]
control: Connection: Upgrade ["upgrade"]
What do you see instead?
Bun emits 'upgrade' for all five:
Upgrade: (empty) ["upgrade"]
Connection: upgrade-x ["upgrade"]
Connection: foo upgrade ["upgrade"]
Connection: Upgrade<HTAB> ["upgrade"]
control: Connection: Upgrade ["upgrade"]
Additional information
Node takes the upgrade flag from llhttp. llhttp sets it when an Upgrade field has a non-empty value and upgrade is a whole token of a Connection list (llhttp__before_headers_complete). In the Connection grammar, llhttp skips SP and HTAB before a token but only SP after it, so a tab after the token hides it.
Bun decides in assignHeadersFromUWebSocketsForCall (src/jsc/bindings/NodeHTTP.cpp). kDispatchHasUpgrade is set for any field named Upgrade, also with an empty value. kDispatchConnUpgrade comes from svValueHasToken(value, "upgrade"), which accepts upgrade at any non-alphanumeric boundary (it mirrors the \W regex that node:http uses for other Connection checks). The header parser also trims the tab before this code sees the value.
packages/bun-uws/src/HttpParser.h has its own Connection walk (hasConnectionClose). One option is that the parser derives the upgrade bit there and publishes it on HttpRequest, and NodeHTTP.cpp reads it, the way #40215 publishes the Transfer-Encoding verdict.
Activity
robobun commentedon Sep 18, 2026
Reproduced: the issue script emits
upgradefor all five requests on bun 1.4.3, Node only for the control.Fix in progress: #43327
robobun commentedon Sep 18, 2026
#43326 adds an llhttp-exact upgrade test to the parser (
isUpgradeinpackages/bun-uws/src/HttpParser.h), for a different purpose: it decides whether aTransfer-Encodingwithoutchunkedraises an error. The dispatcher inNodeHTTP.cppstill uses its own test, so this issue stays open. #43326 also adds fivetest.todorows totest/js/node/http/node-http-transfer-encoding.test.tsthat pin Node's behaviour for the heads above. A fix for this issue can turn them into ordinary tests.robobun commentedon Sep 18, 2026
Reproduced: the issue script emits
upgradefor all five requests on bun 1.4.3, Node only for the control.Fixed by #43557 (merged, 5d5f03f). #43327 is closed as superseded.
node:http: one upgrade verdict for the parser and the dispatcher, and…
node:http: one upgrade verdict for the parser and the dispatcher, and…
node:http: the server follows Node (request body, framing, response f…