Skip to content

Commit 6afa231

Browse files
fix: don't convert header names to lowercase (Kong#178)
* test(headers): failing test for case sensitive headers * fix: convert header names to lowercase only for HTTP/2 request Closes Kong#74 Co-authored-by: Darren Jennings <dmjenn02@gmail.com>
1 parent 7da7657 commit 6afa231

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

src/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,14 @@ HTTPSnippet.prototype.prepare = function (request) {
7373

7474
// construct headers objects
7575
if (request.headers && request.headers.length) {
76-
// loweCase header keys
76+
var http2VersionRegex = /^HTTP\/2/
7777
request.headersObj = request.headers.reduce(function (headers, header) {
78-
headers[header.name.toLowerCase()] = header.value
78+
var headerName = header.name
79+
if (request.httpVersion.match(http2VersionRegex)) {
80+
headerName = headerName.toLowerCase()
81+
}
82+
83+
headers[headerName] = header.value
7984
return headers
8085
}, {})
8186
}

test/index.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,44 @@ describe('HTTPSnippet', function () {
166166
done()
167167
})
168168

169+
it('should add "headersObj" to source object case insensitive when HTTP/1.0', function (done) {
170+
var fixture = Object.assign({}, fixtures.requests.headers)
171+
fixture.httpVersion = 'HTTP/1.1'
172+
fixture.headers = fixture.headers.concat({
173+
name: 'Kong-Admin-Token',
174+
value: 'Hunter1'
175+
})
176+
177+
var req = new HTTPSnippet(fixture).requests[0]
178+
req.headersObj.should.be.an.Object()
179+
req.headersObj.should.eql({
180+
'Kong-Admin-Token': 'Hunter1',
181+
'accept': 'application/json',
182+
'x-foo': 'Bar'
183+
})
184+
185+
done()
186+
})
187+
188+
it('should add "headersObj" to source object in lowercase when HTTP/2.x', function (done) {
189+
var fixture = Object.assign({}, fixtures.requests.headers)
190+
fixture.httpVersion = 'HTTP/2'
191+
fixture.headers = fixture.headers.concat({
192+
name: 'Kong-Admin-Token',
193+
value: 'Hunter1'
194+
})
195+
196+
var req = new HTTPSnippet(fixture).requests[0]
197+
req.headersObj.should.be.an.Object()
198+
req.headersObj.should.eql({
199+
'kong-admin-token': 'Hunter1',
200+
'accept': 'application/json',
201+
'x-foo': 'Bar'
202+
})
203+
204+
done()
205+
})
206+
169207
it('should modify orignal url to strip query string', function (done) {
170208
var req = new HTTPSnippet(fixtures.requests.query).requests[0]
171209

0 commit comments

Comments
 (0)