Skip to content

Commit

Permalink
fix: convert header names to lowercase only for HTTP/2 request
Browse files Browse the repository at this point in the history
Closes Kong#74
  • Loading branch information
jgiovaresco committed Sep 17, 2020
1 parent 04328ee commit 4076e96
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ HTTPSnippet.prototype.prepare = function (request) {
if (request.headers && request.headers.length) {
// loweCase header keys
request.headersObj = request.headers.reduce(function (headers, header) {
headers[header.name.toLowerCase()] = header.value
var headerName = header.name
if (request.httpVersion.match(/^HTTP\/2/)) {
headerName = headerName.toLowerCase()
}

headers[headerName] = header.value
return headers
}, {})
}
Expand Down
24 changes: 22 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,9 @@ describe('HTTPSnippet', function () {
done()
})

it('should add "headersObj" to source object case insensitive', function (done) {
it('should add "headersObj" to source object case insensitive when HTTP/1.0', function (done) {
var fixture = Object.assign({}, fixtures.requests.headers)
fixture.httpVersion = 'HTTP/1.1'
fixture.headers = fixture.headers.concat({
name: 'Kong-Admin-Token',
value: 'Hunter1'
Expand All @@ -178,7 +179,26 @@ describe('HTTPSnippet', function () {
req.headersObj.should.eql({
'Kong-Admin-Token': 'Hunter1',
'accept': 'application/json',
'x-foo': 'Bar',
'x-foo': 'Bar'
})

done()
})

it('should add "headersObj" to source object in lowercase when HTTP/2.x', function (done) {
var fixture = Object.assign({}, fixtures.requests.headers)
fixture.httpVersion = 'HTTP/2'
fixture.headers = fixture.headers.concat({
name: 'Kong-Admin-Token',
value: 'Hunter1'
})

var req = new HTTPSnippet(fixture).requests[0]
req.headersObj.should.be.an.Object()
req.headersObj.should.eql({
'kong-admin-token': 'Hunter1',
'accept': 'application/json',
'x-foo': 'Bar'
})

done()
Expand Down

0 comments on commit 4076e96

Please sign in to comment.