Skip to content

Commit

Permalink
fix: lowercasing incoming request headers
Browse files Browse the repository at this point in the history
closes antongolub#33

- Makes sure incoming header options are always lowercased. This behavior would be the same as in original express request.
  • Loading branch information
naz committed Feb 15, 2022
1 parent 3cc79c9 commit 5473ddc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/main/js/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import url from 'url'
import {
assign,
setprototypeof,
appendAdditionalProps
appendAdditionalProps,
convertKeysToLowerCase
} from './util'
import DEFAULT_APP from './app'

Expand Down Expand Up @@ -74,7 +75,7 @@ export default class Request implements IRequest {
this.socket = opts.socket
this.app = opts.app
this.res = opts.res
this.headers = opts.headers
this.headers = opts.headers ? convertKeysToLowerCase(opts.headers) : {}
this.body = opts.body
this.params = opts.params
this.connection = opts.connection
Expand Down
7 changes: 7 additions & 0 deletions src/test/js/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ describe('request', () => {
expect(req.header('foo')).toBe('bar')
expect(req.get('BAZ')).toBe('qux')
})

it('lowercases incoming headers', () => {
const req = new Request({ headers: { 'BaZ-Header': 'qux' } })

expect(req.get('Baz-Header')).toBe('qux')
expect(req.headers['baz-header']).toBe('qux')
})
})

describe('ip', () => {
Expand Down

0 comments on commit 5473ddc

Please sign in to comment.