Comparing version 2.60.0 to 2.61.0
## Change Log | ||
### v2.61.0 (2015/08/19) | ||
- [#1721](https://github.com/request/request/pull/1721) Minor fix in README.md (@arbaaz) | ||
- [#1733](https://github.com/request/request/pull/1733) Avoid useless Buffer transformation (@michelsalib) | ||
- [#1726](https://github.com/request/request/pull/1726) Update README.md (@paulomcnally) | ||
- [#1715](https://github.com/request/request/pull/1715) Fix forever option in node > 0.10 #1709 (@calibr) | ||
- [#1716](https://github.com/request/request/pull/1716) Do not create Buffer from Object in setContentLength(iojs v3.0 issue) (@calibr) | ||
- [#1711](https://github.com/request/request/pull/1711) Add ability to detect connect timeouts (@kevinburke) | ||
- [#1712](https://github.com/request/request/pull/1712) Set certificate expiration to August 2, 2018 (@kevinburke) | ||
- [#1700](https://github.com/request/request/pull/1700) debug() when JSON.parse() on a response body fails (@phillipj) | ||
### v2.60.0 (2015/07/21) | ||
@@ -4,0 +14,0 @@ - [#1687](https://github.com/request/request/pull/1687) Fix caseless bug - content-type not being set for multipart/form-data (@simov, @garymathews) |
@@ -91,2 +91,4 @@ // Copyright 2010-2012 Mikeal Rogers | ||
target.pool = params.pool || options.pool | ||
if (verb) { | ||
@@ -93,0 +95,0 @@ target.method = (verb === 'del' ? 'DELETE' : verb.toUpperCase()) |
@@ -10,3 +10,3 @@ { | ||
], | ||
"version": "2.60.0", | ||
"version": "2.61.0", | ||
"author": "Mikeal Rogers <mikeal.rogers@gmail.com>", | ||
@@ -13,0 +13,0 @@ "repository": { |
@@ -676,3 +676,3 @@ | ||
// will be ignored | ||
method: 'GET' | ||
method: 'GET', | ||
uri: 'http://www.google.com', | ||
@@ -682,3 +682,3 @@ | ||
har: { | ||
url: 'http://www.mockbin.com/har' | ||
url: 'http://www.mockbin.com/har', | ||
method: 'POST', | ||
@@ -789,6 +789,9 @@ headers: [ | ||
- `timeout` - Integer containing the number of milliseconds to wait for a | ||
request to respond before aborting the request. Note that if the underlying | ||
TCP connection cannot be established, the OS-wide TCP connection timeout will | ||
overrule the `timeout` option ([the default in Linux is around 20 seconds](http://www.sekuda.com/overriding_the_default_linux_kernel_20_second_tcp_socket_connect_timeout)). | ||
server to send response headers (and start the response body) before aborting | ||
the request. Note that if the underlying TCP connection cannot be established, | ||
the OS-wide TCP connection timeout will overrule the `timeout` option ([the | ||
default in Linux can be anywhere from 20-120 seconds][linux-timeout]). | ||
[linux-timeout]: http://www.sekuda.com/overriding_the_default_linux_kernel_20_second_tcp_socket_connect_timeout | ||
--- | ||
@@ -944,3 +947,32 @@ | ||
## Timeouts | ||
Most requests to external servers should have a timeout attached, in case the | ||
server is not responding in a timely manner. Without a timeout, your code may | ||
have a socket open/consume resources for minutes or more. | ||
There are two main types of timeouts: **connection timeouts** and **read | ||
timeouts**. A connect timeout occurs if the timeout is hit while your client is | ||
attempting to establish a connection to a remote machine (corresponding to the | ||
[connect() call][connect] on the socket). A read timeout occurs any time the | ||
server is too slow to send back a part of the response. | ||
These two situations have widely different implications for what went wrong | ||
with the request, so it's useful to be able to distinguish them. You can detect | ||
timeout errors by checking `err.code` for an 'ETIMEDOUT' value. Further, you | ||
can detect whether the timeout was a connection timeout by checking if the | ||
`err.connect` property is set to `true`. | ||
```js | ||
request.get('http://10.255.255.1', {timeout: 1500}, function(err) { | ||
console.log(err.code === 'ETIMEDOUT'); | ||
// Set to `true` if the timeout was a connection timeout, `false` or | ||
// `undefined` otherwise. | ||
console.log(err.connect === true); | ||
process.exit(0); | ||
}); | ||
``` | ||
[connect]: http://linux.die.net/man/2/connect | ||
## Examples: | ||
@@ -1061,4 +1093,4 @@ | ||
request({url: 'http://www.google.com', jar: j}, function () { | ||
var cookie_string = j.getCookieString(uri); // "key1=value1; key2=value2; ..." | ||
var cookies = j.getCookies(uri); | ||
var cookie_string = j.getCookieString(url); // "key1=value1; key2=value2; ..." | ||
var cookies = j.getCookies(url); | ||
// [{key: 'key1', value: 'value1', domain: "www.google.com", ...}, ...] | ||
@@ -1065,0 +1097,0 @@ }) |
@@ -435,9 +435,14 @@ 'use strict' | ||
function setContentLength () { | ||
if (!Buffer.isBuffer(self.body) && !Array.isArray(self.body)) { | ||
self.body = new Buffer(self.body) | ||
} | ||
if (!self.hasHeader('content-length')) { | ||
var length = (Array.isArray(self.body)) | ||
? self.body.reduce(function (a, b) {return a + b.length}, 0) | ||
: self.body.length | ||
var length | ||
if (typeof self.body === 'string') { | ||
length = Buffer.byteLength(self.body) | ||
} | ||
else if (Array.isArray(self.body)) { | ||
length = self.body.reduce(function (a, b) {return a + b.length}, 0) | ||
} | ||
else { | ||
length = self.body.length | ||
} | ||
if (length) { | ||
@@ -487,6 +492,5 @@ self.setHeader('content-length', length) | ||
} else { | ||
self.agent = new self.httpModule.Agent({ | ||
keepAlive: true, | ||
maxSockets: (options.pool && options.pool.maxSockets) || Infinity | ||
}) | ||
self.agentClass = self.httpModule.Agent | ||
self.agentOptions = self.agentOptions || {} | ||
self.agentOptions.keepAlive = true | ||
} | ||
@@ -809,12 +813,23 @@ } else { | ||
var timeout = self.timeout < 0 ? 0 : self.timeout | ||
// Set a timeout in memory - this block will throw if the server takes more | ||
// than `timeout` to write the HTTP status and headers (corresponding to | ||
// the on('response') event on the client). NB: this measures wall-clock | ||
// time, not the time between bytes sent by the server. | ||
self.timeoutTimer = setTimeout(function () { | ||
var connectTimeout = self.req.socket && self.req.socket.readable === false | ||
self.abort() | ||
var e = new Error('ETIMEDOUT') | ||
e.code = 'ETIMEDOUT' | ||
e.connect = connectTimeout | ||
self.emit('error', e) | ||
}, timeout) | ||
// Set additional timeout on socket - in case if remote | ||
// server freeze after sending headers | ||
if (self.req.setTimeout) { // only works on node 0.6+ | ||
// Set an additional timeout on the socket, via the `setsockopt` syscall. | ||
// This timeout sets the amount of time to wait *between* bytes sent | ||
// from the server, and may or may not correspond to the wall-clock time | ||
// elapsed from the start of the request. | ||
// | ||
// In particular, it's useful for erroring if the server fails to send | ||
// data halfway through streaming a response. | ||
self.req.setTimeout(timeout, function () { | ||
@@ -825,2 +840,3 @@ if (self.req) { | ||
e.code = 'ESOCKETTIMEDOUT' | ||
e.connect = false | ||
self.emit('error', e) | ||
@@ -1054,3 +1070,3 @@ } | ||
} catch (e) { | ||
// empty | ||
debug('invalid JSON received', self.uri.href) | ||
} | ||
@@ -1057,0 +1073,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
185524
2349
1096