oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.28k stars 2.69k forks source link

Header Casing Mismatch Between Bun Client and Server #5556

Open prstance opened 1 year ago

prstance commented 1 year ago

What version of Bun is running?

1.0.3+b651b16fdd959b349c09ec5d5056229dcd12c86b

What platform is your computer?

Linux 5.15.90.1-microsoft-standard-WSL2 x86_64 x86_64

What steps can reproduce the bug?

To reproduce the bug, you need to follow these steps:

  1. Start the server code (Node.js) below on one terminal:
    
    const http = require('http');

http.createServer(function (req, res) { res.write(JSON.stringify(req.rawHeaders)); res.end(); }).listen(3000, function() { console.log("server start at port 3000"); });

2. Start the client code (Bun) on another terminal:
```typescript
fetch("http://localhost:3000/", {
    headers: {
        "Accept-Encoding": "gzip, deflate",
        "Accept": "*/*",
        "Connection": "keep-alive",
        "Authorization": "xxx",
        "Origin": "something"
    }
}).then(response => response.json()).then(json => console.log(json))

What is the expected behavior?

The expected behavior is that the headers you set in the client code should be sent to the server as-is, with the same casing (capitalization) that you specified in the headers object. img

What do you see instead?

The issue you're encountering is that when using the Bun runtime, some headers are sent in lowercase instead of the specified casing. This is causing a mismatch with the server's expectation, which may not be case-insensitive and expects headers in the exact casing provided. img

prstance commented 1 year ago

I'm referring to @Vexcited, who is blocked due to this issue; indeed, his "Origin" header gets converted to lowercase because of this bug. #4529

prstance commented 1 year ago

I think it's this pull request (#2288) that broke it. (convertToASCIILowercase)