request
Advanced tools
Comparing version 2.71.0 to 2.72.0
## Change Log | ||
### v2.72.0 (2016/04/17) | ||
- [#2176](https://github.com/request/request/pull/2176) Do not try to pipe Gzip responses with no body (@simov) | ||
- [#2175](https://github.com/request/request/pull/2175) Add 'delete' alias for the 'del' API method (@simov, @MuhanZou) | ||
- [#2172](https://github.com/request/request/pull/2172) Add support for deflate content encoding (@czardoz) | ||
- [#2169](https://github.com/request/request/pull/2169) Add callback option (@simov) | ||
- [#2165](https://github.com/request/request/pull/2165) Check for self.req existence inside the write method (@simov) | ||
- [#2167](https://github.com/request/request/pull/2167) Fix TravisCI badge reference master branch (@a0viedo) | ||
### v2.71.0 (2016/04/12) | ||
@@ -4,0 +12,0 @@ - [#2164](https://github.com/request/request/pull/2164) Catch errors from the underlying http module (@simov) |
11
index.js
@@ -40,3 +40,3 @@ // Copyright 2010-2012 Mikeal Rogers | ||
params.callback = callback | ||
params.callback = callback || params.callback | ||
return params | ||
@@ -60,3 +60,3 @@ } | ||
function verbFunc (verb) { | ||
var method = verb === 'del' ? 'DELETE' : verb.toUpperCase() | ||
var method = verb.toUpperCase() | ||
return function (uri, options, callback) { | ||
@@ -75,3 +75,4 @@ var params = initParams(uri, options, callback) | ||
request.patch = verbFunc('patch') | ||
request.del = verbFunc('del') | ||
request.del = verbFunc('delete') | ||
request['delete'] = verbFunc('delete') | ||
@@ -97,3 +98,3 @@ request.jar = function (store) { | ||
if (verb) { | ||
target.method = (verb === 'del' ? 'DELETE' : verb.toUpperCase()) | ||
target.method = verb.toUpperCase() | ||
} | ||
@@ -121,3 +122,3 @@ | ||
var verbs = ['get', 'head', 'post', 'put', 'patch', 'del'] | ||
var verbs = ['get', 'head', 'post', 'put', 'patch', 'del', 'delete'] | ||
verbs.forEach(function(verb) { | ||
@@ -124,0 +125,0 @@ defaults[verb] = wrapRequestMethod(self[verb], options, requester, verb) |
@@ -10,3 +10,3 @@ { | ||
], | ||
"version": "2.71.0", | ||
"version": "2.72.0", | ||
"author": "Mikeal Rogers <mikeal.rogers@gmail.com>", | ||
@@ -13,0 +13,0 @@ "repository": { |
@@ -6,3 +6,3 @@ | ||
[![Build status](https://img.shields.io/travis/request/request.svg?style=flat-square)](https://travis-ci.org/request/request) | ||
[![Build status](https://img.shields.io/travis/request/request/master.svg?style=flat-square)](https://travis-ci.org/request/request) | ||
[![Coverage](https://img.shields.io/codecov/c/github/request/request.svg?style=flat-square)](https://codecov.io/github/request/request?branch=master) | ||
@@ -818,2 +818,3 @@ [![Coverage](https://img.shields.io/coveralls/request/request.svg?style=flat-square)](https://coveralls.io/r/request/request) | ||
- `har` - A [HAR 1.2 Request Object](http://www.softwareishard.com/blog/har-12-spec/#request), will be processed from HAR format into options overwriting matching values *(see the [HAR 1.2 section](#support-for-har-1.2) for details)* | ||
- `callback` - alternatively pass the request's callback in the options object | ||
@@ -893,3 +894,3 @@ The callback argument gets 3 arguments: | ||
### request.del | ||
### request.del / request.delete | ||
@@ -900,2 +901,3 @@ Same as `request()`, but defaults to `method: "DELETE"`. | ||
request.del(url) | ||
request.delete(url) | ||
``` | ||
@@ -902,0 +904,0 @@ |
@@ -402,3 +402,3 @@ 'use strict' | ||
if (self.gzip && !self.hasHeader('accept-encoding')) { | ||
self.setHeader('accept-encoding', 'gzip') | ||
self.setHeader('accept-encoding', 'gzip, deflate') | ||
} | ||
@@ -924,4 +924,16 @@ | ||
var noBody = function (code) { | ||
return ( | ||
self.method === 'HEAD' | ||
// Informational | ||
|| (code >= 100 && code < 200) | ||
// No Content | ||
|| code === 204 | ||
// Not Modified | ||
|| code === 304 | ||
) | ||
} | ||
var responseContent | ||
if (self.gzip) { | ||
if (self.gzip && !noBody(response.statusCode)) { | ||
var contentEncoding = response.headers['content-encoding'] || 'identity' | ||
@@ -933,2 +945,5 @@ contentEncoding = contentEncoding.trim().toLowerCase() | ||
response.pipe(responseContent) | ||
} else if (contentEncoding === 'deflate') { | ||
responseContent = zlib.createInflate() | ||
response.pipe(responseContent) | ||
} else { | ||
@@ -1017,2 +1032,5 @@ // Since previous versions didn't check for Content-Encoding header, | ||
debug('aborted', self.uri.href) | ||
// `buffer` is defined in the parent scope and used in a closure it exists for the life of the request. | ||
// This can lead to leaky behavior if the user retains a reference to the request object. | ||
buffer.destroy() | ||
return | ||
@@ -1030,2 +1048,5 @@ } | ||
} | ||
// `buffer` is defined in the parent scope and used in a closure it exists for the life of the Request. | ||
// This can lead to leaky behavior if the user retains a reference to the request object. | ||
buffer.destroy() | ||
} else if (strings.length) { | ||
@@ -1390,3 +1411,5 @@ // The UTF8 BOM [0xEF,0xBB,0xBF] is converted to [0xFE,0xFF] in the JS UTC16/UCS2 representation. | ||
} | ||
return self.req.write.apply(self.req, arguments) | ||
if (self.req) { | ||
return self.req.write.apply(self.req, arguments) | ||
} | ||
} | ||
@@ -1393,0 +1416,0 @@ Request.prototype.end = function (chunk) { |
193690
2400
1099