Open bilabror opened 1 month ago
I have made this more minimal:
const express = require('express');
var http = require('http')
const app = express();
app.get('/', (req, res) => {
const date = Date.now()
http.OutgoingMessage.prototype.setHeader.call(res, 'Set-Cookie', [
`a=a${date}; path=/;`,
`ab=b${date}; path=/;`
]);
res.json({ message: 'Session set successfully' });
});
const port = 3001;
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});
I have no idea why http.OutgoingMessage.prototype.setHeader.call
is being weird and only cares about first element in bun
made more minimal again:
const http = require('http');
const res = new http.OutgoingMessage();
res.setHeader("myheader", ["first", "second"]);
console.log(res.getHeaders())
Node returns:
[Object: null prototype] { myheader: [ 'first', 'second' ] }
Bun returns:
{ myheader: "first,second" }
Notice how Bun returns the header value as a single string ("first,second") instead of an array unlike Node.js.
This behavior occurs because Bun uses Headers
, while Node.js has its own implementation.
The difference happens because Bun uses the new Headers constructor in res.setHeader, which automatically joins list values into a single string. However Node.js, uses a different internal implementation for res.setHeader, which preserves an array for headers with multiple values.
@RiskyMH Thank you for confirming that it is a bug from Bun.
What version of Bun is running?
1.1.29+6d43b3662
What platform is your computer?
Darwin 24.0.0 arm64 arm
What steps can reproduce the bug?
here is my express settings
here is how i set the session
here is my encrypt code
my nodemon settings
how i run project
What is the expected behavior?
The
session.sig
cookie should be created automaticallyWhat do you see instead?
Use ts-node :
session.sig
was created.Use bun :
session.sig
was not created.Additional information
No response