Skip to content

Commit

Permalink
Transform user set headers to lowercase (#613)
Browse files Browse the repository at this point in the history
* Change test to use header got wants to set

* Lowercase headers set by user
  • Loading branch information
alextes authored and szmarczak committed Sep 23, 2018
1 parent a45f891 commit a07b2be
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"decompress-response": "^3.3.0",
"duplexer3": "^0.1.4",
"get-stream": "^4.0.0",
"lowercase-keys": "^1.0.1",
"mimic-response": "^1.0.1",
"p-cancelable": "^0.5.0",
"to-readable-stream": "^1.0.0",
Expand Down
8 changes: 7 additions & 1 deletion source/normalize-arguments.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const {URL, URLSearchParams} = require('url'); // TODO: Use the `URL` global whe
const is = require('@sindresorhus/is');
const toReadableStream = require('to-readable-stream');
const urlParseLax = require('url-parse-lax');
const lowercaseKeys = require('lowercase-keys');
const isRetryOnNetworkErrorAllowed = require('./is-retry-on-network-error-allowed');
const urlToOptions = require('./url-to-options');
const isFormData = require('./is-form-data');
Expand All @@ -15,10 +16,15 @@ const retryAfterStatusCodes = new Set([413, 429, 503]);
// While `normalize` does `preNormalize` + handles things related to dynamic options, like URL, headers, body, etc.
const preNormalize = options => {
options = {
headers: {},
...options
};

if (is.nullOrUndefined(options.headers)) {
options.headers = {};
} else {
options.headers = lowercaseKeys(options.headers);
}

if (options.baseUrl && !options.baseUrl.toString().endsWith('/')) {
options.baseUrl += '/';
}
Expand Down
4 changes: 2 additions & 2 deletions test/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ test('host', async t => {
test('transform names to lowercase', async t => {
const headers = (await got(s.url, {
headers: {
'USER-AGENT': 'test'
'ACCEPT-ENCODING': 'identity'
},
json: true
})).body;
t.is(headers['user-agent'], 'test');
t.is(headers['accept-encoding'], 'identity');
});

test('setting content-length to 0', async t => {
Expand Down

0 comments on commit a07b2be

Please sign in to comment.