Skip to content

Commit ffed621

Browse files
authored
fix: ensure all http headers get lower cased (#7823)
1 parent 5b2f0b8 commit ffed621

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

packages/datadog-plugin-http/src/client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ function getHeaders (config) {
211211
if (typeof header === 'string') {
212212
const separatorIndex = header.indexOf(':')
213213
result.push(separatorIndex === -1
214-
? [header, undefined]
214+
? [header.toLowerCase(), undefined]
215215
: [
216216
header.slice(0, separatorIndex).toLowerCase(),
217217
header.slice(separatorIndex + 1),

packages/datadog-plugin-http/test/client.spec.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,7 +1185,7 @@ describe('Plugin', () => {
11851185
config = {
11861186
server: false,
11871187
client: {
1188-
headers: ['host', 'x-foo', 'x-bar:http.bar', 'x-baz:http.baz'],
1188+
headers: ['host', 'x-foo', 'x-bar:http.bar', 'x-baz:http.baz', 'X-Request-Id'],
11891189
},
11901190
}
11911191

@@ -1211,6 +1211,7 @@ describe('Plugin', () => {
12111211
const meta = traces[0][0].meta
12121212

12131213
assert.strictEqual(meta[`${HTTP_REQUEST_HEADERS}.host`], `localhost:${port}`)
1214+
assert.strictEqual(meta[`${HTTP_REQUEST_HEADERS}.x-request-id`], 'request-id')
12141215
assert.strictEqual(meta['http.baz'], 'baz')
12151216
assert.strictEqual(meta[`${HTTP_RESPONSE_HEADERS}.x-foo`], 'foo')
12161217
assert.strictEqual(meta['http.bar'], 'bar')
@@ -1219,7 +1220,7 @@ describe('Plugin', () => {
12191220
.catch(done)
12201221

12211222
const url = `${protocol}://localhost:${port}/user`
1222-
const headers = { 'x-baz': 'baz' }
1223+
const headers = { 'x-baz': 'baz', 'X-Request-Id': 'request-id' }
12231224
const req = http.request(url, { headers }, res => {
12241225
res.on('data', () => {})
12251226
})

0 commit comments

Comments
 (0)