-
-
Notifications
You must be signed in to change notification settings - Fork 404
Open
Labels
bugSomething isn't workingSomething isn't working
Description
What version of Elysia is running?
What platform is your computer?
Darwin 25.1.0 arm64 arm
What environment are you using
1.3.2
Are you using dynamic mode?
no
What steps can reproduce the bug?
When a handler returns a Response with custom headers, and set.headers contains the same header key, values are appended instead of merged:
import { Elysia } from 'elysia'
const app = new Elysia()
.onRequest(({ set }) => {
set.headers['Content-Type'] = 'application/json'
})
.get('/', () => {
return new Response('data', {
headers: { 'Content-Type': 'text/plain' }
})
})
const res = await app.handle(new Request('http://localhost/'))
console.log(res.headers.get('Content-Type'))
// Output: "text/plain, application/json"What is the expected behavior?
Headers should be merged without duplication. Either:
- Response headers take precedence β text/plain
- Or set.headers takes precedence β application/json
Not both appended together.
What do you see instead?
Content-Type: text/plain, application/json
This is invalid for most headers. Content-Type should have a single value.
Additional information
The issue is in src/adapter/utils.ts in createResponseHandler(). It uses response.headers.append() which adds values instead of replacing:
for (const key in set.headers)
response.headers.append(key, set.headers[key]) // append creates duplicatesShould use proper merge logic that handles conflicts.
Have you try removing the node_modules and bun.lockb and try again yet?
yes
Fix implementation
dushebaa
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working