v1.3.4: bugfix keep separate headers and don't keep Content-Length on redirect
This commit is contained in:
parent
50704fdccc
commit
3defd84af4
16
index.js
16
index.js
|
@ -29,13 +29,17 @@ function mergeOrDelete(defaults, updates) {
|
|||
return updates;
|
||||
}
|
||||
|
||||
function hasHeader(reqOpts, header) {
|
||||
function getHeaderName(reqOpts, header) {
|
||||
var headers = {};
|
||||
Object.keys(reqOpts.headers).forEach(function (key) {
|
||||
headers[key.toLowerCase()] = true;
|
||||
headers[key.toLowerCase()] = key;
|
||||
});
|
||||
// returns the key, which in erroneous cases could be an empty string
|
||||
return headers[header.toLowerCase()];
|
||||
}
|
||||
function hasHeader(reqOpts, header) {
|
||||
return 'undefined' !== typeof getHeaderName(reqOpts, header);
|
||||
}
|
||||
|
||||
function toJSONifier(keys) {
|
||||
|
||||
|
@ -98,6 +102,8 @@ function setDefaults(defs) {
|
|||
if (!opts.followOriginalHttpMethod) {
|
||||
opts.method = 'GET';
|
||||
opts.body = null;
|
||||
delete opts.headers[getHeaderName(opts.headers, 'Content-Length')];
|
||||
delete opts.headers[getHeaderName(opts.headers, 'Transfer-Encoding')];
|
||||
}
|
||||
if (opts.removeRefererHeader && opts.headers) {
|
||||
delete opts.headers.referer;
|
||||
|
@ -181,7 +187,7 @@ function setDefaults(defs) {
|
|||
finalOpts[key] = opts.uri[key];
|
||||
});
|
||||
finalOpts.method = opts.method;
|
||||
finalOpts.headers = opts.headers;
|
||||
finalOpts.headers = JSON.parse(JSON.stringify(opts.headers));
|
||||
if (_body) {
|
||||
// Most APIs expect (or require) Content-Length except in the case of multipart uploads
|
||||
// Transfer-Encoding: Chunked (the default) is generally only well-supported downstream
|
||||
|
@ -353,7 +359,9 @@ function setDefaults(defs) {
|
|||
} else {
|
||||
reqOpts.method = (reqOpts.method || 'GET').toUpperCase();
|
||||
}
|
||||
reqOpts.headers = reqOpts.headers || {};
|
||||
if (!reqOpts.headers) {
|
||||
reqOpts.headers = {};
|
||||
}
|
||||
|
||||
// crazy case for easier testing
|
||||
if (!hasHeader(reqOpts, 'CoNTeNT-TyPe')) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@coolaj86/urequest",
|
||||
"version": "1.3.3",
|
||||
"version": "1.3.4",
|
||||
"description": "A lightweight drop-in replacement for request",
|
||||
"main": "index.js",
|
||||
"files": [
|
||||
|
|
Loading…
Reference in New Issue