-
-
Notifications
You must be signed in to change notification settings - Fork 685
Description
Bug Description
Custom HTTP headers (HTTP-Referer, X-Title) are not transmitted when using fetch() in Node.js v22.21.0 (undici 6.22.0), but work correctly with curl and in Node.js v20.19.0 (undici 6.21.1).
Environment
- Node.js version: v22.21.0
- undici version: 6.22.0
- OS: Linux (Debian-based)
- Working versions: Node.js v20.19.0 (undici 6.21.1)
Reproduction
Test endpoint
We tested against both https://postman-echo.com/headers and https://openrouter.ai/api/v1/chat/completions.
Code that fails (undici 6.22.0)
const response = await fetch('https://openrouter.ai/api/v1/chat/completions', {
method: 'POST',
headers: {
'Authorization': 'Bearer xxx',
'Content-Type': 'application/json',
'HTTP-Referer': 'https://github.com/,
'X-Title': 'test bot'
},
body: JSON.stringify({ /* ... */ })
});Result: Headers HTTP-Referer and X-Title are not received by the server.
Same code with curl (works)
curl https://openrouter.ai/api/v1/chat/completions \
-H "Authorization: Bearer xxx" \
-H "Content-Type: application/json" \
-H "HTTP-Referer: https://github.com/" \
-H "X-Title: test bot" \
-d '{"model":"xxx","messages":[...]}'Result: Headers are correctly received (verified in response metadata).
Verification with postman-echo
# Works with curl
curl https://postman-echo.com/headers \
-H "HTTP-Referer: https://github.com/test" \
-H "X-Title: Test"
# Response shows both headers correctlyExpected Behavior
Custom headers should be transmitted to the remote server, just like curl does.
Actual Behavior
Custom headers HTTP-Referer and X-Title are stripped/lost during transmission.
Workaround
Using axios instead of fetch works correctly:
const axios = require('axios');
const response = await axios.post(url, data, {
headers: {
'HTTP-Referer': 'https://github.com',
'X-Title': 'test bot'
}
});Regression
This appears to be a regression introduced in undici 6.22.0, as it works in 6.21.1.
Additional Context
The headers work correctly:
- ✅ With curl on the same machine
- ✅ With Node.js v20.19.0 (undici 6.21.1) on macOS
- ❌ With Node.js v22.21.0 (undici 6.22.0) on Linux
This affects applications that need to identify themselves via custom headers (like OpenRouter's app tracking system).