Comparing version 2.54.0 to 2.55.0
## Change Log | ||
### v2.55.0 (2015/04/05) | ||
- [#1520](https://github.com/request/request/pull/1520) Refactor defaults (@simov) | ||
- [#1525](https://github.com/request/request/pull/1525) Delete request headers with undefined value. (@froatsnook) | ||
- [#1521](https://github.com/request/request/pull/1521) Add promise tests (@simov) | ||
- [#1518](https://github.com/request/request/pull/1518) Fix defaults (@simov) | ||
- [#1515](https://github.com/request/request/pull/1515) Allow static invoking of convenience methods (@simov) | ||
- [#1505](https://github.com/request/request/pull/1505) Fix multipart boundary extraction regexp (@simov) | ||
- [#1510](https://github.com/request/request/pull/1510) Fix basic auth form data (@simov) | ||
### v2.54.0 (2015/03/24) | ||
@@ -4,0 +13,0 @@ - [#1501](https://github.com/request/request/pull/1501) HTTP Archive 1.2 support (@ahmadnassri) |
115
index.js
@@ -22,5 +22,2 @@ // Copyright 2010-2012 Mikeal Rogers | ||
var isFunction = helpers.isFunction | ||
, constructObject = helpers.constructObject | ||
, filterForCallback = helpers.filterForCallback | ||
, constructOptionsFrom = helpers.constructOptionsFrom | ||
, paramsHaveRequestBody = helpers.paramsHaveRequestBody | ||
@@ -31,10 +28,18 @@ | ||
function initParams(uri, options, callback) { | ||
callback = filterForCallback([options, callback]) | ||
options = constructOptionsFrom(uri, options) | ||
if (typeof options === 'function') { | ||
callback = options | ||
} | ||
return constructObject() | ||
.extend({callback: callback}) | ||
.extend({options: options}) | ||
.extend({uri: options.uri}) | ||
.done() | ||
var params = {} | ||
if (typeof options === 'object') { | ||
params = extend({}, options) | ||
params = extend(params, {uri: uri}) | ||
} else if (typeof uri === 'string') { | ||
params = extend({}, {uri: uri}) | ||
} else { | ||
params = extend({}, uri) | ||
} | ||
params.callback = callback | ||
return params | ||
} | ||
@@ -48,11 +53,8 @@ | ||
var params = initParams(uri, options, callback) | ||
options = params.options | ||
options.callback = params.callback | ||
options.uri = params.uri | ||
if (params.options.method === 'HEAD' && paramsHaveRequestBody(params)) { | ||
if (params.method === 'HEAD' && paramsHaveRequestBody(params)) { | ||
throw new Error('HTTP HEAD requests MUST NOT include a request body.') | ||
} | ||
return new request.Request(options) | ||
return new request.Request(params) | ||
} | ||
@@ -62,8 +64,8 @@ | ||
verbs.forEach(function(verb){ | ||
verbs.forEach(function(verb) { | ||
var method = verb === 'del' ? 'DELETE' : verb.toUpperCase() | ||
request[verb] = function(uri, options, callback){ | ||
request[verb] = function (uri, options, callback) { | ||
var params = initParams(uri, options, callback) | ||
params.options.method = method | ||
return this(params.uri || null, params.options, params.callback) | ||
params.method = method | ||
return request(params, params.callback) | ||
} | ||
@@ -80,48 +82,45 @@ }) | ||
request.defaults = function (options, requester) { | ||
function wrapRequestMethod (method, options, requester) { | ||
if (typeof options === 'function') { | ||
requester = options | ||
options = {} | ||
} | ||
return function (uri, opts, callback) { | ||
var params = initParams(uri, opts, callback) | ||
var self = this | ||
var wrap = function (method) { | ||
var headerlessOptions = function (options) { | ||
options = extend({}, options) | ||
delete options.headers | ||
return options | ||
var headerlessOptions = extend({}, options) | ||
delete headerlessOptions.headers | ||
params = extend(headerlessOptions, params) | ||
if (options.headers) { | ||
var headers = extend({}, options.headers) | ||
params.headers = extend(headers, params.headers) | ||
} | ||
var getHeaders = function (params, options) { | ||
return constructObject() | ||
.extend(options.headers) | ||
.extend(params.options.headers) | ||
.done() | ||
if (typeof method === 'string') { | ||
params.method = (method === 'del' ? 'DELETE' : method.toUpperCase()) | ||
method = request[method] | ||
} | ||
return function (uri, opts, callback) { | ||
var params = initParams(uri, opts, callback) | ||
params.options = extend(headerlessOptions(options), params.options) | ||
if (isFunction(requester)) { | ||
method = requester | ||
} | ||
if (options.headers) { | ||
params.options.headers = getHeaders(params, options) | ||
} | ||
return method(params, params.callback) | ||
} | ||
} | ||
if (isFunction(requester)) { | ||
method = requester | ||
} | ||
request.defaults = function (options, requester) { | ||
var self = this | ||
return method(params.options, params.callback) | ||
} | ||
if (typeof options === 'function') { | ||
requester = options | ||
options = {} | ||
} | ||
var defaults = wrap(self) | ||
defaults.get = self.get | ||
defaults.patch = self.patch | ||
defaults.post = self.post | ||
defaults.put = self.put | ||
defaults.head = self.head | ||
defaults.del = self.del | ||
defaults.cookie = self.cookie | ||
var defaults = wrapRequestMethod(self, options, requester) | ||
var verbs = ['get', 'head', 'post', 'put', 'patch', 'del'] | ||
verbs.forEach(function(verb) { | ||
defaults[verb] = wrapRequestMethod(verb, options, requester) | ||
}) | ||
defaults.cookie = wrapRequestMethod(self.cookie, options, requester) | ||
defaults.jar = self.jar | ||
@@ -133,5 +132,5 @@ defaults.defaults = self.defaults | ||
request.forever = function (agentOptions, optionsArg) { | ||
var options = constructObject() | ||
var options = {} | ||
if (optionsArg) { | ||
options.extend(optionsArg) | ||
options = extend({}, optionsArg) | ||
} | ||
@@ -142,4 +141,4 @@ if (agentOptions) { | ||
options.extend({forever: true}) | ||
return request.defaults(options.done()) | ||
options.forever = true | ||
return request.defaults(options) | ||
} | ||
@@ -146,0 +145,0 @@ |
'use strict' | ||
var extend = require('util')._extend | ||
, jsonSafeStringify = require('json-stringify-safe') | ||
var jsonSafeStringify = require('json-stringify-safe') | ||
, crypto = require('crypto') | ||
@@ -15,27 +14,2 @@ | ||
function constructObject(initialObject) { | ||
initialObject = initialObject || {} | ||
return { | ||
extend: function (object) { | ||
return constructObject(extend(initialObject, object)) | ||
}, | ||
done: function () { | ||
return initialObject | ||
} | ||
} | ||
} | ||
function constructOptionsFrom(uri, options) { | ||
var params = constructObject() | ||
if (typeof options === 'object') { | ||
params.extend(options).extend({uri: uri}) | ||
} else if (typeof uri === 'string') { | ||
params.extend({uri: uri}) | ||
} else { | ||
params.extend(uri) | ||
} | ||
return params.done() | ||
} | ||
function isFunction(value) { | ||
@@ -45,13 +19,8 @@ return typeof value === 'function' | ||
function filterForCallback(values) { | ||
var callbacks = values.filter(isFunction) | ||
return callbacks[0] | ||
} | ||
function paramsHaveRequestBody(params) { | ||
return ( | ||
params.options.body || | ||
params.options.requestBodyStream || | ||
(params.options.json && typeof params.options.json !== 'boolean') || | ||
params.options.multipart | ||
params.body || | ||
params.requestBodyStream || | ||
(params.json && typeof params.json !== 'boolean') || | ||
params.multipart | ||
) | ||
@@ -83,5 +52,2 @@ } | ||
exports.isFunction = isFunction | ||
exports.constructObject = constructObject | ||
exports.constructOptionsFrom = constructOptionsFrom | ||
exports.filterForCallback = filterForCallback | ||
exports.paramsHaveRequestBody = paramsHaveRequestBody | ||
@@ -88,0 +54,0 @@ exports.safeStringify = safeStringify |
@@ -59,3 +59,3 @@ 'use strict' | ||
if (header.indexOf('boundary') !== -1) { | ||
self.boundary = header.replace(/.*boundary=([^\s;])+.*/, '$1') | ||
self.boundary = header.replace(/.*boundary=([^\s;]+).*/, '$1') | ||
} else { | ||
@@ -62,0 +62,0 @@ self.request.setHeader('content-type', header + '; boundary=' + self.boundary) |
@@ -10,3 +10,3 @@ { | ||
], | ||
"version": "2.54.0", | ||
"version": "2.55.0", | ||
"author": "Mikeal Rogers <mikeal.rogers@gmail.com>", | ||
@@ -66,4 +66,5 @@ "repository": { | ||
"tape": "~3.0.0", | ||
"taper": "~0.4.0" | ||
"taper": "~0.4.0", | ||
"bluebird": "~2.9.21" | ||
} | ||
} |
@@ -326,2 +326,10 @@ 'use strict' | ||
// Delete headers with value undefined since they break | ||
// ClientRequest.OutgoingMessage.setHeader in node 0.12 | ||
for (var headerName in self.headers) { | ||
if (typeof self.headers[headerName] === 'undefined') { | ||
delete self.headers[headerName] | ||
} | ||
} | ||
caseless.httpify(self, self.headers) | ||
@@ -697,3 +705,8 @@ | ||
if (self._form) { | ||
self._form.pipe(self) | ||
if (!self._auth.hasAuth) { | ||
self._form.pipe(self) | ||
} | ||
else if (self._auth.hasAuth && self._auth.sentAuth) { | ||
self._form.pipe(self) | ||
} | ||
} | ||
@@ -716,2 +729,6 @@ if (self._multipart && self._multipart.chunked) { | ||
} else if (!self.src) { | ||
if (self._auth.hasAuth && !self._auth.sentAuth) { | ||
self.end() | ||
return | ||
} | ||
if (self.method !== 'GET' && typeof self.method !== 'undefined') { | ||
@@ -718,0 +735,0 @@ self.setHeader('content-length', 0) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
172160
3
17
2253