From af5357bddf3d95cb80072c559795720c808bd45b Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Thu, 20 Aug 2015 21:15:17 +0000 Subject: [PATCH] request@2.61.0 --- node_modules/request/CHANGELOG.md | 10 +++++++ node_modules/request/README.md | 46 ++++++++++++++++++++++++++----- node_modules/request/index.js | 2 ++ node_modules/request/package.json | 34 ++++++++++++----------- node_modules/request/request.js | 42 +++++++++++++++++++--------- 5 files changed, 98 insertions(+), 36 deletions(-) diff --git a/node_modules/request/CHANGELOG.md b/node_modules/request/CHANGELOG.md index 4cc1fcbe49f..1e1b02c1dc3 100644 --- a/node_modules/request/CHANGELOG.md +++ b/node_modules/request/CHANGELOG.md @@ -1,5 +1,15 @@ ## 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) - [#1687](https://github.com/request/request/pull/1687) Fix caseless bug - content-type not being set for multipart/form-data (@simov, @garymathews) diff --git a/node_modules/request/README.md b/node_modules/request/README.md index b7227679897..79981137013 100644 --- a/node_modules/request/README.md +++ b/node_modules/request/README.md @@ -673,12 +673,12 @@ a validation step will check if the HAR Request format matches the latest spec ( var request = require('request') request({ // will be ignored - method: 'GET' + method: 'GET', uri: 'http://www.google.com', // HTTP Archive Request Object har: { - url: 'http://www.mockbin.com/har' + url: 'http://www.mockbin.com/har', method: 'POST', headers: [ { @@ -784,9 +784,12 @@ The first argument can be either a `url` or an `options` object. The only requir with your pool options or create the pool object with the `maxSockets` property outside of the loop. - `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 --- @@ -938,6 +941,35 @@ There are at least three ways to debug the operation of `request`: --- +## 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: @@ -1054,8 +1086,8 @@ To inspect your cookie jar after a request: ```js var j = request.jar() 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", ...}, ...] }) ``` diff --git a/node_modules/request/index.js b/node_modules/request/index.js index 3fe60017544..d13ab96b238 100755 --- a/node_modules/request/index.js +++ b/node_modules/request/index.js @@ -88,6 +88,8 @@ function wrapRequestMethod (method, options, requester, verb) { var target = {} extend(true, target, options, params) + target.pool = params.pool || options.pool + if (verb) { target.method = (verb === 'del' ? 'DELETE' : verb.toUpperCase()) } diff --git a/node_modules/request/package.json b/node_modules/request/package.json index c0bd15e8d04..72092ad4233 100644 --- a/node_modules/request/package.json +++ b/node_modules/request/package.json @@ -1,12 +1,12 @@ { "_args": [ [ - "request@2", - "/Users/rebecca/code/npm/node_modules/node-gyp" + "request@2.61.0", + "/Users/rebecca/code/npm" ] ], - "_from": "request@>=2.0.0 <3.0.0", - "_id": "request@2.60.0", + "_from": "request@2.61.0", + "_id": "request@2.61.0", "_inCache": true, "_location": "/request", "_nodeVersion": "0.12.6", @@ -18,21 +18,22 @@ "_phantomChildren": {}, "_requested": { "name": "request", - "raw": "request@2", - "rawSpec": "2", + "raw": "request@2.61.0", + "rawSpec": "2.61.0", "scope": null, - "spec": ">=2.0.0 <3.0.0", - "type": "range" + "spec": "2.61.0", + "type": "version" }, "_requiredBy": [ + "#USER", "/node-gyp", "/npm-registry-client" ], - "_resolved": "https://registry.npmjs.org/request/-/request-2.60.0.tgz", - "_shasum": "498820957fcdded1d37749069610c85f61a29f2d", + "_resolved": "https://registry.npmjs.org/request/-/request-2.61.0.tgz", + "_shasum": "6973cb2ac94885f02693f554eec64481d6013f9f", "_shrinkwrap": null, - "_spec": "request@2", - "_where": "/Users/rebecca/code/npm/node_modules/node-gyp", + "_spec": "request@2.61.0", + "_where": "/Users/rebecca/code/npm", "author": { "email": "mikeal.rogers@gmail.com", "name": "Mikeal Rogers" @@ -85,14 +86,15 @@ }, "directories": {}, "dist": { - "shasum": "498820957fcdded1d37749069610c85f61a29f2d", - "tarball": "http://registry.npmjs.org/request/-/request-2.60.0.tgz" + "shasum": "6973cb2ac94885f02693f554eec64481d6013f9f", + "tarball": "http://registry.npmjs.org/request/-/request-2.61.0.tgz" }, "engines": { "node": ">=0.8.0" }, - "gitHead": "af19cef3bc60e9151ffce5015d8ce3c0728d3aca", + "gitHead": "8492d18add93af1214943ee12e25371f9f9adad3", "homepage": "https://github.com/request/request#readme", + "installable": true, "license": "Apache-2.0", "main": "index.js", "maintainers": [ @@ -132,5 +134,5 @@ "util", "utility" ], - "version": "2.60.0" + "version": "2.61.0" } diff --git a/node_modules/request/request.js b/node_modules/request/request.js index f3f5dd91556..700b9e0a92d 100644 --- a/node_modules/request/request.js +++ b/node_modules/request/request.js @@ -432,13 +432,18 @@ Request.prototype.init = function (options) { } 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) { self.setHeader('content-length', length) } else { @@ -483,10 +488,9 @@ Request.prototype.init = function (options) { if (v.major === 0 && v.minor <= 10) { self.agentClass = protocol === 'http:' ? ForeverAgent : ForeverAgent.SSL } 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 } } else { self.agentClass = self.httpModule.Agent @@ -804,21 +808,33 @@ Request.prototype.start = function () { if (self.timeout && !self.timeoutTimer) { 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 () { if (self.req) { self.req.abort() var e = new Error('ESOCKETTIMEDOUT') e.code = 'ESOCKETTIMEDOUT' + e.connect = false self.emit('error', e) } }) @@ -1047,7 +1063,7 @@ Request.prototype.onRequestResponse = function (response) { try { response.body = JSON.parse(response.body, self._jsonReviver) } catch (e) { - // empty + debug('invalid JSON received', self.uri.href) } } debug('emitting complete', self.uri.href)