From d7ed0a5710a19ea340e8964c7aed2e634d833c41 Mon Sep 17 00:00:00 2001 From: mdemo Date: Sun, 8 Feb 2015 12:24:38 +0800 Subject: [PATCH 001/490] Add node.js 0.12 and io.js to travis.yml --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 0988483f3..f0da7e686 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,8 @@ language: node_js node_js: - "0.8" - "0.10" + - "0.12" + - "io.js" before_install: npm install -g npm@~1.4.6 after_script: ./node_modules/.bin/istanbul cover ./node_modules/tape/bin/tape tests/test-*.js --report lcovonly && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js --verbose webhooks: From 5c46172e5a5d48407a6769d867de6b5afc5060d5 Mon Sep 17 00:00:00 2001 From: James Nylen Date: Tue, 10 Feb 2015 19:14:21 -0600 Subject: [PATCH 002/490] Add note that the project is broken in 0.12.x Hopefully we can get rid of this soon! --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 8b668f99f..d5aeec375 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,14 @@ [![Coverage](https://img.shields.io/coveralls/request/request.svg?style=flat)](https://coveralls.io/r/request/request) [![Gitter](https://img.shields.io/badge/gitter-join_chat-blue.svg?style=flat)](https://gitter.im/request/request?utm_source=badge) +## !!! Does not work with Node v0.12.x !!! + +We're working on this. Want to help? See the +[contribution guidelines](https://github.com/request/request/blob/master/CONTRIBUTING.md), +help us fix the +[failing tests](https://travis-ci.org/request/request/jobs/49916823), +and [submit a PR](https://github.com/request/request/pulls)! + ## Super simple to use Request is designed to be the simplest way possible to make http calls. It supports HTTPS and follows redirects by default. From d94cc5409be6ac09b048c8ca7933565261cca2f3 Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 12 Feb 2015 12:08:48 +0200 Subject: [PATCH 003/490] Allow fully qualified multipart content-type header Major refactoring on multipart chunked detection tests --- lib/multipart.js | 21 +++-- tests/test-multipart-encoding.js | 149 +++++++++++++++++++++++++++++++ tests/test-multipart.js | 143 ++++++++++------------------- 3 files changed, 210 insertions(+), 103 deletions(-) create mode 100644 tests/test-multipart-encoding.js diff --git a/lib/multipart.js b/lib/multipart.js index cddd8d392..390a7f2d1 100644 --- a/lib/multipart.js +++ b/lib/multipart.js @@ -21,14 +21,14 @@ Multipart.prototype.isChunked = function (options) { throw new Error('Argument error, options.multipart.') } - if (self.request.getHeader('transfer-encoding') === 'chunked') { - chunked = true - } - if (options.chunked !== undefined) { chunked = options.chunked } + if (self.request.getHeader('transfer-encoding') === 'chunked') { + chunked = true + } + if (!chunked) { parts.forEach(function (part) { if(typeof part.body === 'undefined') { @@ -51,11 +51,16 @@ Multipart.prototype.setHeaders = function (chunked) { } var header = self.request.getHeader('content-type') - var contentType = (!header || header.indexOf('multipart') === -1) - ? 'multipart/related' - : header.split(';')[0] - self.request.setHeader('content-type', contentType + '; boundary=' + self.boundary) + if (!header || header.indexOf('multipart') === -1) { + self.request.setHeader('content-type', 'multipart/related; boundary=' + self.boundary) + } else { + if (header.indexOf('boundary') !== -1) { + self.boundary = header.replace(/.*boundary=([^\s;])+.*/, '$1') + } else { + self.request.setHeader('content-type', header + '; boundary=' + self.boundary) + } + } } Multipart.prototype.build = function (parts, chunked) { diff --git a/tests/test-multipart-encoding.js b/tests/test-multipart-encoding.js new file mode 100644 index 000000000..4c8383489 --- /dev/null +++ b/tests/test-multipart-encoding.js @@ -0,0 +1,149 @@ +'use strict' + +var http = require('http') + , path = require('path') + , request = require('../index') + , fs = require('fs') + , tape = require('tape') + + +var localFile = path.join(__dirname, 'unicycle.jpg') +var cases = { + // based on body type + '+array -stream': { + options: { + multipart: [{name: 'field', body: 'value'}] + }, + expected: {chunked: false} + }, + '+array +stream': { + options: { + multipart: [{name: 'file', body: null}] + }, + expected: {chunked: true} + }, + // encoding overrides body value + '+array +encoding': { + options: { + headers: {'transfer-encoding': 'chunked'}, + multipart: [{name: 'field', body: 'value'}] + }, + expected: {chunked: true} + }, + + // based on body type + '+object -stream': { + options: { + multipart: {data: [{name: 'field', body: 'value'}]} + }, + expected: {chunked: false} + }, + '+object +stream': { + options: { + multipart: {data: [{name: 'file', body: null}]} + }, + expected: {chunked: true} + }, + // encoding overrides body value + '+object +encoding': { + options: { + headers: {'transfer-encoding': 'chunked'}, + multipart: {data: [{name: 'field', body: 'value'}]} + }, + expected: {chunked: true} + }, + + // based on body type + '+object -chunked -stream': { + options: { + multipart: {chunked: false, data: [{name: 'field', body: 'value'}]} + }, + expected: {chunked: false} + }, + '+object -chunked +stream': { + options: { + multipart: {chunked: false, data: [{name: 'file', body: null}]} + }, + expected: {chunked: true} + }, + // chunked overrides body value + '+object +chunked -stream': { + options: { + multipart: {chunked: true, data: [{name: 'field', body: 'value'}]} + }, + expected: {chunked: true} + }, + // encoding overrides chunked + '+object +encoding -chunked': { + options: { + headers: {'transfer-encoding': 'chunked'}, + multipart: {chunked: false, data: [{name: 'field', body: 'value'}]} + }, + expected: {chunked: true} + } +} + +function runTest(t, test) { + + var server = http.createServer(function(req, res) { + + t.ok(req.headers['content-type'].match(/^multipart\/related; boundary=[^\s;]+$/)) + + if (test.expected.chunked) { + t.ok(req.headers['transfer-encoding'] === 'chunked') + t.notOk(req.headers['content-length']) + } else { + t.ok(req.headers['content-length']) + t.notOk(req.headers['transfer-encoding']) + } + + // temp workaround + var data = '' + req.setEncoding('utf8') + + req.on('data', function(d) { + data += d + }) + + req.on('end', function() { + // check for the fields traces + if (test.expected.chunked && data.indexOf('name: file') !== -1) { + // file + t.ok(data.indexOf('name: file') !== -1) + // check for unicycle.jpg traces + t.ok(data.indexOf('2005:06:21 01:44:12') !== -1) + } else { + // field + t.ok(data.indexOf('name: field') !== -1) + var parts = test.options.multipart.data || test.options.multipart + t.ok(data.indexOf(parts[0].body) !== -1) + } + + res.writeHead(200) + res.end() + }) + }) + + server.listen(6767, function() { + // @NOTE: multipartData properties must be set here + // so that file read stream does not leak in node v0.8 + var parts = test.options.multipart.data || test.options.multipart + if (parts[0].name === 'file') { + parts[0].body = fs.createReadStream(localFile) + } + + request.post('http://localhost:6767', test.options, function (err, res, body) { + t.equal(err, null) + t.equal(res.statusCode, 200) + server.close(function () { + t.end() + }) + }) + }) +} + +Object.keys(cases).forEach(function (name) { + tape('multipart-encoding ' + name, function(t) { + runTest(t, cases[name]) + }) +}) diff --git a/tests/test-multipart.js b/tests/test-multipart.js index cd7d659aa..dafc23805 100644 --- a/tests/test-multipart.js +++ b/tests/test-multipart.js @@ -6,11 +6,11 @@ var http = require('http') , fs = require('fs') , tape = require('tape') + function runTest(t, a) { var remoteFile = path.join(__dirname, 'googledoodle.jpg') , localFile = path.join(__dirname, 'unicycle.jpg') , multipartData = [] - , chunked = a.stream || a.chunked || a.encoding var server = http.createServer(function(req, res) { if (req.url === '/file') { @@ -19,18 +19,15 @@ function runTest(t, a) { return } - if (a.mixed) { - t.ok(req.headers['content-type'].match(/multipart\/mixed/)) - } else { - t.ok(req.headers['content-type'].match(/multipart\/related/)) - } - - if (chunked) { - t.ok(req.headers['transfer-encoding'] === 'chunked') - t.notOk(req.headers['content-length']) + if (a.header) { + if (a.header.indexOf('mixed') !== -1) { + t.ok(req.headers['content-type'].match(/^multipart\/mixed; boundary=[^\s;]+$/)) + } else { + t.ok(req.headers['content-type'] + .match(/^multipart\/related; boundary=XXX; type=text\/xml; start=""$/)) + } } else { - t.ok(req.headers['content-length']) - t.notOk(req.headers['transfer-encoding']) + t.ok(req.headers['content-type'].match(/^multipart\/related; boundary=[^\s;]+$/)) } // temp workaround @@ -42,26 +39,28 @@ function runTest(t, a) { }) req.on('end', function() { - // check for the fields' traces + // check for the fields traces // 1st field : my_field - t.ok( data.indexOf('name: my_field') !== -1 ) - t.ok( data.indexOf(multipartData[0].body) !== -1 ) + t.ok(data.indexOf('name: my_field') !== -1) + t.ok(data.indexOf(multipartData[0].body) !== -1) // 2nd field : my_buffer - t.ok( data.indexOf('name: my_buffer') !== -1 ) - t.ok( data.indexOf(multipartData[1].body) !== -1 ) - - if (chunked) { - // 3rd field : my_file - t.ok( data.indexOf('name: my_file') !== -1 ) - // check for unicycle.jpg traces - t.ok( data.indexOf('2005:06:21 01:44:12') !== -1 ) - - // 4th field : remote_file - t.ok( data.indexOf('name: remote_file') !== -1 ) - // check for http://localhost:6767/file traces - t.ok( data.indexOf('Photoshop ICC') !== -1 ) + t.ok(data.indexOf('name: my_buffer') !== -1) + t.ok(data.indexOf(multipartData[1].body) !== -1) + + // 3rd field : my_file + t.ok(data.indexOf('name: my_file') !== -1) + // check for unicycle.jpg traces + t.ok(data.indexOf('2005:06:21 01:44:12') !== -1) + + // 4th field : remote_file + t.ok(data.indexOf('name: remote_file') !== -1) + // check for http://localhost:6767/file traces + t.ok(data.indexOf('Photoshop ICC') !== -1) + + if (a.header && a.header.indexOf('mixed') !== -1) { + t.ok(data.indexOf('boundary=XXX')) } res.writeHead(200) @@ -72,33 +71,21 @@ function runTest(t, a) { server.listen(6767, function() { // @NOTE: multipartData properties must be set here so that my_file read stream does not leak in node v0.8 - multipartData = chunked - ? [ + multipartData = [ {name: 'my_field', body: 'my_value'}, {name: 'my_buffer', body: new Buffer([1, 2, 3])}, {name: 'my_file', body: fs.createReadStream(localFile)}, {name: 'remote_file', body: request('http://localhost:6767/file')} ] - : [ - {name: 'my_field', body: 'my_value'}, - {name: 'my_buffer', body: new Buffer([1, 2, 3])} - ] var reqOptions = { url: 'http://localhost:6767/upload', - headers: (function () { - var headers = {} - if (a.mixed) { - headers['content-type'] = 'multipart/mixed' - } - if (a.encoding) { - headers['transfer-encoding'] = 'chunked' - } - return headers - }()), - multipart: a.array - ? multipartData - : {chunked: a.chunked, data: multipartData} + multipart: multipartData + } + if (a.header) { + reqOptions.headers = { + 'content-type': a.header + } } if (a.json) { reqOptions.json = true @@ -111,60 +98,26 @@ function runTest(t, a) { t.end() }) }) - }) } -// array - multipart option is array -// object - multipart option is object -// encoding - headers option have transfer-encoding set to chunked -// mixed - headers option have content-type set to something different than multipart/related -// json - json option -// stream - body contains streams or not -// chunked - chunked is set when multipart is object - -// var methods = ['post', 'get'] -var cases = [ - // based on body type - {name: '+array -stream', args: {array: true, encoding: false, stream: false}}, - {name: '+array +stream', args: {array: true, encoding: false, stream: true}}, - // encoding overrides stream - {name: '+array +encoding', args: {array: true, encoding: true, stream: false}}, - - // based on body type - {name: '+object -stream', args: {object: true, encoding: false, stream: false}}, - {name: '+object +stream', args: {object: true, encoding: false, stream: true}}, - // encoding overrides stream - {name: '+object +encoding', args: {object: true, encoding: true, stream: false}}, - - // based on body type - {name: '+object -chunked -stream', args: {object: true, encoding: false, chunked: false, stream: false}}, - {name: '+object -chunked +stream', args: {object: true, encoding: false, chunked: false, stream: true}}, - // chunked overrides stream - {name: '+object +chunked -stream', args: {object: true, encoding: false, chunked: true, stream: false}}, - // chunked overrides encoding - {name: '+object +encoding -chunked', args: {object: true, encoding: true, chunked: false, stream: false}}, - // stream overrides chunked - {name: '+object +encoding -chunked +stream', args: {object: true, encoding: true, chunked: false, stream: true}} +var testHeaders = [ + null, + 'multipart/mixed', + 'multipart/related; boundary=XXX; type=text/xml; start=""' ] var suite = ['post', 'get'].forEach(function(method) { - [true, false].forEach(function(json) { - [true, false].forEach(function(mixed) { - cases.forEach(function (test) { - var name = [ - 'multipart related', method, - (json ? '+' : '-') + 'json', - (mixed ? '+' : '-') + 'mixed', - test.name - ].join(' ') - - tape(name, function(t) { - test.args.method = method - test.args.json = json - test.args.mixed = mixed - runTest(t, test.args) - }) + testHeaders.forEach(function(header) { + [true, false].forEach(function(json) { + var name = [ + 'multipart-related', method.toUpperCase(), + (header || 'default'), + (json ? '+' : '-') + 'json' + ].join(' ') + + tape(name, function(t) { + runTest(t, {method: method, header: header, json: json}) }) }) }) From eecbaf89a35700275e9d744fcffcfddd3d4fcc4d Mon Sep 17 00:00:00 2001 From: Mikeal Rogers Date: Thu, 12 Feb 2015 12:29:09 -0800 Subject: [PATCH 004/490] Removing check for connection header as keep-alive is now default. --- tests/test-proxy-connect.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/test-proxy-connect.js b/tests/test-proxy-connect.js index cc3596874..aa2e35fd2 100644 --- a/tests/test-proxy-connect.js +++ b/tests/test-proxy-connect.js @@ -52,7 +52,7 @@ tape('proxy', function(t) { t.equal(err, null) t.equal(res.statusCode, 200) t.equal(body, 'derp\n') - t.equal(data, [ + var re = new RegExp([ 'CONNECT google.com:80 HTTP/1.1', 'Proxy-Authorization: Basic dXNlcjpwYXNz', 'dont-send-to-dest: ok', @@ -67,10 +67,8 @@ tape('proxy', function(t) { 'accept: yo', 'user-agent: just another foobar', 'host: google.com', - 'Connection: keep-alive', - '', - '' ].join('\r\n')) + t.equal(true, re.test(data)) t.equal(called, true, 'the request must be made to the proxy server') t.end() }) From 355fd44080cd364a166d4d683a39f0ac200851da Mon Sep 17 00:00:00 2001 From: Mikeal Rogers Date: Thu, 12 Feb 2015 13:08:22 -0800 Subject: [PATCH 005/490] Moving to standard stream api. --- tests/test-headers.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/test-headers.js b/tests/test-headers.js index 773cf863d..a01338cae 100644 --- a/tests/test-headers.js +++ b/tests/test-headers.js @@ -94,11 +94,9 @@ tape('upper-case Host header and redirect', function(t) { // core lower-cases the headers) var rawData = '' s.on('connection', function(socket) { - var ondata = socket.ondata - socket.ondata = function(d, start, end) { - rawData += d.slice(start, end).toString() - return ondata.apply(this, arguments) - } + socket.on('data', function(d) { + rawData += d + }) }) function checkHostHeader(host) { From 76b236e8eb95c75fd810e764bab67fdcba5b2db7 Mon Sep 17 00:00:00 2001 From: Mikeal Rogers Date: Thu, 12 Feb 2015 13:09:01 -0800 Subject: [PATCH 006/490] Relaxing comparison to cover differences in error messages. --- tests/test-localAddress.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-localAddress.js b/tests/test-localAddress.js index 4445001d5..1a1723b42 100644 --- a/tests/test-localAddress.js +++ b/tests/test-localAddress.js @@ -9,7 +9,7 @@ tape('bind to invalid address', function(t) { localAddress: '1.2.3.4' }, function(err, res) { t.notEqual(err, null) - t.equal(err.message, 'bind EADDRNOTAVAIL') + t.equal(true, /bind EADDRNOTAVAIL/.test(err.message)) t.equal(res, undefined) t.end() }) From b860c41fa6b698beca4f6c5fc7cb853c24dd4f97 Mon Sep 17 00:00:00 2001 From: Mikeal Rogers Date: Thu, 12 Feb 2015 13:16:15 -0800 Subject: [PATCH 007/490] Fixing lint error. --- tests/test-proxy-connect.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-proxy-connect.js b/tests/test-proxy-connect.js index aa2e35fd2..60e6bab87 100644 --- a/tests/test-proxy-connect.js +++ b/tests/test-proxy-connect.js @@ -66,7 +66,7 @@ tape('proxy', function(t) { 'dont-send-to-proxy: ok', 'accept: yo', 'user-agent: just another foobar', - 'host: google.com', + 'host: google.com' ].join('\r\n')) t.equal(true, re.test(data)) t.equal(called, true, 'the request must be made to the proxy server') From c865d71c1000e93081bd0c363edb84df8fbc54b4 Mon Sep 17 00:00:00 2001 From: Mikeal Rogers Date: Thu, 12 Feb 2015 13:27:23 -0800 Subject: [PATCH 008/490] Fixing to work again on 0.10's broken stream implementation. --- tests/test-headers.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/tests/test-headers.js b/tests/test-headers.js index a01338cae..0b8777124 100644 --- a/tests/test-headers.js +++ b/tests/test-headers.js @@ -93,10 +93,21 @@ tape('upper-case Host header and redirect', function(t) { // Horrible hack to observe the raw data coming to the server (before Node // core lower-cases the headers) var rawData = '' + s.on('connection', function(socket) { - socket.on('data', function(d) { - rawData += d - }) + if (socket.ondata) { + var ondata = socket.ondata + } + function handledata (d, start, end) { + if (ondata) { + rawData += d.slice(start, end).toString() + return ondata.apply(this, arguments) + } else { + rawData += d + } + } + socket.on('data', handledata) + socket.ondata = handledata }) function checkHostHeader(host) { From 7ae61b5f79c106a9404491304580f5e1a2cdf25a Mon Sep 17 00:00:00 2001 From: James Nylen Date: Fri, 13 Feb 2015 09:55:24 -0600 Subject: [PATCH 009/490] Deprecate Node v0.8.x --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0988483f3..b67e2afba 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,6 @@ language: node_js node_js: - - "0.8" - "0.10" -before_install: npm install -g npm@~1.4.6 after_script: ./node_modules/.bin/istanbul cover ./node_modules/tape/bin/tape tests/test-*.js --report lcovonly && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js --verbose webhooks: urls: https://webhooks.gitter.im/e/237280ed4796c19cc626 From 1f895d55be33811a37ae583593d6b70be33cf1ee Mon Sep 17 00:00:00 2001 From: Mordy Tikotzky Date: Sun, 15 Feb 2015 10:19:33 -0500 Subject: [PATCH 010/490] failing test for setting head with a body --- tests/test-errors.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/test-errors.js b/tests/test-errors.js index fde97fefe..bb5ab7ccc 100644 --- a/tests/test-errors.js +++ b/tests/test-errors.js @@ -77,3 +77,22 @@ tape('multipart without body 2', function(t) { }, /^Error: Body attribute missing in multipart\.$/) t.end() }) + +tape('head method with a body', function(t) { + t.throws(function() { + request(local, { + method: 'HEAD', + body: 'foo' + }) + }, /HTTP HEAD requests MUST NOT include a request body/) + t.end() +}) + +tape('head method with a body 2', function(t) { + t.throws(function() { + request.head(local, { + body: 'foo' + }) + }, /HTTP HEAD requests MUST NOT include a request body/) + t.end() +}) From d6c911df9310e2115c21445f90058f1003cd55f7 Mon Sep 17 00:00:00 2001 From: Mordy Tikotzky Date: Sun, 15 Feb 2015 10:21:49 -0500 Subject: [PATCH 011/490] throw error if method is head and sending a body --- index.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 3581b83b4..28c6cf9b6 100755 --- a/index.js +++ b/index.js @@ -47,6 +47,10 @@ function request (uri, options, callback) { options.callback = params.callback options.uri = params.uri + if (params.options.method === 'HEAD' && paramsHaveRequestBody(params)) { + throw new Error('HTTP HEAD requests MUST NOT include a request body.') + } + return new request.Request(options) } @@ -66,11 +70,6 @@ request.get = function (uri, options, callback) { request.head = function (uri, options, callback) { var params = initParams(uri, options, callback) params.options.method = 'HEAD' - - if (paramsHaveRequestBody(params)) { - throw new Error('HTTP HEAD requests MUST NOT include a request body.') - } - return requester(params)(params.uri || null, params.options, params.callback) } From b845f5a75773df1820115d48c058c270a9b3fffc Mon Sep 17 00:00:00 2001 From: Mordy Tikotzky Date: Sun, 15 Feb 2015 10:42:14 -0500 Subject: [PATCH 012/490] failing test for recursive requester when using `request.METHOD` --- tests/test-defaults.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/test-defaults.js b/tests/test-defaults.js index ec827be68..c4d4d66ac 100644 --- a/tests/test-defaults.js +++ b/tests/test-defaults.js @@ -213,6 +213,35 @@ tape('recursive defaults', function(t) { }) }) +tape('recursive defaults requester', function(t) { + t.plan(4) + + var defaultsOne = request.defaults({}, function(options, callback) { + var headers = options.headers || {} + headers.foo = 'bar1' + options.headers = headers + + request(options, callback) + }) + , defaultsTwo = defaultsOne.defaults({}, function(options, callback) { + var headers = options.headers || {} + headers.baz = 'bar2' + options.headers = headers + + defaultsOne(options, callback) + }) + + defaultsOne.get(s.url + '/get_recursive1', function (e, r, b) { + t.equal(e, null) + t.equal(b, 'TESTING!') + }) + + defaultsTwo.get(s.url + '/get_recursive2', function (e, r, b) { + t.equal(e, null) + t.equal(b, 'TESTING!') + }) +}) + tape('test custom request handler function', function(t) { t.plan(2) From 09358c3f5d8ba7e5335300413f1a08f2bc3dfc83 Mon Sep 17 00:00:00 2001 From: Mordy Tikotzky Date: Sun, 15 Feb 2015 10:43:13 -0500 Subject: [PATCH 013/490] fix recursive requester when using `request.METHOD` --- index.js | 39 ++++++++++++++------------------------- 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/index.js b/index.js index 28c6cf9b6..48ddb9170 100755 --- a/index.js +++ b/index.js @@ -54,47 +54,40 @@ function request (uri, options, callback) { return new request.Request(options) } -function requester(params) { - if(typeof params.options._requester === 'function') { - return params.options._requester - } - return request -} - request.get = function (uri, options, callback) { var params = initParams(uri, options, callback) params.options.method = 'GET' - return requester(params)(params.uri || null, params.options, params.callback) + return this(params.uri || null, params.options, params.callback) } request.head = function (uri, options, callback) { var params = initParams(uri, options, callback) params.options.method = 'HEAD' - return requester(params)(params.uri || null, params.options, params.callback) + return this(params.uri || null, params.options, params.callback) } request.post = function (uri, options, callback) { var params = initParams(uri, options, callback) params.options.method = 'POST' - return requester(params)(params.uri || null, params.options, params.callback) + return this(params.uri || null, params.options, params.callback) } request.put = function (uri, options, callback) { var params = initParams(uri, options, callback) params.options.method = 'PUT' - return requester(params)(params.uri || null, params.options, params.callback) + return this(params.uri || null, params.options, params.callback) } request.patch = function (uri, options, callback) { var params = initParams(uri, options, callback) params.options.method = 'PATCH' - return requester(params)(params.uri || null, params.options, params.callback) + return this(params.uri || null, params.options, params.callback) } request.del = function (uri, options, callback) { var params = initParams(uri, options, callback) params.options.method = 'DELETE' - return requester(params)(params.uri || null, params.options, params.callback) + return this(params.uri || null, params.options, params.callback) } request.jar = function (store) { @@ -130,11 +123,7 @@ request.defaults = function (options, requester) { } if (isFunction(requester)) { - if (method === self) { - method = requester - } else { - params.options._requester = requester - } + method = requester } return method(params.options, params.callback) @@ -142,13 +131,13 @@ request.defaults = function (options, requester) { } var defaults = wrap(self) - defaults.get = wrap(self.get) - defaults.patch = wrap(self.patch) - defaults.post = wrap(self.post) - defaults.put = wrap(self.put) - defaults.head = wrap(self.head) - defaults.del = wrap(self.del) - defaults.cookie = wrap(self.cookie) + 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 defaults.jar = self.jar defaults.defaults = self.defaults return defaults From cbb4f18557af2d08cd14a800da2f2f8dbe37a547 Mon Sep 17 00:00:00 2001 From: Seth Pollack Date: Tue, 17 Feb 2015 21:04:00 -0500 Subject: [PATCH 014/490] dry up verb methods --- index.js | 45 ++++++++++----------------------------------- 1 file changed, 10 insertions(+), 35 deletions(-) diff --git a/index.js b/index.js index 48ddb9170..7be6c4e00 100755 --- a/index.js +++ b/index.js @@ -54,41 +54,16 @@ function request (uri, options, callback) { return new request.Request(options) } -request.get = function (uri, options, callback) { - var params = initParams(uri, options, callback) - params.options.method = 'GET' - return this(params.uri || null, params.options, params.callback) -} - -request.head = function (uri, options, callback) { - var params = initParams(uri, options, callback) - params.options.method = 'HEAD' - return this(params.uri || null, params.options, params.callback) -} - -request.post = function (uri, options, callback) { - var params = initParams(uri, options, callback) - params.options.method = 'POST' - return this(params.uri || null, params.options, params.callback) -} - -request.put = function (uri, options, callback) { - var params = initParams(uri, options, callback) - params.options.method = 'PUT' - return this(params.uri || null, params.options, params.callback) -} - -request.patch = function (uri, options, callback) { - var params = initParams(uri, options, callback) - params.options.method = 'PATCH' - return this(params.uri || null, params.options, params.callback) -} - -request.del = function (uri, options, callback) { - var params = initParams(uri, options, callback) - params.options.method = 'DELETE' - return this(params.uri || null, params.options, params.callback) -} +var verbs = ['get', 'head', 'post', 'put', 'patch', 'del'] + +verbs.forEach(function(verb){ + var method = verb === 'del' ? 'DELETE' : verb.toUpperCase() + 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) + } +}) request.jar = function (store) { return cookies.jar(store) From e8eb1e3edb1b20ac760a6d0b037b7b812d3202a5 Mon Sep 17 00:00:00 2001 From: Mordy Tikotzky Date: Tue, 17 Feb 2015 15:10:56 -0500 Subject: [PATCH 015/490] Add ability to set a requester without setting default options --- index.js | 6 ++++++ tests/test-defaults.js | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/index.js b/index.js index 48ddb9170..6da328048 100755 --- a/index.js +++ b/index.js @@ -99,6 +99,12 @@ request.cookie = function (str) { } request.defaults = function (options, requester) { + + if (typeof options === 'function') { + requester = options + options = {} + } + var self = this var wrap = function (method) { var headerlessOptions = function (options) { diff --git a/tests/test-defaults.js b/tests/test-defaults.js index c4d4d66ac..09131a172 100644 --- a/tests/test-defaults.js +++ b/tests/test-defaults.js @@ -266,6 +266,23 @@ tape('test custom request handler function', function(t) { }) }) +tape('test custom request handler function without options', function(t) { + t.plan(1) + + var customHandlerWithoutOptions = request.defaults(function(uri, options, callback) { + var params = request.initParams(uri, options, callback) + var headers = params.options.headers || {} + headers.x = 'y' + headers.foo = 'bar' + params.options.headers = headers + return request(params.uri, params.options, params.callback) + }) + + customHandlerWithoutOptions.get(s.url + '/get_custom', function(e, r, b) { + t.equal(e, null) + }) +}) + tape('test only setting undefined properties', function(t) { request.defaults({ method: 'post', From 237e80fe076680669da7f1d3b42b9cba19e91e1c Mon Sep 17 00:00:00 2001 From: 0x4139 <0x4139@gmail.com> Date: Thu, 19 Feb 2015 13:02:35 +0200 Subject: [PATCH 016/490] fixes the redirect initialization of an object when localAddress or proxy is lost due to the reinitialization without parameters of the request object --- lib/redirect.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/redirect.js b/lib/redirect.js index 2d9a9d518..ff6c32fda 100644 --- a/lib/redirect.js +++ b/lib/redirect.js @@ -138,7 +138,10 @@ Redirect.prototype.onResponse = function (response) { request.emit('redirect') - request.init() + request.init({ + localAddress:self.localAddress, + proxy:self.proxy + }) return true } From 93affc4acc2285dd6ba0c91306df21ae51580271 Mon Sep 17 00:00:00 2001 From: 0x4139 <0x4139@gmail.com> Date: Thu, 19 Feb 2015 15:08:35 +0200 Subject: [PATCH 017/490] bind to localAddress on redirect, and the afferent test --- lib/redirect.js | 6 ++-- tests/test-localAddress.js | 66 ++++++++++++++++++++++++++------------ 2 files changed, 48 insertions(+), 24 deletions(-) diff --git a/lib/redirect.js b/lib/redirect.js index ff6c32fda..b086c1992 100644 --- a/lib/redirect.js +++ b/lib/redirect.js @@ -138,9 +138,9 @@ Redirect.prototype.onResponse = function (response) { request.emit('redirect') - request.init({ - localAddress:self.localAddress, - proxy:self.proxy + request.init({ + localAddress:request.localAddress, + proxy:request.proxy }) return true diff --git a/tests/test-localAddress.js b/tests/test-localAddress.js index 4445001d5..648f422df 100644 --- a/tests/test-localAddress.js +++ b/tests/test-localAddress.js @@ -1,27 +1,51 @@ 'use strict' - var request = require('../index') - , tape = require('tape') + , tape = require('tape') + +tape('bind to invalid address', function (t) { + request.get({ + uri: 'http://www.google.com', + localAddress: '1.2.3.4' + }, function (err, res) { + t.notEqual(err, null) + t.equal(err.message, 'bind EADDRNOTAVAIL') + t.equal(res, undefined) + t.end() + }) +}) -tape('bind to invalid address', function(t) { - request.get({ - uri: 'http://www.google.com', - localAddress: '1.2.3.4' - }, function(err, res) { - t.notEqual(err, null) - t.equal(err.message, 'bind EADDRNOTAVAIL') - t.equal(res, undefined) - t.end() - }) +tape('bind to local address', function (t) { + request.get({ + uri: 'http://www.google.com', + localAddress: '127.0.0.1' + }, function (err, res) { + t.notEqual(err, null) + t.equal(res, undefined) + t.end() + }) }) -tape('bind to local address', function(t) { - request.get({ - uri: 'http://www.google.com', - localAddress: '127.0.0.1' - }, function(err, res) { - t.notEqual(err, null) - t.equal(res, undefined) - t.end() - }) +tape('bind to local address on redirect', function (t) { + var os = require('os') + var localInterfaces = os.networkInterfaces() + var localIPS=[] + Object.keys(localInterfaces).forEach(function (ifname) { + localInterfaces[ifname].forEach(function (iface) { + if ('IPv4' !== iface.family || iface.internal !== false) { + // skip over internal (i.e. 127.0.0.1) and non-ipv4 addresses + return; + } + localIPS.push(iface.address); + }); + }); + request.get({ + uri: 'http://google.com', //redirects to 'http://google.com' + localAddress: localIPS[0] + }, function (err, res) { + t.equal(err, null) + res.body = ""; + console.log(res.request.method); + t.equal(res.request.localAddress, localIPS[0]) + t.end() + }) }) From 92be4017f436b32634e79c68a67962e773c27534 Mon Sep 17 00:00:00 2001 From: 0x4139 <0x4139@gmail.com> Date: Thu, 19 Feb 2015 15:10:24 +0200 Subject: [PATCH 018/490] cleans up test-localAddress --- tests/test-localAddress.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/test-localAddress.js b/tests/test-localAddress.js index 648f422df..325b2985a 100644 --- a/tests/test-localAddress.js +++ b/tests/test-localAddress.js @@ -43,8 +43,6 @@ tape('bind to local address on redirect', function (t) { localAddress: localIPS[0] }, function (err, res) { t.equal(err, null) - res.body = ""; - console.log(res.request.method); t.equal(res.request.localAddress, localIPS[0]) t.end() }) From 52316f7d4e0aff3da49235084108002b74b41b24 Mon Sep 17 00:00:00 2001 From: Ollie Relph Date: Fri, 20 Feb 2015 12:57:01 +0000 Subject: [PATCH 019/490] Set cipher to one that matches the certificates used for testing strictSSL --- tests/server.js | 2 +- tests/test-https.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/server.js b/tests/server.js index e6f398dee..c8556f5e8 100644 --- a/tests/server.js +++ b/tests/server.js @@ -34,7 +34,7 @@ exports.createSSLServer = function(port, opts) { } for (i in options) { - if (i !== 'requestCert' && i !== 'rejectUnauthorized') { + if (i !== 'requestCert' && i !== 'rejectUnauthorized' && i !== 'ciphers') { options[i] = fs.readFileSync(options[i]) } } diff --git a/tests/test-https.js b/tests/test-https.js index 04b1aa423..396a73d83 100644 --- a/tests/test-https.js +++ b/tests/test-https.js @@ -13,6 +13,7 @@ var s = server.createSSLServer() , caFile = path.resolve(__dirname, 'ssl/ca/ca.crt') , ca = fs.readFileSync(caFile) , opts = { + ciphers: 'AES256-SHA', key: path.resolve(__dirname, 'ssl/ca/server.key'), cert: path.resolve(__dirname, 'ssl/ca/server.crt') } From 90dcc2e37380bfbe5d07554e6ef03a45585dd2ea Mon Sep 17 00:00:00 2001 From: guimonz Date: Mon, 23 Feb 2015 20:56:42 -0300 Subject: [PATCH 020/490] Fix issue #1038 --- lib/redirect.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/redirect.js b/lib/redirect.js index 2d9a9d518..46b05d269 100644 --- a/lib/redirect.js +++ b/lib/redirect.js @@ -136,6 +136,7 @@ Redirect.prototype.onResponse = function (response) { } } + request.setHeader('referer', request.uri.href) request.emit('redirect') request.init() From 1a557f5c6a8940253881a45d83c6e3596b72efcd Mon Sep 17 00:00:00 2001 From: guimonz Date: Tue, 24 Feb 2015 00:32:21 -0300 Subject: [PATCH 021/490] adding removeRefererHeader flag to disable the Referer if needed and regenerating the test certificates (were expired) --- README.md | 1 + lib/redirect.js | 9 ++++++- tests/ssl/ca/client-enc.key | 52 ++++++++++++++++++------------------- tests/ssl/ca/client.crt | 24 ++++++++--------- tests/ssl/ca/client.csr | 26 +++++++++---------- tests/ssl/ca/client.key | 50 +++++++++++++++++------------------ tests/ssl/ca/gen-client.sh | 2 +- tests/ssl/ca/localhost.crt | 22 ++++++++-------- tests/ssl/ca/localhost.csr | 26 +++++++++---------- tests/ssl/ca/localhost.key | 50 +++++++++++++++++------------------ 10 files changed, 135 insertions(+), 127 deletions(-) diff --git a/README.md b/README.md index d5aeec375..00f4b17d6 100644 --- a/README.md +++ b/README.md @@ -633,6 +633,7 @@ The first argument can be either a `url` or an `options` object. The only requir tunneling proxy. * `proxyHeaderExclusiveList` - A whitelist of headers to send exclusively to a tunneling proxy and not to destination. +* `removeRefererHeader` - removes the referer header when a redirect happens (default: `false`). The callback argument gets 3 arguments: diff --git a/lib/redirect.js b/lib/redirect.js index 46b05d269..97b133d27 100644 --- a/lib/redirect.js +++ b/lib/redirect.js @@ -12,6 +12,7 @@ function Redirect (request) { this.maxRedirects = 10 this.redirects = [] this.redirectsFollowed = 0 + this.removeRefererHeader = false } Redirect.prototype.onRequest = function () { @@ -33,6 +34,9 @@ Redirect.prototype.onRequest = function () { if (self.followRedirects || self.followAllRedirects) { self.redirects = self.redirects || [] } + if (request.removeRefererHeader !== undefined) { + self.removeRefererHeader = request.removeRefererHeader + } } Redirect.prototype.redirectTo = function (response) { @@ -136,7 +140,10 @@ Redirect.prototype.onResponse = function (response) { } } - request.setHeader('referer', request.uri.href) + if (!self.removeRefererHeader) { + request.setHeader('referer', request.uri.href) + } + request.emit('redirect') request.init() diff --git a/tests/ssl/ca/client-enc.key b/tests/ssl/ca/client-enc.key index 8875c9ffc..f486c14a7 100644 --- a/tests/ssl/ca/client-enc.key +++ b/tests/ssl/ca/client-enc.key @@ -1,30 +1,30 @@ -----BEGIN RSA PRIVATE KEY----- Proc-Type: 4,ENCRYPTED -DEK-Info: AES-128-CBC,E95AEBB470632DA50EC1ABAB7F2D7A2A +DEK-Info: AES-128-CBC,849C363BAF8E1693D5464248A4AFD61A -FDVPpWyXyUn3f+mYpHyQIWa2bnqfnzffLjrZky938WSL43hHL5XmqXXcgemQsoeb -abz68jYpVfDicvcgHprv40c69ZAKv1lmN11P9mHzRmI6HHo1oaQ2Sn13UHxX425W -NZ8IBREbSxm65a5zBYFLQXamNVBkR1z5EIoU/1FJz5CY9TAlmWYrybtUVHbc7V4S -GiiyD0Cm5fyg/436p9bcZPvXxalep9903eWd5kl1A+WO05Sin1Ilk5OVCFLMIiuM -yq4MCtONumDdIWoiSGT488P+/eMe5gfxYGseNR0AEWHYIM+Fptd2qxj9QM6CO6Pc -8EDoPs5zUXitCsTKR1tsNI7WnldMnQGf5J4SG2X5jXX3fyX534bbEBkA/CtkkdCa -A4rjrbBpMpijnq6yEsOxMOE9pqvJsWtBVdVtFtw/bx+oBKD3S2IUn3DVhSFjs62R -OSsWCT8zY0B8+EwXBPQjmfjAU/dq21ot3jxvy5fl627wM1TuEnsrqMiGxZe5mkXJ -wg9Y0c6K4Qwr5bbYIf7WvsMoKj0PfU9NRBUymSdZnaFlNSe5RguBCokaYD9/Kn9E -wyf5AKlI3LrdUk+9AmOKKmejPCzPBaGnhZjpFLLbV2pCkT3pRlrnGk5zvEKLKTdx -MjYzBxxbbBqAk5VHwN5t7D0aPerVPHsyt2bfBC2FWQAbpil70O2KHe90UbAh2VpZ -ofc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U95nVY +EeqwrW/4gUSm113N9riq9Mm2FnWjVKvsB2RuvfIYC9ZALoRyf9igN39DGrxw7rFX +ei7eyYMXBp2stdWAZx+jGy7ifA7vbyAnShNp3Kn7SIdBWFXOotN9gf15ZLhof3aQ +J354cLL2KDnf7whYk7L4sT3BKjOdOG9FcFtehlHFuIfyZzpntUw8AuC8PIeDdbSf +opmEpY49Tt2/roizXfjWloKxyxUFWKx3yKQBc+YzPzTCzZ36NuwSSRRn4f41cCC/ +L425Jm+Zu+NtI1P39qgDIAOREsKnbUrhKhCWAG133Ix7UCoMn8CgAfPWSDT9p81r +BkuF8bOfJZSiFqUdRgSe55Po2AVWbxOx9SwKhgfexl/Ku9TLTlLvOJmxUi7fFB0v -----END RSA PRIVATE KEY----- diff --git a/tests/ssl/ca/client.crt b/tests/ssl/ca/client.crt index 338387b9e..18f59f5b2 100644 --- a/tests/ssl/ca/client.crt +++ b/tests/ssl/ca/client.crt @@ -1,20 +1,20 @@ -----BEGIN CERTIFICATE----- -MIIDLjCCApcCCQCt9iAWqkDJwzANBgkqhkiG9w0BAQUFADCBojELMAkGA1UEBhMC +MIIDLjCCApcCCQCt9iAWqkDJwzANBgkqhkiG9w0BAQsFADCBojELMAkGA1UEBhMC VVMxCzAJBgNVBAgTAkNBMRAwDgYDVQQHEwdPYWtsYW5kMRAwDgYDVQQKEwdyZXF1 ZXN0MSYwJAYDVQQLEx1yZXF1ZXN0IENlcnRpZmljYXRlIEF1dGhvcml0eTESMBAG A1UEAxMJcmVxdWVzdENBMSYwJAYJKoZIhvcNAQkBFhdtaWtlYWxAbWlrZWFscm9n -ZXJzLmNvbTAeFw0xNTAxMjYyMTAxMjNaFw0xNTAyMjUyMTAxMjNaMIGPMQswCQYD +ZXJzLmNvbTAeFw0xNTAyMjQwMzIwNDNaFw0xNTAzMjYwMzIwNDNaMIGPMQswCQYD VQQGEwJVUzELMAkGA1UECBMCQ0ExEDAOBgNVBAcTB09ha2xhbmQxEDAOBgNVBAoT B3JlcX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uHbSUjv6P97YWFHHaggaYtQunAgMBAAEw +DQYJKoZIhvcNAQELBQADgYEAqtIehtQ+wfpOlF9inePBMmuMpd/VQ5Z1tQ25mqfo +NbmV6M6BEd26IVn+CAUmy+Gyh4PZXd03jp74HkSkMmdsIuva7n1/6SQ9O1ssqj/r +p+y8pzgabMId+WfBxpQkLzGDjNY8UPogARO1FcOog/81s0HbhLug098LaIIWjIl9 +d/w= -----END CERTIFICATE----- diff --git a/tests/ssl/ca/client.csr b/tests/ssl/ca/client.csr index 2186fe53d..4dd03c3a3 100644 --- a/tests/ssl/ca/client.csr +++ b/tests/ssl/ca/client.csr @@ -2,17 +2,17 @@ MIIC+DCCAeACAQAwgY8xCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJDQTEQMA4GA1UE BxMHT2FrbGFuZDEQMA4GA1UEChMHcmVxdWVzdDEaMBgGA1UECxQRcmVxdWVzdEBs b2NhbGhvc3QxEzARBgNVBAMTClRlc3RDbGllbnQxHjAcBgkqhkiG9w0BCQEWD2Rv -Lm5vdEBlbWFpbC5tZTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMkO -cTOBamCwTJBwxCeRNObu4U0pg4zvpEgPht0rakdsWVbhkRYL/9EV57heQDMjhipr -S2FJpAGWb9mtAPnDzZeUc1Qy0C4Ik98gwYpRhIG/wvboGPbdfweO7Wfxt2/KoCYu -HSu8u8cXSDwCK2mJC+f4MCGdXsCy3lrzuZRsKgG0ROac5nUdCTx4gn7eRnRZpOYn -LdZjyU/4sDrios4LuSkgqR4ElROd2d513yCerzsCV7VfAsgtTE3WER9sFcsbarGv -xgPJTOe1AwAQM3Ak/yKQJybxiJr4W2nu+6KhW3BH0biVOf7ctjANXaaSLYgCNnRt -NWjAlcW7oDD24uab02kCAwEAAaAjMCEGCSqGSIb3DQEJBzEUExJwYXNzd29yZCBj -aGFsbGVuZ2UwDQYJKoZIhvcNAQELBQADggEBACEqC+TJTli7enf064IaIbaJvN2+ -KyHgOmWvj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v+lyUZlNA6g3aBEI7WmSoC91Gu2g4Kao19XD +EeXjPL81D6Q8vhSEcq4Rdg7SEobpPUbREizBblHwXGavCRiBWsGE1AHyjeI= -----END CERTIFICATE REQUEST----- diff --git a/tests/ssl/ca/client.key b/tests/ssl/ca/client.key index a61e755cf..b1adfee13 100644 --- a/tests/ssl/ca/client.key +++ b/tests/ssl/ca/client.key @@ -1,27 +1,27 @@ -----BEGIN RSA PRIVATE KEY----- -MIIEpAIBAAKCAQEAyQ5xM4FqYLBMkHDEJ5E05u7hTSmDjO+kSA+G3StqR2xZVuGR -Fgv/0RXnuF5AMyOGKmtLYUmkAZZv2a0A+cPNl5RzVDLQLgiT3yDBilGEgb/C9ugY -9t1/B47tZ/G3b8qgJi4dK7y7xxdIPAIraYkL5/gwIZ1ewLLeWvO5lGwqAbRE5pzm -dR0JPHiCft5GdFmk5ict1mPJT/iwOuKizgu5KSCpHgSVE53Z3nXfIJ6vOwJXtV8C -yC1MTdYRH2wVyxtqsa/GA8lM57UDABAzcCT/IpAnJvGImvhbae77oqFbcEfRuJU5 -/ty2MA1dppItiAI2dG01aMCVxbugMPbi5pvTaQIDAQABAoIBAB27wQn47Z529Bu4 -UYn4c3ZjhXY/2XCSUB1IDo3OydzeLSgoG6jDBYYKU0Z0ydHGQyUq0O8GUPbbJJdw -emB1kIYGMjgVe6wTIKsy0Ox/ubTmgxK4qFh50Ttw67MfkB08PgrnbvD07GA5FTmq -qHjnB5e6oIOYHlcpHLEesic9B8lQeHWvCDdmoSS/qSw3t/GR02rlQjE/tEwMDGSl -sDbm/3SgWBFDiNuZsewP3rq+ZaK0BQ2g9BDZjTXQEdyuqEfqZg1idx5UIYUBlaHD -qoT6DxQdhZVk5+DIABHSRhK0InegxtQTVXOwR7HeJFtyu4QqLcfS3RVr8fiv3kx4 -8uoCngECgYEA4vMj6keOPkvHzWLCd8mzdHtQ8Iq+LstSqjYrw/Wu4vYNCbY2bHTD -ZTJYKRy7R81+PXTLZaOSPVVj/gGg/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Qzk1UQn5Pu6o1z9 +Y5a8tizS9fvDuCt1KdnSOKkrbIYR4E1vCoYFp/XYfchD6SaLNQQ5xV2ak08Unxg+ +GyPiuwKBgHh5kUYzHkD2TeSMfEEXx8Q2QNehZfyGHKLRlRW6GD/d/hJTO2tmK7pP +INi4AcTFXeM+Xs4j6h6yazN59VEz4aFp4j39K2GyFgPdVrN5xTW+xreVUtO71oqY +QHEGKdqwxMGBknQmloXM5/eQTZ7Tb3ClQstmiF4bEZyVimmfdmre -----END RSA PRIVATE KEY----- diff --git a/tests/ssl/ca/gen-client.sh b/tests/ssl/ca/gen-client.sh index 953223ef4..c0f6d3be6 100755 --- a/tests/ssl/ca/gen-client.sh +++ b/tests/ssl/ca/gen-client.sh @@ -20,4 +20,4 @@ openssl x509 -req \ -out client.crt # Encrypt with password -openssl rsa -aes128 -in client.key -out client-enc.key -passout 'password' +openssl rsa -aes128 -in client.key -out client-enc.key -passout 'pass:password' diff --git a/tests/ssl/ca/localhost.crt b/tests/ssl/ca/localhost.crt index 7c8ad98c8..7c3d2fe6c 100644 --- a/tests/ssl/ca/localhost.crt +++ b/tests/ssl/ca/localhost.crt @@ -3,18 +3,18 @@ MIIDLTCCApYCCQCt9iAWqkDJwzANBgkqhkiG9w0BAQsFADCBojELMAkGA1UEBhMC VVMxCzAJBgNVBAgTAkNBMRAwDgYDVQQHEwdPYWtsYW5kMRAwDgYDVQQKEwdyZXF1 ZXN0MSYwJAYDVQQLEx1yZXF1ZXN0IENlcnRpZmljYXRlIEF1dGhvcml0eTESMBAG A1UEAxMJcmVxdWVzdENBMSYwJAYJKoZIhvcNAQkBFhdtaWtlYWxAbWlrZWFscm9n -ZXJzLmNvbTAeFw0xNTAxMjQwNDEzMzVaFw0xNTAyMjMwNDEzMzVaMIGOMQswCQYD +ZXJzLmNvbTAeFw0xNTAyMjQwMzA4MTFaFw0xNTAzMjYwMzA4MTFaMIGOMQswCQYD VQQGEwJVUzELMAkGA1UECBMCQ0ExEDAOBgNVBAcT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eX4aMyHXNVx4KQeFvx2p5p1NfhIGPS83I79YDr5LAMso2QkECAwEAATAN +BgkqhkiG9w0BAQsFAAOBgQCJdR6oEMXPpsZ37N2V++WreQrj79RozT0p9yKy6Qjr +ynpgQDQyf9Lf+D1KPmjMHocy01prPiLuR5x3vbVtq/NGp+7zAJWBbQOhXBOz90JP +1gg7iFANrnDQCOKI9sW1+W/+1VwNYNSHfQL99lESBXm/lPRfF9/9nUkqj8FdOxu4 +SA== -----END CERTIFICATE----- diff --git a/tests/ssl/ca/localhost.csr b/tests/ssl/ca/localhost.csr index a74907d20..34c9be6ae 100644 --- a/tests/ssl/ca/localhost.csr +++ b/tests/ssl/ca/localhost.csr @@ -2,17 +2,17 @@ MIIC9zCCAd8CAQAwgY4xCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJDQTEQMA4GA1UE BxMHT2FrbGFuZDEQMA4GA1UEChMHcmVxdWVzdDEaMBgGA1UECxQRcmVxdWVzdEBs b2NhbGhvc3QxEjAQBgNVBAMTCWxvY2FsaG9zdDEeMBwGCSqGSIb3DQEJARYPZG8u -bm90QGVtYWlsLm1lMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnytB -wZtRZctlnRcCrQDk5Ib/K6e7QPnHkZyACuaJajYTCCR0YZ3cOsQKaxcCqDTksNM/ -wuM3nB2+10RdzhH69/nhU38IPfUC0Vcgt8YRBmKha12eL5P0rSMRxW6R2SUDAILW -OOmUnwzFNfIn2kRWjK/+1fgQUx/5rJSwNQJKslAtbTr2JXgZdCCVmvpRV9IbeKnj -7UkO8/QwpSGK19aSsBi1vybfQBJ9GPYt7/0eGEFbDEsMrUbbdOoLzpKp7QyGTlrV -XkMpk9qcOV3mNU0qWtdNQxTg5wtveZ2J0DLmRIWZFIkl1+Jx5eenp4EYrmQ4WhEj -KN4nRS3+e3DZztZwuwIDAQABoCMwIQYJKoZIhvcNAQkHMRQTEnBhc3N3b3JkIGNo -YWxsZW5nZTANBgkqhkiG9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ZY2Nt7YdkNjSM24qLzwE23v ++awtVA2u0ftMXf+wC4C5E/d9xRz8dWbc474DuvdAWBm57KEW/KjbVEc7qaM3WVz6 +UYaP0v65benTmoOpbNPjTKxpgB/CGFgtC9VKX8+wmIC9IOmfk0FYt/6Sow== -----END CERTIFICATE REQUEST----- diff --git a/tests/ssl/ca/localhost.key b/tests/ssl/ca/localhost.key index 2cfeaf458..f10bd2604 100644 --- a/tests/ssl/ca/localhost.key +++ b/tests/ssl/ca/localhost.key @@ -1,27 +1,27 @@ -----BEGIN RSA PRIVATE KEY----- -MIIEogIBAAKCAQEAnytBwZtRZctlnRcCrQDk5Ib/K6e7QPnHkZyACuaJajYTCCR0 -YZ3cOsQKaxcCqDTksNM/wuM3nB2+10RdzhH69/nhU38IPfUC0Vcgt8YRBmKha12e -L5P0rSMRxW6R2SUDAILWOOmUnwzFNfIn2kRWjK/+1fgQUx/5rJSwNQJKslAtbTr2 -JXgZdCCVmvpRV9IbeKnj7UkO8/QwpSGK19aSsBi1vybfQBJ9GPYt7/0eGEFbDEsM -rUbbdOoLzpKp7QyGTlrVXkMpk9qcOV3mNU0qWtdNQxTg5wtveZ2J0DLmRIWZFIkl -1+Jx5eenp4EYrmQ4WhEjKN4nRS3+e3DZztZwuwIDAQABAoIBAE3YJgy+HY0fcM7n -VhOugEOUEnATVG1uu7/nPmgWX9ZmI+Czk4e6YN8MydueIVqKo94nMuPppGTh11gI -w6fo+0kUGLNxSWKj1YD0j7fRUrpAupl768VxIxUaNbLNZN9CTrmNQ6AJ/PnckQbV -K9B/46Ri3steyv0cgkt5XMRQHqAd+OAMiqiSD03gxgcpnyPCskzgk48GIM1NhjwW -Q6ia0uIPUnak7KxW13F6yH9ddnNpS1CJdcStaZeFWlZgDGbTDef9Op2+f42CU54/ -bXlnb6pm8ZHv7NxkMS3ncObv1d1TD3qfFOQpLiWu8EdyqVrCKFbToTnwG0XdYKuG -1+GEe4ECgYEAzSnTI+INAxADuqu/M9KXSKtj30YdAo52s5z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Xo5suZtlPDZ +aDt9GtAlnWJpy5FOBgreNm2qQ/e6u+LpJcu7g0Dn1nKu68WTBiFtBd/FnT8083fi +Nc92DJ+YXUYG8d/GnvvJZVvwwhOZVl/yB8CNp3hPYbuVkGJzspAoDb43BjoBH37D +7VkqtQKBgQC6bLh5EzIZZDi7eDg8PV21soQyYxDt4e4fTq2DQhnbu6BvGiRQjTSk +p3139WsjFE7/Hip4hToqFn1plKwrV8m3PPoU04If+uu0eJLP3NURxMGafPD/Ny2x +mgorghk8Zp9xugD7deTvCCPy13NXtWnZgyVNmFyaynvHTveGI5zo7w== -----END RSA PRIVATE KEY----- From 7759f6006ccfa5f0bf4182c50942f381c4a840d6 Mon Sep 17 00:00:00 2001 From: 0x4139 <0x4139@gmail.com> Date: Wed, 25 Feb 2015 15:51:27 +0200 Subject: [PATCH 022/490] fixed linting --- tests/test-localAddress.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/test-localAddress.js b/tests/test-localAddress.js index 325b2985a..9d65dd157 100644 --- a/tests/test-localAddress.js +++ b/tests/test-localAddress.js @@ -28,16 +28,16 @@ tape('bind to local address', function (t) { tape('bind to local address on redirect', function (t) { var os = require('os') var localInterfaces = os.networkInterfaces() - var localIPS=[] + var localIPS = [] Object.keys(localInterfaces).forEach(function (ifname) { localInterfaces[ifname].forEach(function (iface) { - if ('IPv4' !== iface.family || iface.internal !== false) { + if (iface.family !== 'IPv4' || iface.internal !== false) { // skip over internal (i.e. 127.0.0.1) and non-ipv4 addresses - return; + return } - localIPS.push(iface.address); - }); - }); + localIPS.push(iface.address) + }) + }) request.get({ uri: 'http://google.com', //redirects to 'http://google.com' localAddress: localIPS[0] From ec179e0e9d08dd9a9be8a15c03932c283f88fb0a Mon Sep 17 00:00:00 2001 From: guimonz Date: Thu, 26 Feb 2015 03:16:42 -0300 Subject: [PATCH 023/490] adding tests for new behavior --- tests/test-redirect.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/test-redirect.js b/tests/test-redirect.js index d8301fb60..02e93c583 100644 --- a/tests/test-redirect.js +++ b/tests/test-redirect.js @@ -312,6 +312,40 @@ tape('http to https redirect', function(t) { }) }) +tape('should have the referer when following redirect by default', function(t) { + request.post({ + uri: s.url + '/temp', + jar: jar, + followAllRedirects: true, + headers: { cookie: 'foo=bar' } + }, function(err, res, body) { + t.equal(err, null) + t.equal(res.statusCode, 200) + t.end() + }) + .on('redirect',function() { + t.notEqual(this.headers.referer,undefined) + t.equal(this.headers.referer.substring(this.headers.referer.lastIndexOf('/')),'/temp_landing'); + }) +}) + +tape('should not have a referer when removeRefererHeader is true', function(t) { + request.post({ + uri: s.url + '/temp', + jar: jar, + followAllRedirects: true, + removeRefererHeader: true, + headers: { cookie: 'foo=bar' } + }, function(err, res, body) { + t.equal(err, null) + t.equal(res.statusCode, 200) + t.end() + }) + .on('redirect',function() { + t.equal(this.headers.referer,undefined) + }) +}) + tape('cleanup', function(t) { s.close(function() { ss.close(function() { From c4b710641068be09b392a700d083157630161c11 Mon Sep 17 00:00:00 2001 From: guimonz Date: Thu, 26 Feb 2015 03:20:04 -0300 Subject: [PATCH 024/490] removing semicolon --- tests/test-redirect.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-redirect.js b/tests/test-redirect.js index 02e93c583..f937abc31 100644 --- a/tests/test-redirect.js +++ b/tests/test-redirect.js @@ -325,7 +325,7 @@ tape('should have the referer when following redirect by default', function(t) { }) .on('redirect',function() { t.notEqual(this.headers.referer,undefined) - t.equal(this.headers.referer.substring(this.headers.referer.lastIndexOf('/')),'/temp_landing'); + t.equal(this.headers.referer.substring(this.headers.referer.lastIndexOf('/')),'/temp_landing') }) }) From 1f6fbd57b8e2be0071e9771846790dda137ebb9a Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 26 Feb 2015 08:23:49 +0200 Subject: [PATCH 025/490] Fix indentation and localAddress check in init --- lib/redirect.js | 5 +-- request.js | 4 ++- tests/test-localAddress.js | 74 +++++++++++++++++++------------------- 3 files changed, 41 insertions(+), 42 deletions(-) diff --git a/lib/redirect.js b/lib/redirect.js index b086c1992..2d9a9d518 100644 --- a/lib/redirect.js +++ b/lib/redirect.js @@ -138,10 +138,7 @@ Redirect.prototype.onResponse = function (response) { request.emit('redirect') - request.init({ - localAddress:request.localAddress, - proxy:request.proxy - }) + request.init() return true } diff --git a/request.js b/request.js index 6f1305a41..c6507620c 100644 --- a/request.js +++ b/request.js @@ -322,7 +322,9 @@ Request.prototype.init = function (options) { if (!self.method) { self.method = options.method || 'GET' } - self.localAddress = options.localAddress + if (!self.localAddress) { + self.localAddress = options.localAddress + } if (!self.qsLib) { self.qsLib = (options.useQuerystring ? querystring : qs) diff --git a/tests/test-localAddress.js b/tests/test-localAddress.js index 9d65dd157..faa52fae2 100644 --- a/tests/test-localAddress.js +++ b/tests/test-localAddress.js @@ -1,49 +1,49 @@ 'use strict' var request = require('../index') - , tape = require('tape') + , tape = require('tape') tape('bind to invalid address', function (t) { - request.get({ - uri: 'http://www.google.com', - localAddress: '1.2.3.4' - }, function (err, res) { - t.notEqual(err, null) - t.equal(err.message, 'bind EADDRNOTAVAIL') - t.equal(res, undefined) - t.end() - }) + request.get({ + uri: 'http://www.google.com', + localAddress: '1.2.3.4' + }, function (err, res) { + t.notEqual(err, null) + t.equal(err.message, 'bind EADDRNOTAVAIL') + t.equal(res, undefined) + t.end() + }) }) tape('bind to local address', function (t) { - request.get({ - uri: 'http://www.google.com', - localAddress: '127.0.0.1' - }, function (err, res) { - t.notEqual(err, null) - t.equal(res, undefined) - t.end() - }) + request.get({ + uri: 'http://www.google.com', + localAddress: '127.0.0.1' + }, function (err, res) { + t.notEqual(err, null) + t.equal(res, undefined) + t.end() + }) }) tape('bind to local address on redirect', function (t) { - var os = require('os') - var localInterfaces = os.networkInterfaces() - var localIPS = [] - Object.keys(localInterfaces).forEach(function (ifname) { - localInterfaces[ifname].forEach(function (iface) { - if (iface.family !== 'IPv4' || iface.internal !== false) { - // skip over internal (i.e. 127.0.0.1) and non-ipv4 addresses - return - } - localIPS.push(iface.address) - }) - }) - request.get({ - uri: 'http://google.com', //redirects to 'http://google.com' - localAddress: localIPS[0] - }, function (err, res) { - t.equal(err, null) - t.equal(res.request.localAddress, localIPS[0]) - t.end() + var os = require('os') + var localInterfaces = os.networkInterfaces() + var localIPS = [] + Object.keys(localInterfaces).forEach(function (ifname) { + localInterfaces[ifname].forEach(function (iface) { + if (iface.family !== 'IPv4' || iface.internal !== false) { + // skip over internal (i.e. 127.0.0.1) and non-ipv4 addresses + return + } + localIPS.push(iface.address) }) + }) + request.get({ + uri: 'http://google.com', //redirects to 'http://google.com' + localAddress: localIPS[0] + }, function (err, res) { + t.equal(err, null) + t.equal(res.request.localAddress, localIPS[0]) + t.end() + }) }) From bbcff4188629836662fb6e58c96cdf68f5876cc4 Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 26 Feb 2015 09:41:11 +0200 Subject: [PATCH 026/490] Indentation fixes --- lib/redirect.js | 6 +++--- tests/test-redirect.js | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/redirect.js b/lib/redirect.js index 97b133d27..7dd6c254c 100644 --- a/lib/redirect.js +++ b/lib/redirect.js @@ -140,10 +140,10 @@ Redirect.prototype.onResponse = function (response) { } } - if (!self.removeRefererHeader) { - request.setHeader('referer', request.uri.href) + if (!self.removeRefererHeader) { + request.setHeader('referer', request.uri.href) } - + request.emit('redirect') request.init() diff --git a/tests/test-redirect.js b/tests/test-redirect.js index f937abc31..f5cae24f8 100644 --- a/tests/test-redirect.js +++ b/tests/test-redirect.js @@ -324,8 +324,8 @@ tape('should have the referer when following redirect by default', function(t) { t.end() }) .on('redirect',function() { - t.notEqual(this.headers.referer,undefined) - t.equal(this.headers.referer.substring(this.headers.referer.lastIndexOf('/')),'/temp_landing') + t.notEqual(this.headers.referer, undefined) + t.equal(this.headers.referer.substring(this.headers.referer.lastIndexOf('/')),'/temp_landing') }) }) @@ -342,7 +342,7 @@ tape('should not have a referer when removeRefererHeader is true', function(t) { t.end() }) .on('redirect',function() { - t.equal(this.headers.referer,undefined) + t.equal(this.headers.referer, undefined) }) }) From aaf208ea83f19d6dee232999415540ec0913dfbe Mon Sep 17 00:00:00 2001 From: Nicolas McCurdy Date: Sun, 1 Mar 2015 23:00:36 -0500 Subject: [PATCH 027/490] Allow build failures on Node 0.12 and io.js --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 368e1ee92..98472f761 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,10 @@ node_js: - "0.10" - "0.12" - "io.js" +matrix: + allow_failures: + - node_js: "0.12" + - node_js: "io.js" after_script: ./node_modules/.bin/istanbul cover ./node_modules/tape/bin/tape tests/test-*.js --report lcovonly && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js --verbose webhooks: urls: https://webhooks.gitter.im/e/237280ed4796c19cc626 From e76691996b92d1fb4bdfe96a3a6d8527d02d053b Mon Sep 17 00:00:00 2001 From: Aaron Miller Date: Wed, 4 Mar 2015 20:40:55 -0500 Subject: [PATCH 028/490] add request timing option --- README.md | 2 +- request.js | 21 ++++++++++++-- tests/test-timing.js | 65 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 tests/test-timing.js diff --git a/README.md b/README.md index 00f4b17d6..6d327bfbb 100644 --- a/README.md +++ b/README.md @@ -615,7 +615,7 @@ The first argument can be either a `url` or an `options` object. The only requir * `hawk` - Options for [Hawk signing](https://github.com/hueniverse/hawk). The `credentials` key must contain the necessary signing info, [see hawk docs for details](https://github.com/hueniverse/hawk#usage-example). * `strictSSL` - If `true`, requires SSL certificates be valid. **Note:** to use your own certificate authority, you need to specify an agent that was created with that CA as an option. * `agentOptions` - Object containing user agent options. See documentation above. **Note:** [see tls API doc for TLS/SSL options](http://nodejs.org/api/tls.html#tls_tls_connect_options_callback). - +* `time` - If `true`, the request-response cycle (including all redirects) is timed at millisecond resolution, and the result provided on the response's `elapsedTime` property. * `jar` - If `true` and `tough-cookie` is installed, remember cookies for future use (or define your custom cookie jar; see examples section) * `aws` - `object` containing AWS signing information. Should have the properties `key`, `secret`. Also requires the property `bucket`, unless you’re specifying your `bucket` as part of the path, or the request doesn’t use a bucket (i.e. GET Services) * `httpSignature` - Options for the [HTTP Signature Scheme](https://github.com/joyent/node-http-signature/blob/master/http_signing.md) using [Joyent's library](https://github.com/joyent/node-http-signature). The `keyId` and `key` properties must be specified. See the docs for other options. diff --git a/request.js b/request.js index 6f1305a41..7ac68791e 100644 --- a/request.js +++ b/request.js @@ -282,7 +282,7 @@ Request.prototype.setupTunnel = function () { if (typeof self.proxy === 'string') { self.proxy = url.parse(self.proxy) } - + if (!self.proxy || !self.tunnel) { return false } @@ -298,7 +298,7 @@ Request.prototype.setupTunnel = function () { self.proxyHeaders = constructProxyHeaderWhiteList(self.headers, proxyHeaderWhiteList) self.proxyHeaders.host = constructProxyHost(self.uri) proxyHeaderExclusiveList.forEach(self.removeHeader, self) - + // Set Agent from Tunnel Data var tunnelFn = getTunnelFn(self) var tunnelOptions = constructTunnelOptions(self) @@ -548,6 +548,11 @@ Request.prototype.init = function (options) { self.multipart(options.multipart) } + if (options.time) { + self.timing = true + self.elapsedTime = self.elapsedTime || 0 + } + if (self.body) { var length = 0 if (!Buffer.isBuffer(self.body)) { @@ -869,6 +874,7 @@ Request.prototype.start = function () { // start() is called once we are ready to send the outgoing HTTP request. // this is usually called on the first write(), end() or on nextTick() var self = this + , startTime if (self._aborted) { return @@ -891,8 +897,14 @@ Request.prototype.start = function () { delete reqOptions.auth debug('make request', self.uri.href) + + startTime = new Date().getTime() self.req = self.httpModule.request(reqOptions) + if (self.timing) { + self.startTime = startTime + } + if (self.timeout && !self.timeoutTimer) { self.timeoutTimer = setTimeout(function () { self.abort() @@ -955,6 +967,11 @@ Request.prototype.onRequestResponse = function (response) { var self = this debug('onRequestResponse', self.uri.href, response.statusCode, response.headers) response.on('end', function() { + if (self.timing) { + self.elapsedTime += (new Date().getTime() - self.startTime) + debug('elapsed time', self.elapsedTime) + response.elapsedTime = self.elapsedTime + } debug('response end', self.uri.href, response.statusCode, response.headers) }) diff --git a/tests/test-timing.js b/tests/test-timing.js new file mode 100644 index 000000000..26da91bbf --- /dev/null +++ b/tests/test-timing.js @@ -0,0 +1,65 @@ +'use strict' + +var http = require('http') + , server = require('./server') + , request = require('../index') + , tape = require('tape') + +var plain_server = server.createServer() + , redirect_mock_time = 10 + , non_redirect_time + +tape('setup', function(t) { + plain_server.listen(plain_server.port, function() { + plain_server.on('/', function (req, res) { + res.writeHead(200) + res.end('plain') + }) + plain_server.on('/redir', function (req, res) { + // fake redirect delay to ensure strong signal for rollup check + setTimeout(function() { + res.writeHead(301, { 'location': 'http://localhost:' + plain_server.port + '/' }) + res.end() + }, redirect_mock_time) + }) + + request('http://localhost:' + plain_server.port + '/', {}, function(err, res, body) { + t.equal(err, null) + }) + + t.end() + }) +}) + +tape('no-op', function(t) { + t.end() +}) + +tape('non-redirected request is timed', function(t) { + var options = {time: true} + request('http://localhost:' + plain_server.port + '/', options, function(err, res, body) { + t.equal(err, null) + t.equal(typeof res.elapsedTime, 'number') + t.equal((res.elapsedTime > 0), true) + non_redirect_time = res.elapsedTime + t.end() + }) +}) + +tape('redirected request is timed with rollup', function(t) { + var options = {time: true} + request('http://localhost:' + plain_server.port + '/redir', options, function(err, res, body) { + t.equal(err, null) + t.equal(typeof res.elapsedTime, 'number') + t.equal((res.elapsedTime > 0), true) + t.equal((res.elapsedTime > non_redirect_time), true) + t.equal((res.elapsedTime > redirect_mock_time), true) + t.end() + }) +}) + +tape('cleanup', function(t) { + plain_server.close(function() { + t.end() + }) +}) From 8ce85f2205ac546e9c26a18d7094ac0497be423e Mon Sep 17 00:00:00 2001 From: Aaron Miller Date: Wed, 4 Mar 2015 22:08:25 -0500 Subject: [PATCH 029/490] remove test that fails in CI and is largely obsoleted by redirect_mock_time check --- tests/test-timing.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/test-timing.js b/tests/test-timing.js index 26da91bbf..9ef8f7b5d 100644 --- a/tests/test-timing.js +++ b/tests/test-timing.js @@ -7,7 +7,6 @@ var http = require('http') var plain_server = server.createServer() , redirect_mock_time = 10 - , non_redirect_time tape('setup', function(t) { plain_server.listen(plain_server.port, function() { @@ -41,7 +40,6 @@ tape('non-redirected request is timed', function(t) { t.equal(err, null) t.equal(typeof res.elapsedTime, 'number') t.equal((res.elapsedTime > 0), true) - non_redirect_time = res.elapsedTime t.end() }) }) @@ -52,7 +50,6 @@ tape('redirected request is timed with rollup', function(t) { t.equal(err, null) t.equal(typeof res.elapsedTime, 'number') t.equal((res.elapsedTime > 0), true) - t.equal((res.elapsedTime > non_redirect_time), true) t.equal((res.elapsedTime > redirect_mock_time), true) t.end() }) From 3cbfd21038f8dccdcb01b0b7a9f94e45af73a840 Mon Sep 17 00:00:00 2001 From: simov Date: Mon, 9 Mar 2015 12:33:50 +0200 Subject: [PATCH 030/490] Fix http.setTimeout now allowing negative msecs value --- request.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/request.js b/request.js index c6507620c..d18a559e0 100644 --- a/request.js +++ b/request.js @@ -896,17 +896,18 @@ Request.prototype.start = function () { self.req = self.httpModule.request(reqOptions) if (self.timeout && !self.timeoutTimer) { + var timeout = self.timeout < 0 ? 0 : self.timeout self.timeoutTimer = setTimeout(function () { self.abort() var e = new Error('ETIMEDOUT') e.code = 'ETIMEDOUT' self.emit('error', e) - }, self.timeout) + }, 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+ - self.req.setTimeout(self.timeout, function () { + self.req.setTimeout(timeout, function () { if (self.req) { self.req.abort() var e = new Error('ESOCKETTIMEDOUT') From bca9d92b5d08c5d67913da02ba9820f8e7aea43e Mon Sep 17 00:00:00 2001 From: simov Date: Mon, 9 Mar 2015 12:34:49 +0200 Subject: [PATCH 031/490] Remove npm script left over --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index accaafdd9..d14517142 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "isstream": "~0.1.1" }, "scripts": { - "test": "npm run lint && node node_modules/.bin/taper tests/test-*.js && npm run test-browser && npm run clean", + "test": "npm run lint && node node_modules/.bin/taper tests/test-*.js && npm run test-browser", "test-browser": "node tests/browser/start.js", "lint": "node node_modules/.bin/eslint lib/ *.js tests/ && echo Lint passed." }, From 27b98154592d59528dae2614fb03fea5c6d9c688 Mon Sep 17 00:00:00 2001 From: simov Date: Mon, 9 Mar 2015 12:37:14 +0200 Subject: [PATCH 032/490] Re-enable iojs/node 0.12 in build script, remove message from readme --- .travis.yml | 8 ++------ README.md | 8 -------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index 98472f761..bd0f638eb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,8 @@ language: node_js node_js: - - "0.10" - - "0.12" - "io.js" -matrix: - allow_failures: - - node_js: "0.12" - - node_js: "io.js" + - "0.12" + - "0.10" after_script: ./node_modules/.bin/istanbul cover ./node_modules/tape/bin/tape tests/test-*.js --report lcovonly && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js --verbose webhooks: urls: https://webhooks.gitter.im/e/237280ed4796c19cc626 diff --git a/README.md b/README.md index 00f4b17d6..a966df478 100644 --- a/README.md +++ b/README.md @@ -5,14 +5,6 @@ [![Coverage](https://img.shields.io/coveralls/request/request.svg?style=flat)](https://coveralls.io/r/request/request) [![Gitter](https://img.shields.io/badge/gitter-join_chat-blue.svg?style=flat)](https://gitter.im/request/request?utm_source=badge) -## !!! Does not work with Node v0.12.x !!! - -We're working on this. Want to help? See the -[contribution guidelines](https://github.com/request/request/blob/master/CONTRIBUTING.md), -help us fix the -[failing tests](https://travis-ci.org/request/request/jobs/49916823), -and [submit a PR](https://github.com/request/request/pulls)! - ## Super simple to use Request is designed to be the simplest way possible to make http calls. It supports HTTPS and follows redirects by default. From d13ccd2c242b9ce7cc9f639386253ca4281924ca Mon Sep 17 00:00:00 2001 From: froatsnook Date: Mon, 9 Mar 2015 13:59:58 +0100 Subject: [PATCH 033/490] Implement baseUrl. --- README.md | 1 + request.js | 22 +++++++++ tests/test-baseUrl.js | 110 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 133 insertions(+) create mode 100644 tests/test-baseUrl.js diff --git a/README.md b/README.md index 00f4b17d6..f128899c0 100644 --- a/README.md +++ b/README.md @@ -572,6 +572,7 @@ request.get({ The first argument can be either a `url` or an `options` object. The only required option is `uri`; all others are optional. * `uri` || `url` - fully qualified uri or a parsed url object from `url.parse()` +* `baseUrl` - fully qualified uri used as the base url. Most useful with `request.defaults`, for example when you want to do many requests to the same domain. If `baseUrl` is `https://example.com/api/`, then requesting `end/point?test=true` will fetch `https://example.com/api/end/point?test=true`. * `qs` - object containing querystring values to be appended to the `uri` * `useQuerystring` - If true, use `querystring` to stringify and parse querystrings, otherwise use `qs` (default: `false`). Set this option to diff --git a/request.js b/request.js index c6507620c..082802669 100644 --- a/request.js +++ b/request.js @@ -357,6 +357,28 @@ Request.prototype.init = function (options) { delete self.url } + // If there's a baseUrl, then use it as the base URL (i.e. uri must be + // specified as a relative path and is appended to baseUrl). + if (self.baseUrl) { + if (typeof self.baseUrl !== 'string') { + return self.emit('error', new Error('options.baseUrl must be a string')) + } + + if (typeof self.uri !== 'string') { + return self.emit('error', new Error('options.uri must be a string when using options.baseUrl')) + } + + if (self.uri.indexOf('/') === 0 || self.uri.indexOf('://') !== -1) { + return self.emit('error', new Error('options.uri must be a relative path when using options.baseUrl')) + } + + if (self.baseUrl.lastIndexOf('/') === self.baseUrl.length - 1) { + self.uri = self.baseUrl + self.uri + } else { + self.uri = self.baseUrl + '/' + self.uri + } + } + // A URI is needed by this point, throw if we haven't been able to get one if (!self.uri) { return self.emit('error', new Error('options.uri is a required argument')) diff --git a/tests/test-baseUrl.js b/tests/test-baseUrl.js new file mode 100644 index 000000000..ae9462477 --- /dev/null +++ b/tests/test-baseUrl.js @@ -0,0 +1,110 @@ +'use strict' + +var http = require('http') + , request = require('../index') + , tape = require('tape') + +var s = http.createServer(function(req, res) { + res.statusCode = 200 + res.setHeader('X-PATH', req.url) + res.end('ok') +}) + +tape('setup', function(t) { + s.listen(6767, function() { + t.end() + }) +}) + +tape('baseUrl', function(t) { + request('resource', { + baseUrl: 'http://localhost:6767' + }, function(err, resp, body) { + t.equal(err, null) + t.equal(body, 'ok') + t.end() + }) +}) + +tape('baseUrl defaults', function(t) { + var withDefaults = request.defaults({ + baseUrl: 'http://localhost:6767' + }) + withDefaults('resource', function(err, resp, body) { + t.equal(err, null) + t.equal(body, 'ok') + t.end() + }) +}) + +tape('baseUrl without path', function(t) { + request('resource', { + baseUrl: 'http://localhost:6767' + }, function(err, resp, body) { + t.equal(err, null) + t.equal(body, 'ok') + t.equal(resp.headers['x-path'], '/resource') + t.end() + }) +}) + +tape('baseUrl without path, with trailing slash', function(t) { + request('resource', { + baseUrl: 'http://localhost:6767/' + }, function(err, resp, body) { + t.equal(err, null) + t.equal(body, 'ok') + t.equal(resp.headers['x-path'], '/resource') + t.end() + }) +}) + +tape('baseUrl with path', function(t) { + request('resource', { + baseUrl: 'http://localhost:6767/path/to' + }, function(err, resp, body) { + t.equal(err, null) + t.equal(body, 'ok') + t.equal(resp.headers['x-path'], '/path/to/resource') + t.end() + }) +}) + +tape('baseUrl with path and trailing slash', function(t) { + request('resource', { + baseUrl: 'http://localhost:6767/path/to/' + }, function(err, resp, body) { + t.equal(err, null) + t.equal(body, 'ok') + t.equal(resp.headers['x-path'], '/path/to/resource') + t.end() + }) +}) + +tape('baseUrl with empty uri', function(t) { + request('', { + baseUrl: 'http://localhost:6767/path/to' + }, function(err, resp, body) { + t.equal(err, null) + t.equal(body, 'ok') + t.equal(resp.headers['x-path'], '/path/to/') + t.end() + }) +}) + +tape('baseUrl with trailing slash and empty uri', function(t) { + request('', { + baseUrl: 'http://localhost:6767/path/to/' + }, function(err, resp, body) { + t.equal(err, null) + t.equal(body, 'ok') + t.equal(resp.headers['x-path'], '/path/to/') + t.end() + }) +}) + +tape('cleanup', function(t) { + s.close(function() { + t.end() + }) +}) From e22a1747b363ab1978fd380b46e9395224b0764c Mon Sep 17 00:00:00 2001 From: froatsnook Date: Wed, 11 Mar 2015 14:01:52 +0100 Subject: [PATCH 034/490] Add baseUrl error tests. --- tests/test-baseUrl.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/test-baseUrl.js b/tests/test-baseUrl.js index ae9462477..e8149d557 100644 --- a/tests/test-baseUrl.js +++ b/tests/test-baseUrl.js @@ -3,6 +3,7 @@ var http = require('http') , request = require('../index') , tape = require('tape') + , url = require('url') var s = http.createServer(function(req, res) { res.statusCode = 200 @@ -103,6 +104,42 @@ tape('baseUrl with trailing slash and empty uri', function(t) { }) }) +tape('error on parsed URL baseUrl', function(t) { + request('resource', { + baseUrl: url.parse('http://localhost:6767/path') + }, function(err, resp, body) { + t.notEqual(err, null) + t.end() + }) +}) + +tape('error on baseUrl and parsed URL uri', function(t) { + request(url.parse('resource'), { + baseUrl: 'http://localhost:6767/path' + }, function(err, resp, body) { + t.notEqual(err, null) + t.end() + }) +}) + +tape('error on baseUrl and absolute path uri', function(t) { + request('/end/point', { + baseUrl: 'http://localhost:6767/path/' + }, function(err, resp, body) { + t.notEqual(err, null) + t.end() + }) +}) + +tape('error on baseUrl and uri with scheme', function(t) { + request('http://localhost:6767/path/ignoring/baseUrl', { + baseUrl: 'http://localhost:6767/path/' + }, function(err, resp, body) { + t.notEqual(err, null) + t.end() + }) +}) + tape('cleanup', function(t) { s.close(function() { t.end() From d80416ba29ddc633393b0ed60c16b1cef03e6f3c Mon Sep 17 00:00:00 2001 From: froatsnook Date: Wed, 11 Mar 2015 14:12:21 +0100 Subject: [PATCH 035/490] Document expected uri type when baseUrl given. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f128899c0..f64297d87 100644 --- a/README.md +++ b/README.md @@ -572,7 +572,7 @@ request.get({ The first argument can be either a `url` or an `options` object. The only required option is `uri`; all others are optional. * `uri` || `url` - fully qualified uri or a parsed url object from `url.parse()` -* `baseUrl` - fully qualified uri used as the base url. Most useful with `request.defaults`, for example when you want to do many requests to the same domain. If `baseUrl` is `https://example.com/api/`, then requesting `end/point?test=true` will fetch `https://example.com/api/end/point?test=true`. +* `baseUrl` - fully qualified uri string used as the base url. Most useful with `request.defaults`, for example when you want to do many requests to the same domain. If `baseUrl` is `https://example.com/api/`, then requesting `end/point?test=true` will fetch `https://example.com/api/end/point?test=true`. When `baseUrl` is given, `uri` must also be a string. * `qs` - object containing querystring values to be appended to the `uri` * `useQuerystring` - If true, use `querystring` to stringify and parse querystrings, otherwise use `qs` (default: `false`). Set this option to From 10803329f8c6ba5321ae25abfff51ee4dcd134e7 Mon Sep 17 00:00:00 2001 From: Eric Rykwalder Date: Wed, 11 Mar 2015 00:35:25 -0700 Subject: [PATCH 036/490] require colon in basic auth --- lib/auth.js | 2 +- tests/test-basic-auth.js | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/auth.js b/lib/auth.js index 79f1ce3b4..bd49dfc88 100644 --- a/lib/auth.js +++ b/lib/auth.js @@ -26,7 +26,7 @@ Auth.prototype.basic = function (user, pass, sendImmediately) { self.user = user self.pass = pass self.hasAuth = true - var header = typeof pass !== 'undefined' ? user + ':' + pass : user + var header = user + ':' + (pass || '') if (sendImmediately || typeof sendImmediately === 'undefined') { var authHeader = 'Basic ' + toBase64(header) self.sentAuth = true diff --git a/tests/test-basic-auth.js b/tests/test-basic-auth.js index 1ad452352..5eab311a7 100644 --- a/tests/test-basic-auth.js +++ b/tests/test-basic-auth.js @@ -22,8 +22,6 @@ tape('setup', function(t) { ok = true } else if ( req.headers.authorization === 'Basic ' + new Buffer(':pass').toString('base64')) { ok = true - } else if ( req.headers.authorization === 'Basic ' + new Buffer('user').toString('base64')) { - ok = true } else { // Bad auth header, don't send back WWW-Authenticate header ok = false From ddd3efb763f5825606575fe5bcf2c1fa84e29366 Mon Sep 17 00:00:00 2001 From: Aaron Miller Date: Wed, 11 Mar 2015 16:50:28 -0400 Subject: [PATCH 037/490] update per review feedback --- request.js | 4 +--- tests/test-timing.js | 4 ---- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/request.js b/request.js index 7ac68791e..2ef3211e1 100644 --- a/request.js +++ b/request.js @@ -874,7 +874,6 @@ Request.prototype.start = function () { // start() is called once we are ready to send the outgoing HTTP request. // this is usually called on the first write(), end() or on nextTick() var self = this - , startTime if (self._aborted) { return @@ -898,11 +897,10 @@ Request.prototype.start = function () { debug('make request', self.uri.href) - startTime = new Date().getTime() self.req = self.httpModule.request(reqOptions) if (self.timing) { - self.startTime = startTime + self.startTime = new Date().getTime() } if (self.timeout && !self.timeoutTimer) { diff --git a/tests/test-timing.js b/tests/test-timing.js index 9ef8f7b5d..5040b5c78 100644 --- a/tests/test-timing.js +++ b/tests/test-timing.js @@ -30,10 +30,6 @@ tape('setup', function(t) { }) }) -tape('no-op', function(t) { - t.end() -}) - tape('non-redirected request is timed', function(t) { var options = {time: true} request('http://localhost:' + plain_server.port + '/', options, function(err, res, body) { From 19f0c51b34bb797431369d3cd61bcade7889e03e Mon Sep 17 00:00:00 2001 From: Aaron Miller Date: Wed, 11 Mar 2015 19:04:08 -0400 Subject: [PATCH 038/490] remove another superfluous test --- tests/test-timing.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/test-timing.js b/tests/test-timing.js index 5040b5c78..89ec04655 100644 --- a/tests/test-timing.js +++ b/tests/test-timing.js @@ -22,10 +22,6 @@ tape('setup', function(t) { }, redirect_mock_time) }) - request('http://localhost:' + plain_server.port + '/', {}, function(err, res, body) { - t.equal(err, null) - }) - t.end() }) }) From 8f8bbd52e7f1226aa1827aaf75aed9c44efc74aa Mon Sep 17 00:00:00 2001 From: froatsnook Date: Thu, 12 Mar 2015 19:08:28 +0100 Subject: [PATCH 039/490] Allow absolute path uris when baseUrl is given. --- README.md | 2 +- request.js | 15 ++++++-- tests/test-baseUrl.js | 90 +++++++++++++------------------------------ 3 files changed, 39 insertions(+), 68 deletions(-) diff --git a/README.md b/README.md index f64297d87..c063b86dc 100644 --- a/README.md +++ b/README.md @@ -572,7 +572,7 @@ request.get({ The first argument can be either a `url` or an `options` object. The only required option is `uri`; all others are optional. * `uri` || `url` - fully qualified uri or a parsed url object from `url.parse()` -* `baseUrl` - fully qualified uri string used as the base url. Most useful with `request.defaults`, for example when you want to do many requests to the same domain. If `baseUrl` is `https://example.com/api/`, then requesting `end/point?test=true` will fetch `https://example.com/api/end/point?test=true`. When `baseUrl` is given, `uri` must also be a string. +* `baseUrl` - fully qualified uri string used as the base url. Most useful with `request.defaults`, for example when you want to do many requests to the same domain. If `baseUrl` is `https://example.com/api/`, then requesting `/end/point?test=true` will fetch `https://example.com/api/end/point?test=true`. When `baseUrl` is given, `uri` must also be a string. * `qs` - object containing querystring values to be appended to the `uri` * `useQuerystring` - If true, use `querystring` to stringify and parse querystrings, otherwise use `qs` (default: `false`). Set this option to diff --git a/request.js b/request.js index 082802669..594190e09 100644 --- a/request.js +++ b/request.js @@ -368,12 +368,21 @@ Request.prototype.init = function (options) { return self.emit('error', new Error('options.uri must be a string when using options.baseUrl')) } - if (self.uri.indexOf('/') === 0 || self.uri.indexOf('://') !== -1) { - return self.emit('error', new Error('options.uri must be a relative path when using options.baseUrl')) + if (self.uri.indexOf('//') === 0 || self.uri.indexOf('://') !== -1) { + return self.emit('error', new Error('options.uri must be a path when using options.baseUrl')) } - if (self.baseUrl.lastIndexOf('/') === self.baseUrl.length - 1) { + // Handle all cases to make sure that there's only one slash between + // baseUrl and uri. + var baseUrlEndsWithSlash = self.baseUrl.lastIndexOf('/') === self.baseUrl.length - 1 + var uriStartsWithSlash = self.uri.indexOf('/') === 0 + + if (baseUrlEndsWithSlash && uriStartsWithSlash) { + self.uri = self.baseUrl + self.uri.slice(1) + } else if (baseUrlEndsWithSlash || uriStartsWithSlash) { self.uri = self.baseUrl + self.uri + } else if (self.uri === '') { + self.uri = self.baseUrl } else { self.uri = self.baseUrl + '/' + self.uri } diff --git a/tests/test-baseUrl.js b/tests/test-baseUrl.js index e8149d557..f909359f3 100644 --- a/tests/test-baseUrl.js +++ b/tests/test-baseUrl.js @@ -38,71 +38,33 @@ tape('baseUrl defaults', function(t) { }) }) -tape('baseUrl without path', function(t) { - request('resource', { - baseUrl: 'http://localhost:6767' - }, function(err, resp, body) { - t.equal(err, null) - t.equal(body, 'ok') - t.equal(resp.headers['x-path'], '/resource') - t.end() +function addTest(baseUrl, uri, expected) { + tape('test baseurl="' + baseUrl + '" uri="' + uri + '"', function(t) { + request(uri, { baseUrl: baseUrl }, function(err, resp, body) { + t.equal(err, null) + t.equal(body, 'ok') + t.equal(resp.headers['x-path'], expected) + t.end() + }) }) -}) - -tape('baseUrl without path, with trailing slash', function(t) { - request('resource', { - baseUrl: 'http://localhost:6767/' - }, function(err, resp, body) { - t.equal(err, null) - t.equal(body, 'ok') - t.equal(resp.headers['x-path'], '/resource') - t.end() - }) -}) - -tape('baseUrl with path', function(t) { - request('resource', { - baseUrl: 'http://localhost:6767/path/to' - }, function(err, resp, body) { - t.equal(err, null) - t.equal(body, 'ok') - t.equal(resp.headers['x-path'], '/path/to/resource') - t.end() - }) -}) - -tape('baseUrl with path and trailing slash', function(t) { - request('resource', { - baseUrl: 'http://localhost:6767/path/to/' - }, function(err, resp, body) { - t.equal(err, null) - t.equal(body, 'ok') - t.equal(resp.headers['x-path'], '/path/to/resource') - t.end() - }) -}) - -tape('baseUrl with empty uri', function(t) { - request('', { - baseUrl: 'http://localhost:6767/path/to' - }, function(err, resp, body) { - t.equal(err, null) - t.equal(body, 'ok') - t.equal(resp.headers['x-path'], '/path/to/') - t.end() - }) -}) - -tape('baseUrl with trailing slash and empty uri', function(t) { - request('', { - baseUrl: 'http://localhost:6767/path/to/' - }, function(err, resp, body) { - t.equal(err, null) - t.equal(body, 'ok') - t.equal(resp.headers['x-path'], '/path/to/') - t.end() - }) -}) +} + +addTest('http://localhost:6767', '', '/') +addTest('http://localhost:6767/', '', '/') +addTest('http://localhost:6767', '/', '/') +addTest('http://localhost:6767/', '/', '/') +addTest('http://localhost:6767/api', '', '/api') +addTest('http://localhost:6767/api/', '', '/api/') +addTest('http://localhost:6767/api', '/', '/api/') +addTest('http://localhost:6767/api/', '/', '/api/') +addTest('http://localhost:6767/api', 'resource', '/api/resource') +addTest('http://localhost:6767/api/', 'resource', '/api/resource') +addTest('http://localhost:6767/api', '/resource', '/api/resource') +addTest('http://localhost:6767/api/', '/resource', '/api/resource') +addTest('http://localhost:6767/api', 'resource/', '/api/resource/') +addTest('http://localhost:6767/api/', 'resource/', '/api/resource/') +addTest('http://localhost:6767/api', '/resource/', '/api/resource/') +addTest('http://localhost:6767/api/', '/resource/', '/api/resource/') tape('error on parsed URL baseUrl', function(t) { request('resource', { From 254e2b776ae9419d7e43959fbb3bb1d530acd6fe Mon Sep 17 00:00:00 2001 From: froatsnook Date: Thu, 12 Mar 2015 19:09:13 +0100 Subject: [PATCH 040/490] Test error message values in test-baseUrl.js. --- tests/test-baseUrl.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/test-baseUrl.js b/tests/test-baseUrl.js index f909359f3..3452682c8 100644 --- a/tests/test-baseUrl.js +++ b/tests/test-baseUrl.js @@ -71,6 +71,7 @@ tape('error on parsed URL baseUrl', function(t) { baseUrl: url.parse('http://localhost:6767/path') }, function(err, resp, body) { t.notEqual(err, null) + t.equal(err.message, 'options.baseUrl must be a string') t.end() }) }) @@ -80,24 +81,27 @@ tape('error on baseUrl and parsed URL uri', function(t) { baseUrl: 'http://localhost:6767/path' }, function(err, resp, body) { t.notEqual(err, null) + t.equal(err.message, 'options.uri must be a string when using options.baseUrl') t.end() }) }) -tape('error on baseUrl and absolute path uri', function(t) { - request('/end/point', { +tape('error on baseUrl and uri with scheme', function(t) { + request('http://localhost:6767/path/ignoring/baseUrl', { baseUrl: 'http://localhost:6767/path/' }, function(err, resp, body) { t.notEqual(err, null) + t.equal(err.message, 'options.uri must be a path when using options.baseUrl') t.end() }) }) -tape('error on baseUrl and uri with scheme', function(t) { - request('http://localhost:6767/path/ignoring/baseUrl', { +tape('error on baseUrl and uri with scheme-relative url', function(t) { + request('//localhost:6767/path/ignoring/baseUrl', { baseUrl: 'http://localhost:6767/path/' }, function(err, resp, body) { t.notEqual(err, null) + t.equal(err.message, 'options.uri must be a path when using options.baseUrl') t.end() }) }) From 5080463cf27ae27f684805e5d54cb6c3f2233e3a Mon Sep 17 00:00:00 2001 From: froatsnook Date: Thu, 12 Mar 2015 21:44:22 +0100 Subject: [PATCH 041/490] Improve baseUrl error test names. --- tests/test-baseUrl.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test-baseUrl.js b/tests/test-baseUrl.js index 3452682c8..e0cbe6598 100644 --- a/tests/test-baseUrl.js +++ b/tests/test-baseUrl.js @@ -66,7 +66,7 @@ addTest('http://localhost:6767/api/', 'resource/', '/api/resource/') addTest('http://localhost:6767/api', '/resource/', '/api/resource/') addTest('http://localhost:6767/api/', '/resource/', '/api/resource/') -tape('error on parsed URL baseUrl', function(t) { +tape('error when baseUrl is not a String', function(t) { request('resource', { baseUrl: url.parse('http://localhost:6767/path') }, function(err, resp, body) { @@ -76,7 +76,7 @@ tape('error on parsed URL baseUrl', function(t) { }) }) -tape('error on baseUrl and parsed URL uri', function(t) { +tape('error when uri is not a String', function(t) { request(url.parse('resource'), { baseUrl: 'http://localhost:6767/path' }, function(err, resp, body) { From 282865f9ed7dbaeb32d20f8299ab3605b4c17407 Mon Sep 17 00:00:00 2001 From: simov Date: Fri, 13 Mar 2015 10:01:19 +0200 Subject: [PATCH 042/490] Add support for qs options via qsOptions key --- README.md | 1 + package.json | 2 +- request.js | 13 +++++++++---- tests/test-qs.js | 11 ++++++++++- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a318d3c58..343b0f5fe 100644 --- a/README.md +++ b/README.md @@ -565,6 +565,7 @@ The first argument can be either a `url` or an `options` object. The only requir * `uri` || `url` - fully qualified uri or a parsed url object from `url.parse()` * `qs` - object containing querystring values to be appended to the `uri` +* `qsOptions` - object containing options to pass to the `qs` or `querystring` module * `useQuerystring` - If true, use `querystring` to stringify and parse querystrings, otherwise use `qs` (default: `false`). Set this option to `true` if you need arrays to be serialized as `foo=bar&foo=baz` instead of the diff --git a/package.json b/package.json index d14517142..84d345346 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "json-stringify-safe": "~5.0.0", "mime-types": "~2.0.1", "node-uuid": "~1.4.0", - "qs": "~2.3.1", + "qs": "~2.4.0", "tunnel-agent": "~0.4.0", "tough-cookie": ">=0.12.0", "http-signature": "~0.10.0", diff --git a/request.js b/request.js index 715c640dc..b7dd751a4 100644 --- a/request.js +++ b/request.js @@ -329,6 +329,9 @@ Request.prototype.init = function (options) { if (!self.qsLib) { self.qsLib = (options.useQuerystring ? querystring : qs) } + if (!self.qsOptions) { + self.qsOptions = options.qsOptions + } debug(options) if (!self.pool && self.pool !== false) { @@ -1229,7 +1232,7 @@ Request.prototype.qs = function (q, clobber) { var self = this var base if (!clobber && self.uri.query) { - base = self.qsLib.parse(self.uri.query) + base = self.qsLib.parse(self.uri.query, self.qsOptions) } else { base = {} } @@ -1238,11 +1241,11 @@ Request.prototype.qs = function (q, clobber) { base[i] = q[i] } - if (self.qsLib.stringify(base) === ''){ + if (self.qsLib.stringify(base, self.qsOptions) === ''){ return self } - var qs = self.qsLib.stringify(base) + var qs = self.qsLib.stringify(base, self.qsOptions) self.uri = url.parse(self.uri.href.split('?')[0] + '?' + rfc3986(qs)) self.url = self.uri @@ -1254,7 +1257,9 @@ Request.prototype.form = function (form) { var self = this if (form) { self.setHeader('content-type', 'application/x-www-form-urlencoded') - self.body = (typeof form === 'string') ? form.toString('utf8') : self.qsLib.stringify(form).toString('utf8') + self.body = (typeof form === 'string') + ? form.toString('utf8') + : self.qsLib.stringify(form, self.qsOptions).toString('utf8') self.body = rfc3986(self.body) return self } diff --git a/tests/test-qs.js b/tests/test-qs.js index 511ec88a6..2298baafa 100644 --- a/tests/test-qs.js +++ b/tests/test-qs.js @@ -6,13 +6,15 @@ var request = require('../index') // Run a querystring test. `options` can have the following keys: // - suffix : a string to be added to the URL // - qs : an object to be passed to request's `qs` option +// - qsOptions : an object to be passed to request's `qsOptions` option // - afterRequest : a function to execute after creating the request // - expected : the expected path of the request // - expectedQuerystring : expected path when using the querystring library function runTest(name, options) { var uri = 'http://www.google.com' + (options.suffix || '') , requestOptsQs = { - uri : uri + uri : uri, + qsOptions: options.qsOptions } , requestOptsQuerystring = { uri : uri, @@ -101,3 +103,10 @@ runTest('a query with an array for a value', { expected : esc('/?order[0]=bar&order[1]=desc'), expectedQuerystring : '/?order=bar&order=desc' }) + +runTest('pass options to the qs module via the qsOptions key', { + qs : { order : ['bar', 'desc'] }, + qsOptions: { arrayFormat : 'brackets' }, + expected : esc('/?order[]=bar&order[]=desc'), + expectedQuerystring : '/?order=bar&order=desc' +}) From cb0173c2b81b09e379d48f773ff6659d51a41205 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Str=C3=A1nsk=C3=BD?= Date: Sat, 14 Mar 2015 11:03:27 +0100 Subject: [PATCH 043/490] Fix baseUrl and redirections. --- request.js | 1 + tests/test-baseUrl.js | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/request.js b/request.js index 61eb7739e..0ca8e1c7f 100644 --- a/request.js +++ b/request.js @@ -386,6 +386,7 @@ Request.prototype.init = function (options) { } else { self.uri = self.baseUrl + '/' + self.uri } + delete self.baseUrl } // A URI is needed by this point, throw if we haven't been able to get one diff --git a/tests/test-baseUrl.js b/tests/test-baseUrl.js index e0cbe6598..bf95a78d8 100644 --- a/tests/test-baseUrl.js +++ b/tests/test-baseUrl.js @@ -6,8 +6,14 @@ var http = require('http') , url = require('url') var s = http.createServer(function(req, res) { - res.statusCode = 200 - res.setHeader('X-PATH', req.url) + if(req.url === '/redirect/') { + res.writeHead(302, { + location : '/' + }) + } else { + res.statusCode = 200 + res.setHeader('X-PATH', req.url) + } res.end('ok') }) @@ -38,6 +44,17 @@ tape('baseUrl defaults', function(t) { }) }) +tape('baseUrl and redirects', function(t) { + request('/', { + baseUrl: 'http://localhost:6767/redirect' + }, function(err, resp, body) { + t.equal(err, null) + t.equal(body, 'ok') + t.equal(resp.headers['x-path'], '/') + t.end() + }) +}) + function addTest(baseUrl, uri, expected) { tape('test baseurl="' + baseUrl + '" uri="' + uri + '"', function(t) { request(uri, { baseUrl: baseUrl }, function(err, resp, body) { From 766e291029d4fbc7031624cc2cb9e0b0aed8f32c Mon Sep 17 00:00:00 2001 From: Akshay Patel Date: Sun, 15 Mar 2015 13:14:09 -0700 Subject: [PATCH 044/490] Add a test for the forever agent --- tests/test-agent.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/test-agent.js diff --git a/tests/test-agent.js b/tests/test-agent.js new file mode 100644 index 000000000..cca03d410 --- /dev/null +++ b/tests/test-agent.js @@ -0,0 +1,35 @@ +'use strict' + +var request = require('../index') + , http = require('http') + , tape = require('tape') + +var s = http.createServer(function(req, res) { + res.statusCode = 200 + res.end('ok') +}) + +tape('setup', function(t) { + s.listen(6767, function() { + t.end() + }) +}) + +tape('should work with forever agent', function(t) { + var r = request.forever({maxSockets: 1}) + + r({ + url: 'http://localhost:6767', + headers: { 'Connection':'Close' } + }, function(err, resp, body) { + t.equal(err, null) + t.equal(body, 'ok') + t.end() + }) +}) + +tape('cleanup', function(t) { + s.close(function() { + t.end() + }) +}) From 21f96024475c26d111c130e37ed10879e658a107 Mon Sep 17 00:00:00 2001 From: simov Date: Wed, 18 Mar 2015 16:56:42 +0200 Subject: [PATCH 045/490] Split qsOptions into qsParseOptions and qsStringifyOptions --- README.md | 3 ++- request.js | 15 +++++++++------ tests/test-qs.js | 19 +++++++++++++++---- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 343b0f5fe..c58cf2e6f 100644 --- a/README.md +++ b/README.md @@ -565,7 +565,8 @@ The first argument can be either a `url` or an `options` object. The only requir * `uri` || `url` - fully qualified uri or a parsed url object from `url.parse()` * `qs` - object containing querystring values to be appended to the `uri` -* `qsOptions` - object containing options to pass to the `qs` or `querystring` module +* `qsParseOptions` - object containing options to pass to the [qs.parse](https://github.com/hapijs/qs#parsing-objects) method or [querystring.parse](https://nodejs.org/docs/v0.12.0/api/querystring.html#querystring_querystring_parse_str_sep_eq_options) method +* `qsStringifyOptions` - object containing options to pass to the [qs.stringify](https://github.com/hapijs/qs#stringifying) method or to the [querystring.stringify](https://nodejs.org/docs/v0.12.0/api/querystring.html#querystring_querystring_stringify_obj_sep_eq_options) method. For example, to change the way arrays are converted to query strings pass the `arrayFormat` option with one of `indices|brackets|repeat` * `useQuerystring` - If true, use `querystring` to stringify and parse querystrings, otherwise use `qs` (default: `false`). Set this option to `true` if you need arrays to be serialized as `foo=bar&foo=baz` instead of the diff --git a/request.js b/request.js index b7dd751a4..6976c9fc6 100644 --- a/request.js +++ b/request.js @@ -329,8 +329,11 @@ Request.prototype.init = function (options) { if (!self.qsLib) { self.qsLib = (options.useQuerystring ? querystring : qs) } - if (!self.qsOptions) { - self.qsOptions = options.qsOptions + if (!self.qsParseOptions) { + self.qsParseOptions = options.qsParseOptions + } + if (!self.qsStringifyOptions) { + self.qsStringifyOptions = options.qsStringifyOptions } debug(options) @@ -1232,7 +1235,7 @@ Request.prototype.qs = function (q, clobber) { var self = this var base if (!clobber && self.uri.query) { - base = self.qsLib.parse(self.uri.query, self.qsOptions) + base = self.qsLib.parse(self.uri.query, self.qsParseOptions) } else { base = {} } @@ -1241,11 +1244,11 @@ Request.prototype.qs = function (q, clobber) { base[i] = q[i] } - if (self.qsLib.stringify(base, self.qsOptions) === ''){ + if (self.qsLib.stringify(base, self.qsStringifyOptions) === ''){ return self } - var qs = self.qsLib.stringify(base, self.qsOptions) + var qs = self.qsLib.stringify(base, self.qsStringifyOptions) self.uri = url.parse(self.uri.href.split('?')[0] + '?' + rfc3986(qs)) self.url = self.uri @@ -1259,7 +1262,7 @@ Request.prototype.form = function (form) { self.setHeader('content-type', 'application/x-www-form-urlencoded') self.body = (typeof form === 'string') ? form.toString('utf8') - : self.qsLib.stringify(form, self.qsOptions).toString('utf8') + : self.qsLib.stringify(form, self.qsStringifyOptions).toString('utf8') self.body = rfc3986(self.body) return self } diff --git a/tests/test-qs.js b/tests/test-qs.js index 2298baafa..198621d46 100644 --- a/tests/test-qs.js +++ b/tests/test-qs.js @@ -6,7 +6,8 @@ var request = require('../index') // Run a querystring test. `options` can have the following keys: // - suffix : a string to be added to the URL // - qs : an object to be passed to request's `qs` option -// - qsOptions : an object to be passed to request's `qsOptions` option +// - qsParseOptions : an object to be passed to request's `qsParseOptions` option +// - qsStringifyOptions : an object to be passed to request's `qsStringifyOptions` option // - afterRequest : a function to execute after creating the request // - expected : the expected path of the request // - expectedQuerystring : expected path when using the querystring library @@ -14,7 +15,8 @@ function runTest(name, options) { var uri = 'http://www.google.com' + (options.suffix || '') , requestOptsQs = { uri : uri, - qsOptions: options.qsOptions + qsParseOptions: options.qsParseOptions, + qsStringifyOptions: options.qsStringifyOptions } , requestOptsQuerystring = { uri : uri, @@ -104,9 +106,18 @@ runTest('a query with an array for a value', { expectedQuerystring : '/?order=bar&order=desc' }) -runTest('pass options to the qs module via the qsOptions key', { +runTest('pass options to the qs module via the qsParseOptions key', { + suffix : '?a=1;b=2', + qs: {}, + qsParseOptions: { delimiter : ';' }, + qsStringifyOptions: { delimiter : ';' }, + expected : esc('/?a=1;b=2'), + expectedQuerystring : '/?a=1%3Bb%3D2' +}) + +runTest('pass options to the qs module via the qsStringifyOptions key', { qs : { order : ['bar', 'desc'] }, - qsOptions: { arrayFormat : 'brackets' }, + qsStringifyOptions: { arrayFormat : 'brackets' }, expected : esc('/?order[]=bar&order[]=desc'), expectedQuerystring : '/?order=bar&order=desc' }) From 6a80bb515e7c13204557a57575e10002d4f2da94 Mon Sep 17 00:00:00 2001 From: Alban Mouton Date: Fri, 20 Mar 2015 11:19:01 +0100 Subject: [PATCH 046/490] Parameters encoded to base 64 should be decoded as UTF-8, not ASCII. --- lib/helpers.js | 2 +- tests/test-basic-auth.js | 27 +++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/helpers.js b/lib/helpers.js index fa5712ffb..40e61e129 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -74,7 +74,7 @@ function isReadStream (rs) { } function toBase64 (str) { - return (new Buffer(str || '', 'ascii')).toString('base64') + return (new Buffer(str || '', 'utf8')).toString('base64') } exports.isFunction = isFunction diff --git a/tests/test-basic-auth.js b/tests/test-basic-auth.js index 5eab311a7..8d9e0ebe2 100644 --- a/tests/test-basic-auth.js +++ b/tests/test-basic-auth.js @@ -22,6 +22,8 @@ tape('setup', function(t) { ok = true } else if ( req.headers.authorization === 'Basic ' + new Buffer(':pass').toString('base64')) { ok = true + } else if ( req.headers.authorization === 'Basic ' + new Buffer('user:pâss').toString('base64')) { + ok = true } else { // Bad auth header, don't send back WWW-Authenticate header ok = false @@ -155,6 +157,27 @@ tape('pass - undefined', function(t) { }) }) + +tape('pass - utf8', function(t) { + t.doesNotThrow( function() { + var r = request({ + 'method': 'GET', + 'uri': 'http://localhost:6767/allow_undefined_password/', + 'auth': { + 'user': 'user', + 'pass': 'pâss', + 'sendImmediately': false + } + }, function(error, res, body ) { + t.equal(r._auth.user, 'user') + t.equal(r._auth.pass, 'pâss') + t.equal(res.statusCode, 200) + t.equal(numBasicRequests, 12) + t.end() + }) + }) +}) + tape('auth method', function(t) { var r = request .get('http://localhost:6767/test/') @@ -162,7 +185,7 @@ tape('auth method', function(t) { .on('response', function (res) { t.equal(r._auth.user, 'user') t.equal(res.statusCode, 200) - t.equal(numBasicRequests, 12) + t.equal(numBasicRequests, 14) t.end() }) }) @@ -179,7 +202,7 @@ tape('get method', function(t) { t.equal(r._auth.user, 'user') t.equal(err, null) t.equal(res.statusCode, 200) - t.equal(numBasicRequests, 14) + t.equal(numBasicRequests, 16) t.end() }) }) From b1dec4da367426779709da8786a6ab961429616d Mon Sep 17 00:00:00 2001 From: froatsnook Date: Thu, 19 Mar 2015 11:43:19 +0100 Subject: [PATCH 047/490] Update eslint. --- .eslintrc | 19 ++++++++++++++++++- lib/getProxyFromURI.js | 4 ++-- lib/helpers.js | 2 +- lib/oauth.js | 3 +-- package.json | 2 +- request.js | 4 +--- tests/browser/start.js | 20 ++++++++++---------- tests/browser/test.js | 3 +-- tests/server.js | 3 +-- tests/test-basic-auth.js | 2 +- tests/test-bearer-auth.js | 4 ++-- tests/test-body.js | 4 +--- tests/test-errors.js | 3 +-- tests/test-httpModule.js | 2 +- tests/test-json-request.js | 1 - tests/test-multipart.js | 5 +++-- tests/test-oauth.js | 2 +- tests/test-pipes.js | 3 +-- tests/test-proxy-connect.js | 3 +-- tests/test-redirect-auth.js | 1 - tests/test-redirect-complex.js | 2 +- tests/test-redirect.js | 6 +++--- tests/test-timeout.js | 2 -- tests/test-timing.js | 3 +-- tests/test-toJSON.js | 8 ++++---- tests/test-unix.js | 2 +- 26 files changed, 58 insertions(+), 55 deletions(-) diff --git a/.eslintrc b/.eslintrc index 9c3350d6b..8538b419c 100644 --- a/.eslintrc +++ b/.eslintrc @@ -3,6 +3,8 @@ "node": true }, "rules": { + // 2-space indentation + "indent": [2, 2], // Disallow semi-colons, unless needed to disambiguate statement "semi": [2, "never"], // Require strings to use single quotes @@ -17,6 +19,21 @@ "no-unused-vars": [2, {"args":"none"}], // Allow leading underscores for method names // REASON: we use underscores to denote private methods - "no-underscore-dangle": 0 + "no-underscore-dangle": 0, + // Allow multi spaces around operators since they are + // used for alignment. This is not consistent in the + // code. + "no-multi-spaces": 0, + // Style rule is: most objects use { beforeColon: false, afterColon: true }, unless aligning which uses: + // + // { + // beforeColon : true, + // afterColon : true + // } + // + // eslint can't handle this, so the check is disabled. + "key-spacing": 0, + // Allow shadowing vars in outer scope (needs discussion) + "no-shadow": 0 } } diff --git a/lib/getProxyFromURI.js b/lib/getProxyFromURI.js index 0e54767f5..c2013a6e1 100644 --- a/lib/getProxyFromURI.js +++ b/lib/getProxyFromURI.js @@ -49,7 +49,7 @@ function getProxyFromURI(uri) { if (noProxy === '*') { return null } - + // if the noProxy is not empty and the uri is found return null if (noProxy !== '' && uriInNoProxy(uri, noProxy)) { @@ -62,7 +62,7 @@ function getProxyFromURI(uri) { return process.env.HTTP_PROXY || process.env.http_proxy || null } - + if (uri.protocol === 'https:') { return process.env.HTTPS_PROXY || process.env.https_proxy || diff --git a/lib/helpers.js b/lib/helpers.js index fa5712ffb..26570cabb 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -8,7 +8,7 @@ function deferMethod() { if(typeof setImmediate === 'undefined') { return process.nextTick } - + return setImmediate } diff --git a/lib/oauth.js b/lib/oauth.js index e44263a00..fc1cac6d5 100644 --- a/lib/oauth.js +++ b/lib/oauth.js @@ -1,7 +1,6 @@ 'use strict' -var querystring = require('querystring') - , qs = require('qs') +var qs = require('qs') , caseless = require('caseless') , uuid = require('node-uuid') , oauth = require('oauth-sign') diff --git a/package.json b/package.json index d14517142..cc181b4cd 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "browserify": "~5.9.1", "browserify-istanbul": "~0.1.3", "coveralls": "~2.11.2", - "eslint": "0.5.1", + "eslint": "0.17.1", "function-bind": "~1.0.0", "istanbul": "~0.3.2", "karma": "~0.12.21", diff --git a/request.js b/request.js index 0ca8e1c7f..751fa6c2a 100644 --- a/request.js +++ b/request.js @@ -21,7 +21,6 @@ var http = require('http') , FormData = require('form-data') , cookies = require('./lib/cookies') , copy = require('./lib/copy') - , net = require('net') , getProxyFromURI = require('./lib/getProxyFromURI') , Auth = require('./lib/auth').Auth , OAuth = require('./lib/oauth').OAuth @@ -29,7 +28,6 @@ var http = require('http') , Redirect = require('./lib/redirect').Redirect var safeStringify = helpers.safeStringify - , md5 = helpers.md5 , isReadStream = helpers.isReadStream , toBase64 = helpers.toBase64 , defer = helpers.defer @@ -1292,7 +1290,7 @@ Request.prototype.form = function (form) { } // create form-data object self._form = new FormData() - self._form.on('error',function(err) { + self._form.on('error', function(err) { err.message = 'form-data: ' + err.message self.emit('error', err) self.abort() diff --git a/tests/browser/start.js b/tests/browser/start.js index c515f2be3..2d8fbeae2 100644 --- a/tests/browser/start.js +++ b/tests/browser/start.js @@ -7,16 +7,16 @@ var path = require('path') var port = 6767 var server = https.createServer({ - key: fs.readFileSync(path.join(__dirname, '/ssl/server.key')), - cert: fs.readFileSync(path.join(__dirname, '/ssl/server.crt')), - ca: fs.readFileSync(path.join(__dirname, '/ssl/ca.crt')), - requestCert: true, - rejectUnauthorized: false - }, function (req, res) { - // Set CORS header, since that is something we are testing. - res.setHeader('Access-Control-Allow-Origin', '*') - res.writeHead(200) - res.end('Can you hear the sound of an enormous door slamming in the depths of hell?\n') + key: fs.readFileSync(path.join(__dirname, '/ssl/server.key')), + cert: fs.readFileSync(path.join(__dirname, '/ssl/server.crt')), + ca: fs.readFileSync(path.join(__dirname, '/ssl/ca.crt')), + requestCert: true, + rejectUnauthorized: false +}, function (req, res) { + // Set CORS header, since that is something we are testing. + res.setHeader('Access-Control-Allow-Origin', '*') + res.writeHead(200) + res.end('Can you hear the sound of an enormous door slamming in the depths of hell?\n') }) server.listen(port, function() { console.log('Started https server for karma tests on port ' + port) diff --git a/tests/browser/test.js b/tests/browser/test.js index 2ca07b712..6717ba709 100644 --- a/tests/browser/test.js +++ b/tests/browser/test.js @@ -9,8 +9,7 @@ if (!Function.prototype.bind) { } -var assert = require('assert') - , tape = require('tape') +var tape = require('tape') , request = require('../../index') tape('returns on error', function(t) { diff --git a/tests/server.js b/tests/server.js index c8556f5e8..e152c04a6 100644 --- a/tests/server.js +++ b/tests/server.js @@ -4,14 +4,13 @@ var fs = require('fs') , http = require('http') , path = require('path') , https = require('https') - , events = require('events') , stream = require('stream') , assert = require('assert') exports.port = 6767 exports.portSSL = 16167 -exports.createServer = function (port) { +exports.createServer = function (port) { port = port || exports.port var s = http.createServer(function (req, resp) { s.emit(req.url, req, resp) diff --git a/tests/test-basic-auth.js b/tests/test-basic-auth.js index 5eab311a7..5b0d7fbe2 100644 --- a/tests/test-basic-auth.js +++ b/tests/test-basic-auth.js @@ -158,7 +158,7 @@ tape('pass - undefined', function(t) { tape('auth method', function(t) { var r = request .get('http://localhost:6767/test/') - .auth('user','',false) + .auth('user', '', false) .on('response', function (res) { t.equal(r._auth.user, 'user') t.equal(res.statusCode, 200) diff --git a/tests/test-bearer-auth.js b/tests/test-bearer-auth.js index 38c41f126..fcc3f31d8 100644 --- a/tests/test-bearer-auth.js +++ b/tests/test-bearer-auth.js @@ -98,7 +98,7 @@ tape('', function(t) { tape('', function(t) { request .get('http://localhost:6767/test/') - .auth(null,null,false,'theToken') + .auth(null, null, false, 'theToken') .on('response', function (res) { t.equal(res.statusCode, 200) t.equal(numBearerRequests, 7) @@ -109,7 +109,7 @@ tape('', function(t) { tape('', function(t) { request .get('http://localhost:6767/test/') - .auth(null,null,true,'theToken') + .auth(null, null, true, 'theToken') .on('response', function (res) { t.equal(res.statusCode, 200) t.equal(numBearerRequests, 8) diff --git a/tests/test-body.js b/tests/test-body.js index d605f574f..a49640f87 100644 --- a/tests/test-body.js +++ b/tests/test-body.js @@ -1,8 +1,6 @@ 'use strict' var server = require('./server') - , events = require('events') - , stream = require('stream') , request = require('../index') , tape = require('tape') @@ -146,6 +144,6 @@ addTest('testPutMultipartPostambleCRLF', { tape('cleanup', function(t) { s.close(function() { - t.end() + t.end() }) }) diff --git a/tests/test-errors.js b/tests/test-errors.js index bb5ab7ccc..56f46bd6e 100644 --- a/tests/test-errors.js +++ b/tests/test-errors.js @@ -1,7 +1,6 @@ 'use strict' -var server = require('./server') - , request = require('../index') +var request = require('../index') , tape = require('tape') var local = 'http://localhost:8888/asdf' diff --git a/tests/test-httpModule.js b/tests/test-httpModule.js index 0cb7e606d..dae4845a7 100644 --- a/tests/test-httpModule.js +++ b/tests/test-httpModule.js @@ -64,7 +64,7 @@ tape('setup', function(t) { function run_tests(name, httpModules) { tape(name, function(t) { - var to_https = 'http://localhost:' + plain_server.port + '/to_https' + var to_https = 'http://localhost:' + plain_server.port + '/to_https' , to_plain = 'https://localhost:' + https_server.port + '/to_plain' , options = { httpModules: httpModules, strictSSL: false } , modulesTest = httpModules || {} diff --git a/tests/test-json-request.js b/tests/test-json-request.js index a1d6f32bd..f45c753d7 100644 --- a/tests/test-json-request.js +++ b/tests/test-json-request.js @@ -1,7 +1,6 @@ 'use strict' var server = require('./server') - , stream = require('stream') , request = require('../index') , tape = require('tape') diff --git a/tests/test-multipart.js b/tests/test-multipart.js index dafc23805..f7c6dcb00 100644 --- a/tests/test-multipart.js +++ b/tests/test-multipart.js @@ -107,9 +107,10 @@ var testHeaders = [ 'multipart/related; boundary=XXX; type=text/xml; start=""' ] -var suite = ['post', 'get'].forEach(function(method) { +var methods = ['post', 'get'] +methods.forEach(function(method) { testHeaders.forEach(function(header) { - [true, false].forEach(function(json) { + [true, false].forEach(function(json) { var name = [ 'multipart-related', method.toUpperCase(), (header || 'default'), diff --git a/tests/test-oauth.js b/tests/test-oauth.js index cfb587f04..bc0b131ef 100644 --- a/tests/test-oauth.js +++ b/tests/test-oauth.js @@ -451,7 +451,7 @@ tape('query transport_method with qs parameter and existing query string in url' t.notOk(r.headers.Authorization, 'oauth Authorization header should not be present with transport_method \'query\'') t.notOk(r.path.match(/\?&/), 'there should be no ampersand at the beginning of the query') t.equal('OB33pYjWAnf+xtOHN4Gmbdil168=', qs.parse(r.path).oauth_signature) - + var params = qs.parse(r.path.split('?')[1]) , keys = Object.keys(params) diff --git a/tests/test-pipes.js b/tests/test-pipes.js index 1f42bab75..0e4be002c 100644 --- a/tests/test-pipes.js +++ b/tests/test-pipes.js @@ -1,7 +1,6 @@ 'use strict' var server = require('./server') - , events = require('events') , stream = require('stream') , fs = require('fs') , request = require('../index') @@ -238,7 +237,7 @@ tape('piping after response', function(t) { tape('piping through a redirect', function(t) { s.once('/forward1', function(req, res) { - res.writeHead(302, { location: '/forward2' }) + res.writeHead(302, { location: '/forward2' }) res.end() }) s.once('/forward2', function(req, res) { diff --git a/tests/test-proxy-connect.js b/tests/test-proxy-connect.js index 60e6bab87..f8aeba4ce 100644 --- a/tests/test-proxy-connect.js +++ b/tests/test-proxy-connect.js @@ -1,7 +1,6 @@ 'use strict' -var net = require('net') - , request = require('../index') +var request = require('../index') , tape = require('tape') var port = 6768 diff --git a/tests/test-redirect-auth.js b/tests/test-redirect-auth.js index 510604dbc..ecffdbd8b 100644 --- a/tests/test-redirect-auth.js +++ b/tests/test-redirect-auth.js @@ -3,7 +3,6 @@ var server = require('./server') , request = require('../index') , util = require('util') - , events = require('events') , tape = require('tape') var s = server.createServer() diff --git a/tests/test-redirect-complex.js b/tests/test-redirect-complex.js index d99b962e1..c3ff7a031 100644 --- a/tests/test-redirect-complex.js +++ b/tests/test-redirect-complex.js @@ -73,7 +73,7 @@ tape('lots of redirects', function(t) { }) } - for (var i = 0; i < n; i ++) { + for (var i = 0; i < n; i++) { doRedirect(i) } }) diff --git a/tests/test-redirect.js b/tests/test-redirect.js index f5cae24f8..096229dba 100644 --- a/tests/test-redirect.js +++ b/tests/test-redirect.js @@ -323,9 +323,9 @@ tape('should have the referer when following redirect by default', function(t) { t.equal(res.statusCode, 200) t.end() }) - .on('redirect',function() { + .on('redirect', function() { t.notEqual(this.headers.referer, undefined) - t.equal(this.headers.referer.substring(this.headers.referer.lastIndexOf('/')),'/temp_landing') + t.equal(this.headers.referer.substring(this.headers.referer.lastIndexOf('/')), '/temp_landing') }) }) @@ -341,7 +341,7 @@ tape('should not have a referer when removeRefererHeader is true', function(t) { t.equal(res.statusCode, 200) t.end() }) - .on('redirect',function() { + .on('redirect', function() { t.equal(this.headers.referer, undefined) }) }) diff --git a/tests/test-timeout.js b/tests/test-timeout.js index a270ef1ed..9037c8b88 100644 --- a/tests/test-timeout.js +++ b/tests/test-timeout.js @@ -11,8 +11,6 @@ if (process.env.TRAVIS === 'true') { /*eslint no-process-exit:0*/ } else { var server = require('./server') - , events = require('events') - , stream = require('stream') , request = require('../index') , tape = require('tape') diff --git a/tests/test-timing.js b/tests/test-timing.js index 89ec04655..04b13bdcc 100644 --- a/tests/test-timing.js +++ b/tests/test-timing.js @@ -1,7 +1,6 @@ 'use strict' -var http = require('http') - , server = require('./server') +var server = require('./server') , request = require('../index') , tape = require('tape') diff --git a/tests/test-toJSON.js b/tests/test-toJSON.js index cc983d75e..431600a1b 100644 --- a/tests/test-toJSON.js +++ b/tests/test-toJSON.js @@ -25,12 +25,12 @@ tape('request().toJSON()', function(t) { t.equal(err, null) - t.equal(json_r.uri.href , r.uri.href) - t.equal(json_r.method , r.method) + t.equal(json_r.uri.href, r.uri.href) + t.equal(json_r.method, r.method) t.equal(json_r.headers.foo, r.headers.foo) - t.equal(json_res.statusCode , res.statusCode) - t.equal(json_res.body , res.body) + t.equal(json_res.statusCode, res.statusCode) + t.equal(json_res.body, res.body) t.equal(json_res.headers.date, res.headers.date) t.end() diff --git a/tests/test-unix.js b/tests/test-unix.js index 16a2cc85d..71395a6bc 100644 --- a/tests/test-unix.js +++ b/tests/test-unix.js @@ -27,7 +27,7 @@ tape('setup', function(t) { }) tape('unix socket connection', function(t) { - request('http://unix:' + socket + ':' + path, function(err, res, body) { + request('http://unix:' + socket + ':' + path, function(err, res, body) { t.equal(err, null, 'no error in connection') t.equal(res.statusCode, statusCode, 'got HTTP 200 OK response') t.equal(body, expectedBody, 'expected response body is received') From 28e957cd2862a34bbdda6e4361d4398d35639c10 Mon Sep 17 00:00:00 2001 From: simov Date: Sat, 21 Mar 2015 11:53:54 +0200 Subject: [PATCH 048/490] Add table of contents in readme Add back to top links at the end of each section Add horizontal line divider after each section Add visual cues in options list --- README.md | 590 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 353 insertions(+), 237 deletions(-) diff --git a/README.md b/README.md index b10b4e48a..23f0d67c7 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,18 @@ -# Request — Simplified HTTP client + +# Request - Simplified HTTP client + [![npm package](https://nodei.co/npm/request.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/request/) -[![Build status](https://img.shields.io/travis/request/request.svg?style=flat)](https://travis-ci.org/request/request) -[![Coverage](https://img.shields.io/coveralls/request/request.svg?style=flat)](https://coveralls.io/r/request/request) -[![Gitter](https://img.shields.io/badge/gitter-join_chat-blue.svg?style=flat)](https://gitter.im/request/request?utm_source=badge) +[![Build status](https://img.shields.io/travis/request/request.svg?style=flat-square)](https://travis-ci.org/request/request) +[![Coverage](https://img.shields.io/coveralls/request/request.svg?style=flat-square)](https://coveralls.io/r/request/request) +[![Gitter](https://img.shields.io/badge/gitter-join_chat-blue.svg?style=flat-square)](https://gitter.im/request/request?utm_source=badge) + ## Super simple to use Request is designed to be the simplest way possible to make http calls. It supports HTTPS and follows redirects by default. -```javascript +```js var request = require('request'); request('http://www.google.com', function (error, response, body) { if (!error && response.statusCode == 200) { @@ -18,29 +21,51 @@ request('http://www.google.com', function (error, response, body) { }) ``` + +## Table of contents + +- [Streaming](#streaming) +- [Forms](#forms) +- [HTTP Authentication](#http-authentication) +- [Custom HTTP Headers](#custom-http-headers) +- [OAuth Signing](#oauth-signing) +- [Proxies](#proxies) +- [Unix Domain Sockets](#unix-domain-sockets) +- [TLS/SSL Protocol](#tlsssl-protocol) +- [**All Available Options**](#requestoptions-callback) + +Request also offers [convenience methods](#convenience-methods) like +`request.defaults` and `request.post`, and there are +lots of [usage examples](#examples) and several +[debugging techniques](#debugging). + + +--- + + ## Streaming You can stream any response to a file stream. -```javascript +```js request('http://google.com/doodle.png').pipe(fs.createWriteStream('doodle.png')) ``` You can also stream a file to a PUT or POST request. This method will also check the file extension against a mapping of file extensions to content-types (in this case `application/json`) and use the proper `content-type` in the PUT request (if the headers don’t already provide one). -```javascript +```js fs.createReadStream('file.json').pipe(request.put('http://mysite.com/obj.json')) ``` Request can also `pipe` to itself. When doing so, `content-type` and `content-length` are preserved in the PUT headers. -```javascript +```js request.get('http://google.com/img.png').pipe(request.put('http://mysite.com/img.png')) ``` Request emits a "response" event when a response is received. The `response` argument will be an instance of [http.IncomingMessage](http://nodejs.org/api/http.html#http_http_incomingmessage). -```javascript +```js request .get('http://google.com/img.png') .on('response', function(response) { @@ -52,7 +77,7 @@ request To easily handle errors when streaming requests, listen to the `error` event before piping: -```javascript +```js request .get('http://mysite.com/doodle.png') .on('error', function(err) { @@ -63,7 +88,7 @@ request Now let’s get fancy. -```javascript +```js http.createServer(function (req, resp) { if (req.url === '/doodle.png') { if (req.method === 'PUT') { @@ -77,7 +102,7 @@ http.createServer(function (req, resp) { You can also `pipe()` from `http.ServerRequest` instances, as well as to `http.ServerResponse` instances. The HTTP method, headers, and entity-body data will be sent. Which means that, if you don't really care about security, you can do: -```javascript +```js http.createServer(function (req, resp) { if (req.url === '/doodle.png') { var x = request('http://mysite.com/doodle.png') @@ -89,13 +114,13 @@ http.createServer(function (req, resp) { And since `pipe()` returns the destination stream in ≥ Node 0.5.x you can do one line proxying. :) -```javascript +```js req.pipe(request('http://mysite.com/doodle.png')).pipe(resp) ``` Also, none of this new functionality conflicts with requests previous features, it just expands them. -```javascript +```js var r = request.defaults({'proxy':'http://localproxy.com'}) http.createServer(function (req, resp) { @@ -107,139 +132,22 @@ http.createServer(function (req, resp) { You can still use intermediate proxies, the requests will still follow HTTP forwards, etc. -## Proxies - -If you specify a `proxy` option, then the request (and any subsequent -redirects) will be sent via a connection to the proxy server. - -If your endpoint is an `https` url, and you are using a proxy, then -request will send a `CONNECT` request to the proxy server *first*, and -then use the supplied connection to connect to the endpoint. - -That is, first it will make a request like: - -``` -HTTP/1.1 CONNECT endpoint-server.com:80 -Host: proxy-server.com -User-Agent: whatever user agent you specify -``` - -and then the proxy server make a TCP connection to `endpoint-server` -on port `80`, and return a response that looks like: - -``` -HTTP/1.1 200 OK -``` - -At this point, the connection is left open, and the client is -communicating directly with the `endpoint-server.com` machine. - -See [the wikipedia page on HTTP Tunneling](http://en.wikipedia.org/wiki/HTTP_tunnel) -for more information. - -By default, when proxying `http` traffic, request will simply make a -standard proxied `http` request. This is done by making the `url` -section of the initial line of the request a fully qualified url to -the endpoint. - -For example, it will make a single request that looks like: - -``` -HTTP/1.1 GET http://endpoint-server.com/some-url -Host: proxy-server.com -Other-Headers: all go here - -request body or whatever -``` - -Because a pure "http over http" tunnel offers no additional security -or other features, it is generally simpler to go with a -straightforward HTTP proxy in this case. However, if you would like -to force a tunneling proxy, you may set the `tunnel` option to `true`. - -You can also make a standard proxied `http` request by explicitly setting -`tunnel : false`, but **note that this will allow the proxy to see the traffic -to/from the destination server**. - -If you are using a tunneling proxy, you may set the -`proxyHeaderWhiteList` to share certain headers with the proxy. - -You can also set the `proxyHeaderExclusiveList` to share certain -headers only with the proxy and not with destination host. - -By default, this set is: - -``` -accept -accept-charset -accept-encoding -accept-language -accept-ranges -cache-control -content-encoding -content-language -content-length -content-location -content-md5 -content-range -content-type -connection -date -expect -max-forwards -pragma -proxy-authorization -referer -te -transfer-encoding -user-agent -via -``` - -Note that, when using a tunneling proxy, the `proxy-authorization` -header and any headers from custom `proxyHeaderExclusiveList` are -*never* sent to the endpoint server, but only to the proxy server. +[back to top](#table-of-contents) -### Controlling proxy behaviour using environment variables -The following environment variables are respected by `request`: - - * `HTTP_PROXY` / `http_proxy` - * `HTTPS_PROXY` / `https_proxy` - * `NO_PROXY` / `no_proxy` - -When `HTTP_PROXY` / `http_proxy` are set, they will be used to proxy non-SSL requests that do not have an explicit `proxy` configuration option present. Similarly, `HTTPS_PROXY` / `https_proxy` will be respected for SSL requests that do not have an explicit `proxy` configuration option. It is valid to define a proxy in one of the environment variables, but then override it for a specific request, using the `proxy` configuration option. Furthermore, the `proxy` configuration option can be explicitly set to false / null to opt out of proxying altogether for that request. - -`request` is also aware of the `NO_PROXY`/`no_proxy` environment variables. These variables provide a granular way to opt out of proxying, on a per-host basis. It should contain a comma separated list of hosts to opt out of proxying. It is also possible to opt of proxying when a particular destination port is used. Finally, the variable may be set to `*` to opt out of the implicit proxy configuration of the other environment variables. - -Here's some examples of valid `no_proxy` values: - - * `google.com` - don't proxy HTTP/HTTPS requests to Google. - * `google.com:443` - don't proxy HTTPS requests to Google, but *do* proxy HTTP requests to Google. - * `google.com:443, yahoo.com:80` - don't proxy HTTPS requests to Google, and don't proxy HTTP requests to Yahoo! - * `*` - ignore `https_proxy`/`http_proxy` environment variables altogether. - -## UNIX Socket - -`request` supports making requests to [UNIX Domain Sockets](http://en.wikipedia.org/wiki/Unix_domain_socket). To make one, use the following URL scheme: - -```javascript -/* Pattern */ 'http://unix:SOCKET:PATH' -/* Example */ request.get('http://unix:/absolute/path/to/unix.socket:/request/path') -``` - -Note: The `SOCKET` path is assumed to be absolute to the root of the host file system. +--- ## Forms `request` supports `application/x-www-form-urlencoded` and `multipart/form-data` form uploads. For `multipart/related` refer to the `multipart` API. + #### application/x-www-form-urlencoded (URL-Encoded Forms) URL-encoded forms are simple. -```javascript +```js request.post('http://service.com/upload', {form:{key:'value'}}) // or request.post('http://service.com/upload').form({key:'value'}) @@ -247,12 +155,13 @@ request.post('http://service.com/upload').form({key:'value'}) request.post({url:'http://service.com/upload', form: {key:'value'}}, function(err,httpResponse,body){ /* ... */ }) ``` + #### multipart/form-data (Multipart Form Uploads) For `multipart/form-data` we use the [form-data](https://github.com/felixge/node-form-data) library by [@felixge](https://github.com/felixge). For the most cases, you can pass your upload form data via the `formData` option. -```javascript +```js var formData = { // Pass a simple key-value pair my_field: 'my_value', @@ -286,7 +195,7 @@ request.post({url:'http://service.com/upload', formData: formData}, function opt For advanced cases, you can access the form-data object itself via `r.form()`. This can be modified until the request is fired on the next cycle of the event-loop. (Note that this calling `form()` will clear the currently set form data for that request.) -```javascript +```js // NOTE: Advanced use-case, for normal use see 'formData' usage above var r = request.post('http://service.com/upload', function optionalCallback(err, httpResponse, body) { // ... @@ -297,11 +206,12 @@ form.append('custom_file', fs.createReadStream(__dirname + '/unicycle.jpg'), {fi ``` See the [form-data README](https://github.com/felixge/node-form-data) for more information & examples. + #### multipart/related Some variations in different HTTP implementations require a newline/CRLF before, after, or both before and after the boundary of a `multipart/related` request (using the multipart option). This has been observed in the .NET WebAPI version 4.0. You can turn on a boundary preambleCRLF or postamble by passing them as `true` to your request options. -```javascript +```js request({ method: 'PUT', preambleCRLF: true, @@ -335,10 +245,15 @@ Some variations in different HTTP implementations require a newline/CRLF before, }) ``` +[back to top](#table-of-contents) + + +--- + ## HTTP Authentication -```javascript +```js request.get('http://some.server.com/').auth('username', 'password', false); // or request.get('http://some.server.com/', { @@ -378,7 +293,7 @@ Note that you can also specify basic authentication using the URL itself, as detailed in [RFC 1738](http://www.ietf.org/rfc/rfc1738.txt). Simply pass the `user:password` before the host with an `@` sign: -```javascript +```js var username = 'username', password = 'password', url = 'http://' + username + ':' + password + '@some.server.com'; @@ -398,13 +313,53 @@ available. The value may be either a `String` or a `Function` returning a used in conjuction with `defaults` to allow a single function to supply the last known token at the time of sending a request, or to compute one on the fly. +[back to top](#table-of-contents) + + +--- + + +## Custom HTTP Headers + +HTTP Headers, such as `User-Agent`, can be set in the `options` object. +In the example below, we call the github API to find out the number +of stars and forks for the request repository. This requires a +custom `User-Agent` header as well as https. + +```js +var request = require('request'); + +var options = { + url: 'https://api.github.com/repos/request/request', + headers: { + 'User-Agent': 'request' + } +}; + +function callback(error, response, body) { + if (!error && response.statusCode == 200) { + var info = JSON.parse(body); + console.log(info.stargazers_count + " Stars"); + console.log(info.forks_count + " Forks"); + } +} + +request(options, callback); +``` + +[back to top](#table-of-contents) + + +--- + + ## OAuth Signing [OAuth version 1.0](https://tools.ietf.org/html/rfc5849) is supported. The default signing algorithm is [HMAC-SHA1](https://tools.ietf.org/html/rfc5849#section-3.4.2): -```javascript +```js // OAuth1.0 - 3-legged server side flow (Twitter example) // step 1 var qs = require('querystring') @@ -478,34 +433,148 @@ section of the oauth1 spec: options object. * `transport_method` defaults to `'header'` -## Custom HTTP Headers +[back to top](#table-of-contents) -HTTP Headers, such as `User-Agent`, can be set in the `options` object. -In the example below, we call the github API to find out the number -of stars and forks for the request repository. This requires a -custom `User-Agent` header as well as https. -```javascript -var request = require('request'); +--- -var options = { - url: 'https://api.github.com/repos/request/request', - headers: { - 'User-Agent': 'request' - } -}; -function callback(error, response, body) { - if (!error && response.statusCode == 200) { - var info = JSON.parse(body); - console.log(info.stargazers_count + " Stars"); - console.log(info.forks_count + " Forks"); - } -} +## Proxies -request(options, callback); +If you specify a `proxy` option, then the request (and any subsequent +redirects) will be sent via a connection to the proxy server. + +If your endpoint is an `https` url, and you are using a proxy, then +request will send a `CONNECT` request to the proxy server *first*, and +then use the supplied connection to connect to the endpoint. + +That is, first it will make a request like: + +``` +HTTP/1.1 CONNECT endpoint-server.com:80 +Host: proxy-server.com +User-Agent: whatever user agent you specify +``` + +and then the proxy server make a TCP connection to `endpoint-server` +on port `80`, and return a response that looks like: + +``` +HTTP/1.1 200 OK +``` + +At this point, the connection is left open, and the client is +communicating directly with the `endpoint-server.com` machine. + +See [the wikipedia page on HTTP Tunneling](http://en.wikipedia.org/wiki/HTTP_tunnel) +for more information. + +By default, when proxying `http` traffic, request will simply make a +standard proxied `http` request. This is done by making the `url` +section of the initial line of the request a fully qualified url to +the endpoint. + +For example, it will make a single request that looks like: + +``` +HTTP/1.1 GET http://endpoint-server.com/some-url +Host: proxy-server.com +Other-Headers: all go here + +request body or whatever +``` + +Because a pure "http over http" tunnel offers no additional security +or other features, it is generally simpler to go with a +straightforward HTTP proxy in this case. However, if you would like +to force a tunneling proxy, you may set the `tunnel` option to `true`. + +You can also make a standard proxied `http` request by explicitly setting +`tunnel : false`, but **note that this will allow the proxy to see the traffic +to/from the destination server**. + +If you are using a tunneling proxy, you may set the +`proxyHeaderWhiteList` to share certain headers with the proxy. + +You can also set the `proxyHeaderExclusiveList` to share certain +headers only with the proxy and not with destination host. + +By default, this set is: + +``` +accept +accept-charset +accept-encoding +accept-language +accept-ranges +cache-control +content-encoding +content-language +content-length +content-location +content-md5 +content-range +content-type +connection +date +expect +max-forwards +pragma +proxy-authorization +referer +te +transfer-encoding +user-agent +via +``` + +Note that, when using a tunneling proxy, the `proxy-authorization` +header and any headers from custom `proxyHeaderExclusiveList` are +*never* sent to the endpoint server, but only to the proxy server. + + +### Controlling proxy behaviour using environment variables + +The following environment variables are respected by `request`: + + * `HTTP_PROXY` / `http_proxy` + * `HTTPS_PROXY` / `https_proxy` + * `NO_PROXY` / `no_proxy` + +When `HTTP_PROXY` / `http_proxy` are set, they will be used to proxy non-SSL requests that do not have an explicit `proxy` configuration option present. Similarly, `HTTPS_PROXY` / `https_proxy` will be respected for SSL requests that do not have an explicit `proxy` configuration option. It is valid to define a proxy in one of the environment variables, but then override it for a specific request, using the `proxy` configuration option. Furthermore, the `proxy` configuration option can be explicitly set to false / null to opt out of proxying altogether for that request. + +`request` is also aware of the `NO_PROXY`/`no_proxy` environment variables. These variables provide a granular way to opt out of proxying, on a per-host basis. It should contain a comma separated list of hosts to opt out of proxying. It is also possible to opt of proxying when a particular destination port is used. Finally, the variable may be set to `*` to opt out of the implicit proxy configuration of the other environment variables. + +Here's some examples of valid `no_proxy` values: + + * `google.com` - don't proxy HTTP/HTTPS requests to Google. + * `google.com:443` - don't proxy HTTPS requests to Google, but *do* proxy HTTP requests to Google. + * `google.com:443, yahoo.com:80` - don't proxy HTTPS requests to Google, and don't proxy HTTP requests to Yahoo! + * `*` - ignore `https_proxy`/`http_proxy` environment variables altogether. + +[back to top](#table-of-contents) + + +--- + + +## UNIX Domain Sockets + +`request` supports making requests to [UNIX Domain Sockets](http://en.wikipedia.org/wiki/Unix_domain_socket). To make one, use the following URL scheme: + +```js +/* Pattern */ 'http://unix:SOCKET:PATH' +/* Example */ request.get('http://unix:/absolute/path/to/unix.socket:/request/path') ``` +Note: The `SOCKET` path is assumed to be absolute to the root of the host file system. + +[back to top](#table-of-contents) + + +--- + + ## TLS/SSL Protocol TLS/SSL Protocol options, such as `cert`, `key` and `passphrase`, can be @@ -513,7 +582,7 @@ set in the `agentOptions` property of the `options` object. In the example below, we call an API requires client side SSL certificate (in PEM format) with passphrase protected private key (in PEM format) and disable the SSLv3 protocol: -```javascript +```js var fs = require('fs') , path = require('path') , certFile = path.resolve(__dirname, 'ssl/client.crt') @@ -537,7 +606,7 @@ request.get(options); It is able to force using SSLv3 only by specifying `secureProtocol`: -```javascript +```js request.get({ url: 'https://api.some-server.com/', agentOptions: { @@ -550,7 +619,7 @@ It is possible to accept other certificates than those signed by generally allow This can be useful, for example, when using self-signed certificates. To allow a different certificate, you can specify the signing CA by adding the contents of the CA's certificate file to the `agentOptions`: -```javascript +```js request.get({ url: 'https://api.some-server.com/', agentOptions: { @@ -559,76 +628,103 @@ request.get({ }); ``` +[back to top](#table-of-contents) + + +--- + + ## request(options, callback) The first argument can be either a `url` or an `options` object. The only required option is `uri`; all others are optional. -* `uri` || `url` - fully qualified uri or a parsed url object from `url.parse()` -* `baseUrl` - fully qualified uri string used as the base url. Most useful with `request.defaults`, for example when you want to do many requests to the same domain. If `baseUrl` is `https://example.com/api/`, then requesting `/end/point?test=true` will fetch `https://example.com/api/end/point?test=true`. When `baseUrl` is given, `uri` must also be a string. -* `qs` - object containing querystring values to be appended to the `uri` -* `qsParseOptions` - object containing options to pass to the [qs.parse](https://github.com/hapijs/qs#parsing-objects) method or [querystring.parse](https://nodejs.org/docs/v0.12.0/api/querystring.html#querystring_querystring_parse_str_sep_eq_options) method -* `qsStringifyOptions` - object containing options to pass to the [qs.stringify](https://github.com/hapijs/qs#stringifying) method or to the [querystring.stringify](https://nodejs.org/docs/v0.12.0/api/querystring.html#querystring_querystring_stringify_obj_sep_eq_options) method. For example, to change the way arrays are converted to query strings pass the `arrayFormat` option with one of `indices|brackets|repeat` -* `useQuerystring` - If true, use `querystring` to stringify and parse +- `uri` || `url` - fully qualified uri or a parsed url object from `url.parse()` +- `baseUrl` - fully qualified uri string used as the base url. Most useful with `request.defaults`, for example when you want to do many requests to the same domain. If `baseUrl` is `https://example.com/api/`, then requesting `/end/point?test=true` will fetch `https://example.com/api/end/point?test=true`. When `baseUrl` is given, `uri` must also be a string. +- `method` - http method (default: `"GET"`) +- `headers` - http headers (default: `{}`) + +--- + +- `qs` - object containing querystring values to be appended to the `uri` +- `qsParseOptions` - object containing options to pass to the [qs.parse](https://github.com/hapijs/qs#parsing-objects) method or [querystring.parse](https://nodejs.org/docs/v0.12.0/api/querystring.html#querystring_querystring_parse_str_sep_eq_options) method +- `qsStringifyOptions` - object containing options to pass to the [qs.stringify](https://github.com/hapijs/qs#stringifying) method or to the [querystring.stringify](https://nodejs.org/docs/v0.12.0/api/querystring.html#querystring_querystring_stringify_obj_sep_eq_options) method. For example, to change the way arrays are converted to query strings pass the `arrayFormat` option with one of `indices|brackets|repeat` +- `useQuerystring` - If true, use `querystring` to stringify and parse querystrings, otherwise use `qs` (default: `false`). Set this option to `true` if you need arrays to be serialized as `foo=bar&foo=baz` instead of the default `foo[0]=bar&foo[1]=baz`. -* `method` - http method (default: `"GET"`) -* `headers` - http headers (default: `{}`) -* `body` - entity body for PATCH, POST and PUT requests. Must be a `Buffer` or `String`, unless `json` is `true`. If `json` is `true`, then `body` must be a JSON-serializable object. -* `form` - when passed an object or a querystring, this sets `body` to a querystring representation of value, and adds `Content-type: application/x-www-form-urlencoded` header. When passed no options, a `FormData` instance is returned (and is piped to request). See "Forms" section above. -* `formData` - Data to pass for a `multipart/form-data` request. See + +--- + +- `body` - entity body for PATCH, POST and PUT requests. Must be a `Buffer` or `String`, unless `json` is `true`. If `json` is `true`, then `body` must be a JSON-serializable object. +- `form` - when passed an object or a querystring, this sets `body` to a querystring representation of value, and adds `Content-type: application/x-www-form-urlencoded` header. When passed no options, a `FormData` instance is returned (and is piped to request). See "Forms" section above. +- `formData` - Data to pass for a `multipart/form-data` request. See [Forms](#forms) section above. -* `multipart` - array of objects which contain their own headers and `body` +- `multipart` - array of objects which contain their own headers and `body` attributes. Sends a `multipart/related` request. See [Forms](#forms) section above. - * Alternatively you can pass in an object `{chunked: false, data: []}` where + - Alternatively you can pass in an object `{chunked: false, data: []}` where `chunked` is used to specify whether the request is sent in [chunked transfer encoding](https://en.wikipedia.org/wiki/Chunked_transfer_encoding) In non-chunked requests, data items with body streams are not allowed. -* `auth` - A hash containing values `user` || `username`, `pass` || `password`, and `sendImmediately` (optional). See documentation above. -* `json` - sets `body` but to JSON representation of value and adds `Content-type: application/json` header. Additionally, parses the response body as JSON. -* `jsonReviver` - a [reviver function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse) that will be passed to `JSON.parse()` when parsing a JSON response body. -* `preambleCRLF` - append a newline/CRLF before the boundary of your `multipart/form-data` request. -* `postambleCRLF` - append a newline/CRLF at the end of the boundary of your `multipart/form-data` request. -* `followRedirect` - follow HTTP 3xx responses as redirects (default: `true`). This property can also be implemented as function which gets `response` object as a single argument and should return `true` if redirects should continue or `false` otherwise. -* `followAllRedirects` - follow non-GET HTTP 3xx responses as redirects (default: `false`) -* `maxRedirects` - the maximum number of redirects to follow (default: `10`) -* `encoding` - Encoding to be used on `setEncoding` of response data. If `null`, the `body` is returned as a `Buffer`. Anything else **(including the default value of `undefined`)** will be passed as the [encoding](http://nodejs.org/api/buffer.html#buffer_buffer) parameter to `toString()` (meaning this is effectively `utf8` by default). -* `pool` - An object describing which agents to use for the request. If this option is omitted the request will use the global agent (as long as [your options allow for it](request.js#L747)). Otherwise, request will search the pool for your custom agent. If no custom agent is found, a new agent will be created and added to the pool. - * A `maxSockets` property can also be provided on the `pool` object to set the max number of sockets for all agents created (ex: `pool: {maxSockets: Infinity}`). - * Note that if you are sending multiple requests in a loop and creating +- `preambleCRLF` - append a newline/CRLF before the boundary of your `multipart/form-data` request. +- `postambleCRLF` - append a newline/CRLF at the end of the boundary of your `multipart/form-data` request. +- `json` - sets `body` but to JSON representation of value and adds `Content-type: application/json` header. Additionally, parses the response body as JSON. +- `jsonReviver` - a [reviver function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse) that will be passed to `JSON.parse()` when parsing a JSON response body. + +--- + +- `auth` - A hash containing values `user` || `username`, `pass` || `password`, and `sendImmediately` (optional). See documentation above. +- `oauth` - Options for OAuth HMAC-SHA1 signing. See documentation above. +- `hawk` - Options for [Hawk signing](https://github.com/hueniverse/hawk). The `credentials` key must contain the necessary signing info, [see hawk docs for details](https://github.com/hueniverse/hawk#usage-example). +- `aws` - `object` containing AWS signing information. Should have the properties `key`, `secret`. Also requires the property `bucket`, unless you’re specifying your `bucket` as part of the path, or the request doesn’t use a bucket (i.e. GET Services) +- `httpSignature` - Options for the [HTTP Signature Scheme](https://github.com/joyent/node-http-signature/blob/master/http_signing.md) using [Joyent's library](https://github.com/joyent/node-http-signature). The `keyId` and `key` properties must be specified. See the docs for other options. + +--- + +- `followRedirect` - follow HTTP 3xx responses as redirects (default: `true`). This property can also be implemented as function which gets `response` object as a single argument and should return `true` if redirects should continue or `false` otherwise. +- `followAllRedirects` - follow non-GET HTTP 3xx responses as redirects (default: `false`) +- `maxRedirects` - the maximum number of redirects to follow (default: `10`) + +--- + +- `encoding` - Encoding to be used on `setEncoding` of response data. If `null`, the `body` is returned as a `Buffer`. Anything else **(including the default value of `undefined`)** will be passed as the [encoding](http://nodejs.org/api/buffer.html#buffer_buffer) parameter to `toString()` (meaning this is effectively `utf8` by default). +- `gzip` - If `true`, add an `Accept-Encoding` header to request compressed content encodings from the server (if not already present) and decode supported content encodings in the response. **Note:** Automatic decoding of the response content is performed on the body data returned through `request` (both through the `request` stream and passed to the callback function) but is not performed on the `response` stream (available from the `response` event) which is the unmodified `http.IncomingMessage` object which may contain compressed data. See example below. +- `jar` - If `true` and `tough-cookie` is installed, remember cookies for future use (or define your custom cookie jar; see examples section) + +--- + +- `pool` - An object describing which agents to use for the request. If this option is omitted the request will use the global agent (as long as [your options allow for it](request.js#L747)). Otherwise, request will search the pool for your custom agent. If no custom agent is found, a new agent will be created and added to the pool. + - A `maxSockets` property can also be provided on the `pool` object to set the max number of sockets for all agents created (ex: `pool: {maxSockets: Infinity}`). + - Note that if you are sending multiple requests in a loop and creating multiple new `pool` objects, `maxSockets` will not work as intended. To work around this, either use [`request.defaults`](#requestdefaultsoptions) 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 +- `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)). -* `proxy` - An HTTP proxy to be used. Supports proxy Auth with Basic Auth, identical to support for the `url` parameter (by embedding the auth info in the `uri`) -* `oauth` - Options for OAuth HMAC-SHA1 signing. See documentation above. -* `hawk` - Options for [Hawk signing](https://github.com/hueniverse/hawk). The `credentials` key must contain the necessary signing info, [see hawk docs for details](https://github.com/hueniverse/hawk#usage-example). -* `strictSSL` - If `true`, requires SSL certificates be valid. **Note:** to use your own certificate authority, you need to specify an agent that was created with that CA as an option. -* `agentOptions` - Object containing user agent options. See documentation above. **Note:** [see tls API doc for TLS/SSL options](http://nodejs.org/api/tls.html#tls_tls_connect_options_callback). -* `time` - If `true`, the request-response cycle (including all redirects) is timed at millisecond resolution, and the result provided on the response's `elapsedTime` property. -* `jar` - If `true` and `tough-cookie` is installed, remember cookies for future use (or define your custom cookie jar; see examples section) -* `aws` - `object` containing AWS signing information. Should have the properties `key`, `secret`. Also requires the property `bucket`, unless you’re specifying your `bucket` as part of the path, or the request doesn’t use a bucket (i.e. GET Services) -* `httpSignature` - Options for the [HTTP Signature Scheme](https://github.com/joyent/node-http-signature/blob/master/http_signing.md) using [Joyent's library](https://github.com/joyent/node-http-signature). The `keyId` and `key` properties must be specified. See the docs for other options. -* `localAddress` - Local interface to bind for network connections. -* `gzip` - If `true`, add an `Accept-Encoding` header to request compressed content encodings from the server (if not already present) and decode supported content encodings in the response. **Note:** Automatic decoding of the response content is performed on the body data returned through `request` (both through the `request` stream and passed to the callback function) but is not performed on the `response` stream (available from the `response` event) which is the unmodified `http.IncomingMessage` object which may contain compressed data. See example below. -* `tunnel` - controls the behavior of +- `localAddress` - Local interface to bind for network connections. +- `proxy` - An HTTP proxy to be used. Supports proxy Auth with Basic Auth, identical to support for the `url` parameter (by embedding the auth info in the `uri`) +- `strictSSL` - If `true`, requires SSL certificates be valid. **Note:** to use your own certificate authority, you need to specify an agent that was created with that CA as an option. +- `agentOptions` - Object containing user agent options. See documentation above. **Note:** [see tls API doc for TLS/SSL options](http://nodejs.org/api/tls.html#tls_tls_connect_options_callback). +- `tunnel` - controls the behavior of [HTTP `CONNECT` tunneling](https://en.wikipedia.org/wiki/HTTP_tunnel#HTTP_CONNECT_tunneling) as follows: - * `undefined` (default) - `true` if the destination is `https` or a previous + - `undefined` (default) - `true` if the destination is `https` or a previous request in the redirect chain used a tunneling proxy, `false` otherwise - * `true` - always tunnel to the destination by making a `CONNECT` request to + - `true` - always tunnel to the destination by making a `CONNECT` request to the proxy - * `false` - request the destination as a `GET` request. -* `proxyHeaderWhiteList` - A whitelist of headers to send to a + - `false` - request the destination as a `GET` request. +- `proxyHeaderWhiteList` - A whitelist of headers to send to a tunneling proxy. -* `proxyHeaderExclusiveList` - A whitelist of headers to send +- `proxyHeaderExclusiveList` - A whitelist of headers to send exclusively to a tunneling proxy and not to destination. -* `removeRefererHeader` - removes the referer header when a redirect happens (default: `false`). +- `removeRefererHeader` - removes the referer header when a redirect happens (default: `false`). + +--- + +- `time` - If `true`, the request-response cycle (including all redirects) is timed at millisecond resolution, and the result provided on the response's `elapsedTime` property. The callback argument gets 3 arguments: @@ -637,10 +733,17 @@ The callback argument gets 3 arguments: 2. An [`http.IncomingMessage`](http://nodejs.org/api/http.html#http_http_incomingmessage) object 3. The third is the `response` body (`String` or `Buffer`, or JSON object if the `json` option is supplied) +[back to top](#table-of-contents) + + +--- + + ## Convenience methods There are also shorthand methods for different HTTP METHODs and some other conveniences. + ### request.defaults(options) This method **returns a wrapper** around the normal request API that defaults @@ -653,7 +756,7 @@ instead, it **returns a wrapper** that has your default settings applied to it. `request.defaults` to add/override defaults that were previously defaulted. For example: -```javascript +```js //requests using baseRequest() will set the 'x-token' header var baseRequest = request.defaults({ headers: {x-token: 'my-token'} @@ -670,7 +773,7 @@ var specialRequest = baseRequest.defaults({ Same as `request()`, but defaults to `method: "PUT"`. -```javascript +```js request.put(url) ``` @@ -678,7 +781,7 @@ request.put(url) Same as `request()`, but defaults to `method: "PATCH"`. -```javascript +```js request.patch(url) ``` @@ -686,7 +789,7 @@ request.patch(url) Same as `request()`, but defaults to `method: "POST"`. -```javascript +```js request.post(url) ``` @@ -694,7 +797,7 @@ request.post(url) Same as `request()`, but defaults to `method: "HEAD"`. -```javascript +```js request.head(url) ``` @@ -702,7 +805,7 @@ request.head(url) Same as `request()`, but defaults to `method: "DELETE"`. -```javascript +```js request.del(url) ``` @@ -710,28 +813,52 @@ request.del(url) Same as `request()` (for uniformity). -```javascript +```js request.get(url) ``` ### request.cookie Function that creates a new cookie. -```javascript +```js request.cookie('key1=value1') ``` ### request.jar() Function that creates a new cookie jar. -```javascript +```js request.jar() ``` +[back to top](#table-of-contents) + + +--- + + +## Debugging + +There are at least three ways to debug the operation of `request`: + +1. Launch the node process like `NODE_DEBUG=request node script.js` + (`lib,request,otherlib` works too). + +2. Set `require('request').debug = true` at any time (this does the same thing + as #1). + +3. Use the [request-debug module](https://github.com/nylen/request-debug) to + view request and response headers and bodies. + +[back to top](#table-of-contents) + + +--- + ## Examples: -```javascript +```js var request = require('request') , rand = Math.floor(Math.random()*100000000).toString() ; @@ -762,7 +889,7 @@ that the body data passed through `request` is automatically decompressed while the response object is unmodified and will contain compressed data if the server sent a compressed response. -```javascript +```js var request = require('request') request( { method: 'GET' @@ -789,7 +916,7 @@ the server sent a compressed response. Cookies are disabled by default (else, they would be used in subsequent requests). To enable cookies, set `jar` to `true` (either in `defaults` or `options`) and install `tough-cookie`. -```javascript +```js var request = request.defaults({jar: true}) request('http://www.google.com', function () { request('http://images.google.com') @@ -798,7 +925,7 @@ request('http://www.google.com', function () { To use a custom cookie jar (instead of `request`’s global cookie jar), set `jar` to an instance of `request.jar()` (either in `defaults` or `options`) -```javascript +```js var j = request.jar() var request = request.defaults({jar:j}) request('http://www.google.com', function () { @@ -808,7 +935,7 @@ request('http://www.google.com', function () { OR -```javascript +```js var j = request.jar(); var cookie = request.cookie('key1=value1'); var url = 'http://www.google.com'; @@ -823,7 +950,7 @@ To use a custom cookie store (such as a which supports saving to and restoring from JSON files), pass it as a parameter to `request.jar()`: -```javascript +```js var FileCookieStore = require('tough-cookie-filestore'); // NOTE - currently the 'cookies.json' file must already exist! var j = request.jar(new FileCookieStore('cookies.json')); @@ -841,7 +968,7 @@ for details. To inspect your cookie jar after a request: -```javascript +```js var j = request.jar() request({url: 'http://www.google.com', jar: j}, function () { var cookie_string = j.getCookieString(uri); // "key1=value1; key2=value2; ..." @@ -850,15 +977,4 @@ request({url: 'http://www.google.com', jar: j}, function () { }) ``` -## Debugging - -There are at least three ways to debug the operation of `request`: - -1. Launch the node process like `NODE_DEBUG=request node script.js` - (`lib,request,otherlib` works too). - -2. Set `require('request').debug = true` at any time (this does the same thing - as #1). - -3. Use the [request-debug module](https://github.com/nylen/request-debug) to - view request and response headers and bodies. +[back to top](#table-of-contents) From 132a010da92a67f764c325299c37a87d9a7181a2 Mon Sep 17 00:00:00 2001 From: Ahmad Nassri Date: Sat, 21 Mar 2015 22:22:55 -0700 Subject: [PATCH 049/490] HTTP Archive 1.2 support --- lib/har.js | 191 ++++++++++++++++++++++++++++++++++++++++ request.js | 8 ++ tests/fixtures/har.json | 158 +++++++++++++++++++++++++++++++++ tests/server.js | 22 +++++ tests/test-har.js | 172 ++++++++++++++++++++++++++++++++++++ 5 files changed, 551 insertions(+) create mode 100644 lib/har.js create mode 100644 tests/fixtures/har.json create mode 100644 tests/test-har.js diff --git a/lib/har.js b/lib/har.js new file mode 100644 index 000000000..91c4b91fb --- /dev/null +++ b/lib/har.js @@ -0,0 +1,191 @@ +'use strict' + +var fs = require('fs') +var path = require('path') +var qs = require('querystring') +var util = require('util') + +function Har (request) { + this.request = request +} + +Har.prototype.reducer = function (obj, pair) { + // new property ? + if (obj[pair.name] === undefined) { + obj[pair.name] = pair.value + return obj + } + + // existing? convert to array + var arr = [ + obj[pair.name], + pair.value + ] + + obj[pair.name] = arr + + return obj +} + +Har.prototype.prep = function (har) { + var data = util._extend({}, har) + + // only process the first entry + if (data.log && data.log.entries) { + data = data.log.entries[0] + } + + // construct utility properties + data.queryObj = {} + data.headersObj = {} + data.postData = data.postData ? data.postData : {} + data.postData.jsonObj = false + data.postData.paramsObj = false + + // construct query objects + if (data.queryString && data.queryString.length) { + data.queryObj = data.queryString.reduce(this.reducer, {}) + } + + // construct headers objects + if (data.headers && data.headers.length) { + // loweCase header keys + data.headersObj = data.headers.reduceRight(function (headers, header) { + headers[header.name] = header.value + return headers + }, {}) + } + + // construct Cookie heade + if (data.cookies && data.cookies.length) { + var cookies = data.cookies.map(function (cookie) { + return cookie.name + '=' + cookie.value + }) + + if (cookies.length) { + data.headersObj.cookie = cookies.join('; ') + } + } + + // prep body + switch (data.postData.mimeType) { + case 'multipart/mixed': + case 'multipart/related': + case 'multipart/form-data': + case 'multipart/alternative': + // reset values + data.postData.mimeType = 'multipart/form-data' + break + + case 'application/x-www-form-urlencoded': + if (!data.postData.params) { + data.postData.text = '' + } else { + data.postData.paramsObj = data.postData.params.reduce(this.reducer, {}) + + // always overwrite + data.postData.text = qs.stringify(data.postData.paramsObj) + } + break + + case 'text/json': + case 'text/x-json': + case 'application/json': + case 'application/x-json': + data.postData.mimeType = 'application/json' + + if (data.postData.text) { + try { + data.postData.jsonObj = JSON.parse(data.postData.text) + } catch (e) { + this.request.debug(e) + + // force back to text/plain + data.postData.mimeType = 'text/plain' + } + } + break + } + + return data +} + +Har.prototype.options = function (options) { + // skip if no har property defined + if (!options.har) { + return options + } + + // clean up and get some utility properties + var req = this.prep(options.har) + + // construct new options + if (req.url) { + options.url = req.url + } + + if (req.method) { + options.method = req.method + } + + if (Object.keys(req.queryObj).length) { + options.qs = req.queryObj + } + + if (Object.keys(req.headersObj).length) { + options.headers = req.headersObj + } + + switch (req.postData.mimeType) { + case 'application/x-www-form-urlencoded': + options.form = req.postData.paramsObj + break + + case 'application/json': + if (req.postData.jsonObj) { + options.body = req.postData.jsonObj + options.json = true + } + break + + case 'multipart/form-data': + options.formData = {} + + req.postData.params.forEach(function (param) { + var attachement = {} + + if (!param.fileName && !param.fileName && !param.contentType) { + options.formData[param.name] = param.value + return + } + + // attempt to read from disk! + if (param.fileName && !param.value) { + attachement.value = fs.createReadStream(param.fileName) + } else if (param.value) { + attachement.value = param.value + } + + if (param.fileName) { + var base = path.parse(param.fileName).base + + attachement.options = { + filename: base.length ? base : 'filename', + contentType: param.contentType ? param.contentType : null + } + } + + options.formData[param.name] = attachement + }) + break + + default: + if (req.postData.text) { + options.body = req.postData.text + } + } + + return options +} + +exports.Har = Har diff --git a/request.js b/request.js index d67f0bc22..0737033dd 100644 --- a/request.js +++ b/request.js @@ -22,6 +22,7 @@ var http = require('http') , cookies = require('./lib/cookies') , copy = require('./lib/copy') , getProxyFromURI = require('./lib/getProxyFromURI') + , Har = require('./lib/har').Har , Auth = require('./lib/auth').Auth , OAuth = require('./lib/oauth').OAuth , Multipart = require('./lib/multipart').Multipart @@ -244,6 +245,13 @@ function Request (options) { // call init var self = this + + // start with HAR, then override with additional options + if (options.har) { + self._har = new Har(self) + options = self._har.options(options) + } + stream.Stream.call(self) var reserved = Object.keys(Request.prototype) var nonReserved = filterForNonReserved(reserved, options) diff --git a/tests/fixtures/har.json b/tests/fixtures/har.json new file mode 100644 index 000000000..49799374c --- /dev/null +++ b/tests/fixtures/har.json @@ -0,0 +1,158 @@ +{ + "application-form-encoded": { + "method": "POST", + "headers": [ + { + "name": "content-type", + "value": "application/x-www-form-urlencoded" + } + ], + "postData": { + "mimeType": "application/x-www-form-urlencoded", + "params": [ + { + "name": "foo", + "value": "bar" + }, + { + "name": "hello", + "value": "world" + } + ] + } + }, + + "application-json": { + "method": "POST", + "headers": [ + { + "name": "content-type", + "value": "application/json" + } + ], + "postData": { + "mimeType": "application/json", + "text": "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}]}" + } + }, + + "cookies": { + "method": "POST", + "cookies": [ + { + "name": "foo", + "value": "bar" + }, + { + "name": "bar", + "value": "baz" + } + ] + }, + + "custom-method": { + "method": "PROPFIND" + }, + + "headers": { + "method": "GET", + "headers": [ + { + "name": "x-foo", + "value": "Bar" + } + ] + }, + + "multipart-data": { + "method": "POST", + "headers": [ + { + "name": "content-type", + "value": "multipart/form-data" + } + ], + "postData": { + "mimeType": "multipart/form-data", + "params": [ + { + "name": "foo", + "value": "Hello World", + "fileName": "hello.txt", + "contentType": "text/plain" + } + ] + } + }, + + "multipart-file": { + "method": "POST", + "headers": [ + { + "name": "content-type", + "value": "multipart/form-data" + } + ], + "postData": { + "mimeType": "multipart/form-data", + "params": [ + { + "name": "foo", + "fileName": "../tests/unicycle.jpg", + "contentType": "image/jpeg" + } + ] + } + }, + + "multipart-form-data": { + "method": "POST", + "headers": [ + { + "name": "content-type", + "value": "multipart/form-data" + } + ], + "postData": { + "mimeType": "multipart/form-data", + "params": [ + { + "name": "foo", + "value": "bar" + } + ] + } + }, + + "query": { + "method": "GET", + "queryString": [ + { + "name": "foo", + "value": "bar" + }, + { + "name": "foo", + "value": "baz" + }, + { + "name": "baz", + "value": "abc" + } + ] + }, + + "text-plain": { + "method": "POST", + "headers": [ + { + "name": "content-type", + "value": "text/plain" + } + ], + "postData": { + "mimeType": "text/plain", + "text": "Hello World" + } + } +} diff --git a/tests/server.js b/tests/server.js index e152c04a6..5c5585bb3 100644 --- a/tests/server.js +++ b/tests/server.js @@ -21,6 +21,28 @@ exports.createServer = function (port) { return s } +exports.createEchoServer = function (port) { + port = port || exports.port + var s = http.createServer(function (req, resp) { + var b = '' + req.on('data', function (chunk) {b += chunk}) + req.on('end', function () { + resp.writeHead(200, {'content-type':'application/json'}) + resp.write(JSON.stringify({ + url: req.url, + method: req.method, + headers: req.headers, + body: b + })) + resp.end() + }) + }) + s.port = port + s.url = 'http://localhost:' + port + s.protocol = 'http' + return s +} + exports.createSSLServer = function(port, opts) { port = port || exports.portSSL diff --git a/tests/test-har.js b/tests/test-har.js new file mode 100644 index 000000000..19d2b7532 --- /dev/null +++ b/tests/test-har.js @@ -0,0 +1,172 @@ +'use strict' + +var request = require('..') +var tape = require('tape') +var fixture = require('./fixtures/har.json') +var server = require('./server') + +var s = server.createEchoServer() + +tape('setup', function (t) { + s.listen(s.port, function () { + t.end() + }) +}) + +tape('application-form-encoded', function (t) { + var options = { + url: s.url, + har: fixture['application-form-encoded'] + } + + request(options, function (err, res, body) { + var json = JSON.parse(body) + + t.equal(err, null) + t.equal(json.body, 'foo=bar&hello=world') + t.end() + }) +}) + +tape('application-json', function (t) { + var options = { + url: s.url, + har: fixture['application-json'] + } + + request(options, function (err, res, body) { + t.equal(err, null) + t.equal(body.body, fixture['application-json'].postData.text) + t.end() + }) +}) + +tape('cookies', function (t) { + var options = { + url: s.url, + har: fixture.cookies + } + + request(options, function (err, res, body) { + var json = JSON.parse(body) + + t.equal(err, null) + t.equal(json.headers.cookie, 'foo=bar; bar=baz') + t.end() + }) +}) + +tape('custom-method', function (t) { + var options = { + url: s.url, + har: fixture['custom-method'] + } + + request(options, function (err, res, body) { + var json = JSON.parse(body) + + t.equal(err, null) + t.equal(json.method, fixture['custom-method'].method) + t.end() + }) +}) + +tape('headers', function (t) { + var options = { + url: s.url, + har: fixture.headers + } + + request(options, function (err, res, body) { + var json = JSON.parse(body) + + t.equal(err, null) + t.equal(json.headers['x-foo'], 'Bar') + t.end() + }) +}) + +tape('multipart-data', function (t) { + var options = { + url: s.url, + har: fixture['multipart-data'] + } + + request(options, function (err, res, body) { + var json = JSON.parse(body) + + t.equal(err, null) + t.ok(~json.headers['content-type'].indexOf('multipart/form-data')) + t.ok(~json.body.indexOf('Content-Disposition: form-data; name="foo"; filename="hello.txt"\r\nContent-Type: text/plain\r\n\r\nHello World')) + t.end() + }) +}) + +tape('multipart-file', function (t) { + var options = { + url: s.url, + har: fixture['multipart-file'] + } + + request(options, function (err, res, body) { + var json = JSON.parse(body) + + t.equal(err, null) + t.ok(~json.headers['content-type'].indexOf('multipart/form-data')) + t.ok(~json.body.indexOf('Content-Disposition: form-data; name="foo"; filename="unicycle.jpg"\r\nContent-Type: image/jpeg')) + t.end() + }) +}) + +tape('multipart-form-data', function (t) { + var options = { + url: s.url, + har: fixture['multipart-form-data'] + } + + request(options, function (err, res, body) { + var json = JSON.parse(body) + + t.equal(err, null) + t.ok(~json.headers['content-type'].indexOf('multipart/form-data')) + t.ok(~json.body.indexOf('Content-Disposition: form-data; name="foo"')) + t.end() + }) +}) + +tape('query', function (t) { + var options = { + url: s.url + '/?fff=sss', + har: fixture.query + } + + request(options, function (err, res, body) { + var json = JSON.parse(body) + + t.equal(err, null) + t.equal(json.url, '/?fff=sss&foo%5B0%5D=bar&foo%5B1%5D=baz&baz=abc') + t.end() + }) +}) + +tape('text/plain', function (t) { + var options = { + url: s.url, + har: fixture['text-plain'] + } + + request(options, function (err, res, body) { + var json = JSON.parse(body) + + t.equal(err, null) + t.equal(json.headers['content-type'], 'text/plain') + t.equal(json.body, 'Hello World') + t.end() + }) +}) + +tape('cleanup', function (t) { + s.close(function () { + t.end() + }) +}) From 4396aef1c0b39f90a88a9e45952abd7532e22b50 Mon Sep 17 00:00:00 2001 From: Ahmad Nassri Date: Sat, 21 Mar 2015 23:04:00 -0700 Subject: [PATCH 050/490] adding har validation --- lib/har.js | 37 +++++++++++++++++++++++++++---------- package.json | 3 ++- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/lib/har.js b/lib/har.js index 91c4b91fb..edad416ea 100644 --- a/lib/har.js +++ b/lib/har.js @@ -3,6 +3,7 @@ var fs = require('fs') var path = require('path') var qs = require('querystring') +var validate = require('har-validator') var util = require('util') function Har (request) { @@ -27,18 +28,10 @@ Har.prototype.reducer = function (obj, pair) { return obj } -Har.prototype.prep = function (har) { - var data = util._extend({}, har) - - // only process the first entry - if (data.log && data.log.entries) { - data = data.log.entries[0] - } - +Har.prototype.prep = function (data) { // construct utility properties data.queryObj = {} data.headersObj = {} - data.postData = data.postData ? data.postData : {} data.postData.jsonObj = false data.postData.paramsObj = false @@ -116,8 +109,32 @@ Har.prototype.options = function (options) { return options } + var har = util._extend({}, options.har) + + // only process the first entry + if (har.log && har.log.entries) { + har = har.log.entries[0] + } + + // add optional properties to make validation successful + har.url = har.url || options.url || options.uri || options.baseUrl || '/' + har.httpVersion = har.httpVersion || 'HTTP/1.1' + har.queryString = har.queryString || [] + har.headers = har.headers || [] + har.cookies = har.cookies || [] + har.postData = har.postData || {} + har.postData.mimeType = har.postData.mimeType || 'application/octet-stream' + + har.bodySize = 0 + har.headersSize = 0 + har.postData.size = 0 + + if (!validate.request(har)) { + return options + } + // clean up and get some utility properties - var req = this.prep(options.har) + var req = this.prep(har) // construct new options if (req.url) { diff --git a/package.json b/package.json index f649844ff..83d5f045d 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "aws-sign2": "~0.5.0", "stringstream": "~0.0.4", "combined-stream": "~0.0.5", - "isstream": "~0.1.1" + "isstream": "~0.1.1", + "har-validator": "^1.4.0" }, "scripts": { "test": "npm run lint && node node_modules/.bin/taper tests/test-*.js && npm run test-browser", From 6c6ec04ab72de2f631a79b8d7878bdb4469087ef Mon Sep 17 00:00:00 2001 From: Ahmad Nassri Date: Sat, 21 Mar 2015 23:07:30 -0700 Subject: [PATCH 051/490] adding description for HAR support --- README.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/README.md b/README.md index 23f0d67c7..6e77dd644 100644 --- a/README.md +++ b/README.md @@ -726,6 +726,9 @@ The first argument can be either a `url` or an `options` object. The only requir - `time` - If `true`, the request-response cycle (including all redirects) is timed at millisecond resolution, and the result provided on the response's `elapsedTime` property. +--- + +- `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 example below for details)* The callback argument gets 3 arguments: @@ -738,6 +741,49 @@ The callback argument gets 3 arguments: --- +## Support for HAR 1.2 + +The `options.har` property will override the values: `url`, `method`, `qs`, `headers`, `form`, `formData`, `body`, `json`, as well as construct multipart data and read files from disk when `request.postData.params[].fileName` is present without a matching `value`. + +a validation step will check if the HAR Request format matches the latest spec (v1.2) and will skip parsing if not matching. + +```js + var request = require('request') + request({ + // will be ignored + method: 'GET' + uri: 'http://www.google.com', + + // HTTP Archive Request Object + har: { + url: 'http://www.mockbin.com/har' + method: 'POST', + headers: [ + { + name: 'content-type', + value: 'application/x-www-form-urlencoded' + } + ], + postData: { + mimeType: 'application/x-www-form-urlencoded', + params: [ + { + name: 'foo', + value: 'bar' + }, + { + name: 'hello', + value: 'world' + } + ] + } + } + }) + + // a POST request will be sent to http://www.mockbin.com + // with body an application/x-www-form-urlencoded body: + // foo=bar&hello=world +``` ## Convenience methods From 20597e32c6a944520bb54bc3d20ea5cbb174e64c Mon Sep 17 00:00:00 2001 From: Ahmad Nassri Date: Sat, 21 Mar 2015 23:15:37 -0700 Subject: [PATCH 052/490] support for node 0.10 --- lib/har.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/har.js b/lib/har.js index edad416ea..8e1ec6cf5 100644 --- a/lib/har.js +++ b/lib/har.js @@ -1,7 +1,6 @@ 'use strict' var fs = require('fs') -var path = require('path') var qs = require('querystring') var validate = require('har-validator') var util = require('util') @@ -184,10 +183,8 @@ Har.prototype.options = function (options) { } if (param.fileName) { - var base = path.parse(param.fileName).base - attachement.options = { - filename: base.length ? base : 'filename', + filename: param.fileName, contentType: param.contentType ? param.contentType : null } } From 139fcc0648459916986abbb3a5b3097b1af1aee6 Mon Sep 17 00:00:00 2001 From: Phil Greenberg Date: Sat, 21 Mar 2015 19:23:57 -0700 Subject: [PATCH 053/490] Adding handling for no auth method and null bearer Removed unnecessary test case --- lib/auth.js | 6 ++++-- tests/test-bearer-auth.js | 42 +++++++++++++++++++++++++++++++++------ 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/lib/auth.js b/lib/auth.js index bd49dfc88..13c3ac8f3 100644 --- a/lib/auth.js +++ b/lib/auth.js @@ -42,7 +42,7 @@ Auth.prototype.bearer = function (bearer, sendImmediately) { if (typeof bearer === 'function') { bearer = bearer() } - var authHeader = 'Bearer ' + bearer + var authHeader = 'Bearer ' + (bearer || '') self.sentAuth = true return authHeader } @@ -114,7 +114,9 @@ Auth.prototype.onRequest = function (user, pass, sendImmediately, bearer) { , request = self.request var authHeader - if (bearer !== undefined) { + if (bearer === undefined && user === undefined) { + throw new Error('no auth mechanism defined') + } else if (bearer !== undefined) { authHeader = self.bearer(bearer, sendImmediately) } else { authHeader = self.basic(user, pass, sendImmediately) diff --git a/tests/test-bearer-auth.js b/tests/test-bearer-auth.js index fcc3f31d8..be32505ad 100644 --- a/tests/test-bearer-auth.js +++ b/tests/test-bearer-auth.js @@ -49,7 +49,7 @@ tape('setup', function(t) { }) }) -tape('', function(t) { +tape('bearer auth', function(t) { request({ 'method': 'GET', 'uri': 'http://localhost:6767/test/', @@ -64,7 +64,7 @@ tape('', function(t) { }) }) -tape('', function(t) { +tape('bearer auth with default sendImmediately', function(t) { // If we don't set sendImmediately = false, request will send bearer auth request({ 'method': 'GET', @@ -95,7 +95,7 @@ tape('', function(t) { }) }) -tape('', function(t) { +tape('using .auth, sendImmediately = false', function(t) { request .get('http://localhost:6767/test/') .auth(null, null, false, 'theToken') @@ -106,7 +106,7 @@ tape('', function(t) { }) }) -tape('', function(t) { +tape('using .auth, sendImmediately = true', function(t) { request .get('http://localhost:6767/test/') .auth(null, null, true, 'theToken') @@ -117,7 +117,7 @@ tape('', function(t) { }) }) -tape('', function(t) { +tape('bearer is a function', function(t) { request({ 'method': 'GET', 'uri': 'http://localhost:6767/test/', @@ -132,7 +132,7 @@ tape('', function(t) { }) }) -tape('', function(t) { +tape('bearer is a function, path = test2', function(t) { // If we don't set sendImmediately = false, request will send bearer auth request({ 'method': 'GET', @@ -147,6 +147,36 @@ tape('', function(t) { }) }) +tape('no auth method', function(t) { + t.throws(function() { + request({ + 'method': 'GET', + 'uri': 'http://localhost:6767/test2/', + 'auth': { + 'bearer': undefined + } + }, function(error, res, body) { + t.fail('Requests without a valid auth mechanism are not valid') + t.end() + }) + }, /no auth mechanism defined/) + t.end() +}) + +tape('null bearer', function(t) { + request({ + 'method': 'GET', + 'uri': 'http://localhost:6767/test2/', + 'auth': { + 'bearer': null + } + }, function(error, res, body) { + t.equal(res.statusCode, 401) + t.equal(numBearerRequests, 12) + t.end() + }) +}) + tape('cleanup', function(t) { bearerServer.close(function() { t.end() From d8ee939b195c64249238609b524ff9e83ab2ea45 Mon Sep 17 00:00:00 2001 From: Ahmad Nassri Date: Sun, 22 Mar 2015 22:06:12 -0400 Subject: [PATCH 054/490] fix typos + README section with feedback from @nylen --- README.md | 95 ++++++++++++++++++++++++++++-------------------------- lib/har.js | 12 +++---- 2 files changed, 56 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index 6e77dd644..c8e63e8ec 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ request('http://www.google.com', function (error, response, body) { - [Proxies](#proxies) - [Unix Domain Sockets](#unix-domain-sockets) - [TLS/SSL Protocol](#tlsssl-protocol) +- [Support for HAR 1.2](#support-for-har-1.2) - [**All Available Options**](#requestoptions-callback) Request also offers [convenience methods](#convenience-methods) like @@ -633,6 +634,54 @@ request.get({ --- +## Support for HAR 1.2 + +The `options.har` property will override the values: `url`, `method`, `qs`, `headers`, `form`, `formData`, `body`, `json`, as well as construct multipart data and read files from disk when `request.postData.params[].fileName` is present without a matching `value`. + +a validation step will check if the HAR Request format matches the latest spec (v1.2) and will skip parsing if not matching. + +```js + var request = require('request') + request({ + // will be ignored + method: 'GET' + uri: 'http://www.google.com', + + // HTTP Archive Request Object + har: { + url: 'http://www.mockbin.com/har' + method: 'POST', + headers: [ + { + name: 'content-type', + value: 'application/x-www-form-urlencoded' + } + ], + postData: { + mimeType: 'application/x-www-form-urlencoded', + params: [ + { + name: 'foo', + value: 'bar' + }, + { + name: 'hello', + value: 'world' + } + ] + } + } + }) + + // a POST request will be sent to http://www.mockbin.com + // with body an application/x-www-form-urlencoded body: + // foo=bar&hello=world +``` + +[back to top](#table-of-contents) + + +--- ## request(options, callback) @@ -728,7 +777,7 @@ The first argument can be either a `url` or an `options` object. The only requir --- -- `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 example below for details)* +- `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)* The callback argument gets 3 arguments: @@ -741,50 +790,6 @@ The callback argument gets 3 arguments: --- -## Support for HAR 1.2 - -The `options.har` property will override the values: `url`, `method`, `qs`, `headers`, `form`, `formData`, `body`, `json`, as well as construct multipart data and read files from disk when `request.postData.params[].fileName` is present without a matching `value`. - -a validation step will check if the HAR Request format matches the latest spec (v1.2) and will skip parsing if not matching. - -```js - var request = require('request') - request({ - // will be ignored - method: 'GET' - uri: 'http://www.google.com', - - // HTTP Archive Request Object - har: { - url: 'http://www.mockbin.com/har' - method: 'POST', - headers: [ - { - name: 'content-type', - value: 'application/x-www-form-urlencoded' - } - ], - postData: { - mimeType: 'application/x-www-form-urlencoded', - params: [ - { - name: 'foo', - value: 'bar' - }, - { - name: 'hello', - value: 'world' - } - ] - } - } - }) - - // a POST request will be sent to http://www.mockbin.com - // with body an application/x-www-form-urlencoded body: - // foo=bar&hello=world -``` - ## Convenience methods There are also shorthand methods for different HTTP METHODs and some other conveniences. diff --git a/lib/har.js b/lib/har.js index 8e1ec6cf5..83453a327 100644 --- a/lib/har.js +++ b/lib/har.js @@ -48,7 +48,7 @@ Har.prototype.prep = function (data) { }, {}) } - // construct Cookie heade + // construct Cookie header if (data.cookies && data.cookies.length) { var cookies = data.cookies.map(function (cookie) { return cookie.name + '=' + cookie.value @@ -168,7 +168,7 @@ Har.prototype.options = function (options) { options.formData = {} req.postData.params.forEach(function (param) { - var attachement = {} + var attachment = {} if (!param.fileName && !param.fileName && !param.contentType) { options.formData[param.name] = param.value @@ -177,19 +177,19 @@ Har.prototype.options = function (options) { // attempt to read from disk! if (param.fileName && !param.value) { - attachement.value = fs.createReadStream(param.fileName) + attachment.value = fs.createReadStream(param.fileName) } else if (param.value) { - attachement.value = param.value + attachment.value = param.value } if (param.fileName) { - attachement.options = { + attachment.options = { filename: param.fileName, contentType: param.contentType ? param.contentType : null } } - options.formData[param.name] = attachement + options.formData[param.name] = attachment }) break From a970d68b48ca0595fc81022b8fd1fe5e3e72bea8 Mon Sep 17 00:00:00 2001 From: Ahmad Nassri Date: Sun, 22 Mar 2015 22:07:59 -0400 Subject: [PATCH 055/490] fix TOC link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c8e63e8ec..2abc9e171 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ request('http://www.google.com', function (error, response, body) { - [Proxies](#proxies) - [Unix Domain Sockets](#unix-domain-sockets) - [TLS/SSL Protocol](#tlsssl-protocol) -- [Support for HAR 1.2](#support-for-har-1.2) +- [Support for HAR 1.2](#support-for-har-12) - [**All Available Options**](#requestoptions-callback) Request also offers [convenience methods](#convenience-methods) like From 4b01584294f4398cd9bfd1fb4de5e3f0c2aa84aa Mon Sep 17 00:00:00 2001 From: Akshay Patel Date: Sun, 22 Mar 2015 22:01:16 -0700 Subject: [PATCH 056/490] Upgrade forever-agent to pull in fix for 0.12 and iojs --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d14517142..1b48d8f84 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "dependencies": { "bl": "~0.9.0", "caseless": "~0.9.0", - "forever-agent": "~0.5.0", + "forever-agent": "~0.6.0", "form-data": "~0.2.0", "json-stringify-safe": "~5.0.0", "mime-types": "~2.0.1", From 72f3d68dce2271c4e3d949a758a06da962c1b44a Mon Sep 17 00:00:00 2001 From: simov Date: Tue, 24 Mar 2015 23:54:05 +0200 Subject: [PATCH 057/490] 2.54.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b99fc1502..b726bc126 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.53.1", + "version": "2.54.0", "author": "Mikeal Rogers ", "repository": { "type": "git", From 12080382de2b0e57f3dbaafadc8109af7bbc85ed Mon Sep 17 00:00:00 2001 From: simov Date: Tue, 24 Mar 2015 23:59:35 +0200 Subject: [PATCH 058/490] Update changelog --- CHANGELOG.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cfaf17384..9d6a58ffc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,33 @@ ## Change Log +### v2.54.0 (2015/03/24) +- [#1501](https://github.com/request/request/pull/1501) HTTP Archive 1.2 support (@ahmadnassri) +- [#1486](https://github.com/request/request/pull/1486) Add a test for the forever agent (@akshayp) +- [#1500](https://github.com/request/request/pull/1500) Adding handling for no auth method and null bearer (@philberg) +- [#1498](https://github.com/request/request/pull/1498) Add table of contents in readme (@simov) +- [#1477](https://github.com/request/request/pull/1477) Add support for qs options via qsOptions key (@simov) +- [#1496](https://github.com/request/request/pull/1496) Parameters encoded to base 64 should be decoded as UTF-8, not ASCII. (@albanm) +- [#1494](https://github.com/request/request/pull/1494) Update eslint (@froatsnook) +- [#1474](https://github.com/request/request/pull/1474) Require Colon in Basic Auth (@erykwalder) +- [#1481](https://github.com/request/request/pull/1481) Fix baseUrl and redirections. (@burningtree) +- [#1469](https://github.com/request/request/pull/1469) Feature/base url (@froatsnook) +- [#1459](https://github.com/request/request/pull/1459) Add option to time request/response cycle (including rollup of redirects) (@aaron-em) +- [#1468](https://github.com/request/request/pull/1468) Re-enable io.js/node 0.12 build (@simov, @BBB) +- [#1442](https://github.com/request/request/pull/1442) Fixed the issue with strictSSL tests on 0.12 & io.js by explicitly setting a cipher that matches the cert. (@BBB, @nicolasmccurdy, @simov, @0x4139) +- [#1460](https://github.com/request/request/pull/1460) localAddress or proxy config is lost when redirecting (@simov, @0x4139) +- [#1453](https://github.com/request/request/pull/1453) Test on Node.js 0.12 and io.js with allowed failures (@nicolasmccurdy) +- [#1426](https://github.com/request/request/pull/1426) Fixing tests to pass on io.js and node 0.12 (only test-https.js stiff failing) (@mikeal) +- [#1446](https://github.com/request/request/pull/1446) Missing HTTP referer header with redirects Fixes #1038 (@simov, @guimonz) +- [#1428](https://github.com/request/request/pull/1428) Deprecate Node v0.8.x (@nylen) +- [#1436](https://github.com/request/request/pull/1436) Add ability to set a requester without setting default options (@tikotzky) +- [#1435](https://github.com/request/request/pull/1435) dry up verb methods (@sethpollack) +- [#1423](https://github.com/request/request/pull/1423) Allow fully qualified multipart content-type header (@simov) +- [#1430](https://github.com/request/request/pull/1430) Fix recursive requester (@tikotzky) +- [#1429](https://github.com/request/request/pull/1429) Throw error when making HEAD request with a body (@tikotzky) +- [#1419](https://github.com/request/request/pull/1419) Add note that the project is broken in 0.12.x (@nylen) +- [#1413](https://github.com/request/request/pull/1413) Fix basic auth (@simov) +- [#1397](https://github.com/request/request/pull/1397) Improve pipe-from-file tests (@nylen) + ### v2.53.0 (2015/02/02) - [#1396](https://github.com/request/request/pull/1396) Do not rfc3986 escape JSON bodies (@nylen, @simov) - [#1392](https://github.com/request/request/pull/1392) Improve `timeout` option description (@watson) From e5a5bab2a09d0270ea1f3e3c764fe53c0e70f48d Mon Sep 17 00:00:00 2001 From: simov Date: Wed, 25 Mar 2015 00:01:16 +0200 Subject: [PATCH 059/490] 2.54.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b726bc126..470a02e79 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.54.0", + "version": "2.54.1", "author": "Mikeal Rogers ", "repository": { "type": "git", From fd545b3f3c6b239090cdc0efced354eb01b3a367 Mon Sep 17 00:00:00 2001 From: simov Date: Wed, 25 Mar 2015 14:54:06 +0200 Subject: [PATCH 060/490] Fix multipart boundary extraction regexp --- lib/multipart.js | 2 +- tests/test-multipart.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/multipart.js b/lib/multipart.js index 390a7f2d1..905a54b7f 100644 --- a/lib/multipart.js +++ b/lib/multipart.js @@ -56,7 +56,7 @@ Multipart.prototype.setHeaders = function (chunked) { self.request.setHeader('content-type', 'multipart/related; boundary=' + self.boundary) } else { if (header.indexOf('boundary') !== -1) { - self.boundary = header.replace(/.*boundary=([^\s;])+.*/, '$1') + self.boundary = header.replace(/.*boundary=([^\s;]+).*/, '$1') } else { self.request.setHeader('content-type', header + '; boundary=' + self.boundary) } diff --git a/tests/test-multipart.js b/tests/test-multipart.js index f7c6dcb00..fc64c8493 100644 --- a/tests/test-multipart.js +++ b/tests/test-multipart.js @@ -59,8 +59,8 @@ function runTest(t, a) { // check for http://localhost:6767/file traces t.ok(data.indexOf('Photoshop ICC') !== -1) - if (a.header && a.header.indexOf('mixed') !== -1) { - t.ok(data.indexOf('boundary=XXX')) + if (a.header && a.header.indexOf('boundary=XXX') !== -1) { + t.ok(data.indexOf('--XXX') !== -1) } res.writeHead(200) From acc070674714d8d048492786b21d7c909993af45 Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 26 Mar 2015 18:40:24 +0200 Subject: [PATCH 061/490] Add basic auth test for form data --- tests/test-form-data.js | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/tests/test-form-data.js b/tests/test-form-data.js index 8b09ea17f..605d58e32 100644 --- a/tests/test-form-data.js +++ b/tests/test-form-data.js @@ -7,7 +7,7 @@ var http = require('http') , fs = require('fs') , tape = require('tape') -function runTest(t, json) { +function runTest(t, options) { var remoteFile = path.join(__dirname, 'googledoodle.jpg') , localFile = path.join(__dirname, 'unicycle.jpg') , multipartFormData = {} @@ -19,6 +19,16 @@ function runTest(t, json) { return } + if (options.auth) { + if (!req.headers.authorization) { + res.writeHead(401, {'www-authenticate': 'Basic realm="Private"'}) + res.end() + return + } else { + t.ok(req.headers.authorization === 'Basic ' + new Buffer('user:pass').toString('base64')) + } + } + // temp workaround var data = '' req.setEncoding('utf8') @@ -63,7 +73,7 @@ function runTest(t, json) { t.ok( data.indexOf('Content-Type: ' + mime.lookup(remoteFile) ) !== -1 ) res.writeHead(200) - res.end(json ? JSON.stringify({status: 'done'}) : 'done') + res.end(options.json ? JSON.stringify({status: 'done'}) : 'done') }) }) @@ -90,13 +100,16 @@ function runTest(t, json) { url: 'http://localhost:6767/upload', formData: multipartFormData } - if (json) { + if (options.json) { reqOptions.json = true } + if (options.auth) { + reqOptions.auth = {user: 'user', pass: 'pass', sendImmediately: false} + } request.post(reqOptions, function (err, res, body) { t.equal(err, null) t.equal(res.statusCode, 200) - t.deepEqual(body, json ? {status: 'done'} : 'done') + t.deepEqual(body, options.json ? {status: 'done'} : 'done') server.close(function() { t.end() }) @@ -106,9 +119,13 @@ function runTest(t, json) { } tape('multipart formData', function(t) { - runTest(t, false) + runTest(t, {json: false}) }) tape('multipart formData + JSON', function(t) { - runTest(t, true) + runTest(t, {json: true}) +}) + +tape('multipart formData + basic auth', function(t) { + runTest(t, {json: false, auth: true}) }) From 8770e6fcc9857e1d80767b59b3dfcb23af1a5a84 Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 26 Mar 2015 18:41:24 +0200 Subject: [PATCH 062/490] Pipe form data after basic auth was sent --- request.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/request.js b/request.js index 0737033dd..8e79001d0 100644 --- a/request.js +++ b/request.js @@ -693,7 +693,12 @@ Request.prototype.init = function (options) { var end = function () { 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) + } } if (self._multipart && self._multipart.chunked) { self._multipart.body.pipe(self) @@ -711,6 +716,10 @@ Request.prototype.init = function (options) { console.warn('options.requestBodyStream is deprecated, please pass the request object to stream.pipe.') self.requestBodyStream.pipe(self) } else if (!self.src) { + if (self._auth.hasAuth && !self._auth.sentAuth) { + self.end() + return + } if (self.method !== 'GET' && typeof self.method !== 'undefined') { self.setHeader('content-length', 0) } From d6f557a7a5526d5ffe70974c421dd47a28c5263e Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 26 Mar 2015 19:02:45 +0200 Subject: [PATCH 063/490] Generate certificates --- tests/ssl/ca/client-enc.key | 52 ++++++++++++++++++------------------- tests/ssl/ca/client.crt | 22 ++++++++-------- tests/ssl/ca/client.csr | 26 +++++++++---------- tests/ssl/ca/client.key | 50 +++++++++++++++++------------------ tests/ssl/ca/localhost.crt | 22 ++++++++-------- tests/ssl/ca/localhost.csr | 26 +++++++++---------- tests/ssl/ca/localhost.key | 50 +++++++++++++++++------------------ 7 files changed, 124 insertions(+), 124 deletions(-) diff --git a/tests/ssl/ca/client-enc.key b/tests/ssl/ca/client-enc.key index f486c14a7..41de6e6c0 100644 --- a/tests/ssl/ca/client-enc.key +++ b/tests/ssl/ca/client-enc.key @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PmkUBL1MbGAbKqs7ohIhwtne9SOZsaqGtHYfyarYlLaSMkCCVt +EbgHPEVTrOnIHb/mnIiiKx7+jzYq+k+8Soqd0jZrLtHkYc5iJkog0fjxmvK7/Lpx +M17y2oxQzIh4RQ4879/uCTSATg7rXJm23qjbeo0F9gVZl+dv9V/5RlejeAumNdnA -----END RSA PRIVATE KEY----- diff --git a/tests/ssl/ca/client.crt b/tests/ssl/ca/client.crt index 18f59f5b2..24cede76b 100644 --- a/tests/ssl/ca/client.crt +++ b/tests/ssl/ca/client.crt @@ -3,18 +3,18 @@ MIIDLjCCApcCCQCt9iAWqkDJwzANBgkqhkiG9w0BAQsFADCBojELMAkGA1UEBhMC VVMxCzAJBgNVBAgTAkNBMRAwDgYDVQQHEwdPYWtsYW5kMRAwDgYDVQQKEwdyZXF1 ZXN0MSYwJAYDVQQLEx1yZXF1ZXN0IENlcnRpZmljYXRlIEF1dGhvcml0eTESMBAG A1UEAxMJcmVxdWVzdENBMSYwJAYJKoZIhvcNAQkBFhdtaWtlYWxAbWlrZWFscm9n -ZXJzLmNvbTAeFw0xNTAyMjQwMzIwNDNaFw0xNTAzMjYwMzIwNDNaMIGPMQswCQYD +ZXJzLmNvbTAeFw0xNTAzMjYxNzAxNTdaFw0xNTA0MjUxNzAxNTdaMIGPMQswCQYD VQQGEwJVUzELMAkGA1UECBMCQ0ExEDAOBgNVBAcTB09ha2xhbmQxEDAOBgNVBAoT B3JlcXVlc3QxGjAYBgNVBAsUEXJlcXVlc3RAbG9jYWxob3N0MRMwEQYDVQQDEwpU ZXN0Q2xpZW50MR4wHAYJKoZIhvcNAQkBFg9kby5ub3RAZW1haWwubWUwggEiMA0G -CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDedUp5BgI+5UwtA8dk05fri2NJTQT8 -/v3gdzA/6mqSZENquJGV4230iay6JDiJRNnID/0cYQrjx+LtxoOcSWcuRYzIIIPr -rlcg6EdukPMky0S6ToOZ+BEgpyqDno2NenIPBfx1B51qd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Q8vhSEcq4Rdg7SEobpPUbREizBblHwXGavCRiBWsGE1AHyjeI= +Lm5vdEBlbWFpbC5tZTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAK7r +5ks8yKZ7dHJpQKaoxT1Dzy202uAUW4ZEENXBW19WOTJjeS2hzNIn9Uxjp3TE+nTm +XFXcJl94lvPriXi0oJ1/IENKl6jMbF1e31tgNJmeVdTdWk3dVWhDw57R9VOner6d +mG66pp9qMBNNcLNH3VeG4NPy8uND8sd/2lRTcrUkZ1kflaADlNHE52fxsanUhJiQ +AJJq0OQocDmDoK5K8sYnYGbRovc71pTIY7UnGGEKHbLA4IUi3ujzpp6PYH+rL8zY +bwzoW5pCM/xMm3xKH5uQiIjGCXDtAsybPdzSwuYLV5HEW0CI5oEfmwPlWtgAQIUL +HlvrkIwIS+wJtVV1JLMCAwEAAaAjMCEGCSqGSIb3DQEJBzEUExJwYXNzd29yZCBj +aGFsbGVuZ2UwDQYJKoZIhvcNAQELBQADggEBABBBhNmJjJZJ0I/eMK6SqV9kDiT/ +2HwinjOabeR2A2cRwQxH9FKqdDerl4pmlrluH+NuFdZyOCMGsa1SFdTTGnlVFC0F +w/AVblXLigZcfK8WLpKxe9ITTMxMLn3YEacC7+ICbBPBT6NLiDd/d3V46Q1vVwk0 +QS8DDpwLfmFAUHDeMfLGestFrJpNR1WSlytdt5CfFWJ+Hhj+769LkqmlN1j23UOp +MNxmObkocET5rFqoC2VAzA8cCH6QS7pck+3UlK7OXsyTblqwuCOTcPpIdzVYKcEG +qVZBLF3ClCPEQOjWWYqX5NSxPu8Au1/Q7ZU5Gy1hNPzXTsvobKC0ZXswdKA= -----END CERTIFICATE REQUEST----- diff --git a/tests/ssl/ca/client.key b/tests/ssl/ca/client.key index b1adfee13..0b92241c9 100644 --- a/tests/ssl/ca/client.key +++ b/tests/ssl/ca/client.key @@ -1,27 +1,27 @@ -----BEGIN RSA PRIVATE KEY----- -MIIEowIBAAKCAQEA3nVKeQYCPuVM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VATE KEY----- diff --git a/tests/ssl/ca/localhost.crt b/tests/ssl/ca/localhost.crt index 7c3d2fe6c..c445342f4 100644 --- a/tests/ssl/ca/localhost.crt +++ b/tests/ssl/ca/localhost.crt @@ -3,18 +3,18 @@ MIIDLTCCApYCCQCt9iAWqkDJwzANBgkqhkiG9w0BAQsFADCBojELMAkGA1UEBhMC VVMxCzAJBgNVBAgTAkNBMRAwDgYDVQQHEwdPYWtsYW5kMRAwDgYDVQQKEwdyZXF1 ZXN0MSYwJAYDVQQLEx1yZXF1ZXN0IENlcnRpZmljYXRlIEF1dGhvcml0eTESMBAG A1UEAxMJcmVxdWVzdENBMSYwJAYJKoZIhvcNAQkBFhdtaWtlYWxAbWlrZWFscm9n -ZXJzLmNvbTAeFw0xNTAyMjQwMzA4MTFaFw0xNTAzMjYwMzA4MTFaMIGOMQswCQYD +ZXJzLmNvbTAeFw0xNTAzMjYxNzAwMTZaFw0xNTA0MjUxNzAwMTZaMIGOMQswCQYD VQQGEwJVUzELMAkGA1UECBMCQ0ExEDAOBgNVBAcTB09ha2xhbmQxEDAOBgNVBAoT B3JlcXVlc3QxGjAYBgNVBAsUEXJlcXVlc3RAbG9jYWxob3N0MRIwEAYDVQQDEwls b2NhbGhvc3QxHjAcBgkqhkiG9w0BCQEWD2RvLm5vdEBlbWFpbC5tZTCCASIwDQYJ -KoZIhvcNAQEBBQADggEPADCCAQoCggEBAK2Gf9cnN22CchHhbKUGL0EImozz7D30 -C1IwoOnaJ/kTXWbRDQaF7Crycxd5eo1b/GyKvQW7+e4uDAilyUN/LR3zlBaGFODG -+EnQKo0cDlDiqCxH98dNmifZ5D9OrNjFVWgA1taKv3x3vsBeaP0oafeUAyx3ib6l -OgqcjI2nMNwWfilDZps2YTTcIDBQF8NXB0bgspDxsy3bBObEfnMlCd7N2daAQMV0 -vIf7GhIgO8+3aW8kAGh5KkwSG4ByYNXmQCtqoebpwFCnCTxLp4voAgSjGmc9KNfh -ga2wXDFeX4aMyHXNVx4KQeFvx2p5p1NfhIGPS83I79YDr5LAMso2QkECAwEAATAN -BgkqhkiG9w0BAQsFAAOBgQCJdR6oEMXPpsZ37N2V++WreQrj79RozT0p9yKy6Qjr -ynpgQDQyf9Lf+D1KPmjMHocy01prPiLuR5x3vbVtq/NGp+7zAJWBbQOhXBOz90JP -1gg7iFANrnDQCOKI9sW1+W/+1VwNYNSHfQL99lESBXm/lPRfF9/9nUkqj8FdOxu4 -SA== +KoZIhvcNAQEBBQADggEPADCCAQoCggEBAMHImh271ebLb3RNZLTJSmiAEZfXG7b1 +zsF5UOEIZ3dKGDB4ljKBUUimNOctls1GR7wY8Mhzm2kxtnqPwdP5ABWPFsaO2nJL +4wUK0hyV/IC3/j5BlHYea7oba5Ii0SPxnEgrJ6N0brpksae2KREyDZ3KAdSUefvE +pmgeBE+mbbYhY3X0D886eXz8fnTOdOSpT+dbeOo6hKmhV1jlwSXRkDpqLM+mqRzi +HlOb6PHMHU6GEK/1sOyg6fywYlbnH2cTMRlL0e7RC5DzokoecNhJUpRx1Lww79AO +EmRnd4OxJw6nTe9OyDbahvzEzmhFdzYePS/eExGO4Kp41cMQmTkAEtkCAwEAATAN +BgkqhkiG9w0BAQsFAAOBgQBf0UxfDk6j58mXxeNDQAcHe8qYZvXNnwBvF1ZuCjuw +LyL4orEWQNvmHJDTEXjYQKZLWeihdZ/Ir/L1ZsaIrdezzL2lDXocLCenIbdydO4E +Pn6H9mKFynJrlesEX7GBaaRXqCbvkbRKefW4Zi7Q+zYvV8eJTQgAbRxVcyfv9IMj +bg== -----END CERTIFICATE----- diff --git a/tests/ssl/ca/localhost.csr b/tests/ssl/ca/localhost.csr index 34c9be6ae..1d05464a6 100644 --- a/tests/ssl/ca/localhost.csr +++ b/tests/ssl/ca/localhost.csr @@ -2,17 +2,17 @@ MIIC9zCCAd8CAQAwgY4xCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJDQTEQMA4GA1UE BxMHT2FrbGFuZDEQMA4GA1UEChMHcmVxdWVzdDEaM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yHObaTG2eo/B0/kAFY8Wxo7ackvjBQrSHJX8gLf+PkGUdh5ruhtrkiLRI/GcSCsn +o3RuumSxp7YpETINncoB1JR5+8SmaB4ET6ZttiFjdfQPzzp5fPx+dM505KlP51t4 +6jqEqaFXWOXBJdGQOmosz6apHOIeU5vo8cwdToYQr/Ww7KDp/LBiVucfZxMxGUvR +7tELkPOiSh5w2ElSlHHUvDDv0A4SZGd3g7EnDqdN707INtqG/MTOaEV3Nh49L94T +EY7gqnjVwxCZOQAS2QIDAQABoCMwIQYJKoZIhvcNAQkHMRQTEnBhc3N3b3JkIGNo +YWxsZW5nZTANBgkqhkiG9w0BAQsFAAOCAQEAvJChZZ716s0dQeOsdu1UaxY/YoHt +UFTQoBZf5FKgqGq7S1wGalQna7fawIOS608VRvZFdmQghQm/JEW21H6zeHO48aJg +E4rx3PFufFO/4RJsip5LotAl8eJ788FgIDimv3Dh/PZzgCbK1sNBiIuqcVnbmLQX +T51jS9ndXbY2vxvDNXqUAULTfUNk+esYH6e4SmQfWqv7rh/VV6die3P6yw6Vaprc +X/W+hGHB0MGpHAY3jzPfIh/FHnJZaszJ1WDCpcC0AYQTFyD+zQFdmfeajI6roAEd +kZPIl4wF3IfHi6g5HtNkUNNpzqtQCpfTCiYKfCIF//o1bFwu9H4J9ZJNug== -----END CERTIFICATE REQUEST----- diff --git a/tests/ssl/ca/localhost.key b/tests/ssl/ca/localhost.key index f10bd2604..88fa7bb13 100644 --- a/tests/ssl/ca/localhost.key +++ b/tests/ssl/ca/localhost.key @@ -1,27 +1,27 @@ -----BEGIN RSA PRIVATE KEY----- -MIIEpAIBAAKCAQEArYZ/1yc3bYJyEeFspQYvQQiajPPsPfQLUjCg6don+RNdZtEN -BoXsKvJzF3l6jVv8bIq9Bbv57i4MCKXJQ38tHfOUFoYU4Mb4SdAqjRwOUOKoLEf3 -x02aJ9nkP06s2MVVaADW1oq/fHe+wF5o/Shp95QDLHeJvqU6CpyMjacw3BZ+KUNm -mzZhNNwgMFAX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aTJ5aZdiHgr7yv0kDjMzDArWE7TRkRtC1 +6xdoj0dK04qC0mJDtpv2ROTytanB8g5Xm9mZIF+2iOI9TTZpvuZmQKqIE6z20TiT +Hny72M5gWVsHikqQ+Ne08YRwMSZXc/DZVwpLCgk03DgIPg5XlcDbaQECgYEA016F +2ltQEpJ+5k//l+J+jlyWYB6nSLBVgf3IAOXU/WynxFVSNwvzNfX/9QpW10yK7ENK +hLXGyaJRmLx8VGIFCZnKR93K8vR1ka1sVRx214kurJvTOvIn+6UGkNPdsRHg01Zm +/Tz2Rfh9SmfrYW2JAJoLKE65gLJ1MnDhsqoLEdkCgYBTWU9KachT5Ige2E7okbUc +xJfB13W4XuuCNwHFvOn8Sk5cluCNrY0NYhDF4UGXgncXE8KMVTLOIKh5D0JLHgDK +3indL2B5mC7A/vPq0ZO6n1UX97Lndjn4978WLaRV11gEKpr1ZFVj9+6H5d/k0sG8 +gXFIrSBSnKuArkM4cXb6AQKBgBPnE52C+aA2ESLop32KwzXue+5jFIdgqzyJQ/rp +qUuPnqB7FDnAs08Cce6F4bV2LKKgl3S1lRlJYnuKS/66GBVWWNi5hrGn2SY1eTzu +aDZVYYK5TYOAZ8lnOZ4LhRV2RIBB44K26c2e31VRQbWz1bGrz58lAoyewTBVtrrX +DiHJAoGAQAIKPZLlkqO+jhDqyA1NnaTisy2OJK7qXxksja0dUvxLeRNzH9/dfaAu +tEyfGP5gyaW6IvUVeiTciTIRwLBn8EdeGCaqL8CAHhO6xpLKScz+vLFoU0F9wnfa +mr2UBuCBBDNFs3OhcyDW19aSznLusVAKhlgisYkyE30ek74wIs0= -----END RSA PRIVATE KEY----- From c43477eb0484c328d9734ad1809a4a2ff18615d3 Mon Sep 17 00:00:00 2001 From: simov Date: Fri, 27 Mar 2015 10:34:38 +0200 Subject: [PATCH 064/490] Allow static invoking of convenience methods --- index.js | 2 +- tests/test-defaults.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index f8b35150e..45bba9eee 100755 --- a/index.js +++ b/index.js @@ -61,7 +61,7 @@ verbs.forEach(function(verb){ 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) + return (this || request)(params.uri || null, params.options, params.callback) } }) diff --git a/tests/test-defaults.js b/tests/test-defaults.js index 09131a172..f00ee3cdc 100644 --- a/tests/test-defaults.js +++ b/tests/test-defaults.js @@ -105,6 +105,11 @@ tape('setup', function(t) { }) }) + s.on('/function', function(req, resp) { + resp.writeHead(200, {'Content-Type': 'text/plain'}) + resp.end() + }) + t.end() }) }) @@ -299,6 +304,16 @@ tape('test only setting undefined properties', function(t) { }) }) +tape('test only function', function(t) { + var post = request.post + t.doesNotThrow(function () { + post(s.url + '/function', function (e, r, b) { + t.equal(r.statusCode, 200) + t.end() + }) + }) +}) + tape('cleanup', function(t) { s.close(function() { t.end() From 381aa871c043963ad0bba6d2793e3f6cf314a138 Mon Sep 17 00:00:00 2001 From: simov Date: Sun, 29 Mar 2015 12:32:00 +0300 Subject: [PATCH 065/490] Convenience methods should be wrapped in order to use defaults --- index.js | 14 +++++++------- tests/test-defaults.js | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 45bba9eee..37adf99f6 100755 --- a/index.js +++ b/index.js @@ -112,13 +112,13 @@ request.defaults = function (options, requester) { } 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 + defaults.get = wrap(self.get) + defaults.patch = wrap(self.patch) + defaults.post = wrap(self.post) + defaults.put = wrap(self.put) + defaults.head = wrap(self.head) + defaults.del = wrap(self.del) + defaults.cookie = wrap(self.cookie) defaults.jar = self.jar defaults.defaults = self.defaults return defaults diff --git a/tests/test-defaults.js b/tests/test-defaults.js index f00ee3cdc..e4afa6d21 100644 --- a/tests/test-defaults.js +++ b/tests/test-defaults.js @@ -314,6 +314,30 @@ tape('test only function', function(t) { }) }) +tape('invoke defaults', function(t) { + var d = request.defaults({ + uri: s.url + '/get', + headers: { foo: 'bar' } + }) + d({}, function (e, r, b) { + t.equal(e, null) + t.equal(b, 'TESTING!') + t.end() + }) +}) + +tape('invoke convenience method from defaults', function(t) { + var d = request.defaults({ + uri: s.url + '/get', + headers: { foo: 'bar' } + }) + d.get({}, function (e, r, b) { + t.equal(e, null) + t.equal(b, 'TESTING!') + t.end() + }) +}) + tape('cleanup', function(t) { s.close(function() { t.end() From aa4fd5ef4617ff648a42557c2c206cfa932fbb3c Mon Sep 17 00:00:00 2001 From: simov Date: Sun, 29 Mar 2015 12:34:18 +0300 Subject: [PATCH 066/490] Temporary fix for head convenience method + This check should happen before invoking the custom requester function --- index.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 37adf99f6..902f4cc8a 100755 --- a/index.js +++ b/index.js @@ -99,6 +99,15 @@ request.defaults = function (options, requester) { var params = initParams(uri, opts, callback) params.options = extend(headerlessOptions(options), params.options) + if (typeof method === 'string') { + params.options.method = (method === 'del' ? 'DELETE' : method.toUpperCase()) + method = request[method] + } + + if (params.options.method === 'HEAD' && paramsHaveRequestBody(params)) { + throw new Error('HTTP HEAD requests MUST NOT include a request body.') + } + if (options.headers) { params.options.headers = getHeaders(params, options) } @@ -112,12 +121,12 @@ request.defaults = function (options, requester) { } var defaults = wrap(self) - defaults.get = wrap(self.get) - defaults.patch = wrap(self.patch) - defaults.post = wrap(self.post) - defaults.put = wrap(self.put) - defaults.head = wrap(self.head) - defaults.del = wrap(self.del) + defaults.get = wrap('get') + defaults.patch = wrap('patch') + defaults.post = wrap('post') + defaults.put = wrap('put') + defaults.head = wrap('head') + defaults.del = wrap('del') defaults.cookie = wrap(self.cookie) defaults.jar = self.jar defaults.defaults = self.defaults From 9d055b48ab67f857b6c02eac3c540e701820eb5e Mon Sep 17 00:00:00 2001 From: simov Date: Mon, 30 Mar 2015 14:46:55 +0300 Subject: [PATCH 067/490] Simplify params initialization + Simplify defaults method + Move wrap closure outside of the defaults method --- index.js | 116 ++++++++++++++++++++++++------------------------- lib/helpers.js | 36 +-------------- 2 files changed, 57 insertions(+), 95 deletions(-) diff --git a/index.js b/index.js index 902f4cc8a..2f7ed6e8d 100755 --- a/index.js +++ b/index.js @@ -19,22 +19,30 @@ var extend = require('util')._extend , helpers = require('./lib/helpers') var isFunction = helpers.isFunction - , constructObject = helpers.constructObject - , filterForCallback = helpers.filterForCallback - , constructOptionsFrom = helpers.constructOptionsFrom , paramsHaveRequestBody = helpers.paramsHaveRequestBody // organize params for patch, post, put, head, del function initParams(uri, options, callback) { - callback = filterForCallback([options, callback]) - options = constructOptionsFrom(uri, options) - - return constructObject() - .extend({callback: callback}) - .extend({options: options}) - .extend({uri: options.uri}) - .done() + if (typeof options === 'function') { + callback = options + } + + 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) + } + + return { + uri: params.uri, + options: params, + callback: callback + } } function request (uri, options, callback) { @@ -56,9 +64,9 @@ function request (uri, options, callback) { var verbs = ['get', 'head', 'post', 'put', 'patch', 'del'] -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 || request)(params.uri || null, params.options, params.callback) @@ -73,77 +81,65 @@ request.cookie = function (str) { return cookies.parse(str) } -request.defaults = function (options, requester) { +function wrap (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.options = extend(headerlessOptions, params.options) + + if (typeof method === 'string') { + params.options.method = (method === 'del' ? 'DELETE' : method.toUpperCase()) + method = request[method] } - var getHeaders = function (params, options) { - return constructObject() - .extend(options.headers) - .extend(params.options.headers) - .done() + if (options.headers) { + var headers = extend({}, options.headers) + params.options.headers = extend(headers, params.options.headers) } - return function (uri, opts, callback) { - var params = initParams(uri, opts, callback) - params.options = extend(headerlessOptions(options), params.options) + if (isFunction(requester)) { + method = requester + } - if (typeof method === 'string') { - params.options.method = (method === 'del' ? 'DELETE' : method.toUpperCase()) - method = request[method] - } + return method(params.options, params.callback) + } +} - if (params.options.method === 'HEAD' && paramsHaveRequestBody(params)) { - throw new Error('HTTP HEAD requests MUST NOT include a request body.') - } +request.defaults = function (options, requester) { + var self = this - if (options.headers) { - params.options.headers = getHeaders(params, options) - } + if (typeof options === 'function') { + requester = options + options = {} + } - if (isFunction(requester)) { - method = requester - } + var defaults = wrap(self, options, requester) - return method(params.options, params.callback) - } - } + var verbs = ['get', 'head', 'post', 'put', 'patch', 'del'] + verbs.forEach(function(verb) { + defaults[verb] = wrap(verb, options, requester) + }) - var defaults = wrap(self) - defaults.get = wrap('get') - defaults.patch = wrap('patch') - defaults.post = wrap('post') - defaults.put = wrap('put') - defaults.head = wrap('head') - defaults.del = wrap('del') - defaults.cookie = wrap(self.cookie) + defaults.cookie = wrap(self.cookie, options, requester) defaults.jar = self.jar defaults.defaults = self.defaults return defaults } request.forever = function (agentOptions, optionsArg) { - var options = constructObject() + var options = {} if (optionsArg) { - options.extend(optionsArg) + options = extend({}, optionsArg) } if (agentOptions) { options.agentOptions = agentOptions } - options.extend({forever: true}) - return request.defaults(options.done()) + options = extend(options, {forever: true}) + return request.defaults(options) } // Exports diff --git a/lib/helpers.js b/lib/helpers.js index 036b0d6f1..78c0aee8f 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -1,7 +1,6 @@ 'use strict' -var extend = require('util')._extend - , jsonSafeStringify = require('json-stringify-safe') +var jsonSafeStringify = require('json-stringify-safe') , crypto = require('crypto') function deferMethod() { @@ -12,40 +11,10 @@ function deferMethod() { return setImmediate } -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) { return typeof value === 'function' } -function filterForCallback(values) { - var callbacks = values.filter(isFunction) - return callbacks[0] -} - function paramsHaveRequestBody(params) { return ( params.options.body || @@ -78,9 +47,6 @@ function toBase64 (str) { } exports.isFunction = isFunction -exports.constructObject = constructObject -exports.constructOptionsFrom = constructOptionsFrom -exports.filterForCallback = filterForCallback exports.paramsHaveRequestBody = paramsHaveRequestBody exports.safeStringify = safeStringify exports.md5 = md5 From 45623b73979c1da46dee8f2da0f89a1585a50d13 Mon Sep 17 00:00:00 2001 From: simov Date: Tue, 31 Mar 2015 12:38:09 +0300 Subject: [PATCH 068/490] Add promise tests --- package.json | 3 ++- tests/test-promise.js | 52 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 tests/test-promise.js diff --git a/package.json b/package.json index 470a02e79..0caa95566 100644 --- a/package.json +++ b/package.json @@ -62,6 +62,7 @@ "rimraf": "~2.2.8", "server-destroy": "~1.0.0", "tape": "~3.0.0", - "taper": "~0.4.0" + "taper": "~0.4.0", + "bluebird": "~2.9.21" } } diff --git a/tests/test-promise.js b/tests/test-promise.js new file mode 100644 index 000000000..d310890db --- /dev/null +++ b/tests/test-promise.js @@ -0,0 +1,52 @@ +'use strict' + +var http = require('http') + , request = require('../index') + , tape = require('tape') + , Promise = require('bluebird') + +var s = http.createServer(function(req, res) { + res.writeHead(200, {}) + res.end('ok') +}) + +tape('setup', function(t) { + s.listen(6767, function() { + t.end() + }) +}) + +tape('promisify convenience method', function(t) { + var get = request.get + var p = Promise.promisify(get) + p('http://localhost:6767') + .then(function (results) { + var res = results[0] + t.equal(res.statusCode, 200) + t.end() + }) +}) + +tape('promisify request function', function(t) { + var p = Promise.promisify(request) + p('http://localhost:6767') + .spread(function (res, body) { + t.equal(res.statusCode, 200) + t.end() + }) +}) + +tape('promisify all methods', function(t) { + Promise.promisifyAll(request) + request.getAsync('http://localhost:6767') + .spread(function (res, body) { + t.equal(res.statusCode, 200) + t.end() + }) +}) + +tape('cleanup', function(t) { + s.close(function() { + t.end() + }) +}) From 98e47fb94f0654edfd384891a521f02072bcab84 Mon Sep 17 00:00:00 2001 From: simov Date: Wed, 1 Apr 2015 15:52:17 +0300 Subject: [PATCH 069/490] Remove uneeded data structure returned by initParams --- index.js | 46 ++++++++++++++++++------------------------ lib/helpers.js | 8 ++++---- tests/test-defaults.js | 11 +++++----- 3 files changed, 29 insertions(+), 36 deletions(-) diff --git a/index.js b/index.js index 2f7ed6e8d..347484080 100755 --- a/index.js +++ b/index.js @@ -28,7 +28,7 @@ function initParams(uri, options, callback) { callback = options } - var params + var params = {} if (typeof options === 'object') { params = extend({}, options) params = extend(params, {uri: uri}) @@ -38,11 +38,8 @@ function initParams(uri, options, callback) { params = extend({}, uri) } - return { - uri: params.uri, - options: params, - callback: callback - } + params.callback = callback + return params } function request (uri, options, callback) { @@ -51,15 +48,12 @@ function request (uri, options, callback) { } 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) } var verbs = ['get', 'head', 'post', 'put', 'patch', 'del'] @@ -68,8 +62,8 @@ verbs.forEach(function(verb) { var method = verb === 'del' ? 'DELETE' : verb.toUpperCase() request[verb] = function (uri, options, callback) { var params = initParams(uri, options, callback) - params.options.method = method - return (this || request)(params.uri || null, params.options, params.callback) + params.method = method + return request(params, params.callback) } }) @@ -81,30 +75,30 @@ request.cookie = function (str) { return cookies.parse(str) } -function wrap (method, options, requester) { +function wrapRequestMethod (method, options, requester) { return function (uri, opts, callback) { var params = initParams(uri, opts, callback) var headerlessOptions = extend({}, options) delete headerlessOptions.headers - params.options = extend(headerlessOptions, params.options) - - if (typeof method === 'string') { - params.options.method = (method === 'del' ? 'DELETE' : method.toUpperCase()) - method = request[method] - } + params = extend(headerlessOptions, params) if (options.headers) { var headers = extend({}, options.headers) - params.options.headers = extend(headers, params.options.headers) + params.headers = extend(headers, params.headers) + } + + if (typeof method === 'string') { + params.method = (method === 'del' ? 'DELETE' : method.toUpperCase()) + method = request[method] } if (isFunction(requester)) { method = requester } - return method(params.options, params.callback) + return method(params, params.callback) } } @@ -116,14 +110,14 @@ request.defaults = function (options, requester) { options = {} } - var defaults = wrap(self, options, requester) + var defaults = wrapRequestMethod(self, options, requester) var verbs = ['get', 'head', 'post', 'put', 'patch', 'del'] verbs.forEach(function(verb) { - defaults[verb] = wrap(verb, options, requester) + defaults[verb] = wrapRequestMethod(verb, options, requester) }) - defaults.cookie = wrap(self.cookie, options, requester) + defaults.cookie = wrapRequestMethod(self.cookie, options, requester) defaults.jar = self.jar defaults.defaults = self.defaults return defaults @@ -138,7 +132,7 @@ request.forever = function (agentOptions, optionsArg) { options.agentOptions = agentOptions } - options = extend(options, {forever: true}) + options.forever = true return request.defaults(options) } diff --git a/lib/helpers.js b/lib/helpers.js index 78c0aee8f..8530d4013 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -17,10 +17,10 @@ function isFunction(value) { 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 ) } diff --git a/tests/test-defaults.js b/tests/test-defaults.js index e4afa6d21..f8449f993 100644 --- a/tests/test-defaults.js +++ b/tests/test-defaults.js @@ -255,9 +255,8 @@ tape('test custom request handler function', function(t) { body: 'TESTING!' }, function(uri, options, callback) { var params = request.initParams(uri, options, callback) - options = params.options - options.headers.x = 'y' - return request(params.uri, params.options, params.callback) + params.headers.x = 'y' + return request(params.uri, params, params.callback) }) t.throws(function() { @@ -276,11 +275,11 @@ tape('test custom request handler function without options', function(t) { var customHandlerWithoutOptions = request.defaults(function(uri, options, callback) { var params = request.initParams(uri, options, callback) - var headers = params.options.headers || {} + var headers = params.headers || {} headers.x = 'y' headers.foo = 'bar' - params.options.headers = headers - return request(params.uri, params.options, params.callback) + params.headers = headers + return request(params.uri, params, params.callback) }) customHandlerWithoutOptions.get(s.url + '/get_custom', function(e, r, b) { From 6173d757396b4fbac61c5207ce3754599cff1c38 Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 2 Apr 2015 09:43:51 +0300 Subject: [PATCH 070/490] Resolve image path in har test --- tests/test-har.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test-har.js b/tests/test-har.js index 19d2b7532..f0dca791c 100644 --- a/tests/test-har.js +++ b/tests/test-har.js @@ -1,5 +1,6 @@ 'use strict' +var path = require('path') var request = require('..') var tape = require('tape') var fixture = require('./fixtures/har.json') @@ -107,6 +108,8 @@ tape('multipart-file', function (t) { url: s.url, har: fixture['multipart-file'] } + var absolutePath = path.resolve(__dirname, options.har.postData.params[0].fileName) + options.har.postData.params[0].fileName = absolutePath request(options, function (err, res, body) { var json = JSON.parse(body) From 3f914bb4af00b0c67d8ab35ef5d0a6b53e541cfc Mon Sep 17 00:00:00 2001 From: froatsnook Date: Thu, 2 Apr 2015 10:41:43 +0200 Subject: [PATCH 071/490] Delete request headers with undefined value. --- request.js | 8 ++++++++ tests/test-defaults.js | 18 ++++++++++++++++++ tests/test-headers.js | 24 ++++++++++++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/request.js b/request.js index 8e79001d0..5f8f26844 100644 --- a/request.js +++ b/request.js @@ -323,6 +323,14 @@ Request.prototype.init = function (options) { } self.headers = self.headers ? copy(self.headers) : {} + // 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) if (!self.method) { diff --git a/tests/test-defaults.js b/tests/test-defaults.js index e4afa6d21..847044d19 100644 --- a/tests/test-defaults.js +++ b/tests/test-defaults.js @@ -23,6 +23,14 @@ tape('setup', function(t) { resp.end() }) + s.on('/foo-no-test', function(req, resp) { + assert.equal(req.headers.foo, 'bar') + assert.equal('test' in req.headers, false) + assert.equal(req.method, 'GET') + resp.writeHead(200, {'Content-Type': 'text/plain'}) + resp.end('TESTING!') + }) + s.on('/post', function (req, resp) { assert.equal(req.headers.foo, 'bar') assert.equal(req.headers['content-type'], null) @@ -136,6 +144,16 @@ tape('merge headers', function(t) { }) }) +tape('default undefined header', function(t) { + request.defaults({ + headers: { foo: 'bar', test: undefined } + })(s.url + '/foo-no-test', function(e, r, b) { + t.equal(e, null) + t.equal(b, 'TESTING!') + t.end() + }) +}) + tape('post(string, object, function)', function(t) { request.defaults({ headers: { foo: 'bar' } diff --git a/tests/test-headers.js b/tests/test-headers.js index 0b8777124..6ec9dba04 100644 --- a/tests/test-headers.js +++ b/tests/test-headers.js @@ -18,6 +18,14 @@ s.on('/redirect/to', function(req, res) { res.end('ok') }) +s.on('/headers.json', function(req, res) { + res.writeHead(200, { + 'Content-Type': 'application/json' + }) + + res.end(JSON.stringify(req.headers)) +}) + tape('setup', function(t) { s.listen(s.port, function() { t.end() @@ -138,6 +146,22 @@ tape('upper-case Host header and redirect', function(t) { }) }) +tape('undefined headers', function(t) { + request({ + url: s.url + '/headers.json', + headers: { + 'X-TEST-1': 'test1', + 'X-TEST-2': undefined + }, + json: true + }, function(err, res, body) { + t.equal(err, null) + t.equal(body['x-test-1'], 'test1') + t.equal(typeof body['x-test-2'], 'undefined') + t.end() + }) +}) + tape('cleanup', function(t) { s.close(function() { t.end() From cf1d1423aec08da73dc749e942fb403612ecf85b Mon Sep 17 00:00:00 2001 From: Tristan Davies Date: Thu, 26 Mar 2015 13:19:18 -0400 Subject: [PATCH 072/490] Test forever with pool, thanks to @simov --- tests/test-pool.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/test-pool.js b/tests/test-pool.js index 417870369..b59bd3362 100644 --- a/tests/test-pool.js +++ b/tests/test-pool.js @@ -30,6 +30,34 @@ tape('pool', function(t) { }) }) +tape('forever', function(t) { + var r = request({ + url: 'http://localhost:6767', + forever: true, + pool: {maxSockets: 1024} + }, function(err, res, body) { + // explicitly shut down the agent + if (r.agent.destroy === typeof 'function') { + r.agent.destroy() + } else { + // node < 0.12 + Object.keys(r.agent.sockets).forEach(function (name) { + r.agent.sockets[name].forEach(function (socket) { + socket.end() + }) + }) + } + + t.equal(err, null) + t.equal(res.statusCode, 200) + t.equal(body, 'asdf') + + var agent = res.request.agent + t.equal(agent.maxSockets, 1024) + t.end() + }) +}) + tape('cleanup', function(t) { s.close(function() { t.end() From 04bcd915dff978bd4874faafdf5567abe9230636 Mon Sep 17 00:00:00 2001 From: simov Date: Sun, 5 Apr 2015 07:22:28 +0300 Subject: [PATCH 073/490] 2.55.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0caa95566..b1d88dfeb 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.54.1", + "version": "2.55.0", "author": "Mikeal Rogers ", "repository": { "type": "git", From b6000376387db12d0c2d7ed9ee87b0ba123e36dc Mon Sep 17 00:00:00 2001 From: simov Date: Sun, 5 Apr 2015 07:24:21 +0300 Subject: [PATCH 074/490] Update changelog --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d6a58ffc..1c01d0875 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ ## 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) - [#1501](https://github.com/request/request/pull/1501) HTTP Archive 1.2 support (@ahmadnassri) - [#1486](https://github.com/request/request/pull/1486) Add a test for the forever agent (@akshayp) From 920fb1a31be0994455d18b2dafc0969e2450dc14 Mon Sep 17 00:00:00 2001 From: simov Date: Sun, 5 Apr 2015 07:24:42 +0300 Subject: [PATCH 075/490] 2.55.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b1d88dfeb..6e410da7c 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.55.0", + "version": "2.55.1", "author": "Mikeal Rogers ", "repository": { "type": "git", From 548a4bf434827db666d3fdc8e65bf7c850aa4925 Mon Sep 17 00:00:00 2001 From: YasharF Date: Wed, 8 Apr 2015 23:18:19 -0700 Subject: [PATCH 076/490] Adding dependency status bar to README.md Adding dependency status bar to README.md to make it easier to identify when one or more dependencies are out of date. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 2abc9e171..ed81aa6c5 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ [![Build status](https://img.shields.io/travis/request/request.svg?style=flat-square)](https://travis-ci.org/request/request) [![Coverage](https://img.shields.io/coveralls/request/request.svg?style=flat-square)](https://coveralls.io/r/request/request) +[![Dependency Status](https://david-dm.org/request/request.svg?style=flat-square)](https://david-dm.org/request/request) [![Gitter](https://img.shields.io/badge/gitter-join_chat-blue.svg?style=flat-square)](https://gitter.im/request/request?utm_source=badge) From 893e3db19f96772c96faac5e03ffeccdc7deeed8 Mon Sep 17 00:00:00 2001 From: froatsnook Date: Thu, 9 Apr 2015 22:24:45 +0200 Subject: [PATCH 077/490] Update eslint to 0.18.0. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6e410da7c..9b86d9696 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "browserify": "~5.9.1", "browserify-istanbul": "~0.1.3", "coveralls": "~2.11.2", - "eslint": "0.17.1", + "eslint": "0.18.0", "function-bind": "~1.0.0", "istanbul": "~0.3.2", "karma": "~0.12.21", From 38c44280c41216745824dd5207bb2141092aae21 Mon Sep 17 00:00:00 2001 From: YasharF Date: Fri, 10 Apr 2015 01:56:45 -0700 Subject: [PATCH 078/490] Updating the dependency status bar in README.md Updating the dependency status bar in README.md to use the badge from shields.io --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ed81aa6c5..abcf7feb8 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![Build status](https://img.shields.io/travis/request/request.svg?style=flat-square)](https://travis-ci.org/request/request) [![Coverage](https://img.shields.io/coveralls/request/request.svg?style=flat-square)](https://coveralls.io/r/request/request) -[![Dependency Status](https://david-dm.org/request/request.svg?style=flat-square)](https://david-dm.org/request/request) +[![Dependency Status](https://img.shields.io/david/request/request.svg?style=flat-square)](https://david-dm.org/request/request) [![Gitter](https://img.shields.io/badge/gitter-join_chat-blue.svg?style=flat-square)](https://gitter.im/request/request?utm_source=badge) From cc493b3a7d09d0f2e4df03b0c172cefee21f1ded Mon Sep 17 00:00:00 2001 From: Ahmad Nassri Date: Fri, 10 Apr 2015 23:12:49 -0400 Subject: [PATCH 079/490] ensure the latest version of har-validator is included --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6e410da7c..edf8edadb 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "stringstream": "~0.0.4", "combined-stream": "~0.0.5", "isstream": "~0.1.1", - "har-validator": "^1.4.0" + "har-validator": "^1.6.1" }, "scripts": { "test": "npm run lint && node node_modules/.bin/taper tests/test-*.js && npm run test-browser", From c98eaa609ab9525be67a006bf22292611068ab05 Mon Sep 17 00:00:00 2001 From: simov Date: Sat, 11 Apr 2015 10:51:17 +0300 Subject: [PATCH 080/490] Fix recursive defaults for convenience methods --- index.js | 9 ++++----- tests/test-defaults.js | 7 ++++++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 347484080..8bc39545c 100755 --- a/index.js +++ b/index.js @@ -75,7 +75,7 @@ request.cookie = function (str) { return cookies.parse(str) } -function wrapRequestMethod (method, options, requester) { +function wrapRequestMethod (method, options, requester, verb) { return function (uri, opts, callback) { var params = initParams(uri, opts, callback) @@ -89,9 +89,8 @@ function wrapRequestMethod (method, options, requester) { params.headers = extend(headers, params.headers) } - if (typeof method === 'string') { - params.method = (method === 'del' ? 'DELETE' : method.toUpperCase()) - method = request[method] + if (verb) { + params.method = (verb === 'del' ? 'DELETE' : verb.toUpperCase()) } if (isFunction(requester)) { @@ -114,7 +113,7 @@ request.defaults = function (options, requester) { var verbs = ['get', 'head', 'post', 'put', 'patch', 'del'] verbs.forEach(function(verb) { - defaults[verb] = wrapRequestMethod(verb, options, requester) + defaults[verb] = wrapRequestMethod(self[verb], options, requester, verb) }) defaults.cookie = wrapRequestMethod(self.cookie, options, requester) diff --git a/tests/test-defaults.js b/tests/test-defaults.js index e980aacfe..50cf213c3 100644 --- a/tests/test-defaults.js +++ b/tests/test-defaults.js @@ -208,7 +208,7 @@ tape('head(object, function)', function(t) { }) tape('recursive defaults', function(t) { - t.plan(6) + t.plan(8) var defaultsOne = request.defaults({ headers: { foo: 'bar1' } }) , defaultsTwo = defaultsOne.defaults({ headers: { baz: 'bar2' } }) @@ -234,6 +234,11 @@ tape('recursive defaults', function(t) { t.equal(e, null) t.equal(b, 'TESTING!') }) + + defaultsTwo.get(s.url + '/get_recursive2', function (e, r, b) { + t.equal(e, null) + t.equal(b, 'TESTING!') + }) }) tape('recursive defaults requester', function(t) { From 8e294c6351402942928f615be189361de5f8368d Mon Sep 17 00:00:00 2001 From: simov Date: Sat, 11 Apr 2015 14:28:29 +0300 Subject: [PATCH 081/490] Disable https strict test when running under istanbul Somehow this test modifies the process state Test coverage runs all tests in a single process via tape Executing this test causes one of the tests in test-tunnel to throw --- tests/test-https.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/test-https.js b/tests/test-https.js index 396a73d83..dc870df83 100644 --- a/tests/test-https.js +++ b/tests/test-https.js @@ -117,4 +117,10 @@ function runAllTests(strict, s) { } runAllTests(false, s) -runAllTests(true, sStrict) + +if (!process.env.running_under_istanbul) { + // somehow this test modifies the process state + // test coverage runs all tests in a single process via tape + // executing this test causes one of the tests in test-tunnel.js to throw + runAllTests(true, sStrict) +} From 6e0309eb9be8f496d583038eb87e6d202b6b9fbb Mon Sep 17 00:00:00 2001 From: froatsnook Date: Thu, 9 Apr 2015 22:28:51 +0200 Subject: [PATCH 082/490] eslint: always space-after-keywords. --- .eslintrc | 5 ++++- lib/helpers.js | 2 +- lib/multipart.js | 2 +- request.js | 10 +++++----- tests/test-baseUrl.js | 2 +- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/.eslintrc b/.eslintrc index 8538b419c..b0be1f5df 100644 --- a/.eslintrc +++ b/.eslintrc @@ -34,6 +34,9 @@ // eslint can't handle this, so the check is disabled. "key-spacing": 0, // Allow shadowing vars in outer scope (needs discussion) - "no-shadow": 0 + "no-shadow": 0, + // Use if () { } + // ^ space + "space-after-keywords": [2, "always"] } } diff --git a/lib/helpers.js b/lib/helpers.js index 8530d4013..1d588ca94 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -4,7 +4,7 @@ var jsonSafeStringify = require('json-stringify-safe') , crypto = require('crypto') function deferMethod() { - if(typeof setImmediate === 'undefined') { + if (typeof setImmediate === 'undefined') { return process.nextTick } diff --git a/lib/multipart.js b/lib/multipart.js index 905a54b7f..f95f8a390 100644 --- a/lib/multipart.js +++ b/lib/multipart.js @@ -31,7 +31,7 @@ Multipart.prototype.isChunked = function (options) { if (!chunked) { parts.forEach(function (part) { - if(typeof part.body === 'undefined') { + if (typeof part.body === 'undefined') { throw new Error('Body attribute missing in multipart.') } if (isstream(part.body)) { diff --git a/request.js b/request.js index 5f8f26844..d7f083394 100644 --- a/request.js +++ b/request.js @@ -415,7 +415,7 @@ Request.prototype.init = function (options) { } // If a string URI/URL was given, parse it into a URL object - if(typeof self.uri === 'string') { + if (typeof self.uri === 'string') { self.uri = url.parse(self.uri) } @@ -425,7 +425,7 @@ Request.prototype.init = function (options) { } // Support Unix Sockets - if(self.uri.host === 'unix') { + if (self.uri.host === 'unix') { // Get the socket & request paths from the URL var unixParts = self.uri.path.split(':') , host = unixParts[0] @@ -443,7 +443,7 @@ Request.prototype.init = function (options) { self.rejectUnauthorized = false } - if(!self.hasOwnProperty('proxy')) { + if (!self.hasOwnProperty('proxy')) { self.proxy = getProxyFromURI(self.uri) } @@ -1213,14 +1213,14 @@ Request.prototype.onRequestResponse = function (response) { } catch (e) {} } debug('emitting complete', self.uri.href) - if(typeof response.body === 'undefined' && !self._json) { + if (typeof response.body === 'undefined' && !self._json) { response.body = self.encoding === null ? new Buffer(0) : '' } self.emit('complete', response, response.body) }) } //if no callback - else{ + else { self.on('end', function () { if (self._aborted) { debug('aborted', self.uri.href) diff --git a/tests/test-baseUrl.js b/tests/test-baseUrl.js index bf95a78d8..fb523eadd 100644 --- a/tests/test-baseUrl.js +++ b/tests/test-baseUrl.js @@ -6,7 +6,7 @@ var http = require('http') , url = require('url') var s = http.createServer(function(req, res) { - if(req.url === '/redirect/') { + if (req.url === '/redirect/') { res.writeHead(302, { location : '/' }) From 005cf774dfea00b64d9440ef7e7fcec978b29903 Mon Sep 17 00:00:00 2001 From: froatsnook Date: Mon, 13 Apr 2015 14:20:47 +0200 Subject: [PATCH 083/490] eslint: always space-before-blocks. --- .eslintrc | 5 ++++- request.js | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.eslintrc b/.eslintrc index b0be1f5df..e79f481f0 100644 --- a/.eslintrc +++ b/.eslintrc @@ -37,6 +37,9 @@ "no-shadow": 0, // Use if () { } // ^ space - "space-after-keywords": [2, "always"] + "space-after-keywords": [2, "always"], + // Use if () { } + // ^ space + "space-before-blocks": [2, "always"] } } diff --git a/request.js b/request.js index d7f083394..4a401a86b 100644 --- a/request.js +++ b/request.js @@ -579,12 +579,12 @@ Request.prototype.init = function (options) { } if (self.uri.auth && !self.hasHeader('authorization')) { - var uriAuthPieces = self.uri.auth.split(':').map(function(item){ return querystring.unescape(item) }) + var uriAuthPieces = self.uri.auth.split(':').map(function(item) { return querystring.unescape(item) }) self.auth(uriAuthPieces[0], uriAuthPieces.slice(1).join(':'), true) } if (!self.tunnel && self.proxy && self.proxy.auth && !self.hasHeader('proxy-authorization')) { - var proxyAuthPieces = self.proxy.auth.split(':').map(function(item){ + var proxyAuthPieces = self.proxy.auth.split(':').map(function(item) { return querystring.unescape(item) }) var authHeader = 'Basic ' + toBase64(proxyAuthPieces.join(':')) @@ -1299,7 +1299,7 @@ Request.prototype.qs = function (q, clobber) { base[i] = q[i] } - if (self.qsLib.stringify(base, self.qsStringifyOptions) === ''){ + if (self.qsLib.stringify(base, self.qsStringifyOptions) === '') { return self } From 759ffc3195ffd64ae9b9b9f2e3adb9bc390018d2 Mon Sep 17 00:00:00 2001 From: froatsnook Date: Thu, 9 Apr 2015 22:35:07 +0200 Subject: [PATCH 084/490] Explicitly comment empty block as empty. --- request.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/request.js b/request.js index 4a401a86b..201be667d 100644 --- a/request.js +++ b/request.js @@ -1210,7 +1210,9 @@ Request.prototype.onRequestResponse = function (response) { if (self._json) { try { response.body = JSON.parse(response.body, self._jsonReviver) - } catch (e) {} + } catch (e) { + // empty + } } debug('emitting complete', self.uri.href) if (typeof response.body === 'undefined' && !self._json) { From b35418cb38a4c8e1961e5b9f7e90ddef34a2567b Mon Sep 17 00:00:00 2001 From: Aesop Wolf Date: Mon, 13 Apr 2015 16:08:19 -0700 Subject: [PATCH 085/490] initial support for oauth_body_hash on json payloads --- request.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/request.js b/request.js index 201be667d..99ae491fa 100644 --- a/request.js +++ b/request.js @@ -27,6 +27,7 @@ var http = require('http') , OAuth = require('./lib/oauth').OAuth , Multipart = require('./lib/multipart').Multipart , Redirect = require('./lib/redirect').Redirect + , crypto = require('crypto') var safeStringify = helpers.safeStringify , isReadStream = helpers.isReadStream @@ -541,6 +542,44 @@ Request.prototype.init = function (options) { self.path = '/' } + // Add support for oauth_body_hash + // See https://oauth.googlecode.com/svn/spec/ext/body_hash/1.0/oauth-bodyhash.html + // Only supports JSON payloads at the moment + // ==================== + + // Check for an explicit 'true' value, in case someone is already generating their own hash + if (options.oauth && typeof options.oauth.body_hash === 'boolean') { + // 4.1.1b: OAuth Consumers MUST NOT include an oauth_body_hash parameter on requests with form-encoded request bodies. + // -------------------- + if (self.getHeader('content-type') === 'application/x-www-form-urlencoded') { + throw new Error('oauth_body_hash is not supported with form-encoded request bodies.') + } + else { + // 3.1a: If the OAuth signature method is HMAC-SHA1 or RSA-SHA1, SHA1 [RFC3174] MUST be used as the body hash algorithm. + // -------------------- + var acceptedSignatureMethods = ['HMAC-SHA1', 'RSA-SHA1'] + var index = acceptedSignatureMethods.indexOf(options.oauth.signature_method) + + if (!options.oauth.signature_method || index > -1) { + // 3.2a: The body hash value is calculated by executing the selected hash algorithm over the request body. The request body is the entity body as defined in [RFC2616] section 7.2. If the request does not have an entity body, the hash should be taken over the empty string. + // -------------------- + var shasum = crypto.createHash('sha1') + shasum.update(options.json.toString() || '') + var sha1 = shasum.digest('hex') + + // 3.2b: The calculated body hash value is encoded using Base64 per [RFC4648]. + // -------------------- + // oauth_body_hash_base64 = new Buffer(sha1).toString('base64'); + options.oauth.body_hash = new Buffer(sha1).toString('base64') + } + else { + // 3.1b: If the OAuth signature method is PLAINTEXT, use of this specification provides no security benefit and is NOT RECOMMENDED. + // -------------------- + throw new Error(options.oauth.signature_method + ' signature_method not supported with body_hash signing.') + } + } + } + // Auth must happen last in case signing is dependent on other headers if (options.oauth) { self.oauth(options.oauth) From bcfe1266811fed98904c6ed3c98d8b3c0808af85 Mon Sep 17 00:00:00 2001 From: Aesop Wolf Date: Tue, 14 Apr 2015 10:25:40 -0700 Subject: [PATCH 086/490] oauth_body_hash cleanup/structuring --- lib/oauth.js | 20 ++++++++++++++++++++ request.js | 49 +++++-------------------------------------------- 2 files changed, 25 insertions(+), 44 deletions(-) diff --git a/lib/oauth.js b/lib/oauth.js index fc1cac6d5..2f01cb571 100644 --- a/lib/oauth.js +++ b/lib/oauth.js @@ -4,6 +4,7 @@ var qs = require('qs') , caseless = require('caseless') , uuid = require('node-uuid') , oauth = require('oauth-sign') + , crypto = require('crypto') function OAuth (request) { @@ -57,6 +58,21 @@ OAuth.prototype.buildParams = function (_oauth, uri, method, query, form, qsLib) return oa } +OAuth.prototype.buildBodyHash = function(_oauth, body) { + var acceptedSignatureMethods = ['HMAC-SHA1', 'RSA-SHA1'] + var index = acceptedSignatureMethods.indexOf(_oauth.signature_method) + + if (!_oauth.signature_method || index > -1) { + var shasum = crypto.createHash('sha1') + shasum.update(body || '') + var sha1 = shasum.digest('hex') + + return new Buffer(sha1).toString('base64') + } else { + throw new Error('oauth: ' + _oauth.signature_method + ' signature_method not supported with body_hash signing.') + } +} + OAuth.prototype.concatParams = function (oa, sep, wrap) { wrap = wrap || '' @@ -102,6 +118,10 @@ OAuth.prototype.onRequest = function (_oauth) { 'and content-type \'' + formContentType + '\'') } + if (!form && typeof _oauth.body_hash === 'boolean') { + _oauth.body_hash = this.buildBodyHash(_oauth, this.request.body.toString()) + } + var oa = this.buildParams(_oauth, uri, method, query, form, qsLib) switch (transport) { diff --git a/request.js b/request.js index 99ae491fa..397ef91a9 100644 --- a/request.js +++ b/request.js @@ -27,7 +27,6 @@ var http = require('http') , OAuth = require('./lib/oauth').OAuth , Multipart = require('./lib/multipart').Multipart , Redirect = require('./lib/redirect').Redirect - , crypto = require('crypto') var safeStringify = helpers.safeStringify , isReadStream = helpers.isReadStream @@ -542,49 +541,6 @@ Request.prototype.init = function (options) { self.path = '/' } - // Add support for oauth_body_hash - // See https://oauth.googlecode.com/svn/spec/ext/body_hash/1.0/oauth-bodyhash.html - // Only supports JSON payloads at the moment - // ==================== - - // Check for an explicit 'true' value, in case someone is already generating their own hash - if (options.oauth && typeof options.oauth.body_hash === 'boolean') { - // 4.1.1b: OAuth Consumers MUST NOT include an oauth_body_hash parameter on requests with form-encoded request bodies. - // -------------------- - if (self.getHeader('content-type') === 'application/x-www-form-urlencoded') { - throw new Error('oauth_body_hash is not supported with form-encoded request bodies.') - } - else { - // 3.1a: If the OAuth signature method is HMAC-SHA1 or RSA-SHA1, SHA1 [RFC3174] MUST be used as the body hash algorithm. - // -------------------- - var acceptedSignatureMethods = ['HMAC-SHA1', 'RSA-SHA1'] - var index = acceptedSignatureMethods.indexOf(options.oauth.signature_method) - - if (!options.oauth.signature_method || index > -1) { - // 3.2a: The body hash value is calculated by executing the selected hash algorithm over the request body. The request body is the entity body as defined in [RFC2616] section 7.2. If the request does not have an entity body, the hash should be taken over the empty string. - // -------------------- - var shasum = crypto.createHash('sha1') - shasum.update(options.json.toString() || '') - var sha1 = shasum.digest('hex') - - // 3.2b: The calculated body hash value is encoded using Base64 per [RFC4648]. - // -------------------- - // oauth_body_hash_base64 = new Buffer(sha1).toString('base64'); - options.oauth.body_hash = new Buffer(sha1).toString('base64') - } - else { - // 3.1b: If the OAuth signature method is PLAINTEXT, use of this specification provides no security benefit and is NOT RECOMMENDED. - // -------------------- - throw new Error(options.oauth.signature_method + ' signature_method not supported with body_hash signing.') - } - } - } - - // Auth must happen last in case signing is dependent on other headers - if (options.oauth) { - self.oauth(options.oauth) - } - if (options.aws) { self.aws(options.aws) } @@ -669,6 +625,11 @@ Request.prototype.init = function (options) { } } + // Auth must happen last in case signing is dependent on other headers + if (options.oauth) { + self.oauth(options.oauth) + } + var protocol = self.proxy && !self.tunnel ? self.proxy.protocol : self.uri.protocol , defaultModules = {'http:':http, 'https:':https} , httpModules = self.httpModules || {} From 5ebab4cd37933c8d06a810148e469856916f0a1d Mon Sep 17 00:00:00 2001 From: simov Date: Sat, 11 Apr 2015 15:10:19 +0300 Subject: [PATCH 087/490] Skip agentOptions tests when running under istanbul --- tests/test-agentOptions.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/test-agentOptions.js b/tests/test-agentOptions.js index 665e7408c..97cf46f6d 100644 --- a/tests/test-agentOptions.js +++ b/tests/test-agentOptions.js @@ -1,5 +1,11 @@ 'use strict' +if (process.env.running_under_istanbul) { + // test-agent.js modifies the process state + // causing these tests to fail when running under single process via tape + return +} + var request = require('../index') , http = require('http') , server = require('./server') From a17d16dd35de7dc8df5ce7b91c36ab990220d610 Mon Sep 17 00:00:00 2001 From: Aesop Wolf Date: Tue, 21 Apr 2015 16:10:12 -0700 Subject: [PATCH 088/490] added test for body_hash --- lib/oauth.js | 17 +++++++---------- request.js | 2 +- tests/test-oauth.js | 27 +++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/lib/oauth.js b/lib/oauth.js index 2f01cb571..2918fb2d5 100644 --- a/lib/oauth.js +++ b/lib/oauth.js @@ -59,18 +59,15 @@ OAuth.prototype.buildParams = function (_oauth, uri, method, query, form, qsLib) } OAuth.prototype.buildBodyHash = function(_oauth, body) { - var acceptedSignatureMethods = ['HMAC-SHA1', 'RSA-SHA1'] - var index = acceptedSignatureMethods.indexOf(_oauth.signature_method) - - if (!_oauth.signature_method || index > -1) { - var shasum = crypto.createHash('sha1') - shasum.update(body || '') - var sha1 = shasum.digest('hex') - - return new Buffer(sha1).toString('base64') - } else { + if (['HMAC-SHA1', 'RSA-SHA1'].indexOf(_oauth.signature_method || 'HMAC-SHA1') < 0) { throw new Error('oauth: ' + _oauth.signature_method + ' signature_method not supported with body_hash signing.') } + + var shasum = crypto.createHash('sha1') + shasum.update(body || '') + var sha1 = shasum.digest('hex') + + return new Buffer(sha1).toString('base64') } OAuth.prototype.concatParams = function (oa, sep, wrap) { diff --git a/request.js b/request.js index 397ef91a9..1339435df 100644 --- a/request.js +++ b/request.js @@ -541,6 +541,7 @@ Request.prototype.init = function (options) { self.path = '/' } + // Auth must happen last in case signing is dependent on other headers if (options.aws) { self.aws(options.aws) } @@ -625,7 +626,6 @@ Request.prototype.init = function (options) { } } - // Auth must happen last in case signing is dependent on other headers if (options.oauth) { self.oauth(options.oauth) } diff --git a/tests/test-oauth.js b/tests/test-oauth.js index bc0b131ef..7d7a6bf0c 100644 --- a/tests/test-oauth.js +++ b/tests/test-oauth.js @@ -527,3 +527,30 @@ tape('body transport_method with prexisting body params', function(t) { t.end() }) }) + +tape('body_hash integrity check', function(t) { + function getBodyHash(r) { + var body_hash + r.headers.Authorization.slice('OAuth '.length).replace(/,\ /g, ',').split(',').forEach(function(v) { + if (v.slice(0, 'oauth_body_hash="'.length) === 'oauth_body_hash="') { + body_hash = v.slice('oauth_body_hash="'.length, -1) + } + }) + return body_hash + } + + var body_hash = request.post( + { url: 'http://example.com' + , oauth: + { consumer_secret: 'consumer_secret' + , body_hash: true + } + , json: {foo: 'bar'} + }) + + process.nextTick(function() { + t.equal('YTVlNzQ0ZDAxNjQ1NDBkMzNiMWQ3ZWE2MTZjMjhmMmZhOTdlNzU0YQ%3D%3D', getBodyHash(body_hash)) + body_hash.abort() + t.end() + }) +}) From c48eb5d3efa47aa26cf4ca30af85824b32b2d1d8 Mon Sep 17 00:00:00 2001 From: simov Date: Wed, 22 Apr 2015 15:59:54 +0300 Subject: [PATCH 089/490] Simplify oauth_body_hash integrity check test --- tests/test-oauth.js | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/tests/test-oauth.js b/tests/test-oauth.js index 7d7a6bf0c..29f75a96f 100644 --- a/tests/test-oauth.js +++ b/tests/test-oauth.js @@ -529,17 +529,7 @@ tape('body transport_method with prexisting body params', function(t) { }) tape('body_hash integrity check', function(t) { - function getBodyHash(r) { - var body_hash - r.headers.Authorization.slice('OAuth '.length).replace(/,\ /g, ',').split(',').forEach(function(v) { - if (v.slice(0, 'oauth_body_hash="'.length) === 'oauth_body_hash="') { - body_hash = v.slice('oauth_body_hash="'.length, -1) - } - }) - return body_hash - } - - var body_hash = request.post( + var r = request.post( { url: 'http://example.com' , oauth: { consumer_secret: 'consumer_secret' @@ -549,8 +539,9 @@ tape('body_hash integrity check', function(t) { }) process.nextTick(function() { - t.equal('YTVlNzQ0ZDAxNjQ1NDBkMzNiMWQ3ZWE2MTZjMjhmMmZhOTdlNzU0YQ%3D%3D', getBodyHash(body_hash)) - body_hash.abort() + var body_hash = r.headers.Authorization.replace(/.*oauth_body_hash="([^"]+)".*/, '$1') + t.equal('YTVlNzQ0ZDAxNjQ1NDBkMzNiMWQ3ZWE2MTZjMjhmMmZhOTdlNzU0YQ%3D%3D', body_hash) + r.abort() t.end() }) }) From 3f55a40102eee629045d9e62ac2e5ea9171ffef2 Mon Sep 17 00:00:00 2001 From: simov Date: Wed, 22 Apr 2015 16:24:04 +0300 Subject: [PATCH 090/490] Add test for manual built oauth_body_hash --- tests/test-oauth.js | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/tests/test-oauth.js b/tests/test-oauth.js index 29f75a96f..92c195b77 100644 --- a/tests/test-oauth.js +++ b/tests/test-oauth.js @@ -6,6 +6,7 @@ var oauth = require('oauth-sign') , path = require('path') , request = require('../index') , tape = require('tape') + , crypto = require('crypto') function getSignature(r) { var sign @@ -528,7 +529,33 @@ tape('body transport_method with prexisting body params', function(t) { }) }) -tape('body_hash integrity check', function(t) { +tape('body_hash manual built', function(t) { + function buildBodyHash (body) { + var shasum = crypto.createHash('sha1') + shasum.update(body || '') + var sha1 = shasum.digest('hex') + return new Buffer(sha1).toString('base64') + } + + var json = {foo: 'bar'} + var r = request.post( + { url: 'http://example.com' + , oauth: + { consumer_secret: 'consumer_secret' + , body_hash: buildBodyHash(JSON.stringify(json)) + } + , json: json + }) + + process.nextTick(function() { + var body_hash = r.headers.Authorization.replace(/.*oauth_body_hash="([^"]+)".*/, '$1') + t.equal('YTVlNzQ0ZDAxNjQ1NDBkMzNiMWQ3ZWE2MTZjMjhmMmZhOTdlNzU0YQ%3D%3D', body_hash) + r.abort() + t.end() + }) +}) + +tape('body_hash automatic built', function(t) { var r = request.post( { url: 'http://example.com' , oauth: From 5498b463e143dd475e0db75bc856d0e5921ebbff Mon Sep 17 00:00:00 2001 From: Aesop Wolf Date: Fri, 24 Apr 2015 10:08:51 -0700 Subject: [PATCH 091/490] added test for PLAINTEXT oauth_body_hash --- tests/test-oauth.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/test-oauth.js b/tests/test-oauth.js index 92c195b77..a4148a9c8 100644 --- a/tests/test-oauth.js +++ b/tests/test-oauth.js @@ -572,3 +572,22 @@ tape('body_hash automatic built', function(t) { t.end() }) }) + +tape('body_hash PLAINTEXT signature_method', function(t) { + try { + request.post( + { url: 'http://example.com' + , oauth: + { consumer_secret: 'consumer_secret' + , body_hash: true + , signature_method: 'PLAINTEXT' + } + , json: {foo: 'bar'} + }) + } catch(e) { + process.nextTick(function() { + t.equal(typeof e, 'object') + t.end() + }) + } +}) From b9c3c432ac1dd0489c86dcbca9527fc6d0804bbe Mon Sep 17 00:00:00 2001 From: Aesop Wolf Date: Fri, 24 Apr 2015 15:11:28 -0700 Subject: [PATCH 092/490] refactored test for oauth_body_hash PLAINTEXT signature_method --- tests/test-oauth.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/test-oauth.js b/tests/test-oauth.js index a4148a9c8..2da346c10 100644 --- a/tests/test-oauth.js +++ b/tests/test-oauth.js @@ -574,7 +574,7 @@ tape('body_hash automatic built', function(t) { }) tape('body_hash PLAINTEXT signature_method', function(t) { - try { + t.throws(function() { request.post( { url: 'http://example.com' , oauth: @@ -583,11 +583,10 @@ tape('body_hash PLAINTEXT signature_method', function(t) { , signature_method: 'PLAINTEXT' } , json: {foo: 'bar'} - }) - } catch(e) { - process.nextTick(function() { - t.equal(typeof e, 'object') + }, function () { + t.fail('body_hash is not allowed with PLAINTEXT signature_method') t.end() }) - } + }, /oauth: PLAINTEXT signature_method not supported with body_hash signing/) + t.end() }) From e2fa5e9278e9f25b57d865167c263c271e629079 Mon Sep 17 00:00:00 2001 From: simov Date: Tue, 28 Apr 2015 10:36:01 +0300 Subject: [PATCH 093/490] Add OAuth body_hash to the docs --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index abcf7feb8..fcda9ff4a 100644 --- a/README.md +++ b/README.md @@ -435,6 +435,10 @@ section of the oauth1 spec: options object. * `transport_method` defaults to `'header'` +To use [Request Body Hash](https://oauth.googlecode.com/svn/spec/ext/body_hash/1.0/oauth-bodyhash.html) you can either +* Manually generate the body hash and pass it as a string `body_hash: '...'` +* Automatically generate the body hash by passing `body_hash: true` + [back to top](#table-of-contents) From 0dd911d035685fb1e49b042d4c69f83855ff5bd0 Mon Sep 17 00:00:00 2001 From: simov Date: Tue, 28 Apr 2015 11:28:33 +0300 Subject: [PATCH 094/490] Regenerate certificates --- tests/ssl/ca/client-enc.key | 52 ++++++++++++++++++------------------- tests/ssl/ca/client.crt | 22 ++++++++-------- tests/ssl/ca/client.csr | 26 +++++++++---------- tests/ssl/ca/client.key | 50 +++++++++++++++++------------------ tests/ssl/ca/localhost.crt | 22 ++++++++-------- tests/ssl/ca/localhost.csr | 26 +++++++++---------- tests/ssl/ca/localhost.key | 50 +++++++++++++++++------------------ 7 files changed, 124 insertions(+), 124 deletions(-) diff --git a/tests/ssl/ca/client-enc.key b/tests/ssl/ca/client-enc.key index 41de6e6c0..57128e13c 100644 --- a/tests/ssl/ca/client-enc.key +++ b/tests/ssl/ca/client-enc.key @@ -1,30 +1,30 @@ -----BEGIN RSA PRIVATE KEY----- Proc-Type: 4,ENCRYPTED -DEK-Info: AES-128-CBC,B8B0445E2D4EBC1F9E68A29701D6F0D5 +DEK-Info: AES-128-CBC,2406B8B3D193CFC0B923B4542CABD70E -qatnPHGWoKrESnOORk87YQ4AiMGLaJf+nP3imMfqnzGm5xVJKzh4It5vvS3YP8ON -45EpVRvNO/8GHhrr5Opu8PVFE53hk9AOaVpLFeJfT26+mwCrXl9Fvno1z9Hj6ZzI -UNPGZz/Igy61UtdEoBnjprUfhyHE8UnH3oW33iiu9hSPI4yHjyTiNre0psO13KUk -HRlKJzzEVXk6eBxuNtKtYXN1utVNaK7v0K0XxmMXFxWzQOPm8l7XXv31qUZoTtor -vnr4jv6D4kpjXnMrHtBSHS49CkNJvkwnifEWfcNAOXmMLbrM0rflBPdP74ldSS5o -34jzVByYMdsXsjTYp5kN8OoEW0dRgZpPEcCEwZ/lik58C+1JPT+/QXVTZm5wv5f0 -xBaQ89Ze5B5gLd2ThKKE+MMn8bvn7q6dgzTkQr40McG4RMRSLk2HbM7ogDR1N45I -6fivhTDg+TEasI00hrwUv974WliqP6hRXd/m9YADyj64VPGKHTuhQGwinO87p+To -IAbsPp2gnihc2jav0Cbid/H1FYs/f4biFmCFPhG0M8sU/T2i9CZ66FTpib73f4tl -n+pS0u3DXeF2r4RAR2Oe/hionrF0Xeai/X6gelDWxZceQiOZQNeortRFldRtlRD0 -7zvHVVysydV4amUqN0L/7PyxMgiAvAfxn08DySGW9RHtjLISzkOjT5cyBL9rr6qz -8yHtbiJtYOlcwfV6tTv/9bKok1qivbM9dnLMlRoYrzJpPzTZV6NtZqSXAb7aJIQp -6vF+4IFLF/yM6l0rZ8jwjJr1avR9WXMG3hP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QESgomHQSTy0N1COHn9QEufQNALvwpnxhT9vqrhqiE4QcO9T5PZ+tmXY +XE2vCdteJaPxykBSk+7edIdsWk/bew9CslE5TojV5EWlh+BrFRXhxIc0VIcBMK6B +e7/z9vx/Id47qIB7EJ0bxdDXQfVvFWh8IRf/mfGVzTX1Zj4pNO7QCexElpGI/1g/ +Vfhds+TLoICZlJuqMwbJlJrRhtFw7I7wGnN8UcFS+FTl3r6xgfZNELXtFBES5suh +n+3d3LxAG0Q7VoEwE87h9HFqNykPRQL20z7DNUfSE8S0X4xvBufNSAeOYwO7d8f9 -----END RSA PRIVATE KEY----- diff --git a/tests/ssl/ca/client.crt b/tests/ssl/ca/client.crt index 24cede76b..ace9a2122 100644 --- a/tests/ssl/ca/client.crt +++ b/tests/ssl/ca/client.crt @@ -3,18 +3,18 @@ MIIDLjCCApcCCQCt9iAWqkDJwzANBgkqhkiG9w0BAQsFADCBojELMAkGA1UEBhMC VVMxCzAJBgNVBAgTAkNBMRAwDgYDVQQHEwdPYWtsYW5kMRAwDgYDVQQKEwdyZXF1 ZXN0MSYwJAYDVQQLEx1yZXF1ZXN0IENlcnRpZmljYXRlIEF1dGhvcml0eTESMBAG A1UEAxMJcmVxdWVzdENBMSYwJAYJKoZIhvcNAQkBFhdtaWtlYWxAbWlrZWFscm9n -ZXJzLmNvbTAeFw0xNTAzMjYxNzAxNTdaFw0xNTA0MjUxNzAxNTdaMIGPMQswCQYD +ZXJzLmNvbTAeFw0xNTA0MjgwODI2MTZaFw0xNTA1MjgwODI2MTZaMIGPMQswCQYD VQQGEwJVUzELMAkGA1UECBMCQ0ExEDAOBgNVBAcTB09ha2xhbmQxEDAOBgNVBAoT B3JlcXVlc3QxGjAYBgNVBAsUEXJlcXVlc3RAbG9jYWxob3N0MRMwEQYDVQQDEwpU ZXN0Q2xpZW50MR4wHAYJKoZIhvcNAQkBFg9kby5ub3RAZW1haWwubWUwggEiMA0G -CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCu6+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g77xUX +IUen54bjo4tosv6orXCqsxHIciclO4Vti1uTzNv74TQVIeglunylzN2Ib3Q1m/03 +YHs= -----END CERTIFICATE----- diff --git a/tests/ssl/ca/client.csr b/tests/ssl/ca/client.csr index efa4e48c3..cfa96c175 100644 --- a/tests/ssl/ca/client.csr +++ b/tests/ssl/ca/client.csr @@ -2,17 +2,17 @@ MIIC+DCCAeACAQAwgY8xCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJDQTEQMA4GA1UE BxMHT2FrbGFuZDEQMA4GA1UEChMHcmVxdWVzdDEaMBgGA1UECxQRcmVxdWVzdEBs b2NhbGhvc3QxEzARBgNVBAMTClRlc3RDbGllbnQxHjAcBgkqhkiG9w0BCQEWD2Rv -Lm5vdEBlbWFpbC5tZTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAK7r -5ks8yKZ7dHJpQKaoxT1Dzy202uAUW4ZEENXBW19WOTJjeS2hzNIn9Uxjp3TE+nTm -XFXcJl94lvPriXi0oJ1/IENKl6jMbF1e31tgNJmeVdTdWk3dVWhDw57R9VOner6d -mG66pp9qMBNNcLNH3VeG4NPy8uND8sd/2lRTcrUkZ1kflaADlNHE52fxsanUhJiQ -AJJq0OQocDmDoK5K8sYnYGbRovc71pTIY7UnGGEKHbLA4IUi3ujzpp6PYH+rL8zY -bwzoW5pCM/xMm3xKH5uQiIjGCXDtAsybPdzSwuYLV5HEW0CI5oEfmwPlWtgAQIUL -HlvrkIwIS+wJtVV1JLMCAwEAAaAjMCEGCSqGSIb3DQEJBzEUExJwYXNzd29yZCBj -aGFsbGVuZ2UwDQYJKoZIhvcNAQELBQADggEBABBBhNmJjJZJ0I/eMK6SqV9kDiT/ -2HwinjOabeR2A2cRwQxH9FKqdDerl4pmlrluH+NuFdZyOCMGsa1SFdTTGnlVFC0F -w/AVblXLigZcfK8WLpKxe9ITTMxMLn3YEacC7+ICbBPBT6NLiDd/d3V46Q1vVwk0 -QS8DDpwLfmFAUHDeMfLGestFrJpNR1WSlytdt5CfFWJ+Hhj+769LkqmlN1j23UOp -MNxmObkocET5rFqoC2VAzA8cCH6QS7pck+3UlK7OXsyTblqwuCOTcPpIdzVYKcEG -qVZBLF3ClCPEQOjWWYqX5NSxPu8Au1/Q7ZU5Gy1hNPzXTsvobKC0ZXswdKA= +Lm5vdEBlbWFpbC5tZTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMMX +R6hWbCFmBSzok5fNECJ8GPdkcJhfENkirgopTSXv3sFV8rTOaxZ6YHrbZGbQkxJV +Cr+7tazIxCELbpbDt5As0gw9Qm81BWGywRzs/5sLSM5lJmyfie/qVhKRGNULdAOF +BdXXjVzcNrR5tShhKGPFpxqTsXC7LG22OCUfYDyQT6Xiz6HQbybXpdsTVHt8lNvA +wGL0WMnlHmr/X0CV9Q5HcA+mcA1TpK9L8ai8T2gxwiGBM2lgixqrhFYBJymguMuw +p7RaDgJwKl2PBj41zHB4rw/7WfghhW3/i+pO8ErzI1Z1iX2VzWUHa4Tyg0RU7JzH +Vk2YGUqu1puOOXr1FvUCAwEAAaAjMCEGCSqGSIb3DQEJBzEUExJwYXNzd29yZCBj +aGFsbGVuZ2UwDQYJKoZIhvcNAQELBQADggEBAGRSMsy7AECtc+R7OABdzjupzJfa +oPLMqCZYPbFaPIG0EKFlv+BEAXi0Fho5yWdA3gy58ssAkXtBLYJB1H3g/UPF+dZx +TR8cytJ4b+X5mP60vxo718+H9dPikH3kmWyr0zFV4mIlmigFcPvUsi1a67sT5AOT +xhOarg69ZuLtS43IMeCXcJ5mJnBLdAwWEQEpBrdhktwroIygD9n0ClXjhmc8p4cj +V9i/WF2AshrZtTgzk/VzKbXXhDOsNjqYQKobZEgeC+o7nhJvz/G3QGtiLAkcpMLw +X6BZEQ4Z9yzsCEbWdT4kE75SvhuM45Q8Rovx0GShAKO/CQIy91nfLFKFZ1g= -----END CERTIFICATE REQUEST----- diff --git a/tests/ssl/ca/client.key b/tests/ssl/ca/client.key index 0b92241c9..7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+4kXAz58GKLM7Vmlvg40f6cv7045dA7RdvYlF7FN46KXpZRmsJReEA5xM11vgXmNk +8GarSyvBIS8xlvHvKGh8Puw+OrPCjRiYRtjbmQ+Efrc8sk7yQvVF4ts= -----END RSA PRIVATE KEY----- diff --git a/tests/ssl/ca/localhost.crt b/tests/ssl/ca/localhost.crt index c445342f4..409716e4b 100644 --- a/tests/ssl/ca/localhost.crt +++ b/tests/ssl/ca/localhost.crt @@ -3,18 +3,18 @@ MIIDLTCCApYCCQCt9iAWqkDJwzANBgkqhkiG9w0BAQsFADCBojELMAkGA1UEBhMC VVMxCzAJBgNVBAgTAkNBMRAwDgYDVQQHEwdPYWtsYW5kMRAwDgYDVQQKEwdyZXF1 ZXN0MSYwJAYDVQQLEx1yZXF1ZXN0IENlcnRpZmljYXRlIEF1dGhvcml0eTESMBAG A1UEAxMJcmVxdWVzdENBMSYwJAYJKoZIhvcNAQkBFhdtaWtlYWxAbWlrZWFscm9n -ZXJzLmNvbTAeFw0xNTAzMjYxNzAwMTZaFw0xNTA0MjUxNzAwMTZaMIGOMQswCQYD +ZXJzLmNvbTAeFw0xNTA0MjgwODI3NTNaFw0xNTA1MjgwODI3NTNaMIGOMQswCQYD VQQGEwJVUzELMAkGA1UECBMCQ0ExEDAOBgNVBAcTB09ha2xhbmQxEDAOBgNVBAoT B3JlcXVlc3QxGjAYBgNVBAsUEXJlcXVlc3RAbG9jYWxob3N0MRIwEAYDVQQDEwls b2NhbGhvc3QxHjAcBgkqhkiG9w0BCQEWD2RvLm5vdEBlbWFpbC5tZTCCASIwDQYJ -KoZIhvcNAQEBBQADggEPADCCAQoCggEBAMHImh271ebLb3RNZLTJSmiAEZfXG7b1 -zsF5UOEIZ3dKGDB4ljKBUUimNOctls1GR7wY8Mhzm2kxtnqPwdP5ABWPFsaO2nJL -4wUK0hyV/IC3/j5BlHYea7oba5Ii0SPxnEgrJ6N0brpksae2KREyDZ3KAdSUefvE -pmgeBE+mbbYhY3X0D886eXz8fnTOdOSpT+dbeOo6hKmhV1jlwSXRkDpqLM+mqRzi -HlOb6PHMHU6GEK/1sOyg6fywYlbnH2cTMRlL0e7RC5DzokoecNhJUpRx1Lww79AO -EmRnd4OxJw6nTe9OyDbahvzEzmhFdzYePS/eExGO4Kp41cMQmTkAEtkCAwEAATAN -BgkqhkiG9w0BAQsFAAOBgQBf0UxfDk6j58mXxeNDQAcHe8qYZvXNnwBvF1ZuCjuw -LyL4orEWQNvmHJDTEXjYQKZLWeihdZ/Ir/L1ZsaIrdezzL2lDXocLCenIbdydO4E -Pn6H9mKFynJrlesEX7GBaaRXqCbvkbRKefW4Zi7Q+zYvV8eJTQgAbRxVcyfv9IMj -bg== +KoZIhvcNAQEBBQADggEPADCCAQoCggEBALa0VP6fC/PBUqwUgJeKR3/Uq+CyBDbP +3A19m1+jgO1MpswXZitXCnkn7zOSczc7NTyErY0zhUwtyIvaNQtAmpDtPTjGNbFJ +hYGvIHlIlG+qedXcYbeBUVrpzTwae7X43xNCcejqPX9J0mSQFhTFp+SSkNbyqnPt +eWEeB81FnwT/t8yAcxMCocwGtjcn0DBm8MsWD0hB9lfVl2Sv20nSD7NP/oosVEbI +zWV31IrIjd01UCNgbuqvcHWO4IUy0HqLgsWcfaNSNdmjf8kL9lZ0UvjU5R/sRVX/ +yeGRHcYj5FjhXWuX0+PIJIMa28O/AhDgPwF/IA//vYthC7ChZgZQd2sCAwEAATAN +BgkqhkiG9w0BAQsFAAOBgQC27LqfOUoStYB3AmrEY8kMComIuVR/Inl42cIQSH8J +oCHzHGvuEnutZXsZyNxMRxyWOEjniYPgJnu6lq0X6vJUoTcR13olMZ/tgRL4ezNJ +cPE896oTy81YId4b/OFtj00iB3eKHwfYoSnJAuwOZS/r4tYkggXJzthZqv10I6es +zQ== -----END CERTIFICATE----- diff --git a/tests/ssl/ca/localhost.csr b/tests/ssl/ca/localhost.csr index 1d05464a6..250b52217 100644 --- a/tests/ssl/ca/localhost.csr +++ b/tests/ssl/ca/localhost.csr @@ -2,17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iG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtrRU +/p8L88FSrBSAl4pHf9Sr4LIENs/cDX2bX6OA7UymzBdmK1cKeSfvM5JzNzs1PISt +jTOFTC3Ii9o1C0CakO09OMY1sUmFga8geUiUb6p51dxht4FRWunNPBp7tfjfE0Jx +6Oo9f0nSZJAWFMWn5JKQ1vKqc+15YR4HzUWfBP+3zIBzEwKhzAa2NyfQMGbwyxYP +SEH2V9WXZK/bSdIPs0/+iixURsjNZXfUisiN3TVQI2Bu6q9wdY7ghTLQeouCxZx9 +o1I12aN/yQv2VnRS+NTlH+xFVf/J4ZEdxiPkWOFda5fT48gkgxrbw78CEOA/AX8g +D/+9i2ELsKFmBlB3awIDAQABoCMwIQYJKoZIhvcNAQkHMRQTEnBhc3N3b3JkIGNo +YWxsZW5nZTANBgkqhkiG9w0BAQsFAAOCAQEAAZIRdVIoqlSqKHYWVdLeulIsUP77 +EgJgH/HHvEa15pH+rJJ07+djznFe+ywXuenanDIaoUTDG2ATxNdu4y5aCK5nvDRY ++0bgRcphpo4UBtZE/xFpRAefacdP06bLCyW0DAR+wTnLwbpDSgrL+kc9S19f4d2N +tCjqLsOcvolKaT/6cyOUpsQ9wC5V39k7AXk59PcsEso7rjk9t+Guik0G0uk87FDg +6xw0slu/OFlPj8g/PJoH5E8Cs3hwpdqmGO6Dp8umkyUa/ACn7ZXFm3K+fmvHLo6/ +90h49VU6OWcqs5/j8OoTG4QkFGZvItykhCL0mOdTCcAr9LyJREaAwfN3tg== -----END CERTIFICATE REQUEST----- diff --git a/tests/ssl/ca/localhost.key b/tests/ssl/ca/localhost.key index 88fa7bb13..3b073256c 100644 --- a/tests/ssl/ca/localhost.key +++ b/tests/ssl/ca/localhost.key @@ -1,27 +1,27 @@ -----BEGIN RSA PRIVATE KEY----- -MIIEogIBAAKCAQEAwciaHbvV5stvdE1ktMlKaIARl9cbtvXOwXlQ4Qhnd0oYMHiW -MoFRSKY05y2WzUZHvBjwyHObaTG2eo/B0/k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le1 +rFV01ToI0YgSIe8zNdBnRPyLvTs1My1fhM1VJGoJrldumxJRH6xDuf/V+LdQPI4g +FCpZXYECgYEA5fxlEc7uSmXBTQOze3VUl5ZbTshaCPZqXm5OprLHR3nH1GFv9L7a +KgLUBpD92/j7YncG7pjJF/VFP14TuCPKVFgx9tdJR8b0GdUGs+ukjUc11SHPAY6Y +ZkeD8oRwz5iCaYhMFjttxe+1xKNnDZ3k/tecP6PhZmBmMntG6RntrvsCgYEAy17T +ryi3cwEplqQBxp70x6Q/Y4KdTyGkGw8Ml6yCmOl4F8JoZvr6KCtLjWx+qQA+Xs2W +Xhynl+eKr6iObQ78baN40YGecLVFVrgc+Fdxlm0GQgiEAavL8ehMhI+7/PpZbR5Q +uPj3qOHrzBjsULHD7lT1yCzv9PdNtluz6hoRLlECgYAyIhiuDxumoBPJA/uF+Aee +m6n/vHDT71M0jnsan3INRKCozSyof0nzSnaJj+Wmo9m4lxWtwSRk0pRrwcgupa6f +QDJ0Cm3w9Y+UaflyEvXlzhYQBbSoNDtIYGKE5RXqSuZytsFPP1kogp5u5Oe78iVO +4BUxUjn6JR1h97l3aq2DLQKBgD/E/k+gTtXK+YV46+2iDlNDl3TWkgksHU82ytYM +i+7y1mts1FvmOua5nLk92gGYR/ZmNM5R4eNqATzPd8mOt2yRo+Ld6BajYJiuprbg +hIeMrDesf+gePJcgJk4y29mZjsz+goVd3BqirNOUxRUQiMWE8oTQQnXnzgBuhN3V +SqnhAoGBAIk61OdvqKSyD46UyvO+saCtFQdL1uC2IF17PK9jxQD41NLZ8Beg2R0r +sxB6wifKHffPRg8bpSeGtF7RN7H3v0HH8eju5IFIA7yooVkHzXjaUKBs6usu92PM +HazWXfpBgFtFLU+juv4wXZosnUsv/9OI+4z9Zla+2eswwpEVa0li -----END RSA PRIVATE KEY----- From ebca6227db92e326aec03b818bdad37386f6db80 Mon Sep 17 00:00:00 2001 From: simov Date: Fri, 1 May 2015 10:10:48 +0300 Subject: [PATCH 095/490] Emit error instead of throw --- lib/auth.js | 4 ++-- lib/multipart.js | 4 ++-- lib/oauth.js | 30 +++++++++++++++--------------- request.js | 10 +++++----- tests/test-bearer-auth.js | 25 +++++++++++-------------- tests/test-oauth.js | 7 ++----- 6 files changed, 37 insertions(+), 43 deletions(-) diff --git a/lib/auth.js b/lib/auth.js index 13c3ac8f3..6a42ba30e 100644 --- a/lib/auth.js +++ b/lib/auth.js @@ -21,7 +21,7 @@ function Auth (request) { Auth.prototype.basic = function (user, pass, sendImmediately) { var self = this if (typeof user !== 'string' || (pass !== undefined && typeof pass !== 'string')) { - throw new Error('auth() received invalid user or password') + self.request.emit('error', new Error('auth() received invalid user or password')) } self.user = user self.pass = pass @@ -115,7 +115,7 @@ Auth.prototype.onRequest = function (user, pass, sendImmediately, bearer) { var authHeader if (bearer === undefined && user === undefined) { - throw new Error('no auth mechanism defined') + self.request.emit('error', new Error('no auth mechanism defined')) } else if (bearer !== undefined) { authHeader = self.bearer(bearer, sendImmediately) } else { diff --git a/lib/multipart.js b/lib/multipart.js index f95f8a390..03618588c 100644 --- a/lib/multipart.js +++ b/lib/multipart.js @@ -18,7 +18,7 @@ Multipart.prototype.isChunked = function (options) { , parts = options.data || options if (!parts.forEach) { - throw new Error('Argument error, options.multipart.') + self.request.emit('error', new Error('Argument error, options.multipart.')) } if (options.chunked !== undefined) { @@ -32,7 +32,7 @@ Multipart.prototype.isChunked = function (options) { if (!chunked) { parts.forEach(function (part) { if (typeof part.body === 'undefined') { - throw new Error('Body attribute missing in multipart.') + self.request.emit('error', new Error('Body attribute missing in multipart.')) } if (isstream(part.body)) { chunked = true diff --git a/lib/oauth.js b/lib/oauth.js index 2918fb2d5..14ffa8a53 100644 --- a/lib/oauth.js +++ b/lib/oauth.js @@ -60,7 +60,8 @@ OAuth.prototype.buildParams = function (_oauth, uri, method, query, form, qsLib) OAuth.prototype.buildBodyHash = function(_oauth, body) { if (['HMAC-SHA1', 'RSA-SHA1'].indexOf(_oauth.signature_method || 'HMAC-SHA1') < 0) { - throw new Error('oauth: ' + _oauth.signature_method + ' signature_method not supported with body_hash signing.') + this.request.emit('error', new Error('oauth: ' + _oauth.signature_method + + ' signature_method not supported with body_hash signing.')) } var shasum = crypto.createHash('sha1') @@ -89,13 +90,12 @@ OAuth.prototype.concatParams = function (oa, sep, wrap) { OAuth.prototype.onRequest = function (_oauth) { var self = this - , request = self.request - var uri = request.uri || {} - , method = request.method || '' - , headers = caseless(request.headers) - , body = request.body || '' - , qsLib = request.qsLib || qs + var uri = self.request.uri || {} + , method = self.request.method || '' + , headers = caseless(self.request.headers) + , body = self.request.body || '' + , qsLib = self.request.qsLib || qs var form , query @@ -111,31 +111,31 @@ OAuth.prototype.onRequest = function (_oauth) { query = uri.query } if (transport === 'body' && (method !== 'POST' || contentType !== formContentType)) { - throw new Error('oauth: transport_method of \'body\' requires \'POST\' ' + - 'and content-type \'' + formContentType + '\'') + self.request.emit('error', new Error('oauth: transport_method of body requires POST ' + + 'and content-type ' + formContentType)) } if (!form && typeof _oauth.body_hash === 'boolean') { - _oauth.body_hash = this.buildBodyHash(_oauth, this.request.body.toString()) + _oauth.body_hash = self.buildBodyHash(_oauth, self.request.body.toString()) } - var oa = this.buildParams(_oauth, uri, method, query, form, qsLib) + var oa = self.buildParams(_oauth, uri, method, query, form, qsLib) switch (transport) { case 'header': - request.setHeader('Authorization', 'OAuth ' + this.concatParams(oa, ',', '"')) + self.request.setHeader('Authorization', 'OAuth ' + self.concatParams(oa, ',', '"')) break case 'query': - request.path = (query ? '&' : '?') + this.concatParams(oa, '&') + self.request.path = (query ? '&' : '?') + self.concatParams(oa, '&') break case 'body': - request.body = (form ? form + '&' : '') + this.concatParams(oa, '&') + self.request.body = (form ? form + '&' : '') + self.concatParams(oa, '&') break default: - throw new Error('oauth: transport_method invalid') + self.request.emit('error', new Error('oauth: transport_method invalid')) } } diff --git a/request.js b/request.js index 1339435df..ec89e9de7 100644 --- a/request.js +++ b/request.js @@ -409,7 +409,7 @@ Request.prototype.init = function (options) { delete self.baseUrl } - // A URI is needed by this point, throw if we haven't been able to get one + // A URI is needed by this point, emit error if we haven't been able to get one if (!self.uri) { return self.emit('error', new Error('options.uri is a required argument')) } @@ -622,7 +622,7 @@ Request.prototype.init = function (options) { self.setHeader('content-length', length) } } else { - throw new Error('Argument error, options.body.') + self.emit('error', new Error('Argument error, options.body.')) } } @@ -666,7 +666,7 @@ Request.prototype.init = function (options) { self.on('pipe', function (src) { if (self.ntick && self._started) { - throw new Error('You cannot pipe to this stream after the outbound request has started.') + self.emit('error', new Error('You cannot pipe to this stream after the outbound request has started.')) } self.src = src if (isReadStream(src)) { @@ -1503,9 +1503,9 @@ Request.prototype.pipe = function (dest, opts) { if (self.response) { if (self._destdata) { - throw new Error('You cannot pipe after data has been emitted from the response.') + self.emit('error', new Error('You cannot pipe after data has been emitted from the response.')) } else if (self._ended) { - throw new Error('You cannot pipe after the response has been ended.') + self.emit('error', new Error('You cannot pipe after the response has been ended.')) } else { stream.Stream.prototype.pipe.call(self, dest, opts) self.pipeDest(dest) diff --git a/tests/test-bearer-auth.js b/tests/test-bearer-auth.js index be32505ad..2417fa8f9 100644 --- a/tests/test-bearer-auth.js +++ b/tests/test-bearer-auth.js @@ -148,19 +148,16 @@ tape('bearer is a function, path = test2', function(t) { }) tape('no auth method', function(t) { - t.throws(function() { - request({ - 'method': 'GET', - 'uri': 'http://localhost:6767/test2/', - 'auth': { - 'bearer': undefined - } - }, function(error, res, body) { - t.fail('Requests without a valid auth mechanism are not valid') - t.end() - }) - }, /no auth mechanism defined/) - t.end() + request({ + 'method': 'GET', + 'uri': 'http://localhost:6767/test2/', + 'auth': { + 'bearer': undefined + } + }, function(error, res, body) { + t.equal(error.message, 'no auth mechanism defined') + t.end() + }) }) tape('null bearer', function(t) { @@ -172,7 +169,7 @@ tape('null bearer', function(t) { } }, function(error, res, body) { t.equal(res.statusCode, 401) - t.equal(numBearerRequests, 12) + t.equal(numBearerRequests, 13) t.end() }) }) diff --git a/tests/test-oauth.js b/tests/test-oauth.js index 2da346c10..1562638cf 100644 --- a/tests/test-oauth.js +++ b/tests/test-oauth.js @@ -353,7 +353,7 @@ tape('invalid method while using transport_method \'body\'', function(t) { { transport_method: 'body' } }) - }, /requires 'POST'/) + }, /requires POST/) t.end() }) @@ -367,7 +367,7 @@ tape('invalid content-type while using transport_method \'body\'', function(t) { { transport_method: 'body' } }) - }, /requires 'POST'/) + }, /requires POST/) t.end() }) @@ -583,9 +583,6 @@ tape('body_hash PLAINTEXT signature_method', function(t) { , signature_method: 'PLAINTEXT' } , json: {foo: 'bar'} - }, function () { - t.fail('body_hash is not allowed with PLAINTEXT signature_method') - t.end() }) }, /oauth: PLAINTEXT signature_method not supported with body_hash signing/) t.end() From 8105c8efe37e9283d8af3f8b016f7ede1950811a Mon Sep 17 00:00:00 2001 From: Mike Atkins Date: Mon, 4 May 2015 21:52:18 -0400 Subject: [PATCH 096/490] Update combined-stream This updated combined-stream now uses an updated delayed-stream which no longer uses the non-standard `__defineGetter__` syntax. By removing this, request can now be loaded in IE10. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7903920aa..c3e9ed00d 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "hawk": "~2.3.0", "aws-sign2": "~0.5.0", "stringstream": "~0.0.4", - "combined-stream": "~0.0.5", + "combined-stream": "~1.0.1", "isstream": "~0.1.1", "har-validator": "^1.6.1" }, From bd3d3ad5348da66f4cf00b51b26fd8cf8ec622ad Mon Sep 17 00:00:00 2001 From: Kevin Locke Date: Thu, 7 May 2015 23:28:07 -0600 Subject: [PATCH 097/490] Pause/Resume response content, not response When the response content is piped through additional streams for decoding (e.g. for gzip decompression), pause and resume calls should be propagated to the last stream in the pipeline so that back pressure propagates correctly. This avoids an issue where simultaneous back pressure from the content decoding stream and from a stream to which Request is piped could cause the response stream to get stuck waiting for a drain event on the content decoding stream which never occurs. See #1567 for an example. This commit also renames dataStream to responseContent to remedy my previous poor choice of name, since the name will be exposed on the Request instance it should be clearer and closer to the name used to refer to this data in the relevant RFCs. Fixes #1567 Signed-off-by: Kevin Locke --- request.js | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/request.js b/request.js index 1339435df..f8c33f49f 100644 --- a/request.js +++ b/request.js @@ -1120,56 +1120,58 @@ Request.prototype.onRequestResponse = function (response) { self._ended = true }) - var dataStream + var responseContent if (self.gzip) { var contentEncoding = response.headers['content-encoding'] || 'identity' contentEncoding = contentEncoding.trim().toLowerCase() if (contentEncoding === 'gzip') { - dataStream = zlib.createGunzip() - response.pipe(dataStream) + responseContent = zlib.createGunzip() + response.pipe(responseContent) } else { // Since previous versions didn't check for Content-Encoding header, // ignore any invalid values to preserve backwards-compatibility if (contentEncoding !== 'identity') { debug('ignoring unrecognized Content-Encoding ' + contentEncoding) } - dataStream = response + responseContent = response } } else { - dataStream = response + responseContent = response } if (self.encoding) { if (self.dests.length !== 0) { console.error('Ignoring encoding parameter as this stream is being piped to another stream which makes the encoding option invalid.') - } else if (dataStream.setEncoding) { - dataStream.setEncoding(self.encoding) + } else if (responseContent.setEncoding) { + responseContent.setEncoding(self.encoding) } else { // Should only occur on node pre-v0.9.4 (joyent/node@9b5abe5) with // zlib streams. // If/When support for 0.9.4 is dropped, this should be unnecessary. - dataStream = dataStream.pipe(stringstream(self.encoding)) + responseContent = responseContent.pipe(stringstream(self.encoding)) } } + self.responseContent = responseContent + self.emit('response', response) self.dests.forEach(function (dest) { self.pipeDest(dest) }) - dataStream.on('data', function (chunk) { + responseContent.on('data', function (chunk) { self._destdata = true self.emit('data', chunk) }) - dataStream.on('end', function (chunk) { + responseContent.on('end', function (chunk) { self.emit('end', chunk) }) - dataStream.on('error', function (error) { + responseContent.on('error', function (error) { self.emit('error', error) }) - dataStream.on('close', function () {self.emit('close')}) + responseContent.on('close', function () {self.emit('close')}) if (self.callback) { var buffer = bl() @@ -1536,18 +1538,18 @@ Request.prototype.end = function (chunk) { } Request.prototype.pause = function () { var self = this - if (!self.response) { + if (!self.responseContent) { self._paused = true } else { - self.response.pause.apply(self.response, arguments) + self.responseContent.pause.apply(self.responseContent, arguments) } } Request.prototype.resume = function () { var self = this - if (!self.response) { + if (!self.responseContent) { self._paused = false } else { - self.response.resume.apply(self.response, arguments) + self.responseContent.resume.apply(self.responseContent, arguments) } } Request.prototype.destroy = function () { From e43218dd74c73a4cbd284d5679b888fd48b4abba Mon Sep 17 00:00:00 2001 From: Kevin Locke Date: Fri, 8 May 2015 15:52:45 -0600 Subject: [PATCH 098/490] Fix pause before response arrives Due to #1568, we now propagate pause and resume to the response content stream, rather than the response stream. However, when pause is called before the response arrives, the pause is still being applied to the response object directly. Fix this by applying it to the response content stream in both cases. This avoids the issue that if pause is called on a gzip request before the response arrives, it pauses the response then resumes the response content, meaning the response can not be resumed. Also add tests of the pause/resume behavior for both the gzip and non-gzip case both before and after the response has arrived. This commit also makes the ancillary change that resume is now called unconditionally (when defined) in Redirect, since we always want to dump the response data (and it was previously called unconditionally in onRequestResponse). Signed-off-by: Kevin Locke --- lib/redirect.js | 3 +- package.json | 1 + request.js | 10 +++--- tests/test-gzip.js | 74 +++++++++++++++++++++++++++++++++++++++++++-- tests/test-pipes.js | 60 ++++++++++++++++++++++++++++++++++++ 5 files changed, 139 insertions(+), 9 deletions(-) diff --git a/lib/redirect.js b/lib/redirect.js index 7dd6c254c..ce83ffec8 100644 --- a/lib/redirect.js +++ b/lib/redirect.js @@ -87,7 +87,8 @@ Redirect.prototype.onResponse = function (response) { // ignore any potential response body. it cannot possibly be useful // to us at this point. - if (request._paused) { + // response.resume should be defined, but check anyway before calling. Workaround for browserify. + if (response.resume) { response.resume() } diff --git a/package.json b/package.json index c3e9ed00d..a0dbaba23 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "devDependencies": { "browserify": "~5.9.1", "browserify-istanbul": "~0.1.3", + "buffer-equal": "0.0.1", "coveralls": "~2.11.2", "eslint": "0.18.0", "function-bind": "~1.0.0", diff --git a/request.js b/request.js index f8c33f49f..88cf6dd5d 100644 --- a/request.js +++ b/request.js @@ -1047,12 +1047,6 @@ Request.prototype.onRequestResponse = function (response) { response.resume() return } - if (self._paused) { - response.pause() - } else if (response.resume) { - // response.resume should be defined, but check anyway before calling. Workaround for browserify. - response.resume() - } self.response = response response.request = self @@ -1153,6 +1147,10 @@ Request.prototype.onRequestResponse = function (response) { } } + if (self._paused) { + responseContent.pause() + } + self.responseContent = responseContent self.emit('response', response) diff --git a/tests/test-gzip.js b/tests/test-gzip.js index 5c2b3c1ae..fef772055 100644 --- a/tests/test-gzip.js +++ b/tests/test-gzip.js @@ -4,9 +4,12 @@ var request = require('../index') , http = require('http') , zlib = require('zlib') , assert = require('assert') + , bufferEqual = require('buffer-equal') , tape = require('tape') var testContent = 'Compressible response content.\n' + , testContentBig + , testContentBigGzip , testContentGzip var server = http.createServer(function(req, res) { @@ -18,6 +21,10 @@ var server = http.createServer(function(req, res) { if (req.url === '/error') { // send plaintext instead of gzip (should cause an error for the client) res.end(testContent) + } else if (req.url === '/chunks') { + res.writeHead(200) + res.write(testContentBigGzip.slice(0, 4096)) + setTimeout(function() { res.end(testContentBigGzip.slice(4096)) }, 10) } else { zlib.gzip(testContent, function(err, data) { assert.equal(err, null) @@ -30,11 +37,30 @@ var server = http.createServer(function(req, res) { }) tape('setup', function(t) { + // Need big compressed content to be large enough to chunk into gzip blocks. + // Want it to be deterministic to ensure test is reliable. + // Generate pseudo-random printable ASCII characters using MINSTD + var a = 48271 + , m = 0x7FFFFFFF + , x = 1 + testContentBig = new Buffer(10240) + for (var i = 0; i < testContentBig.length; ++i) { + x = (a * x) & m + // Printable ASCII range from 32-126, inclusive + testContentBig[i] = (x % 95) + 32 + } + zlib.gzip(testContent, function(err, data) { t.equal(err, null) testContentGzip = data - server.listen(6767, function() { - t.end() + + zlib.gzip(testContentBig, function(err, data2) { + t.equal(err, null) + testContentBigGzip = data2 + + server.listen(6767, function() { + t.end() + }) }) }) }) @@ -139,6 +165,50 @@ tape('transparently supports gzip error to pipes', function(t) { }) }) +tape('pause when streaming from a gzip request object', function(t) { + var chunks = [] + var paused = false + var options = { url: 'http://localhost:6767/chunks', gzip: true } + request.get(options) + .on('data', function(chunk) { + var self = this + + t.notOk(paused, 'Only receive data when not paused') + + chunks.push(chunk) + if (chunks.length === 1) { + self.pause() + paused = true + setTimeout(function() { + paused = false + self.resume() + }, 100) + } + }) + .on('end', function() { + t.ok(chunks.length > 1, 'Received multiple chunks') + t.ok(bufferEqual(Buffer.concat(chunks), testContentBig), 'Expected content') + t.end() + }) +}) + +tape('pause before streaming from a gzip request object', function(t) { + var paused = true + var options = { url: 'http://localhost:6767/foo', gzip: true } + var r = request.get(options) + r.pause() + r.on('data', function(data) { + t.notOk(paused, 'Only receive data when not paused') + t.equal(data.toString(), testContent) + }) + r.on('end', t.end.bind(t)) + + setTimeout(function() { + paused = false + r.resume() + }, 100) +}) + tape('cleanup', function(t) { server.close(function() { t.end() diff --git a/tests/test-pipes.js b/tests/test-pipes.js index 0e4be002c..3763f5781 100644 --- a/tests/test-pipes.js +++ b/tests/test-pipes.js @@ -131,6 +131,66 @@ tape('piping from a request object', function(t) { } }) +tape('pause when piping from a request object', function(t) { + s.once('/chunks', function(req, res) { + res.writeHead(200, { + 'content-type': 'text/plain' + }) + res.write('Chunk 1') + setTimeout(function() { res.end('Chunk 2') }, 10) + }) + + var chunkNum = 0 + var paused = false + request({ + url: s.url + '/chunks' + }) + .on('data', function(chunk) { + var self = this + + t.notOk(paused, 'Only receive data when not paused') + + ++chunkNum + if (chunkNum === 1) { + t.equal(chunk.toString(), 'Chunk 1') + self.pause() + paused = true + setTimeout(function() { + paused = false + self.resume() + }, 100) + } else { + t.equal(chunk.toString(), 'Chunk 2') + } + }) + .on('end', t.end.bind(t)) +}) + +tape('pause before piping from a request object', function(t) { + s.once('/pause-before', function(req, res) { + res.writeHead(200, { + 'content-type': 'text/plain' + }) + res.end('Data') + }) + + var paused = true + var r = request({ + url: s.url + '/pause-before' + }) + r.pause() + r.on('data', function(data) { + t.notOk(paused, 'Only receive data when not paused') + t.equal(data.toString(), 'Data') + }) + r.on('end', t.end.bind(t)) + + setTimeout(function() { + paused = false + r.resume() + }, 100) +}) + var fileContents = fs.readFileSync(__filename).toString() function testPipeFromFile(testName, hasContentLength) { tape(testName, function(t) { From e90fe728dcfeb35e7a4b2ad5332f0036181d3eaf Mon Sep 17 00:00:00 2001 From: seanstrom Date: Sat, 9 May 2015 15:02:07 -0700 Subject: [PATCH 099/490] changes tests to run assertions on tests --- tests/test-body.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/test-body.js b/tests/test-body.js index a49640f87..335267bc1 100644 --- a/tests/test-body.js +++ b/tests/test-body.js @@ -20,6 +20,11 @@ function addTest(name, data) { t.equal(err, null) if (data.expectBody && Buffer.isBuffer(data.expectBody)) { t.deepEqual(data.expectBody.toString(), body.toString()) + } else if (data.expectBody) { + t.deepEqual(data.expectBody, body) + } else { + // not sure what to test when we dont have expectBody + console.log('untested code') } t.end() }) From 8a478f0ef36912b737df9c5aea900e7f776ed371 Mon Sep 17 00:00:00 2001 From: seanstrom Date: Tue, 12 May 2015 09:15:45 -0700 Subject: [PATCH 100/490] revise tests and test helpers --- tests/server.js | 2 +- tests/test-body.js | 3 --- tests/test-pipes.js | 9 +++++---- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/tests/server.js b/tests/server.js index 5c5585bb3..99d004a30 100644 --- a/tests/server.js +++ b/tests/server.js @@ -94,7 +94,7 @@ exports.createPostValidator = function (text, reqContentType) { assert.ok(~req.headers['content-type'].indexOf(reqContentType)) } resp.writeHead(200, {'content-type':'text/plain'}) - resp.write('OK') + resp.write(r) resp.end() }) } diff --git a/tests/test-body.js b/tests/test-body.js index 335267bc1..77b826d46 100644 --- a/tests/test-body.js +++ b/tests/test-body.js @@ -22,9 +22,6 @@ function addTest(name, data) { t.deepEqual(data.expectBody.toString(), body.toString()) } else if (data.expectBody) { t.deepEqual(data.expectBody, body) - } else { - // not sure what to test when we dont have expectBody - console.log('untested code') } t.end() }) diff --git a/tests/test-pipes.js b/tests/test-pipes.js index 0e4be002c..140c96c4d 100644 --- a/tests/test-pipes.js +++ b/tests/test-pipes.js @@ -80,7 +80,7 @@ tape('piping to a request object', function(t) { }, function(err, res, body) { t.equal(err, null) t.equal(res.statusCode, 200) - t.equal(body, 'OK') + t.equal(body, 'mydata') t.end() }) mydata.pipe(r1) @@ -90,8 +90,9 @@ tape('piping to a request object', function(t) { }) tape('piping to a request object with a json body', function(t) { - s.once('/push-json', server.createPostValidator('{"foo":"bar"}', 'application/json')) - + var obj = {foo: 'bar'} + var json = JSON.stringify(obj) + s.once('/push-json', server.createPostValidator(json, 'application/json')) var mybodydata = new stream.Stream() mybodydata.readable = true @@ -101,7 +102,7 @@ tape('piping to a request object with a json body', function(t) { }, function(err, res, body) { t.equal(err, null) t.equal(res.statusCode, 200) - t.equal(body, 'OK') + t.deepEqual(body, obj) t.end() }) mybodydata.pipe(r2) From 12ff8334d50df2b0e83d9e8342148a36cc922e06 Mon Sep 17 00:00:00 2001 From: simov Date: Wed, 13 May 2015 14:06:31 +0300 Subject: [PATCH 101/490] Refresh the oauth_nonce on redirect (#1573) - Cache the initial oauth options passed to request in _oauth.params - On subsequent calls to init() use the cached _oauth.params to invoke the oauth params generation logic again --- lib/oauth.js | 2 ++ request.js | 2 ++ tests/test-oauth.js | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/lib/oauth.js b/lib/oauth.js index 14ffa8a53..84059724a 100644 --- a/lib/oauth.js +++ b/lib/oauth.js @@ -9,6 +9,7 @@ var qs = require('qs') function OAuth (request) { this.request = request + this.params = null } OAuth.prototype.buildParams = function (_oauth, uri, method, query, form, qsLib) { @@ -90,6 +91,7 @@ OAuth.prototype.concatParams = function (oa, sep, wrap) { OAuth.prototype.onRequest = function (_oauth) { var self = this + self.params = _oauth var uri = self.request.uri || {} , method = self.request.method || '' diff --git a/request.js b/request.js index cb0eeb981..660d4686d 100644 --- a/request.js +++ b/request.js @@ -628,6 +628,8 @@ Request.prototype.init = function (options) { if (options.oauth) { self.oauth(options.oauth) + } else if (self._oauth.params) { + self.oauth(self._oauth.params) } var protocol = self.proxy && !self.tunnel ? self.proxy.protocol : self.uri.protocol diff --git a/tests/test-oauth.js b/tests/test-oauth.js index 1562638cf..81ce46fc6 100644 --- a/tests/test-oauth.js +++ b/tests/test-oauth.js @@ -7,6 +7,7 @@ var oauth = require('oauth-sign') , request = require('../index') , tape = require('tape') , crypto = require('crypto') + , http = require('http') function getSignature(r) { var sign @@ -587,3 +588,35 @@ tape('body_hash PLAINTEXT signature_method', function(t) { }, /oauth: PLAINTEXT signature_method not supported with body_hash signing/) t.end() }) + +tape('refresh oauth_nonce on redirect', function(t) { + var oauth_nonce1, oauth_nonce2 + var s = http.createServer(function (req, res) { + if (req.url === '/redirect') { + oauth_nonce1 = req.headers.authorization.replace(/.*oauth_nonce="([^"]+)".*/, '$1') + res.writeHead(302, {location:'http://localhost:6767/response'}) + res.end() + } else if (req.url === '/response') { + oauth_nonce2 = req.headers.authorization.replace(/.*oauth_nonce="([^"]+)".*/, '$1') + res.writeHead(200, {'content-type':'text/plain'}) + res.end() + } + }) + s.listen(6767, function () { + request.get( + { url: 'http://localhost:6767/redirect' + , oauth: + { consumer_key: 'consumer_key' + , consumer_secret: 'consumer_secret' + , token: 'token' + , token_secret: 'token_secret' + } + }, function (err, res, body) { + t.equal(err, null) + t.notEqual(oauth_nonce1, oauth_nonce2) + s.close(function () { + t.end() + }) + }) + }) +}) From 195d4c0dce5c1fa4c95ff4c3e9fd39f92a2403d7 Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 14 May 2015 13:15:37 +0300 Subject: [PATCH 102/490] Refresh oauth_nonce only when redirecting to the same hostname https://github.com/request/request/pull/1574#issuecomment-101749016 --- request.js | 2 +- tests/test-oauth.js | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/request.js b/request.js index 660d4686d..e8da29a88 100644 --- a/request.js +++ b/request.js @@ -628,7 +628,7 @@ Request.prototype.init = function (options) { if (options.oauth) { self.oauth(options.oauth) - } else if (self._oauth.params) { + } else if (self._oauth.params && self.hasHeader('authorization')) { self.oauth(self._oauth.params) } diff --git a/tests/test-oauth.js b/tests/test-oauth.js index 81ce46fc6..b716167c7 100644 --- a/tests/test-oauth.js +++ b/tests/test-oauth.js @@ -620,3 +620,35 @@ tape('refresh oauth_nonce on redirect', function(t) { }) }) }) + +tape('no credentials on external redirect', function(t) { + var s1 = http.createServer(function (req, res) { + res.writeHead(302, {location:'http://127.0.0.1:6768'}) + res.end() + }) + var s2 = http.createServer(function (req, res) { + res.writeHead(200, {'content-type':'text/plain'}) + res.end() + }) + s1.listen(6767, function () { + s2.listen(6768, function () { + request.get( + { url: 'http://localhost:6767' + , oauth: + { consumer_key: 'consumer_key' + , consumer_secret: 'consumer_secret' + , token: 'token' + , token_secret: 'token_secret' + } + }, function (err, res, body) { + t.equal(err, null) + t.equal(res.request.headers.Authorization, undefined) + s1.close(function () { + s2.close(function () { + t.end() + }) + }) + }) + }) + }) +}) From 950d7ba4f943ad152749941444e275f80bedc224 Mon Sep 17 00:00:00 2001 From: simov Date: Sun, 17 May 2015 12:38:40 +0300 Subject: [PATCH 103/490] Refactor test-default tests (according to comments in #1430) --- tests/test-defaults.js | 250 +++++++++++++++-------------------------- 1 file changed, 90 insertions(+), 160 deletions(-) diff --git a/tests/test-defaults.js b/tests/test-defaults.js index 50cf213c3..112033357 100644 --- a/tests/test-defaults.js +++ b/tests/test-defaults.js @@ -1,7 +1,6 @@ 'use strict' var server = require('./server') - , assert = require('assert') , request = require('../index') , tape = require('tape') @@ -9,115 +8,29 @@ var s = server.createServer() tape('setup', function(t) { s.listen(s.port, function() { - s.on('/get', function(req, resp) { - assert.equal(req.headers.foo, 'bar') - assert.equal(req.method, 'GET') - resp.writeHead(200, {'Content-Type': 'text/plain'}) - resp.end('TESTING!') + s.on('/', function (req, res) { + res.writeHead(200, {'content-type': 'application/json'}) + res.end(JSON.stringify({method: req.method, headers: req.headers})) }) - s.on('/merge-headers', function (req, resp) { - assert.equal(req.headers.foo, 'bar') - assert.equal(req.headers.merged, 'yes') - resp.writeHead(200) - resp.end() + s.on('/head', function (req, res) { + res.writeHead(200, {'x-data': + JSON.stringify({method: req.method, headers: req.headers})}) + res.end() }) - s.on('/foo-no-test', function(req, resp) { - assert.equal(req.headers.foo, 'bar') - assert.equal('test' in req.headers, false) - assert.equal(req.method, 'GET') - resp.writeHead(200, {'Content-Type': 'text/plain'}) - resp.end('TESTING!') - }) - - s.on('/post', function (req, resp) { - assert.equal(req.headers.foo, 'bar') - assert.equal(req.headers['content-type'], null) - assert.equal(req.method, 'POST') - resp.writeHead(200, {'Content-Type': 'application/json'}) - resp.end(JSON.stringify({foo:'bar'})) - }) - - s.on('/patch', function (req, resp) { - assert.equal(req.headers.foo, 'bar') - assert.equal(req.headers['content-type'], null) - assert.equal(req.method, 'PATCH') - resp.writeHead(200, {'Content-Type': 'application/json'}) - resp.end(JSON.stringify({foo:'bar'})) - }) - - s.on('/post-body', function (req, resp) { - assert.equal(req.headers.foo, 'bar') - assert.equal(req.headers['content-type'], 'application/json') - assert.equal(req.method, 'POST') - resp.writeHead(200, {'Content-Type': 'application/json'}) - resp.end(JSON.stringify({foo:'bar'})) - }) - - s.on('/del', function (req, resp) { - assert.equal(req.headers.foo, 'bar') - assert.equal(req.method, 'DELETE') - resp.writeHead(200, {'Content-Type': 'application/json'}) - resp.end(JSON.stringify({foo:'bar'})) - }) - - s.on('/head', function (req, resp) { - assert.equal(req.headers.foo, 'bar') - assert.equal(req.method, 'HEAD') - resp.writeHead(200, {'Content-Type': 'text/plain'}) - resp.end() - }) - - s.on('/get_recursive1', function (req, resp) { - assert.equal(req.headers.foo, 'bar1') - assert.equal(req.method, 'GET') - resp.writeHead(200, {'Content-Type': 'text/plain'}) - resp.end('TESTING!') - }) - - s.on('/get_recursive2', function (req, resp) { - assert.equal(req.headers.foo, 'bar1') - assert.equal(req.headers.baz, 'bar2') - assert.equal(req.method, 'GET') - resp.writeHead(200, {'Content-Type': 'text/plain'}) - resp.end('TESTING!') - }) - - s.on('/get_recursive3', function (req, resp) { - assert.equal(req.headers.foo, 'bar3') - assert.equal(req.headers.baz, 'bar2') - assert.equal(req.method, 'GET') - resp.writeHead(200, {'Content-Type': 'text/plain'}) - resp.end('TESTING!') - }) - - s.on('/get_custom', function(req, resp) { - assert.equal(req.headers.foo, 'bar') - assert.equal(req.headers.x, 'y') - resp.writeHead(200, {'Content-Type': 'text/plain'}) - resp.end() - }) - - s.on('/set-undefined', function (req, resp) { - assert.equal(req.method, 'POST') - assert.equal(req.headers['content-type'], 'application/json') - assert.equal(req.headers['x-foo'], 'baz') + s.on('/set-undefined', function (req, res) { var data = '' req.on('data', function(d) { data += d }) req.on('end', function() { - resp.writeHead(200, {'Content-Type': 'application/json'}) - resp.end(data) + res.writeHead(200, {'Content-Type': 'application/json'}) + res.end(JSON.stringify({ + method: req.method, headers: req.headers, data: JSON.parse(data)})) }) }) - s.on('/function', function(req, resp) { - resp.writeHead(200, {'Content-Type': 'text/plain'}) - resp.end() - }) - t.end() }) }) @@ -125,9 +38,10 @@ tape('setup', function(t) { tape('get(string, function)', function(t) { request.defaults({ headers: { foo: 'bar' } - })(s.url + '/get', function (e, r, b) { - t.equal(e, null) - t.equal(b, 'TESTING!') + })(s.url + '/', function (e, r, b) { + b = JSON.parse(b) + t.equal(b.method, 'GET') + t.equal(b.headers.foo, 'bar') t.end() }) }) @@ -135,21 +49,22 @@ tape('get(string, function)', function(t) { tape('merge headers', function(t) { request.defaults({ headers: { foo: 'bar', merged: 'no' } - })(s.url + '/merge-headers', { - headers: { merged: 'yes' } + })(s.url + '/', { + headers: { merged: 'yes' }, json: true }, function (e, r, b) { - t.equal(e, null) - t.equal(r.statusCode, 200) + t.equal(b.headers.foo, 'bar') + t.equal(b.headers.merged, 'yes') t.end() }) }) tape('default undefined header', function(t) { request.defaults({ - headers: { foo: 'bar', test: undefined } - })(s.url + '/foo-no-test', function(e, r, b) { - t.equal(e, null) - t.equal(b, 'TESTING!') + headers: { foo: 'bar', test: undefined }, json: true + })(s.url + '/', function(e, r, b) { + t.equal(b.method, 'GET') + t.equal(b.headers.foo, 'bar') + t.equal(b.headers.test, undefined) t.end() }) }) @@ -157,9 +72,10 @@ tape('default undefined header', function(t) { tape('post(string, object, function)', function(t) { request.defaults({ headers: { foo: 'bar' } - }).post(s.url + '/post', { json: true }, function (e, r, b) { - t.equal(e, null) - t.equal(b.foo, 'bar') + }).post(s.url + '/', { json: true }, function (e, r, b) { + t.equal(b.method, 'POST') + t.equal(b.headers.foo, 'bar') + t.equal(b.headers['content-type'], undefined) t.end() }) }) @@ -167,9 +83,10 @@ tape('post(string, object, function)', function(t) { tape('patch(string, object, function)', function(t) { request.defaults({ headers: { foo: 'bar' } - }).patch(s.url + '/patch', { json: true }, function (e, r, b) { - t.equal(e, null) - t.equal(b.foo, 'bar') + }).patch(s.url + '/', { json: true }, function (e, r, b) { + t.equal(b.method, 'PATCH') + t.equal(b.headers.foo, 'bar') + t.equal(b.headers['content-type'], undefined) t.end() }) }) @@ -177,12 +94,13 @@ tape('patch(string, object, function)', function(t) { tape('post(string, object, function) with body', function(t) { request.defaults({ headers: { foo: 'bar' } - }).post(s.url + '/post-body', { + }).post(s.url + '/', { json: true, body: { bar: 'baz' } }, function (e, r, b) { - t.equal(e, null) - t.equal(b.foo, 'bar') + t.equal(b.method, 'POST') + t.equal(b.headers.foo, 'bar') + t.equal(b.headers['content-type'], 'application/json') t.end() }) }) @@ -191,9 +109,9 @@ tape('del(string, function)', function(t) { request.defaults({ headers: {foo: 'bar'}, json: true - }).del(s.url + '/del', function (e, r, b) { - t.equal(e, null) - t.equal(b.foo, 'bar') + }).del(s.url + '/', function (e, r, b) { + t.equal(b.method, 'DELETE') + t.equal(b.headers.foo, 'bar') t.end() }) }) @@ -202,13 +120,15 @@ tape('head(object, function)', function(t) { request.defaults({ headers: { foo: 'bar' } }).head({ uri: s.url + '/head' }, function (e, r, b) { - t.equal(e, null) + b = JSON.parse(r.headers['x-data']) + t.equal(b.method, 'HEAD') + t.equal(b.headers.foo, 'bar') t.end() }) }) tape('recursive defaults', function(t) { - t.plan(8) + t.plan(11) var defaultsOne = request.defaults({ headers: { foo: 'bar1' } }) , defaultsTwo = defaultsOne.defaults({ headers: { baz: 'bar2' } }) @@ -219,30 +139,33 @@ tape('recursive defaults', function(t) { defaultsTwo(options, callback) }) - defaultsOne(s.url + '/get_recursive1', function (e, r, b) { - t.equal(e, null) - t.equal(b, 'TESTING!') + defaultsOne(s.url + '/', {json: true}, function (e, r, b) { + t.equal(b.method, 'GET') + t.equal(b.headers.foo, 'bar1') }) - defaultsTwo(s.url + '/get_recursive2', function (e, r, b) { - t.equal(e, null) - t.equal(b, 'TESTING!') + defaultsTwo(s.url + '/', {json: true}, function (e, r, b) { + t.equal(b.method, 'GET') + t.equal(b.headers.foo, 'bar1') + t.equal(b.headers.baz, 'bar2') }) // requester function on recursive defaults - defaultsThree(s.url + '/get_recursive3', function (e, r, b) { - t.equal(e, null) - t.equal(b, 'TESTING!') + defaultsThree(s.url + '/', {json: true}, function (e, r, b) { + t.equal(b.method, 'GET') + t.equal(b.headers.foo, 'bar3') + t.equal(b.headers.baz, 'bar2') }) - defaultsTwo.get(s.url + '/get_recursive2', function (e, r, b) { - t.equal(e, null) - t.equal(b, 'TESTING!') + defaultsTwo.get(s.url + '/', {json: true}, function (e, r, b) { + t.equal(b.method, 'GET') + t.equal(b.headers.foo, 'bar1') + t.equal(b.headers.baz, 'bar2') }) }) tape('recursive defaults requester', function(t) { - t.plan(4) + t.plan(5) var defaultsOne = request.defaults({}, function(options, callback) { var headers = options.headers || {} @@ -259,19 +182,20 @@ tape('recursive defaults requester', function(t) { defaultsOne(options, callback) }) - defaultsOne.get(s.url + '/get_recursive1', function (e, r, b) { - t.equal(e, null) - t.equal(b, 'TESTING!') + defaultsOne.get(s.url + '/', {json: true}, function (e, r, b) { + t.equal(b.method, 'GET') + t.equal(b.headers.foo, 'bar1') }) - defaultsTwo.get(s.url + '/get_recursive2', function (e, r, b) { - t.equal(e, null) - t.equal(b, 'TESTING!') + defaultsTwo.get(s.url + '/', {json: true}, function (e, r, b) { + t.equal(b.method, 'GET') + t.equal(b.headers.foo, 'bar1') + t.equal(b.headers.baz, 'bar2') }) }) tape('test custom request handler function', function(t) { - t.plan(2) + t.plan(3) var requestWithCustomHandler = request.defaults({ headers: { foo: 'bar' }, @@ -283,18 +207,20 @@ tape('test custom request handler function', function(t) { }) t.throws(function() { - requestWithCustomHandler.head(s.url + '/get_custom', function(e, r, b) { + requestWithCustomHandler.head(s.url + '/', function(e, r, b) { throw new Error('We should never get here') }) }, /HTTP HEAD requests MUST NOT include a request body/) - requestWithCustomHandler.get(s.url + '/get_custom', function(e, r, b) { - t.equal(e, null) + requestWithCustomHandler.get(s.url + '/', function(e, r, b) { + b = JSON.parse(b) + t.equal(b.headers.foo, 'bar') + t.equal(b.headers.x, 'y') }) }) tape('test custom request handler function without options', function(t) { - t.plan(1) + t.plan(2) var customHandlerWithoutOptions = request.defaults(function(uri, options, callback) { var params = request.initParams(uri, options, callback) @@ -305,8 +231,10 @@ tape('test custom request handler function without options', function(t) { return request(params.uri, params, params.callback) }) - customHandlerWithoutOptions.get(s.url + '/get_custom', function(e, r, b) { - t.equal(e, null) + customHandlerWithoutOptions.get(s.url + '/', function(e, r, b) { + b = JSON.parse(b) + t.equal(b.headers.foo, 'bar') + t.equal(b.headers.x, 'y') }) }) @@ -320,8 +248,10 @@ tape('test only setting undefined properties', function(t) { json: {foo: 'bar'}, headers: {'x-foo': 'baz'} }, function (e, r, b) { - t.equal(e, null) - t.deepEqual(b, { foo: 'bar' }) + t.equal(b.method, 'POST') + t.equal(b.headers['content-type'], 'application/json') + t.equal(b.headers['x-foo'], 'baz') + t.deepEqual(b.data, { foo: 'bar' }) t.end() }) }) @@ -329,7 +259,7 @@ tape('test only setting undefined properties', function(t) { tape('test only function', function(t) { var post = request.post t.doesNotThrow(function () { - post(s.url + '/function', function (e, r, b) { + post(s.url + '/', function (e, r, b) { t.equal(r.statusCode, 200) t.end() }) @@ -338,24 +268,24 @@ tape('test only function', function(t) { tape('invoke defaults', function(t) { var d = request.defaults({ - uri: s.url + '/get', + uri: s.url + '/', headers: { foo: 'bar' } }) - d({}, function (e, r, b) { - t.equal(e, null) - t.equal(b, 'TESTING!') + d({json: true}, function (e, r, b) { + t.equal(b.method, 'GET') + t.equal(b.headers.foo, 'bar') t.end() }) }) tape('invoke convenience method from defaults', function(t) { var d = request.defaults({ - uri: s.url + '/get', + uri: s.url + '/', headers: { foo: 'bar' } }) - d.get({}, function (e, r, b) { - t.equal(e, null) - t.equal(b, 'TESTING!') + d.get({json: true}, function (e, r, b) { + t.equal(b.method, 'GET') + t.equal(b.headers.foo, 'bar') t.end() }) }) From 41742f75beac0808fd00df1fd118ab0f66f47741 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Gonz=C3=A1lez?= Date: Sun, 17 May 2015 12:50:58 +0200 Subject: [PATCH 104/490] Fixing documentation regarding TLS options (#1583) Fixing the documentation to recommend using `options.ca`, `options.cer`, `options.key` and `options.passphrase` instead of `options.agentOptions.` homologues, to avoid trouble in proxied environments, as commented in #1583 --- README.md | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fcda9ff4a..09fcf0e74 100644 --- a/README.md +++ b/README.md @@ -584,7 +584,30 @@ Note: The `SOCKET` path is assumed to be absolute to the root of the host file s ## TLS/SSL Protocol TLS/SSL Protocol options, such as `cert`, `key` and `passphrase`, can be -set in the `agentOptions` property of the `options` object. +set directly in `options` object, in the `agentOptions` property of the `options` object, or even in `https.globalAgent.options`. Keep in mind that, although `agentOptions` allows for a slightly wider range of configurations, the recommendend way is via `options` object directly, as using `agentOptions` or `https.globalAgent.options` would not be applied in the same way in proxied environments (as data travels through a TLS connection instead of an http/https agent). + +```js +var fs = require('fs') + , path = require('path') + , certFile = path.resolve(__dirname, 'ssl/client.crt') + , keyFile = path.resolve(__dirname, 'ssl/client.key') + , caFile = path.resolve(__dirname, 'ssl/ca.cert.pem') + , request = require('request'); + +var options = { + url: 'https://api.some-server.com/', + cert: fs.readFileSync(certFile), + key: fs.readFileSync(keyFile), + passphrase: 'password', + ca: fs.readFileSync(caFile) + } +}; + +request.get(options); +``` + +### Using `options.agentOptions` + In the example below, we call an API requires client side SSL certificate (in PEM format) with passphrase protected private key (in PEM format) and disable the SSLv3 protocol: From 3249d71d36ded7e84d271e688316469ed8ac092a Mon Sep 17 00:00:00 2001 From: simov Date: Wed, 20 May 2015 20:35:42 +0300 Subject: [PATCH 105/490] A few minor fixes: - Moved `removeRefererHeader` to the appropriate section of the options docs - Pass `options` to the redirect's module `onRequest` method, as it makes it more obvious from where these options are coming from (the extending of the request object in the ctor is a bit unexpected to say the least) - Attached the `debug` function to the request's prototype to make it accessible to the modules through the request instance --- README.md | 2 +- lib/auth.js | 2 +- lib/redirect.js | 28 +++++++++++++--------------- request.js | 3 ++- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 09fcf0e74..2dc526b2b 100644 --- a/README.md +++ b/README.md @@ -761,6 +761,7 @@ The first argument can be either a `url` or an `options` object. The only requir - `followRedirect` - follow HTTP 3xx responses as redirects (default: `true`). This property can also be implemented as function which gets `response` object as a single argument and should return `true` if redirects should continue or `false` otherwise. - `followAllRedirects` - follow non-GET HTTP 3xx responses as redirects (default: `false`) - `maxRedirects` - the maximum number of redirects to follow (default: `10`) +- `removeRefererHeader` - removes the referer header when a redirect happens (default: `false`). --- @@ -797,7 +798,6 @@ The first argument can be either a `url` or an `options` object. The only requir tunneling proxy. - `proxyHeaderExclusiveList` - A whitelist of headers to send exclusively to a tunneling proxy and not to destination. -- `removeRefererHeader` - removes the referer header when a redirect happens (default: `false`). --- diff --git a/lib/auth.js b/lib/auth.js index 6a42ba30e..1be1f4258 100644 --- a/lib/auth.js +++ b/lib/auth.js @@ -136,7 +136,7 @@ Auth.prototype.onResponse = function (response) { var authHeader = c.get('www-authenticate') var authVerb = authHeader && authHeader.split(' ')[0].toLowerCase() - // debug('reauth', authVerb) + request.debug('reauth', authVerb) switch (authVerb) { case 'basic': diff --git a/lib/redirect.js b/lib/redirect.js index ce83ffec8..1d4650299 100644 --- a/lib/redirect.js +++ b/lib/redirect.js @@ -15,27 +15,26 @@ function Redirect (request) { this.removeRefererHeader = false } -Redirect.prototype.onRequest = function () { +Redirect.prototype.onRequest = function (options) { var self = this - , request = self.request - if (request.maxRedirects !== undefined) { - self.maxRedirects = request.maxRedirects + if (options.maxRedirects !== undefined) { + self.maxRedirects = options.maxRedirects } - if (typeof request.followRedirect === 'function') { - self.allowRedirect = request.followRedirect + if (typeof options.followRedirect === 'function') { + self.allowRedirect = options.followRedirect } - if (request.followRedirect !== undefined) { - self.followRedirects = !!request.followRedirect + if (options.followRedirect !== undefined) { + self.followRedirects = !!options.followRedirect } - if (request.followAllRedirects !== undefined) { - self.followAllRedirects = request.followAllRedirects + if (options.followAllRedirects !== undefined) { + self.followAllRedirects = options.followAllRedirects } if (self.followRedirects || self.followAllRedirects) { self.redirects = self.redirects || [] } - if (request.removeRefererHeader !== undefined) { - self.removeRefererHeader = request.removeRefererHeader + if (options.removeRefererHeader !== undefined) { + self.removeRefererHeader = options.removeRefererHeader } } @@ -46,7 +45,7 @@ Redirect.prototype.redirectTo = function (response) { var redirectTo = null if (response.statusCode >= 300 && response.statusCode < 400 && response.caseless.has('location')) { var location = response.caseless.get('location') - // debug('redirect', location) + request.debug('redirect', location) if (self.followAllRedirects) { redirectTo = location @@ -82,8 +81,7 @@ Redirect.prototype.onResponse = function (response) { return false } - - // debug('redirect to', redirectTo) + request.debug('redirect to', redirectTo) // ignore any potential response body. it cannot possibly be useful // to us at this point. diff --git a/request.js b/request.js index e8da29a88..055c7bfec 100644 --- a/request.js +++ b/request.js @@ -281,6 +281,7 @@ function debug() { console.error('REQUEST %s', util.format.apply(util, arguments)) } } +Request.prototype.debug = debug Request.prototype.setupTunnel = function () { var self = this @@ -469,7 +470,7 @@ Request.prototype.init = function (options) { return self.emit('error', new Error(message)) } - self._redirect.onRequest() + self._redirect.onRequest(options) self.setHost = false if (!self.hasHeader('host')) { From 9c9918b1108d7dc84bcfa5a13fd111148431d36c Mon Sep 17 00:00:00 2001 From: Kremlin Date: Sun, 24 May 2015 01:01:33 +0100 Subject: [PATCH 106/490] fix the way http verbs are defined I changed the way they are defined so that they are more IDE-friendly. The way they were defined, an IDE wouldn't easily recognize them and would often show 'request.get' or 'request.post' etc as a possible error. Ctrl+clicking on the 'get' function wouldn't take you to where it was defined. Now it will! --- index.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 8bc39545c..6296fea27 100755 --- a/index.js +++ b/index.js @@ -56,16 +56,23 @@ function request (uri, options, callback) { return new request.Request(params) } -var verbs = ['get', 'head', 'post', 'put', 'patch', 'del'] - -verbs.forEach(function(verb) { - var method = verb === 'del' ? 'DELETE' : verb.toUpperCase() - request[verb] = function (uri, options, callback) { - var params = initParams(uri, options, callback) - params.method = method - return request(params, params.callback) +(function() { + var verbFunc = function(verb) { + var method = verb === 'del' ? 'DELETE' : verb.toUpperCase() + return function (uri, options, callback) { + var params = initParams(uri, options, callback) + params.method = method + return request(params, params.callback) + } } -}) + + request.get = verbFunc('get') + request.head = verbFunc('head') + request.post = verbFunc('post') + request.put = verbFunc('put') + request.patch = verbFunc('patch') + request.del = verbFunc('del') +})() request.jar = function (store) { return cookies.jar(store) From a15463cfbfb7c78bc7a6b74348a8eceb1b61d346 Mon Sep 17 00:00:00 2001 From: simov Date: Mon, 25 May 2015 15:45:45 +0300 Subject: [PATCH 107/490] Move getProxyFromURI logic below the check for Invaild URI (#1595) --- request.js | 18 +++++++++--------- tests/test-errors.js | 11 +++++++++++ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/request.js b/request.js index 055c7bfec..2d1cf7ac2 100644 --- a/request.js +++ b/request.js @@ -444,15 +444,6 @@ Request.prototype.init = function (options) { self.rejectUnauthorized = false } - if (!self.hasOwnProperty('proxy')) { - self.proxy = getProxyFromURI(self.uri) - } - - self.tunnel = getTunnelOption(self, options) - if (self.proxy) { - self.setupTunnel() - } - if (!self.uri.pathname) {self.uri.pathname = '/'} if (!(self.uri.host || (self.uri.hostname && self.uri.port)) && !self.uri.isUnix) { @@ -470,6 +461,15 @@ Request.prototype.init = function (options) { return self.emit('error', new Error(message)) } + if (!self.hasOwnProperty('proxy')) { + self.proxy = getProxyFromURI(self.uri) + } + + self.tunnel = getTunnelOption(self, options) + if (self.proxy) { + self.setupTunnel() + } + self._redirect.onRequest(options) self.setHost = false diff --git a/tests/test-errors.js b/tests/test-errors.js index 56f46bd6e..bfd7c4962 100644 --- a/tests/test-errors.js +++ b/tests/test-errors.js @@ -30,6 +30,17 @@ tape('invalid uri 2', function(t) { t.end() }) +tape('invalid uri + NO_PROXY', function(t) { + process.env.NO_PROXY = 'google.com' + t.throws(function() { + request({ + uri: 'invalid' + }) + }, /^Error: Invalid URI/) + delete process.env.NO_PROXY + t.end() +}) + tape('deprecated unix URL', function(t) { t.throws(function() { request({ From 20e9b578de0fe92195606d1be6307048bf157af0 Mon Sep 17 00:00:00 2001 From: simov Date: Mon, 25 May 2015 18:22:36 +0300 Subject: [PATCH 108/490] Add comment about pleasing intellisense IDEs --- index.js | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/index.js b/index.js index 6296fea27..5872824c8 100755 --- a/index.js +++ b/index.js @@ -56,23 +56,22 @@ function request (uri, options, callback) { return new request.Request(params) } -(function() { - var verbFunc = function(verb) { - var method = verb === 'del' ? 'DELETE' : verb.toUpperCase() - return function (uri, options, callback) { - var params = initParams(uri, options, callback) - params.method = method - return request(params, params.callback) - } +function verbFunc (verb) { + var method = verb === 'del' ? 'DELETE' : verb.toUpperCase() + return function (uri, options, callback) { + var params = initParams(uri, options, callback) + params.method = method + return request(params, params.callback) } +} - request.get = verbFunc('get') - request.head = verbFunc('head') - request.post = verbFunc('post') - request.put = verbFunc('put') - request.patch = verbFunc('patch') - request.del = verbFunc('del') -})() +// define like this to please codeintel/intellisense IDEs +request.get = verbFunc('get') +request.head = verbFunc('head') +request.post = verbFunc('post') +request.put = verbFunc('put') +request.patch = verbFunc('patch') +request.del = verbFunc('del') request.jar = function (store) { return cookies.jar(store) From 9513deb13103986c4f456935e73022c3fb334607 Mon Sep 17 00:00:00 2001 From: simov Date: Mon, 25 May 2015 21:41:45 +0300 Subject: [PATCH 109/490] Extract the querystring logic into separate module: - Update `qs` to version 3.0.0 with support for rfc3986 encoding - Use request's rfc3986 only when using the `querystring` module - Add test branch for rfc3986 encoding tests using `querystring` - Support for `eq`, `sep` and `options` arguments for `querystring` `parse` and `stringify` methods via option keys --- lib/querystring.js | 51 +++++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- request.js | 42 ++++++++++------------------------- tests/test-rfc3986.js | 11 +++++++--- 4 files changed, 72 insertions(+), 34 deletions(-) create mode 100644 lib/querystring.js diff --git a/lib/querystring.js b/lib/querystring.js new file mode 100644 index 000000000..baf5e8021 --- /dev/null +++ b/lib/querystring.js @@ -0,0 +1,51 @@ +'use strict' + +var qs = require('qs') + , querystring = require('querystring') + + +function Querystring (request) { + this.request = request + this.lib = null + this.useQuerystring = null + this.parseOptions = null + this.stringifyOptions = null +} + +Querystring.prototype.init = function (options) { + if (this.lib) {return} + + this.useQuerystring = options.useQuerystring + this.lib = (this.useQuerystring ? querystring : qs) + + this.parseOptions = options.qsParseOptions || {} + this.stringifyOptions = options.qsStringifyOptions || {} +} + +Querystring.prototype.stringify = function (obj) { + return (this.useQuerystring) + ? this.rfc3986(this.lib.stringify(obj, + this.stringifyOptions.sep || null, + this.stringifyOptions.eq || null, + this.stringifyOptions)) + : this.lib.stringify(obj, this.stringifyOptions) +} + +Querystring.prototype.parse = function (str) { + return (this.useQuerystring) + ? this.lib.parse(str, + this.parseOptions.sep || null, + this.parseOptions.eq || null, + this.parseOptions) + : this.lib.parse(str, this.parseOptions) +} + +Querystring.prototype.rfc3986 = function (str) { + return str.replace(/[!'()*]/g, function (c) { + return '%' + c.charCodeAt(0).toString(16).toUpperCase() + }) +} + +Querystring.prototype.unescape = querystring.unescape + +exports.Querystring = Querystring diff --git a/package.json b/package.json index a0dbaba23..6aa028422 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "json-stringify-safe": "~5.0.0", "mime-types": "~2.0.1", "node-uuid": "~1.4.0", - "qs": "~2.4.0", + "qs": "~3.0.0", "tunnel-agent": "~0.4.0", "tough-cookie": ">=0.12.0", "http-signature": "~0.10.0", diff --git a/request.js b/request.js index 055c7bfec..359f7df6e 100644 --- a/request.js +++ b/request.js @@ -5,8 +5,6 @@ var http = require('http') , url = require('url') , util = require('util') , stream = require('stream') - , qs = require('qs') - , querystring = require('querystring') , zlib = require('zlib') , helpers = require('./lib/helpers') , bl = require('bl') @@ -22,6 +20,7 @@ var http = require('http') , cookies = require('./lib/cookies') , copy = require('./lib/copy') , getProxyFromURI = require('./lib/getProxyFromURI') + , Querystring = require('./lib/querystring').Querystring , Har = require('./lib/har').Har , Auth = require('./lib/auth').Auth , OAuth = require('./lib/oauth').OAuth @@ -229,13 +228,6 @@ function responseToJSON() { } } -// encode rfc3986 characters -function rfc3986 (str) { - return str.replace(/[!'()*]/g, function(c) { - return '%' + c.charCodeAt(0).toString(16).toUpperCase() - }) -} - function Request (options) { // if given the method property in options, set property explicitMethod to true @@ -265,6 +257,7 @@ function Request (options) { if (options.method) { self.explicitMethod = true } + self._qs = new Querystring(self) self._auth = new Auth(self) self._oauth = new OAuth(self) self._multipart = new Multipart(self) @@ -341,15 +334,7 @@ Request.prototype.init = function (options) { self.localAddress = options.localAddress } - if (!self.qsLib) { - self.qsLib = (options.useQuerystring ? querystring : qs) - } - if (!self.qsParseOptions) { - self.qsParseOptions = options.qsParseOptions - } - if (!self.qsStringifyOptions) { - self.qsStringifyOptions = options.qsStringifyOptions - } + self._qs.init(options) debug(options) if (!self.pool && self.pool !== false) { @@ -576,14 +561,12 @@ Request.prototype.init = function (options) { } if (self.uri.auth && !self.hasHeader('authorization')) { - var uriAuthPieces = self.uri.auth.split(':').map(function(item) { return querystring.unescape(item) }) + var uriAuthPieces = self.uri.auth.split(':').map(function(item) {return self._qs.unescape(item)}) self.auth(uriAuthPieces[0], uriAuthPieces.slice(1).join(':'), true) } if (!self.tunnel && self.proxy && self.proxy.auth && !self.hasHeader('proxy-authorization')) { - var proxyAuthPieces = self.proxy.auth.split(':').map(function(item) { - return querystring.unescape(item) - }) + var proxyAuthPieces = self.proxy.auth.split(':').map(function(item) {return self._qs.unescape(item)}) var authHeader = 'Basic ' + toBase64(proxyAuthPieces.join(':')) self.setHeader('proxy-authorization', authHeader) } @@ -1295,7 +1278,7 @@ Request.prototype.qs = function (q, clobber) { var self = this var base if (!clobber && self.uri.query) { - base = self.qsLib.parse(self.uri.query, self.qsParseOptions) + base = self._qs.parse(self.uri.query) } else { base = {} } @@ -1304,13 +1287,13 @@ Request.prototype.qs = function (q, clobber) { base[i] = q[i] } - if (self.qsLib.stringify(base, self.qsStringifyOptions) === '') { + if (self._qs.stringify(base) === '') { return self } - var qs = self.qsLib.stringify(base, self.qsStringifyOptions) + var qs = self._qs.stringify(base) - self.uri = url.parse(self.uri.href.split('?')[0] + '?' + rfc3986(qs)) + self.uri = url.parse(self.uri.href.split('?')[0] + '?' + qs) self.url = self.uri self.path = self.uri.path @@ -1321,9 +1304,8 @@ Request.prototype.form = function (form) { if (form) { self.setHeader('content-type', 'application/x-www-form-urlencoded') self.body = (typeof form === 'string') - ? form.toString('utf8') - : self.qsLib.stringify(form, self.qsStringifyOptions).toString('utf8') - self.body = rfc3986(self.body) + ? self._qs.rfc3986(form.toString('utf8')) + : self._qs.stringify(form).toString('utf8') return self } // create form-data object @@ -1359,7 +1341,7 @@ Request.prototype.json = function (val) { if (!/^application\/x-www-form-urlencoded\b/.test(self.getHeader('content-type'))) { self.body = safeStringify(self.body) } else { - self.body = rfc3986(self.body) + self.body = self._qs.rfc3986(self.body) } if (!self.hasHeader('content-type')) { self.setHeader('content-type', 'application/json') diff --git a/tests/test-rfc3986.js b/tests/test-rfc3986.js index cfd27f11b..50868ab47 100644 --- a/tests/test-rfc3986.js +++ b/tests/test-rfc3986.js @@ -97,8 +97,13 @@ var cases = [ } ] -cases.forEach(function (options) { - tape('rfc3986 ' + options._name, function(t) { - runTest(t, options) +var libs = ['qs', 'querystring'] + +libs.forEach(function (lib) { + cases.forEach(function (options) { + options.useQuerystring = (lib === 'querystring') + tape(lib + ' rfc3986 ' + options._name, function(t) { + runTest(t, options) + }) }) }) From 2830cdb50a1a055d8e896e7df56010ba567a3d72 Mon Sep 17 00:00:00 2001 From: simov Date: Tue, 26 May 2015 18:56:42 +0300 Subject: [PATCH 110/490] Migrate to codecov --- .travis.yml | 6 ++++-- README.md | 2 +- package.json | 6 ++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index bd0f638eb..046a7431a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,10 +3,12 @@ node_js: - "io.js" - "0.12" - "0.10" -after_script: ./node_modules/.bin/istanbul cover ./node_modules/tape/bin/tape tests/test-*.js --report lcovonly && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js --verbose +sudo: false + +after_script: "npm run test-cov && cat ./coverage/lcov.info | ./node_modules/codecov.io/bin/codecov.io.js" + webhooks: urls: https://webhooks.gitter.im/e/237280ed4796c19cc626 on_success: change # options: [always|never|change] default: always on_failure: always # options: [always|never|change] default: always on_start: false # default: false -sudo: false diff --git a/README.md b/README.md index 2dc526b2b..5e6def2a4 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![npm package](https://nodei.co/npm/request.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/request/) [![Build status](https://img.shields.io/travis/request/request.svg?style=flat-square)](https://travis-ci.org/request/request) -[![Coverage](https://img.shields.io/coveralls/request/request.svg?style=flat-square)](https://coveralls.io/r/request/request) +[![Coverage](https://img.shields.io/codecov/c/github/request/request.svg?style=flat-square)](https://codecov.io/github/request/request) [![Dependency Status](https://img.shields.io/david/request/request.svg?style=flat-square)](https://david-dm.org/request/request) [![Gitter](https://img.shields.io/badge/gitter-join_chat-blue.svg?style=flat-square)](https://gitter.im/request/request?utm_source=badge) diff --git a/package.json b/package.json index a0dbaba23..9a4cdf441 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,9 @@ "har-validator": "^1.6.1" }, "scripts": { - "test": "npm run lint && node node_modules/.bin/taper tests/test-*.js && npm run test-browser", + "test": "npm run lint && npm run test-ci && npm run test-browser", + "test-ci": "node node_modules/.bin/taper tests/test-*.js", + "test-cov": "node node_modules/.bin/istanbul cover ./node_modules/tape/bin/tape tests/test-*.js", "test-browser": "node tests/browser/start.js", "lint": "node node_modules/.bin/eslint lib/ *.js tests/ && echo Lint passed." }, @@ -50,7 +52,7 @@ "browserify": "~5.9.1", "browserify-istanbul": "~0.1.3", "buffer-equal": "0.0.1", - "coveralls": "~2.11.2", + "codecov.io": "~0.1.2", "eslint": "0.18.0", "function-bind": "~1.0.0", "istanbul": "~0.3.2", From e2f3ef8d0eb15561df3bf370d89b39e679411f4f Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 28 May 2015 11:42:30 +0300 Subject: [PATCH 111/490] Re-generate certificates --- tests/ssl/ca/client-enc.key | 52 ++++++++++++++++++------------------- tests/ssl/ca/client.crt | 22 ++++++++-------- tests/ssl/ca/client.csr | 26 +++++++++---------- tests/ssl/ca/client.key | 50 +++++++++++++++++------------------ tests/ssl/ca/localhost.crt | 22 ++++++++-------- tests/ssl/ca/localhost.csr | 26 +++++++++---------- tests/ssl/ca/localhost.key | 50 +++++++++++++++++------------------ 7 files changed, 124 insertions(+), 124 deletions(-) diff --git a/tests/ssl/ca/client-enc.key b/tests/ssl/ca/client-enc.key index 57128e13c..2e8d7f40d 100644 --- a/tests/ssl/ca/client-enc.key +++ b/tests/ssl/ca/client-enc.key @@ -1,30 +1,30 @@ -----BEGIN RSA PRIVATE KEY----- Proc-Type: 4,ENCRYPTED -DEK-Info: AES-128-CBC,2406B8B3D193CFC0B923B4542CABD70E +DEK-Info: AES-128-CBC,6C31267B8D3AF32D4F73B2E751233B50 -GYTztL5oLQknjscUuGR392S/uWD3TDeNr8Rwaobvr0EH3SNm4TSQaQWzfFGVpp5a -Lh9xvakNiNcnvqjRbe/Mz7pJ0GcYqqlnCIkJHuy4YlFDS0DhvsaHv3UM+3t+e3xm -+CmHSSqbGS5CDw+phmudF76QvfsL54LyDabpQ+PIZvV6BpIzSY+lFDf7hxR7mJ6X -or+gVprT9Bn0G661eEAFYTM9KWl1HE+SKQLOOGHuLTaE9shPzVmMfDCZ5DdM4BKe -VpKTXJdyiG470X74IzVfBApzvraDFCtXYxr+YcP+0Onn100XDN6hKz9IUa9Ib2uk -n8pxITP5s/Kd7DvUI8GOpkrigFvTVxk2EXZz7w+ZR1F4Q/jDxMU2PFcRf86ALWRW -d0io+rXtCkl6rd32WjlfU68CKC/y7w5tJ5YQZr2ZN+oRn0vw83K3NnPYGI3WYSIF -iT0r0gHnxnBNielIqXZvkeacZH3y5iSQBqMjxMeW4lXM+t0APVdooKx4a8Q78/a6 -9n7w5678EZDxZ3u2He+yP5hqaq1QCrjZoH5HcboDXq3Keh0z9YXIB6MLXsGWHXYx -vX8lLHdePih6RHtgxrF8osZVi331KuqUpAbiapKGQNxWwd+1ls0y64aNeWRUfUd1 -ZwGMNusaPU1KLrpvQ+wa6mLZk7v/0xpSgMfuy6GU9OIqQcoSjpCw0hHcXOU0tKR0 -+uRlzhsKhEhGyVHTD89+AbgjSA9OGY9oKBbSWBUcQuhNE87SY7wRrjvHCRvzK8UR -GEY7HqLjG1U6qfNk7+5VbFUa/hTUT6tG85O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CnmyqLky2HZlK4M140QKUnxFyZcX +KuBp64AVFwoFV6050ihZ17CS77cky/1Nn5Nv7lkcAKR9sDhwrizbOLTQFJwjIvgP +r9LwN6WTSIE7ZgpHu2HwqzhJIsxiS1ge7+sniLoaX92R8/hGxhxaPRt3S/Aq83qx +RXz7rmoWT0BdrrbSGv2DvuFByfyuMEw+V7oQ06O3wcNJk+xxX9Uq9qogwLkaSTId +mXUSshWhx+Jnejx6LEKcb1jwOvQRfoqN2NA0bCPAseazJnAjmG5Y9afhuPKK/K0q -----END RSA PRIVATE KEY----- diff --git a/tests/ssl/ca/client.crt b/tests/ssl/ca/client.crt index ace9a2122..fe8610067 100644 --- a/tests/ssl/ca/client.crt +++ b/tests/ssl/ca/client.crt @@ -3,18 +3,18 @@ MIIDLjCCApcCCQCt9iAWqkDJwzANBgkqhkiG9w0BAQsFADCBojELMAkGA1UEBhMC VVMxCzAJBgNVBAgTAkNBMRAwDgYDVQQHEwdPYWtsYW5kMRAwDgYDVQQKEwdyZXF1 ZXN0MSYwJAYDVQQLEx1yZXF1ZXN0IENlcnRpZmljYXRlIEF1dGhvcml0eTESMBAG A1UEAxMJcmVxdWVzdENBMSYwJAYJKoZIhvcNAQkBFhdtaWtlYWxAbWlrZWFscm9n -ZXJzLmNvbTAeFw0xNTA0MjgwODI2MTZaFw0xNTA1MjgwODI2MTZaMIGPMQswCQYD +ZXJzLmNvbTAeFw0xNTA1MjgwODQwNTVaFw0xNTA2MjcwODQwNTVaMIGPMQswCQYD VQQGEwJVUzELMAkGA1UECBMCQ0ExEDAOBgNVBAcTB09ha2xhbmQxEDAOBgNVBAoT B3JlcXVlc3QxGjAYBgNVBAsUEXJlcXVlc3RAbG9jYWxob3N0MRMwEQYDVQQDEwpU ZXN0Q2xpZW50MR4wHAYJKoZIhvcNAQkBFg9kby5ub3RAZW1haWwubWUwggEiMA0G -CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDDF0eoVmwhZgUs6JOXzRAifBj3ZHCY -X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qMLnEiGA//dU0MOZXVWxhy6eTL8E +34s= -----END CERTIFICATE----- diff --git a/tests/ssl/ca/client.csr b/tests/ssl/ca/client.csr index cfa96c175..ed1df4870 100644 --- a/tests/ssl/ca/client.csr +++ b/tests/ssl/ca/client.csr @@ -2,17 +2,17 @@ MIIC+DCCAeACAQAwgY8xCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJDQTEQMA4GA1UE BxMHT2FrbGFuZDEQMA4GA1UEChMHcmVxdWVzdDEaMBgGA1UECxQRcmVxdWVzdEBs b2NhbGhvc3QxEzARBgNVBAMTClRlc3RDbGllbnQxHjAcBgkqhkiG9w0BCQEWD2Rv -Lm5vdEBlbWFpbC5tZTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMMX -R6hWbCFmBSzok5fNECJ8GPdkcJhfENkirgopTSXv3sFV8rTOaxZ6YHrbZGbQkxJV -Cr+7tazIxCELbpbDt5As0gw9Qm81BWGywRzs/5sLSM5lJmyfie/qVhKRGNULdAOF -BdXXjVzcNrR5tShhKGPFpxqTsXC7LG22OCUfYDyQT6Xiz6HQbybXpdsTVHt8lNvA -wGL0WMnlHmr/X0CV9Q5HcA+mcA1TpK9L8ai8T2gxwiGBM2lgixqrhFYBJymguMuw -p7RaDgJwKl2PBj41zHB4rw/7WfghhW3/i+pO8ErzI1Z1iX2VzWUHa4Tyg0RU7JzH -Vk2YGUqu1puOOXr1FvUCAwEAAaAjMCEGCSqGSIb3DQEJBzEUExJwYXNzd29yZCBj -aGFsbGVuZ2UwDQYJKoZIhvcNAQELBQADggEBAGRSMsy7AECtc+R7OABdzjupzJfa -oPLMqCZYPbFaPIG0EKFlv+BEAXi0Fho5yWdA3gy58ssAkXtBLYJB1H3g/UPF+dZx -TR8cytJ4b+X5mP60vxo718+H9dPikH3kmWyr0zFV4mIlmigFcPvUsi1a67sT5AOT -xhOarg69ZuLtS43IMeCXcJ5mJnBLdAwWEQEpBrdhktwroIygD9n0ClXjhmc8p4cj -V9i/WF2AshrZtTgzk/VzKbXXhDOsNjqYQKobZEgeC+o7nhJvz/G3QGtiLAkcpMLw -X6BZEQ4Z9yzsCEbWdT4kE75SvhuM45Q8Rovx0GShAKO/CQIy91nfLFKFZ1g= +Lm5vdEBlbWFpbC5tZTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMdy +4OyQ4gf7UmtjP2oB/q+lj8O0Y3a2X8/0ZFJBusuEb59d33IT67Wr4zrkak0trpKT +YKdrOWeQQ1wMWVgCgHwZQUgBIbOXruKHH7gPOrK24S0yY8l3PAqYn6AduiXyFBWq +41vHTg71XAA4X+L7vBR/ywaeBuRLeCBVPLW64EA+TPQmSiL5zFh9jkT2HEZW5cl2 +yw/QgXRodh0ZsfWd19aTlB8x1hzNlec6m6s1WctldCu/xNjnmMnSVyPIUsO5Vi9E +E7g7cy52H41XZd8vEdAcbtOf8J+OaX1bKClhIB5iCPj5mxJVIdPQYYlLWSmVMlqo +EVSai7pZODMmGeFxgOcCAwEAAaAjMCEGCSqGSIb3DQEJBzEUExJwYXNzd29yZCBj +aGFsbGVuZ2UwDQYJKoZIhvcNAQELBQADggEBACch/zWTz2YwWKZ3yz9JhGf4prrt +k2OAnpILVCXqe38peZlKYXYoP1H2ulKuyI3y6CZb2nvY/hXUfvDkJI+Xt916f3YM +N0EVKpzIoi5vjooLbyDIHFDtaRDmQJoV7u95bHNu3PL2lZNVXHHpgLwyKXLtL1an +yeo/UjbbWvzONBLmd7qn5BfKXu57An2fQCs+YN8kaMvgHqZfzbo2WjGbf9UK/wHT +YmQOPSHG1DboAFdabk0tCN6ZL2SH9uU9oyGwVeudeTfpfzY/oycQT0YQ0Tuii1f7 +5mUtw+5awV10lb15KaVChxhxYBkF9n4TtNyW5ID7+hY5IXiqyFjqjWpXU/w= -----END CERTIFICATE REQUEST----- diff --git a/tests/ssl/ca/client.key b/tests/ssl/ca/client.key index 7add2bf45..d20b79329 100644 --- a/tests/ssl/ca/client.key +++ b/tests/ssl/ca/client.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O5FKr65ObRC0QpLir9lzLcLbF+y1AvSeatxm+ICaJj7oPXZrvX -----END RSA PRIVATE KEY----- diff --git a/tests/ssl/ca/localhost.crt b/tests/ssl/ca/localhost.crt index 409716e4b..920845529 100644 --- a/tests/ssl/ca/localhost.crt +++ b/tests/ssl/ca/localhost.crt @@ -3,18 +3,18 @@ MIIDLTCCApYCCQCt9iAWqkDJwzANBgkqhkiG9w0BAQsFADCBojELMAkGA1UEBhMC VVMxCzAJBgNVBAgTAkNBMRAwDgYDVQQHEwdPYWtsYW5kMRAwDgYDVQQKEwdyZXF1 ZXN0MSYwJAYDVQQLEx1yZXF1ZXN0IENlcnRpZmljYXRlIEF1dGhvcml0eTESMBAG A1UEAxMJcmVxdWVzdENBMSYwJAYJKoZIhvcNAQkBFhdtaWtlYWxAbWlrZWFscm9n -ZXJzLmNvbTAeFw0xNTA0MjgwODI3NTNaFw0xNTA1MjgwODI3NTNaMIGOMQswCQYD +ZXJzLmNvbTAeFw0xNTA1MjgwODQxNDNaFw0xNTA2MjcwODQxNDNaMIGOMQswCQYD VQQGEwJVUzELMAkGA1UECBMCQ0ExEDAOBgNVBAcTB09ha2xhbmQxEDAOBgNVBAoT B3JlcXVlc3QxGjAYBgNVBAsUEXJlcXVlc3RAbG9jYWxob3N0MRIwEAYDVQQDEwls b2NhbGhvc3QxHjAcBgkqhkiG9w0BCQEWD2RvLm5vdEBlbWFpbC5tZTCCASIwDQYJ -KoZIhvcNAQEBBQADggEPADCCAQoCggEBALa0VP6fC/PBUqwUgJeKR3/Uq+CyBDbP -3A19m1+jgO1MpswXZitXCnkn7zOSczc7NTyErY0zhUwtyIvaNQtAmpDtPTjGNbFJ -hYGvIHlIlG+qedXcYbeBUVrpzTwae7X43xNCcejqPX9J0mSQFhTFp+SSkNbyqnPt -eWEeB81FnwT/t8yAcxMCocwGtjcn0DBm8MsWD0hB9lfVl2Sv20nSD7NP/oosVEbI -zWV31IrIjd01UCNgbuqvcHWO4IUy0HqLgsWcfaNSNdmjf8kL9lZ0UvjU5R/sRVX/ -yeGRHcYj5FjhXWuX0+PIJIMa28O/AhDgPwF/IA//vYthC7ChZgZQd2sCAwEAATAN -BgkqhkiG9w0BAQsFAAOBgQC27LqfOUoStYB3AmrEY8kMComIuVR/Inl42cIQSH8J -oCHzHGvuEnutZXsZyNxMRxyWOEjniYPgJnu6lq0X6vJUoTcR13olMZ/tgRL4ezNJ -cPE896oTy81YId4b/OFtj00iB3eKHwfYoSnJAuwOZS/r4tYkggXJzthZqv10I6es -zQ== +KoZIhvcNAQEBBQADggEPADCCAQoCggEBANhbOLcJncdyjcKno/YMiPS4jnibv3Yc +caYCgHGeu8K/hJikfI5ExLGb8DV/vjgBKZOtQ2ZqsO2uwqysxBthumq6Dy+iddc/ +b3FxEN+lNnJr7riIg8k9ET5v5tmzg8zWeQgO4rzPjjrfVV4Etm95u3/4b8AD5EmG +iiMSdciNLtOja+csOUz9+kza+/RC9dz/TKTNBLS9bTiA1tH9gdrbDfqdzSxAKObE +JOvNUBM5ll0g26Mg7uoJa4HuMRI8f9ifsEhgEUJKjKNTDTdOEQAj8foeVPkofq2d +ZbLv9DbkjFR8pC0Ax6DaYJEHCI5ixDPPMpTQgAxeHlYO4zSfhSavskcCAwEAATAN +BgkqhkiG9w0BAQsFAAOBgQCgK2mq6rX4C1mdD6kQ/AucqpXivlO2mMqOsp8udWcN +ymFZbjvTYgpUA8fxmiM2xfkdwrSS9ei2u6WVSR0jQdsm6vRnvFx8A+lrbQzvKLSL +pj/5I4e2D9sZruLWw3LCPURSirNObvkE1dKuOauLRlLKSYCeOp33Hfkc+375zQU0 +Pg== -----END CERTIFICATE----- diff --git a/tests/ssl/ca/localhost.csr b/tests/ssl/ca/localhost.csr index 250b52217..c3a954346 100644 --- a/tests/ssl/ca/localhost.csr +++ b/tests/ssl/ca/localhost.csr @@ -2,17 +2,17 @@ MIIC9zCCAd8CAQAwgY4xCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJDQTEQMA4GA1UE BxM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cZ67wr+EmKR8jkTEsZvwNX++OAEpk61D +Zmqw7a7CrKzEG2G6aroPL6J11z9vcXEQ36U2cmvuuIiDyT0RPm/m2bODzNZ5CA7i +vM+OOt9VXgS2b3m7f/hvwAPkSYaKIxJ1yI0u06Nr5yw5TP36TNr79EL13P9MpM0E +tL1tOIDW0f2B2tsN+p3NLEAo5sQk681QEzmWXSDboyDu6glrge4xEjx/2J+wSGAR +QkqMo1MNN04RACPx+h5U+Sh+rZ1lsu/0NuSMVHykLQDHoNpgkQcIjmLEM88ylNCA +DF4eVg7jNJ+FJq+yRwIDAQABoCMwIQYJKoZIhvcNAQkHMRQTEnBhc3N3b3JkIGNo +YWxsZW5nZTANBgkqhkiG9w0BAQsFAAOCAQEAWukhhV30mrfgCK5XfaE49LhWHX/c +sObvBRkPMdtSxRryhKPHNRS51l2JceTZPwvCsICbfX83j+AFsIu/cwJJmG0/s2WF +WREONcRWrOP5SxexyV3/Urce3b3+9fP1+njxOlj/Dr+UJVOe3D1dGo8SZMPfZvFr +eqp/sypvVnY6n6n7dflrY7aQ79vGlQex6KXHU2ACAFUS+4GfIPwOcfDviDriYQ5J +j22vu6DKP5cdU2xgqFk0EgnSF5qS4kC7GB5bcLYLKA/EviCRkjP5bY0MvRJ7TJ6N +hHewplOMrl1BzNNLRtJ4NIG15Q/QMCtbHtFeVuVDXM29czy1af/FwEwupA== -----END CERTIFICATE REQUEST----- diff --git a/tests/ssl/ca/localhost.key b/tests/ssl/ca/localhost.key index 3b073256c..f4fa70fd4 100644 --- a/tests/ssl/ca/localhost.key +++ b/tests/ssl/ca/localhost.key @@ -1,27 +1,27 @@ -----BEGIN RSA PRIVATE KEY----- -MIIEowIBAAKCAQEAtrRU/p8L88FSrBSAl4pHf9Sr4LIENs/cDX2bX6OA7UymzBdm -K1cKeSfvM5JzNzs1PIStjTOFTC3Ii9o1C0CakO09OMY1sUmFga8geUiUb6p51dxh -t4FRWunNPBp7tfjfE0Jx6Oo9f0nSZJAWFMWn5JKQ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aWRSVSXFOk+ +xXJXqSECgYEA/OG6lmzDcGRtT94DY89tRJds/AhppY1ou6pROb7ChOunVX3m2Bhd +OzJEwNNhRH4wl7ulk51CnH1nIl8bG3/bElSRxICPAlIQ9gZdcqcg6sVxD9Qb+p/r +6ajkg6mSiVi5HEFb3Bv9J32/SGE+mmecdYQ/ZAa+n01svL50U1YTgRkCgYEA2wYx +aArDAJEt27f/t2HoINPjJaEkBDn10Z4peQo27kSncXA3yCDcc669J7Q4xWUhlM72 +OFWFx686elwpxccTdF3yDxfqgphj1G8X0F1Xx7zFDw4WyhYL4JaIDR9GCqjpH0UQ +WrtZA1Kn9aTqyyNsvkB7LxT0jpcHCIcG7hyQWl8CgYEAmzlj8xnoDYFXqAK7SfT1 +OXlJqJrxXnGirC8rlKqHdFfCazPREyxBbii5EzOtLQHYigrg4+9QCAbh27NNTF/6 +9RF8OIZBQkdlqd7WVZ5JElMHx5OHaRvpD5BgVIEuNaiEV9e2rzFu/2Ksm501dEnN +PEVlM9z//YDlEiZF+TGI32ECgYAka8k3deKra3jmupgpVHyXSOTS0xL8KO85pkVb +PVmZEY2OjYyZGO3PxtTpj0yJdqG47xl+kKooZHki88R2gP45MY4Y+G8kvFaNctPQ +8FSygC98q2kavcPH2wBQvkyVZTUu3/syO0k4Bjyr2nq4wPFKScqyL5fjRjYDMwDy +A4n1nQKBgDdy7Z0iwxkOgrzvuw5S/hRARvMKVSKabmMechor5RXOWhe7aL9q7hR4 +c/vSglv/Ino0cOe7oRr8tmsv/77tYfLWhLXqMFHtIGx9eUPn7qJ7GzKLG46f6qNO +iSzZhqbTt6s7LXbDfPS/AoQNqP41L4o+ZakL0IWKEqp+HoElFrcn -----END RSA PRIVATE KEY----- From 5cdcbe5a8fcb973db7731c448ed1ff5788f4017b Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 28 May 2015 20:33:47 +0300 Subject: [PATCH 112/490] Add docs and tests for passing options to the querystring's parse and stringify methods --- README.md | 7 +++---- tests/test-qs.js | 42 +++++++++++++++++++++++++++--------------- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 2dc526b2b..d8bd40570 100644 --- a/README.md +++ b/README.md @@ -199,8 +199,7 @@ For advanced cases, you can access the form-data object itself via `r.form()`. T ```js // NOTE: Advanced use-case, for normal use see 'formData' usage above -var r = request.post('http://service.com/upload', function optionalCallback(err, httpResponse, body) { // ... - +var r = request.post('http://service.com/upload', function optionalCallback(err, httpResponse, body) {...}) var form = r.form(); form.append('my_field', 'my_value'); form.append('my_buffer', new Buffer([1, 2, 3])); @@ -723,8 +722,8 @@ The first argument can be either a `url` or an `options` object. The only requir --- - `qs` - object containing querystring values to be appended to the `uri` -- `qsParseOptions` - object containing options to pass to the [qs.parse](https://github.com/hapijs/qs#parsing-objects) method or [querystring.parse](https://nodejs.org/docs/v0.12.0/api/querystring.html#querystring_querystring_parse_str_sep_eq_options) method -- `qsStringifyOptions` - object containing options to pass to the [qs.stringify](https://github.com/hapijs/qs#stringifying) method or to the [querystring.stringify](https://nodejs.org/docs/v0.12.0/api/querystring.html#querystring_querystring_stringify_obj_sep_eq_options) method. For example, to change the way arrays are converted to query strings pass the `arrayFormat` option with one of `indices|brackets|repeat` +- `qsParseOptions` - object containing options to pass to the [qs.parse](https://github.com/hapijs/qs#parsing-objects) method. Alternatively pass options to the [querystring.parse](https://nodejs.org/docs/v0.12.0/api/querystring.html#querystring_querystring_parse_str_sep_eq_options) method using this format `{sep:';', eq:':', options:{}}` +- `qsStringifyOptions` - object containing options to pass to the [qs.stringify](https://github.com/hapijs/qs#stringifying) method. Alternatively pass options to the [querystring.stringify](https://nodejs.org/docs/v0.12.0/api/querystring.html#querystring_querystring_stringify_obj_sep_eq_options) method using this format `{sep:';', eq:':', options:{}}`. For example, to change the way arrays are converted to query strings using the `qs` module pass the `arrayFormat` option with one of `indices|brackets|repeat` - `useQuerystring` - If true, use `querystring` to stringify and parse querystrings, otherwise use `qs` (default: `false`). Set this option to `true` if you need arrays to be serialized as `foo=bar&foo=baz` instead of the diff --git a/tests/test-qs.js b/tests/test-qs.js index 198621d46..85d741403 100644 --- a/tests/test-qs.js +++ b/tests/test-qs.js @@ -13,23 +13,18 @@ var request = require('../index') // - expectedQuerystring : expected path when using the querystring library function runTest(name, options) { var uri = 'http://www.google.com' + (options.suffix || '') - , requestOptsQs = { - uri : uri, - qsParseOptions: options.qsParseOptions, - qsStringifyOptions: options.qsStringifyOptions - } - , requestOptsQuerystring = { - uri : uri, - useQuerystring : true - } + var opts = { + uri : uri, + qsParseOptions: options.qsParseOptions, + qsStringifyOptions: options.qsStringifyOptions + } if (options.qs) { - requestOptsQs.qs = options.qs - requestOptsQuerystring.qs = options.qs + opts.qs = options.qs } - tape(name + ' using qs', function(t) { - var r = request.get(requestOptsQs) + tape(name + ' - using qs', function(t) { + var r = request.get(opts) if (typeof options.afterRequest === 'function') { options.afterRequest(r) } @@ -40,8 +35,9 @@ function runTest(name, options) { }) }) - tape(name + ' using querystring', function(t) { - var r = request.get(requestOptsQuerystring) + tape(name + ' - using querystring', function(t) { + opts.useQuerystring = true + var r = request.get(opts) if (typeof options.afterRequest === 'function') { options.afterRequest(r) } @@ -121,3 +117,19 @@ runTest('pass options to the qs module via the qsStringifyOptions key', { expected : esc('/?order[]=bar&order[]=desc'), expectedQuerystring : '/?order=bar&order=desc' }) + +runTest('pass options to the querystring module via the qsParseOptions key', { + suffix : '?a=1;b=2', + qs: {}, + qsParseOptions: { sep : ';' }, + qsStringifyOptions: { sep : ';' }, + expected : esc('/?a=1%3Bb%3D2'), + expectedQuerystring : '/?a=1;b=2' +}) + +runTest('pass options to the querystring module via the qsStringifyOptions key', { + qs : { order : ['bar', 'desc'] }, + qsStringifyOptions: { sep : ';' }, + expected : esc('/?order[0]=bar&order[1]=desc'), + expectedQuerystring : '/?order=bar;order=desc' +}) From a4130f5b82db6844236cb1a1734207a671df3d25 Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 28 May 2015 20:52:21 +0300 Subject: [PATCH 113/490] Bump module dependencies --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 6aa028422..1b36b94a5 100644 --- a/package.json +++ b/package.json @@ -23,17 +23,17 @@ "main": "index.js", "dependencies": { "bl": "~0.9.0", - "caseless": "~0.9.0", + "caseless": "~0.10.0", "forever-agent": "~0.6.0", "form-data": "~0.2.0", "json-stringify-safe": "~5.0.0", "mime-types": "~2.0.1", "node-uuid": "~1.4.0", - "qs": "~3.0.0", + "qs": "~3.1.0", "tunnel-agent": "~0.4.0", "tough-cookie": ">=0.12.0", - "http-signature": "~0.10.0", - "oauth-sign": "~0.6.0", + "http-signature": "~0.11.0", + "oauth-sign": "~0.8.0", "hawk": "~2.3.0", "aws-sign2": "~0.5.0", "stringstream": "~0.0.4", From 9554a0e12bf3e46a518c7d86b680526152cfa738 Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 28 May 2015 20:59:14 +0300 Subject: [PATCH 114/490] 2.56.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1b36b94a5..56dcba76e 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.55.1", + "version": "2.56.0", "author": "Mikeal Rogers ", "repository": { "type": "git", From dec45b11eb264a8100e8c43fa44817d62368f780 Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 28 May 2015 21:02:53 +0300 Subject: [PATCH 115/490] Update changelog --- CHANGELOG.md | 45 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c01d0875..7d861f171 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,28 @@ ## Change Log +### v2.56.0 (2015/05/28) +- [#1610](https://github.com/request/request/pull/1610) Bump module dependencies (@simov) +- [#1600](https://github.com/request/request/pull/1600) Extract the querystring logic into separate module (@simov) +- [#1607](https://github.com/request/request/pull/1607) Re-generate certificates (@simov) +- [#1599](https://github.com/request/request/pull/1599) Move getProxyFromURI logic below the check for Invaild URI (#1595) (@simov) +- [#1598](https://github.com/request/request/pull/1598) Fix the way http verbs are defined in order to please intellisense IDEs (@simov, @flannelJesus) +- [#1591](https://github.com/request/request/pull/1591) A few minor fixes: (@simov) +- [#1584](https://github.com/request/request/pull/1584) Refactor test-default tests (according to comments in #1430) (@simov) +- [#1585](https://github.com/request/request/pull/1585) Fixing documentation regarding TLS options (#1583) (@mainakae) +- [#1574](https://github.com/request/request/pull/1574) Refresh the oauth_nonce on redirect (#1573) (@simov) +- [#1570](https://github.com/request/request/pull/1570) Discovered tests that weren't properly running (@seanstrom) +- [#1569](https://github.com/request/request/pull/1569) Fix pause before response arrives (@kevinoid) +- [#1558](https://github.com/request/request/pull/1558) Emit error instead of throw (@simov) +- [#1568](https://github.com/request/request/pull/1568) Fix stall when piping gzipped response (@kevinoid) +- [#1560](https://github.com/request/request/pull/1560) Update combined-stream (@apechimp) +- [#1543](https://github.com/request/request/pull/1543) Initial support for oauth_body_hash on json payloads (@simov, @aesopwolf) +- [#1541](https://github.com/request/request/pull/1541) Fix coveralls (@simov) +- [#1540](https://github.com/request/request/pull/1540) Fix recursive defaults for convenience methods (@simov) +- [#1536](https://github.com/request/request/pull/1536) More eslint style rules (@froatsnook) +- [#1533](https://github.com/request/request/pull/1533) Adding dependency status bar to README.md (@YasharF) +- [#1539](https://github.com/request/request/pull/1539) ensure the latest version of har-validator is included (@ahmadnassri) +- [#1516](https://github.com/request/request/pull/1516) forever+pool test (@devTristan) + ### 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) @@ -21,7 +44,7 @@ - [#1481](https://github.com/request/request/pull/1481) Fix baseUrl and redirections. (@burningtree) - [#1469](https://github.com/request/request/pull/1469) Feature/base url (@froatsnook) - [#1459](https://github.com/request/request/pull/1459) Add option to time request/response cycle (including rollup of redirects) (@aaron-em) -- [#1468](https://github.com/request/request/pull/1468) Re-enable io.js/node 0.12 build (@simov, @BBB) +- [#1468](https://github.com/request/request/pull/1468) Re-enable io.js/node 0.12 build (@simov, @mikeal, @BBB) - [#1442](https://github.com/request/request/pull/1442) Fixed the issue with strictSSL tests on 0.12 & io.js by explicitly setting a cipher that matches the cert. (@BBB, @nicolasmccurdy, @simov, @0x4139) - [#1460](https://github.com/request/request/pull/1460) localAddress or proxy config is lost when redirecting (@simov, @0x4139) - [#1453](https://github.com/request/request/pull/1453) Test on Node.js 0.12 and io.js with allowed failures (@nicolasmccurdy) @@ -69,7 +92,7 @@ - [#1327](https://github.com/request/request/pull/1327) Fix errors generating coverage reports. (@nylen) - [#1330](https://github.com/request/request/pull/1330) Return empty buffer upon empty response body and encoding is set to null (@seanstrom) - [#1326](https://github.com/request/request/pull/1326) Use faster container-based infrastructure on Travis (@nylen) -- [#1315](https://github.com/request/request/pull/1315) Implement rfc3986 option (@simov) +- [#1315](https://github.com/request/request/pull/1315) Implement rfc3986 option (@simov, @nylen, @apoco, @DullReferenceException, @mmalecki, @oliamb, @cliffcrosland, @LewisJEllis, @eiriksm, @poislagarde) - [#1314](https://github.com/request/request/pull/1314) Detect urlencoded form data header via regex (@simov) - [#1317](https://github.com/request/request/pull/1317) Improve OAuth1.0 server side flow example (@simov) @@ -214,13 +237,13 @@ - [#1025](https://github.com/request/request/pull/1025) [fixes #1023] Set self._ended to true once response has ended (@mridgway) - [#1020](https://github.com/request/request/pull/1020) Add back removed debug metadata (@FredKSchott) - [#1008](https://github.com/request/request/pull/1008) Moving to module instead of cutomer buffer concatenation. (@mikeal) -- [#770](https://github.com/request/request/pull/770) Added dependency badge for README file; (@timgluz) +- [#770](https://github.com/request/request/pull/770) Added dependency badge for README file; (@timgluz, @mafintosh, @lalitkapoor, @stash, @bobyrizov) - [#1016](https://github.com/request/request/pull/1016) toJSON no longer results in an infinite loop, returns simple objects (@FredKSchott) - [#1018](https://github.com/request/request/pull/1018) Remove pre-0.4.4 HTTPS fix (@mmalecki) - [#1006](https://github.com/request/request/pull/1006) Migrate to caseless, fixes #1001 (@mikeal) - [#995](https://github.com/request/request/pull/995) Fix parsing array of objects (@sjonnet19) - [#999](https://github.com/request/request/pull/999) Fix fallback for browserify for optional modules. (@eiriksm) -- [#996](https://github.com/request/request/pull/996) Wrong oauth signature when multiple same param keys exist [updated] (@bengl) +- [#996](https://github.com/request/request/pull/996) Wrong oauth signature when multiple same param keys exist [updated] (@bengl, @hyjin) ### v2.40.0 (2014/08/06) - [#992](https://github.com/request/request/pull/992) Fix security vulnerability. Update qs (@poeticninja) @@ -297,7 +320,7 @@ ### v2.28.0 (2013/12/04) - [#724](https://github.com/request/request/pull/724) README.md: add custom HTTP Headers example. (@tcort) -- [#719](https://github.com/request/request/pull/719) Made a comment gender neutral. (@oztu) +- [#719](https://github.com/request/request/pull/719) Made a comment gender neutral. (@unsetbit) - [#715](https://github.com/request/request/pull/715) Request.multipart no longer crashes when header 'Content-type' present (@pastaclub) - [#710](https://github.com/request/request/pull/710) Fixing listing in callback part of docs. (@lukasz-zak) - [#696](https://github.com/request/request/pull/696) Edited README.md for formatting and clarity of phrasing (@Zearin) @@ -363,10 +386,10 @@ - [#460](https://github.com/request/request/pull/460) hawk 0.10.0 (@hueniverse) - [#462](https://github.com/request/request/pull/462) if query params are empty, then request path shouldn't end with a '?' (merges cleanly now) (@jaipandya) - [#456](https://github.com/request/request/pull/456) hawk 0.9.0 (@hueniverse) -- [#429](https://github.com/request/request/pull/429) Copy options before adding callback. (@nrn) +- [#429](https://github.com/request/request/pull/429) Copy options before adding callback. (@nrn, @nfriedly, @youurayy, @jplock, @kapetan, @landeiro, @othiym23, @mmalecki) - [#454](https://github.com/request/request/pull/454) Destroy the response if present when destroying the request (clean merge) (@mafintosh) -- [#310](https://github.com/request/request/pull/310) Twitter Oauth Stuff Out of Date; Now Updated (@joemccann) -- [#413](https://github.com/request/request/pull/413) rename googledoodle.png to .jpg (@nfriedly) +- [#310](https://github.com/request/request/pull/310) Twitter Oauth Stuff Out of Date; Now Updated (@joemccann, @isaacs, @mscdex) +- [#413](https://github.com/request/request/pull/413) rename googledoodle.png to .jpg (@nfriedly, @youurayy, @jplock, @kapetan, @landeiro, @othiym23, @mmalecki) - [#448](https://github.com/request/request/pull/448) Convenience method for PATCH (@mloar) - [#444](https://github.com/request/request/pull/444) protect against double callbacks on error path (@spollack) - [#433](https://github.com/request/request/pull/433) Added support for HTTPS cert & key (@mmalecki) @@ -401,7 +424,7 @@ - [#280](https://github.com/request/request/pull/280) Like in node.js print options if NODE_DEBUG contains the word request (@Filirom1) - [#207](https://github.com/request/request/pull/207) Fix #206 Change HTTP/HTTPS agent when redirecting between protocols (@isaacs) - [#214](https://github.com/request/request/pull/214) documenting additional behavior of json option (@jphaas) -- [#272](https://github.com/request/request/pull/272) Boundary begins with CRLF? (@elspoono) +- [#272](https://github.com/request/request/pull/272) Boundary begins with CRLF? (@elspoono, @timshadel, @naholyr, @nanodocumet, @TehShrike) - [#284](https://github.com/request/request/pull/284) Remove stray `console.log()` call in multipart generator. (@bcherry) - [#241](https://github.com/request/request/pull/241) Composability updates suggested by issue #239 (@polotek) - [#282](https://github.com/request/request/pull/282) OAuth Authorization header contains non-"oauth_" parameters (@jplock) @@ -412,7 +435,7 @@ - [#265](https://github.com/request/request/pull/265) uncaughtException when redirected to invalid URI (@naholyr) - [#262](https://github.com/request/request/pull/262) JSON test should check for equality (@timshadel) - [#261](https://github.com/request/request/pull/261) Setting 'pool' to 'false' does NOT disable Agent pooling (@timshadel) -- [#249](https://github.com/request/request/pull/249) Fix for the fix of your (closed) issue #89 where self.headers[content-length] is set to 0 for all methods (@sethbridges) +- [#249](https://github.com/request/request/pull/249) Fix for the fix of your (closed) issue #89 where self.headers[content-length] is set to 0 for all methods (@sethbridges, @polotek, @zephrax, @jeromegn) - [#255](https://github.com/request/request/pull/255) multipart allow body === '' ( the empty string ) (@Filirom1) - [#260](https://github.com/request/request/pull/260) fixed just another leak of 'i' (@sreuter) - [#246](https://github.com/request/request/pull/246) Fixing the set-cookie header (@jeromegn) @@ -456,7 +479,7 @@ - [#81](https://github.com/request/request/pull/81) Enhance redirect handling (@danmactough) - [#78](https://github.com/request/request/pull/78) Don't try to do strictSSL for non-ssl connections (@isaacs) - [#76](https://github.com/request/request/pull/76) Bug when a request fails and a timeout is set (@Marsup) -- [#70](https://github.com/request/request/pull/70) add test script to package.json (@isaacs) +- [#70](https://github.com/request/request/pull/70) add test script to package.json (@isaacs, @aheckmann) - [#73](https://github.com/request/request/pull/73) Fix #71 Respect the strictSSL flag (@isaacs) - [#69](https://github.com/request/request/pull/69) Flatten chunked requests properly (@isaacs) - [#67](https://github.com/request/request/pull/67) fixed global variable leaks (@aheckmann) From 3512cdd522eb24a3bf9ef0808770a5512585fe58 Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 28 May 2015 21:03:14 +0300 Subject: [PATCH 116/490] 2.56.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 56dcba76e..969e12890 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.56.0", + "version": "2.56.1", "author": "Mikeal Rogers ", "repository": { "type": "git", From 37372c467ca87db2f78790d8e283bf0454f58cd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=BA=D0=BE=D0=B2=D0=BE=D1=80=D0=BE=D0=B4=D0=B0=20?= =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=90=D0=BD=D0=B4=D1=80?= =?UTF-8?q?=D0=B5=D0=B5=D0=B2=D0=B8=D1=87?= Date: Sun, 31 May 2015 18:52:39 +0300 Subject: [PATCH 117/490] Replace '.client' with '.socket' as the former was deprecated in 2.2.0. --- request.js | 6 +++--- tests/ssl/ca/localhost.js | 4 ++-- tests/ssl/ca/server.js | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/request.js b/request.js index ab7c3278a..21b4f5294 100644 --- a/request.js +++ b/request.js @@ -1040,10 +1040,10 @@ Request.prototype.onRequestResponse = function (response) { // XXX This is different on 0.10, because SSL is strict by default if (self.httpModule === https && - self.strictSSL && (!response.hasOwnProperty('client') || - !response.client.authorized)) { + self.strictSSL && (!response.hasOwnProperty('socket') || + !response.socket.authorized)) { debug('strict ssl error', self.uri.href) - var sslErr = response.hasOwnProperty('client') ? response.client.authorizationError : self.uri.href + ' does not support SSL' + var sslErr = response.hasOwnProperty('socket') ? response.socket.authorizationError : self.uri.href + ' does not support SSL' self.emit('error', new Error('SSL Error: ' + sslErr)) return } diff --git a/tests/ssl/ca/localhost.js b/tests/ssl/ca/localhost.js index 515700c01..c40fb1aa4 100644 --- a/tests/ssl/ca/localhost.js +++ b/tests/ssl/ca/localhost.js @@ -21,9 +21,9 @@ https.request({ host: 'localhost' , agent: agent , ca: [ ca ] , path: '/' }, function (res) { - if (res.client.authorized) { + if (res.socket.authorized) { console.log('node test: OK') } else { - throw new Error(res.client.authorizationError) + throw new Error(res.socket.authorizationError) } }).end() diff --git a/tests/ssl/ca/server.js b/tests/ssl/ca/server.js index 2e216d5c6..c47ce4ca5 100644 --- a/tests/ssl/ca/server.js +++ b/tests/ssl/ca/server.js @@ -22,9 +22,9 @@ https.request({ host: 'localhost' , agent: agent , ca: [ ca ] , path: '/' }, function (res) { - if (res.client.authorized) { + if (res.socket.authorized) { console.log('node test: OK') } else { - throw new Error(res.client.authorizationError) + throw new Error(res.socket.authorizationError) } }).end() From 7afa680ca568fd51f537c02fabf7ce6806277fb7 Mon Sep 17 00:00:00 2001 From: simov Date: Sun, 31 May 2015 22:02:58 +0300 Subject: [PATCH 118/490] 2.57.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 969e12890..030dca734 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.56.1", + "version": "2.57.0", "author": "Mikeal Rogers ", "repository": { "type": "git", From 1fafe0dc387e5efa9ae95b40aa80c43e83e1b98f Mon Sep 17 00:00:00 2001 From: simov Date: Sun, 31 May 2015 22:04:12 +0300 Subject: [PATCH 119/490] Update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d861f171..2de0061ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## Change Log +### v2.57.0 (2015/05/31) +- [#1615](https://github.com/request/request/pull/1615) Replace '.client' with '.socket' as the former was deprecated in 2.2.0. (@ChALkeR) + ### v2.56.0 (2015/05/28) - [#1610](https://github.com/request/request/pull/1610) Bump module dependencies (@simov) - [#1600](https://github.com/request/request/pull/1600) Extract the querystring logic into separate module (@simov) From e5a94c34690f9c8011d54135946870bdc05f7d9c Mon Sep 17 00:00:00 2001 From: simov Date: Sun, 31 May 2015 22:04:47 +0300 Subject: [PATCH 120/490] 2.57.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 030dca734..76be1b36c 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.57.0", + "version": "2.57.1", "author": "Mikeal Rogers ", "repository": { "type": "git", From 4848560caf6b142f85ec01db29ea75c70b25f1cd Mon Sep 17 00:00:00 2001 From: simov Date: Sat, 6 Jun 2015 10:47:37 +0300 Subject: [PATCH 121/490] Move copy method to helpers --- lib/copy.js | 10 ---------- lib/helpers.js | 9 +++++++++ request.js | 4 ++-- 3 files changed, 11 insertions(+), 12 deletions(-) delete mode 100644 lib/copy.js diff --git a/lib/copy.js b/lib/copy.js deleted file mode 100644 index ad162a508..000000000 --- a/lib/copy.js +++ /dev/null @@ -1,10 +0,0 @@ -'use strict' - -module.exports = -function copy (obj) { - var o = {} - Object.keys(obj).forEach(function (i) { - o[i] = obj[i] - }) - return o -} diff --git a/lib/helpers.js b/lib/helpers.js index 1d588ca94..5cc79da86 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -46,10 +46,19 @@ function toBase64 (str) { return (new Buffer(str || '', 'utf8')).toString('base64') } +function copy (obj) { + var o = {} + Object.keys(obj).forEach(function (i) { + o[i] = obj[i] + }) + return o +} + exports.isFunction = isFunction exports.paramsHaveRequestBody = paramsHaveRequestBody exports.safeStringify = safeStringify exports.md5 = md5 exports.isReadStream = isReadStream exports.toBase64 = toBase64 +exports.copy = copy exports.defer = deferMethod() diff --git a/request.js b/request.js index 21b4f5294..678c16741 100644 --- a/request.js +++ b/request.js @@ -6,7 +6,6 @@ var http = require('http') , util = require('util') , stream = require('stream') , zlib = require('zlib') - , helpers = require('./lib/helpers') , bl = require('bl') , hawk = require('hawk') , aws = require('aws-sign2') @@ -17,8 +16,8 @@ var http = require('http') , caseless = require('caseless') , ForeverAgent = require('forever-agent') , FormData = require('form-data') + , helpers = require('./lib/helpers') , cookies = require('./lib/cookies') - , copy = require('./lib/copy') , getProxyFromURI = require('./lib/getProxyFromURI') , Querystring = require('./lib/querystring').Querystring , Har = require('./lib/har').Har @@ -31,6 +30,7 @@ var safeStringify = helpers.safeStringify , isReadStream = helpers.isReadStream , toBase64 = helpers.toBase64 , defer = helpers.defer + , copy = helpers.copy , globalCookieJar = cookies.jar() From da7bab63d79a1ac8362346a3bce7bf76d165ea53 Mon Sep 17 00:00:00 2001 From: simov Date: Sat, 6 Jun 2015 12:55:53 +0300 Subject: [PATCH 122/490] Move tunnel logic into separate module --- lib/tunnel.js | 173 ++++++++++++++++++++++++++++++++++++++++++++++++++ request.js | 171 ++----------------------------------------------- 2 files changed, 180 insertions(+), 164 deletions(-) create mode 100644 lib/tunnel.js diff --git a/lib/tunnel.js b/lib/tunnel.js new file mode 100644 index 000000000..bb0e2e4f7 --- /dev/null +++ b/lib/tunnel.js @@ -0,0 +1,173 @@ +'use strict' + +var url = require('url') + , tunnel = require('tunnel-agent') + +var defaultProxyHeaderWhiteList = [ + 'accept', + 'accept-charset', + 'accept-encoding', + 'accept-language', + 'accept-ranges', + 'cache-control', + 'content-encoding', + 'content-language', + 'content-length', + 'content-location', + 'content-md5', + 'content-range', + 'content-type', + 'connection', + 'date', + 'expect', + 'max-forwards', + 'pragma', + 'referer', + 'te', + 'transfer-encoding', + 'user-agent', + 'via' +] + +var defaultProxyHeaderExclusiveList = [ + 'proxy-authorization' +] + +function constructProxyHost(uriObject) { + var port = uriObject.portA + , protocol = uriObject.protocol + , proxyHost = uriObject.hostname + ':' + + if (port) { + proxyHost += port + } else if (protocol === 'https:') { + proxyHost += '443' + } else { + proxyHost += '80' + } + + return proxyHost +} + +function constructProxyHeaderWhiteList(headers, proxyHeaderWhiteList) { + var whiteList = proxyHeaderWhiteList + .reduce(function (set, header) { + set[header.toLowerCase()] = true + return set + }, {}) + + return Object.keys(headers) + .filter(function (header) { + return whiteList[header.toLowerCase()] + }) + .reduce(function (set, header) { + set[header] = headers[header] + return set + }, {}) +} + +function constructTunnelOptions (request) { + var proxy = request.proxy + + var tunnelOptions = { + proxy : { + host : proxy.hostname, + port : +proxy.port, + proxyAuth : proxy.auth, + headers : request.proxyHeaders + }, + headers : request.headers, + ca : request.ca, + cert : request.cert, + key : request.key, + passphrase : request.passphrase, + pfx : request.pfx, + ciphers : request.ciphers, + rejectUnauthorized : request.rejectUnauthorized, + secureOptions : request.secureOptions, + secureProtocol : request.secureProtocol + } + + return tunnelOptions +} + +function constructTunnelFnName(uri, proxy) { + var uriProtocol = (uri.protocol === 'https:' ? 'https' : 'http') + var proxyProtocol = (proxy.protocol === 'https:' ? 'Https' : 'Http') + return [uriProtocol, proxyProtocol].join('Over') +} + +function getTunnelFn(request) { + var uri = request.uri + var proxy = request.proxy + var tunnelFnName = constructTunnelFnName(uri, proxy) + return tunnel[tunnelFnName] +} + + +function Tunnel (request) { + this.request = request +} + +Tunnel.prototype.isEnabled = function (options) { + var request = this.request + // Tunnel HTTPS by default, or if a previous request in the redirect chain + // was tunneled. Allow the user to override this setting. + + // If self.tunnel is already set (because this is a redirect), use the + // existing value. + if (typeof request.tunnel !== 'undefined') { + return request.tunnel + } + + // If options.tunnel is set (the user specified a value), use it. + if (typeof options.tunnel !== 'undefined') { + return options.tunnel + } + + // If the destination is HTTPS, tunnel. + if (request.uri.protocol === 'https:') { + return true + } + + // Otherwise, leave tunnel unset, because if a later request in the redirect + // chain is HTTPS then that request (and any subsequent ones) should be + // tunneled. + return undefined +} + +Tunnel.prototype.setup = function () { + var self = this + , request = self.request + + if (typeof request.proxy === 'string') { + request.proxy = url.parse(request.proxy) + } + + if (!request.proxy || !request.tunnel) { + return false + } + + // Setup Proxy Header Exclusive List and White List + request.proxyHeaderExclusiveList = request.proxyHeaderExclusiveList || [] + request.proxyHeaderWhiteList = request.proxyHeaderWhiteList || defaultProxyHeaderWhiteList + var proxyHeaderExclusiveList = request.proxyHeaderExclusiveList.concat(defaultProxyHeaderExclusiveList) + var proxyHeaderWhiteList = request.proxyHeaderWhiteList.concat(proxyHeaderExclusiveList) + + // Setup Proxy Headers and Proxy Headers Host + // Only send the Proxy White Listed Header names + request.proxyHeaders = constructProxyHeaderWhiteList(request.headers, proxyHeaderWhiteList) + request.proxyHeaders.host = constructProxyHost(request.uri) + proxyHeaderExclusiveList.forEach(request.removeHeader, request) + + // Set Agent from Tunnel Data + var tunnelFn = getTunnelFn(request) + var tunnelOptions = constructTunnelOptions(request) + request.agent = tunnelFn(tunnelOptions) + + return true +} + +Tunnel.defaultProxyHeaderWhiteList = defaultProxyHeaderWhiteList +Tunnel.defaultProxyHeaderExclusiveList = defaultProxyHeaderExclusiveList +exports.Tunnel = Tunnel diff --git a/request.js b/request.js index 678c16741..c94d24089 100644 --- a/request.js +++ b/request.js @@ -11,7 +11,6 @@ var http = require('http') , aws = require('aws-sign2') , httpSignature = require('http-signature') , mime = require('mime-types') - , tunnel = require('tunnel-agent') , stringstream = require('stringstream') , caseless = require('caseless') , ForeverAgent = require('forever-agent') @@ -25,6 +24,7 @@ var http = require('http') , OAuth = require('./lib/oauth').OAuth , Multipart = require('./lib/multipart').Multipart , Redirect = require('./lib/redirect').Redirect + , Tunnel = require('./lib/tunnel').Tunnel var safeStringify = helpers.safeStringify , isReadStream = helpers.isReadStream @@ -36,36 +36,6 @@ var safeStringify = helpers.safeStringify var globalPool = {} -var defaultProxyHeaderWhiteList = [ - 'accept', - 'accept-charset', - 'accept-encoding', - 'accept-language', - 'accept-ranges', - 'cache-control', - 'content-encoding', - 'content-language', - 'content-length', - 'content-location', - 'content-md5', - 'content-range', - 'content-type', - 'connection', - 'date', - 'expect', - 'max-forwards', - 'pragma', - 'referer', - 'te', - 'transfer-encoding', - 'user-agent', - 'via' -] - -var defaultProxyHeaderExclusiveList = [ - 'proxy-authorization' -] - function filterForNonReserved(reserved, options) { // Filter out properties that are not reserved. // Reserved values are passed in at call site. @@ -96,103 +66,6 @@ function filterOutReservedFunctions(reserved, options) { } -function constructProxyHost(uriObject) { - var port = uriObject.portA - , protocol = uriObject.protocol - , proxyHost = uriObject.hostname + ':' - - if (port) { - proxyHost += port - } else if (protocol === 'https:') { - proxyHost += '443' - } else { - proxyHost += '80' - } - - return proxyHost -} - -function constructProxyHeaderWhiteList(headers, proxyHeaderWhiteList) { - var whiteList = proxyHeaderWhiteList - .reduce(function (set, header) { - set[header.toLowerCase()] = true - return set - }, {}) - - return Object.keys(headers) - .filter(function (header) { - return whiteList[header.toLowerCase()] - }) - .reduce(function (set, header) { - set[header] = headers[header] - return set - }, {}) -} - -function getTunnelOption(self, options) { - // Tunnel HTTPS by default, or if a previous request in the redirect chain - // was tunneled. Allow the user to override this setting. - - // If self.tunnel is already set (because this is a redirect), use the - // existing value. - if (typeof self.tunnel !== 'undefined') { - return self.tunnel - } - - // If options.tunnel is set (the user specified a value), use it. - if (typeof options.tunnel !== 'undefined') { - return options.tunnel - } - - // If the destination is HTTPS, tunnel. - if (self.uri.protocol === 'https:') { - return true - } - - // Otherwise, leave tunnel unset, because if a later request in the redirect - // chain is HTTPS then that request (and any subsequent ones) should be - // tunneled. - return undefined -} - -function constructTunnelOptions(request) { - var proxy = request.proxy - - var tunnelOptions = { - proxy : { - host : proxy.hostname, - port : +proxy.port, - proxyAuth : proxy.auth, - headers : request.proxyHeaders - }, - headers : request.headers, - ca : request.ca, - cert : request.cert, - key : request.key, - passphrase : request.passphrase, - pfx : request.pfx, - ciphers : request.ciphers, - rejectUnauthorized : request.rejectUnauthorized, - secureOptions : request.secureOptions, - secureProtocol : request.secureProtocol - } - - return tunnelOptions -} - -function constructTunnelFnName(uri, proxy) { - var uriProtocol = (uri.protocol === 'https:' ? 'https' : 'http') - var proxyProtocol = (proxy.protocol === 'https:' ? 'Https' : 'Http') - return [uriProtocol, proxyProtocol].join('Over') -} - -function getTunnelFn(request) { - var uri = request.uri - var proxy = request.proxy - var tunnelFnName = constructTunnelFnName(uri, proxy) - return tunnel[tunnelFnName] -} - // Function for properly handling a connection error function connectionErrorHandler(error) { var socket = this @@ -262,6 +135,7 @@ function Request (options) { self._oauth = new OAuth(self) self._multipart = new Multipart(self) self._redirect = new Redirect(self) + self._tunnel = new Tunnel(self) self.init(options) } @@ -276,37 +150,6 @@ function debug() { } Request.prototype.debug = debug -Request.prototype.setupTunnel = function () { - var self = this - - if (typeof self.proxy === 'string') { - self.proxy = url.parse(self.proxy) - } - - if (!self.proxy || !self.tunnel) { - return false - } - - // Setup Proxy Header Exclusive List and White List - self.proxyHeaderExclusiveList = self.proxyHeaderExclusiveList || [] - self.proxyHeaderWhiteList = self.proxyHeaderWhiteList || defaultProxyHeaderWhiteList - var proxyHeaderExclusiveList = self.proxyHeaderExclusiveList.concat(defaultProxyHeaderExclusiveList) - var proxyHeaderWhiteList = self.proxyHeaderWhiteList.concat(proxyHeaderExclusiveList) - - // Setup Proxy Headers and Proxy Headers Host - // Only send the Proxy White Listed Header names - self.proxyHeaders = constructProxyHeaderWhiteList(self.headers, proxyHeaderWhiteList) - self.proxyHeaders.host = constructProxyHost(self.uri) - proxyHeaderExclusiveList.forEach(self.removeHeader, self) - - // Set Agent from Tunnel Data - var tunnelFn = getTunnelFn(self) - var tunnelOptions = constructTunnelOptions(self) - self.agent = tunnelFn(tunnelOptions) - - return true -} - Request.prototype.init = function (options) { // init() contains all the code to setup the request object. // the actual outgoing request is not started until start() is called @@ -450,9 +293,9 @@ Request.prototype.init = function (options) { self.proxy = getProxyFromURI(self.uri) } - self.tunnel = getTunnelOption(self, options) + self.tunnel = self._tunnel.isEnabled(options) if (self.proxy) { - self.setupTunnel() + self._tunnel.setup() } self._redirect.onRequest(options) @@ -750,7 +593,7 @@ Request.prototype._updateProtocol = function () { // previously was doing http, now doing https // if it's https, then we might need to tunnel now. if (self.proxy) { - if (self.setupTunnel()) { + if (self._tunnel.setup()) { return } } @@ -1545,10 +1388,10 @@ Request.prototype.destroy = function () { } Request.defaultProxyHeaderWhiteList = - defaultProxyHeaderWhiteList.slice() + Tunnel.defaultProxyHeaderWhiteList.slice() Request.defaultProxyHeaderExclusiveList = - defaultProxyHeaderExclusiveList.slice() + Tunnel.defaultProxyHeaderExclusiveList.slice() // Exports From 6e50b3593be481cf53facb84fb2ff7a4e027c303 Mon Sep 17 00:00:00 2001 From: simov Date: Sat, 6 Jun 2015 15:52:22 +0300 Subject: [PATCH 123/490] Minor refactoring in the tunnel module: - proxyHeaderWhiteList, proxyHeaderExclusiveList and proxyHeaders are no longer public properties of the request instance --- lib/tunnel.js | 30 ++++++++++++++++++++---------- request.js | 2 +- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/lib/tunnel.js b/lib/tunnel.js index bb0e2e4f7..cf28016e2 100644 --- a/lib/tunnel.js +++ b/lib/tunnel.js @@ -66,7 +66,7 @@ function constructProxyHeaderWhiteList(headers, proxyHeaderWhiteList) { }, {}) } -function constructTunnelOptions (request) { +function constructTunnelOptions (request, proxyHeaders) { var proxy = request.proxy var tunnelOptions = { @@ -74,7 +74,7 @@ function constructTunnelOptions (request) { host : proxy.hostname, port : +proxy.port, proxyAuth : proxy.auth, - headers : request.proxyHeaders + headers : proxyHeaders }, headers : request.headers, ca : request.ca, @@ -107,6 +107,8 @@ function getTunnelFn(request) { function Tunnel (request) { this.request = request + this.proxyHeaderWhiteList = defaultProxyHeaderWhiteList + this.proxyHeaderExclusiveList = [] } Tunnel.prototype.isEnabled = function (options) { @@ -136,10 +138,12 @@ Tunnel.prototype.isEnabled = function (options) { return undefined } -Tunnel.prototype.setup = function () { +Tunnel.prototype.setup = function (options) { var self = this , request = self.request + options = options || {} + if (typeof request.proxy === 'string') { request.proxy = url.parse(request.proxy) } @@ -149,20 +153,26 @@ Tunnel.prototype.setup = function () { } // Setup Proxy Header Exclusive List and White List - request.proxyHeaderExclusiveList = request.proxyHeaderExclusiveList || [] - request.proxyHeaderWhiteList = request.proxyHeaderWhiteList || defaultProxyHeaderWhiteList - var proxyHeaderExclusiveList = request.proxyHeaderExclusiveList.concat(defaultProxyHeaderExclusiveList) - var proxyHeaderWhiteList = request.proxyHeaderWhiteList.concat(proxyHeaderExclusiveList) + if (options.proxyHeaderWhiteList) { + self.proxyHeaderWhiteList = options.proxyHeaderWhiteList + } + if (options.proxyHeaderExclusiveList) { + self.proxyHeaderExclusiveList = options.proxyHeaderExclusiveList + } + + var proxyHeaderExclusiveList = self.proxyHeaderExclusiveList.concat(defaultProxyHeaderExclusiveList) + var proxyHeaderWhiteList = self.proxyHeaderWhiteList.concat(proxyHeaderExclusiveList) // Setup Proxy Headers and Proxy Headers Host // Only send the Proxy White Listed Header names - request.proxyHeaders = constructProxyHeaderWhiteList(request.headers, proxyHeaderWhiteList) - request.proxyHeaders.host = constructProxyHost(request.uri) + var proxyHeaders = constructProxyHeaderWhiteList(request.headers, proxyHeaderWhiteList) + proxyHeaders.host = constructProxyHost(request.uri) + proxyHeaderExclusiveList.forEach(request.removeHeader, request) // Set Agent from Tunnel Data var tunnelFn = getTunnelFn(request) - var tunnelOptions = constructTunnelOptions(request) + var tunnelOptions = constructTunnelOptions(request, proxyHeaders) request.agent = tunnelFn(tunnelOptions) return true diff --git a/request.js b/request.js index c94d24089..c032ea8f6 100644 --- a/request.js +++ b/request.js @@ -295,7 +295,7 @@ Request.prototype.init = function (options) { self.tunnel = self._tunnel.isEnabled(options) if (self.proxy) { - self._tunnel.setup() + self._tunnel.setup(options) } self._redirect.onRequest(options) From 1b9055eae9688cf4aa9af7ee358ff70099876ee1 Mon Sep 17 00:00:00 2001 From: simov Date: Mon, 8 Jun 2015 19:01:55 +0300 Subject: [PATCH 124/490] Fix OAuth query transport_method Improve OAuth transport_method related tests --- lib/oauth.js | 7 ++- tests/test-oauth.js | 106 +++++++++++++++++++++++++++----------------- 2 files changed, 70 insertions(+), 43 deletions(-) diff --git a/lib/oauth.js b/lib/oauth.js index 84059724a..b0f7ab884 100644 --- a/lib/oauth.js +++ b/lib/oauth.js @@ -1,6 +1,7 @@ 'use strict' -var qs = require('qs') +var url = require('url') + , qs = require('qs') , caseless = require('caseless') , uuid = require('node-uuid') , oauth = require('oauth-sign') @@ -129,7 +130,9 @@ OAuth.prototype.onRequest = function (_oauth) { break case 'query': - self.request.path = (query ? '&' : '?') + self.concatParams(oa, '&') + var href = self.request.uri.href += (query ? '&' : '?') + self.concatParams(oa, '&') + self.request.uri = url.parse(href) + self.request.path = self.request.uri.path break case 'body': diff --git a/tests/test-oauth.js b/tests/test-oauth.js index b716167c7..940fe0ec3 100644 --- a/tests/test-oauth.js +++ b/tests/test-oauth.js @@ -322,16 +322,6 @@ tape('plaintext signature method', function(t) { }) tape('invalid transport_method', function(t) { - t.throws( - function () { - request.post( - { url: 'http://example.com/' - , oauth: - { transport_method: 'some random string' - } - }) - }, /transport_method invalid/) - t.throws( function () { request.post( @@ -372,7 +362,7 @@ tape('invalid content-type while using transport_method \'body\'', function(t) { t.end() }) -tape('query transport_method simple url', function(t) { +tape('query transport_method', function(t) { var r = request.post( { url: 'https://api.twitter.com/oauth/access_token' , oauth: @@ -391,14 +381,23 @@ tape('query transport_method simple url', function(t) { process.nextTick(function() { t.notOk(r.headers.Authorization, 'oauth Authorization header should not be present with transport_method \'query\'') - t.equal(accsign, qs.parse(r.path).oauth_signature) - t.notOk(r.path.match(/\?&/), 'there should be no ampersand at the beginning of the query') + t.equal(r.uri.path, r.path, 'r.uri.path should equal r.path') + t.ok(r.path.match(/^\/oauth\/access_token\?/), 'path should contain path + query') + t.deepEqual(qs.parse(r.uri.query), + { oauth_consumer_key: 'GDdmIQH6jhtmLUypg82g', + oauth_nonce: '9zWH6qe0qG7Lc1telCn7FhUbLyVdjEaL3MO5uHxn8', + oauth_signature_method: 'HMAC-SHA1', + oauth_timestamp: '1272323047', + oauth_token: '8ldIZyxQeVrFZXFOZH5tAwj6vzJYuLQpl0WUEYtWc', + oauth_verifier: 'pDNg57prOHapMbhv25RNf75lVRd6JDsni1AJJIDYoTY', + oauth_version: '1.0', + oauth_signature: accsign }) r.abort() t.end() }) }) -tape('query transport_method with prexisting url params', function(t) { +tape('query transport_method + form option + url params', function(t) { var r = request.post( { url: 'http://example.com/request?b5=%3D%253D&a3=a&c%40=&a2=r%20b' , oauth: @@ -420,14 +419,26 @@ tape('query transport_method with prexisting url params', function(t) { process.nextTick(function() { t.notOk(r.headers.Authorization, 'oauth Authorization header should not be present with transport_method \'query\'') - t.notOk(r.path.match(/\?&/), 'there should be no ampersand at the beginning of the query') - t.equal('OB33pYjWAnf+xtOHN4Gmbdil168=', qs.parse(r.path).oauth_signature) + t.equal(r.uri.path, r.path, 'r.uri.path should equal r.path') + t.ok(r.path.match(/^\/request\?/), 'path should contain path + query') + t.deepEqual(qs.parse(r.uri.query), + { b5: '=%3D', + a3: 'a', + 'c@': '', + a2: 'r b', + realm: 'Example', + oauth_nonce: '7d8f3e4a', + oauth_signature_method: 'HMAC-SHA1', + oauth_timestamp: '137131201', + oauth_token: 'kkk9d7dh3k39sjv7', + oauth_version: '1.0', + oauth_signature: 'OB33pYjWAnf+xtOHN4Gmbdil168=' }) r.abort() t.end() }) }) -tape('query transport_method with qs parameter and existing query string in url', function(t) { +tape('query transport_method + qs option + url params', function(t) { var r = request.post( { url: 'http://example.com/request?a2=r%20b' , oauth: @@ -451,30 +462,28 @@ tape('query transport_method with qs parameter and existing query string in url' process.nextTick(function() { t.notOk(r.headers.Authorization, 'oauth Authorization header should not be present with transport_method \'query\'') - t.notOk(r.path.match(/\?&/), 'there should be no ampersand at the beginning of the query') - t.equal('OB33pYjWAnf+xtOHN4Gmbdil168=', qs.parse(r.path).oauth_signature) - - var params = qs.parse(r.path.split('?')[1]) - , keys = Object.keys(params) - - var paramNames = [ - 'a2', 'b5', 'a3[0]', 'a3[1]', 'c@', 'c2', - 'realm', 'oauth_nonce', 'oauth_signature_method', 'oauth_timestamp', - 'oauth_token', 'oauth_version', 'oauth_signature' - ] - - for (var i = 0; i < keys.length; i++) { - t.ok(keys[i] === paramNames[i], - 'Non-oauth query params should be first, ' + - 'OAuth query params should be second in query string') - } - + t.equal(r.uri.path, r.path, 'r.uri.path should equal r.path') + t.ok(r.path.match(/^\/request\?/), 'path should contain path + query') + t.deepEqual(qs.parse(r.uri.query), + { a2: 'r b', + b5: '=%3D', + 'a3[0]': 'a', + 'a3[1]': '2 q', + 'c@': '', + c2: '', + realm: 'Example', + oauth_nonce: '7d8f3e4a', + oauth_signature_method: 'HMAC-SHA1', + oauth_timestamp: '137131201', + oauth_token: 'kkk9d7dh3k39sjv7', + oauth_version: '1.0', + oauth_signature: 'OB33pYjWAnf+xtOHN4Gmbdil168=' }) r.abort() t.end() }) }) -tape('body transport_method empty body', function(t) { +tape('body transport_method', function(t) { var r = request.post( { url: 'https://api.twitter.com/oauth/access_token' , headers: { 'content-type': 'application/x-www-form-urlencoded; charset=UTF-8' } @@ -494,14 +503,21 @@ tape('body transport_method empty body', function(t) { process.nextTick(function() { t.notOk(r.headers.Authorization, 'oauth Authorization header should not be present with transport_method \'body\'') - t.equal(accsign, qs.parse(r.body.toString()).oauth_signature) - t.notOk(r.body.toString().match(/^&/), 'there should be no ampersand at the beginning of the body') + t.deepEqual(qs.parse(r.body), + { oauth_consumer_key: 'GDdmIQH6jhtmLUypg82g', + oauth_nonce: '9zWH6qe0qG7Lc1telCn7FhUbLyVdjEaL3MO5uHxn8', + oauth_signature_method: 'HMAC-SHA1', + oauth_timestamp: '1272323047', + oauth_token: '8ldIZyxQeVrFZXFOZH5tAwj6vzJYuLQpl0WUEYtWc', + oauth_verifier: 'pDNg57prOHapMbhv25RNf75lVRd6JDsni1AJJIDYoTY', + oauth_version: '1.0', + oauth_signature: accsign }) r.abort() t.end() }) }) -tape('body transport_method with prexisting body params', function(t) { +tape('body transport_method + form option + url params', function(t) { var r = request.post( { url: 'http://example.com/request?b5=%3D%253D&a3=a&c%40=&a2=r%20b' , oauth: @@ -523,8 +539,16 @@ tape('body transport_method with prexisting body params', function(t) { process.nextTick(function() { t.notOk(r.headers.Authorization, 'oauth Authorization header should not be present with transport_method \'body\'') - t.notOk(r.body.toString().match(/^&/), 'there should be no ampersand at the beginning of the body') - t.equal('OB33pYjWAnf+xtOHN4Gmbdil168=', qs.parse(r.body.toString()).oauth_signature) + t.deepEqual(qs.parse(r.body), + { c2: '', + a3: '2 q', + realm: 'Example', + oauth_nonce: '7d8f3e4a', + oauth_signature_method: 'HMAC-SHA1', + oauth_timestamp: '137131201', + oauth_token: 'kkk9d7dh3k39sjv7', + oauth_version: '1.0', + oauth_signature: 'OB33pYjWAnf+xtOHN4Gmbdil168=' }) r.abort() t.end() }) From 9701a3c0685c851108d8475c9d302782875bbe17 Mon Sep 17 00:00:00 2001 From: simov Date: Mon, 8 Jun 2015 20:16:44 +0300 Subject: [PATCH 125/490] Return back coveralls, clean npm scripts --- .travis.yml | 2 +- README.md | 3 ++- package.json | 7 ++++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 046a7431a..6180cb5d7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ node_js: - "0.10" sudo: false -after_script: "npm run test-cov && cat ./coverage/lcov.info | ./node_modules/codecov.io/bin/codecov.io.js" +after_script: "npm run test-cov && cat ./coverage/lcov.info | codecov && cat ./coverage/lcov.info | coveralls" webhooks: urls: https://webhooks.gitter.im/e/237280ed4796c19cc626 diff --git a/README.md b/README.md index 5e6def2a4..5fee320d2 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,8 @@ [![npm package](https://nodei.co/npm/request.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/request/) [![Build status](https://img.shields.io/travis/request/request.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) +[![Coverage](https://img.shields.io/codecov/c/github/request/request.svg?style=flat-square)](https://codecov.io/github/request/request?branch=master) +[![Coverage](https://img.shields.io/coveralls/request/request.svg?style=flat-square)](https://coveralls.io/r/request/request) [![Dependency Status](https://img.shields.io/david/request/request.svg?style=flat-square)](https://david-dm.org/request/request) [![Gitter](https://img.shields.io/badge/gitter-join_chat-blue.svg?style=flat-square)](https://gitter.im/request/request?utm_source=badge) diff --git a/package.json b/package.json index 9a4cdf441..da142404c 100644 --- a/package.json +++ b/package.json @@ -43,16 +43,17 @@ }, "scripts": { "test": "npm run lint && npm run test-ci && npm run test-browser", - "test-ci": "node node_modules/.bin/taper tests/test-*.js", - "test-cov": "node node_modules/.bin/istanbul cover ./node_modules/tape/bin/tape tests/test-*.js", + "test-ci": "taper tests/test-*.js", + "test-cov": "istanbul cover tape tests/test-*.js", "test-browser": "node tests/browser/start.js", - "lint": "node node_modules/.bin/eslint lib/ *.js tests/ && echo Lint passed." + "lint": "eslint lib/ *.js tests/ && echo Lint passed." }, "devDependencies": { "browserify": "~5.9.1", "browserify-istanbul": "~0.1.3", "buffer-equal": "0.0.1", "codecov.io": "~0.1.2", + "coveralls": "~2.11.2", "eslint": "0.18.0", "function-bind": "~1.0.0", "istanbul": "~0.3.2", From eb710b0cbd99bf9d0aaad6a6399f81f425c249cb Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 11 Jun 2015 21:39:17 +0300 Subject: [PATCH 126/490] Use the `extend` module to deep extend when using the defaults method --- index.js | 25 +++++++++---------------- package.json | 1 + tests/server.js | 2 +- tests/test-defaults.js | 24 +++++++++++++++++++++++- 4 files changed, 34 insertions(+), 18 deletions(-) diff --git a/index.js b/index.js index 5872824c8..3fe600175 100755 --- a/index.js +++ b/index.js @@ -14,7 +14,7 @@ 'use strict' -var extend = require('util')._extend +var extend = require('extend') , cookies = require('./lib/cookies') , helpers = require('./lib/helpers') @@ -30,12 +30,11 @@ function initParams(uri, options, callback) { var params = {} if (typeof options === 'object') { - params = extend({}, options) - params = extend(params, {uri: uri}) + extend(params, options, {uri: uri}) } else if (typeof uri === 'string') { - params = extend({}, {uri: uri}) + extend(params, {uri: uri}) } else { - params = extend({}, uri) + extend(params, uri) } params.callback = callback @@ -86,24 +85,18 @@ function wrapRequestMethod (method, options, requester, verb) { return function (uri, opts, callback) { var params = initParams(uri, opts, callback) - 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 target = {} + extend(true, target, options, params) if (verb) { - params.method = (verb === 'del' ? 'DELETE' : verb.toUpperCase()) + target.method = (verb === 'del' ? 'DELETE' : verb.toUpperCase()) } if (isFunction(requester)) { method = requester } - return method(params, params.callback) + return method(target, target.callback) } } @@ -131,7 +124,7 @@ request.defaults = function (options, requester) { request.forever = function (agentOptions, optionsArg) { var options = {} if (optionsArg) { - options = extend({}, optionsArg) + extend(options, optionsArg) } if (agentOptions) { options.agentOptions = agentOptions diff --git a/package.json b/package.json index ab753d1ca..26167305e 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "dependencies": { "bl": "~0.9.0", "caseless": "~0.10.0", + "extend": "~2.0.1", "forever-agent": "~0.6.0", "form-data": "~0.2.0", "json-stringify-safe": "~5.0.0", diff --git a/tests/server.js b/tests/server.js index 99d004a30..34d9d1ffc 100644 --- a/tests/server.js +++ b/tests/server.js @@ -13,7 +13,7 @@ exports.portSSL = 16167 exports.createServer = function (port) { port = port || exports.port var s = http.createServer(function (req, resp) { - s.emit(req.url, req, resp) + s.emit(req.url.replace(/(\?.*)/, ''), req, resp) }) s.port = port s.url = 'http://localhost:' + port diff --git a/tests/test-defaults.js b/tests/test-defaults.js index 112033357..265d5d1fb 100644 --- a/tests/test-defaults.js +++ b/tests/test-defaults.js @@ -2,6 +2,7 @@ var server = require('./server') , request = require('../index') + , qs = require('qs') , tape = require('tape') var s = server.createServer() @@ -10,7 +11,10 @@ tape('setup', function(t) { s.listen(s.port, function() { s.on('/', function (req, res) { res.writeHead(200, {'content-type': 'application/json'}) - res.end(JSON.stringify({method: req.method, headers: req.headers})) + res.end(JSON.stringify({ + method: req.method, headers: req.headers, + qs: qs.parse(req.url.replace(/.*\?(.*)/, '$1')) + })) }) s.on('/head', function (req, res) { @@ -58,6 +62,24 @@ tape('merge headers', function(t) { }) }) +tape('deep extend', function(t) { + request.defaults({ + headers: {a: 1, b: 2 }, + qs: { a: 1, b: 2 } + })(s.url + '/', { + headers: { b: 3, c: 4 }, + qs: { b: 3, c: 4 }, + json: true + }, function (e, r, b) { + delete b.headers.host + delete b.headers.accept + delete b.headers.connection + t.deepEqual(b.headers, { a: '1', b: '3', c: '4' }) + t.deepEqual(b.qs, { a: '1', b: '3', c: '4' }) + t.end() + }) +}) + tape('default undefined header', function(t) { request.defaults({ headers: { foo: 'bar', test: undefined }, json: true From 012577f36b31edf0371d855a7371d82ae71d8f0b Mon Sep 17 00:00:00 2001 From: simov Date: Mon, 15 Jun 2015 12:36:04 +0300 Subject: [PATCH 127/490] Bump form-data version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 26167305e..e5fa62c0e 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "caseless": "~0.10.0", "extend": "~2.0.1", "forever-agent": "~0.6.0", - "form-data": "~0.2.0", + "form-data": "~1.0.0-rc1", "json-stringify-safe": "~5.0.0", "mime-types": "~2.0.1", "node-uuid": "~1.4.0", From c6657dfc23fc154d864e89e3d9fffaba390f7ea6 Mon Sep 17 00:00:00 2001 From: simov Date: Tue, 16 Jun 2015 12:34:34 +0300 Subject: [PATCH 128/490] Fix OAuth docs - closes #1632 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b5d9df650..8530d1054 100644 --- a/README.md +++ b/README.md @@ -411,7 +411,7 @@ request.post({url:url, oauth:oauth}, function (e, r, body) { , user_id: perm_data.user_id } ; - request.get({url:url, oauth:oauth, json:true}, function (e, r, user) { + request.get({url:url, oauth:oauth, qs:qs, json:true}, function (e, r, user) { console.log(user) }) }) From 422904fff031c3c2f39c569fc3bc2cbb6c9691cd Mon Sep 17 00:00:00 2001 From: simov Date: Tue, 16 Jun 2015 14:25:56 +0300 Subject: [PATCH 129/490] 2.58.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e5fa62c0e..ed0822461 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.57.1", + "version": "2.58.0", "author": "Mikeal Rogers ", "repository": { "type": "git", From ab40f9e61f813f9cc68257c17621b7879561486c Mon Sep 17 00:00:00 2001 From: simov Date: Tue, 16 Jun 2015 14:27:45 +0300 Subject: [PATCH 130/490] Update changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2de0061ad..6b3905edb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ ## Change Log +### v2.58.0 (2015/06/16) +- [#1638](https://github.com/request/request/pull/1638) Use the `extend` module to deep extend in the defaults method (@simov) +- [#1631](https://github.com/request/request/pull/1631) Move tunnel logic into separate module (@simov) +- [#1634](https://github.com/request/request/pull/1634) Fix OAuth query transport_method (@simov) +- [#1603](https://github.com/request/request/pull/1603) Add codecov (@simov) + ### v2.57.0 (2015/05/31) - [#1615](https://github.com/request/request/pull/1615) Replace '.client' with '.socket' as the former was deprecated in 2.2.0. (@ChALkeR) From f0c4ec061141051988d1216c24936ad2e7d5c45d Mon Sep 17 00:00:00 2001 From: simov Date: Tue, 16 Jun 2015 14:28:12 +0300 Subject: [PATCH 131/490] 2.58.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ed0822461..03350096d 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.58.0", + "version": "2.58.1", "author": "Mikeal Rogers ", "repository": { "type": "git", From 17274790f4c4a7b4f01886d1fbd1b11437ea9621 Mon Sep 17 00:00:00 2001 From: Jeffrey Charles Date: Wed, 17 Jun 2015 10:54:31 -0400 Subject: [PATCH 132/490] Clarify the nature of setting `ca` in `agentOptions` The `ca` option in https://nodejs.org/api/tls.html#tls_tls_connect_options_callback indicates that the certificate presented must be signed by one of the certificates provided. The existing wording in request led me to believe that setting it augmented the list of acceptable certificates rather than replacing it. --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8530d1054..d033aeb96 100644 --- a/README.md +++ b/README.md @@ -646,7 +646,8 @@ request.get({ It is possible to accept other certificates than those signed by generally allowed Certificate Authorities (CAs). This can be useful, for example, when using self-signed certificates. -To allow a different certificate, you can specify the signing CA by adding the contents of the CA's certificate file to the `agentOptions`: +To require a different root certificate, you can specify the signing CA by adding the contents of the CA's certificate file to the `agentOptions`. +The certificate the domain presents must be signed by the root certificate specified: ```js request.get({ From 86571c794b75bb637b39eb7574e825e461647151 Mon Sep 17 00:00:00 2001 From: simov Date: Sun, 21 Jun 2015 21:29:32 +0300 Subject: [PATCH 133/490] Allow content-type overriding when using the `form` option --- request.js | 4 +++- tests/test-form-urlencoded.js | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/request.js b/request.js index c032ea8f6..7384cf6bb 100644 --- a/request.js +++ b/request.js @@ -1145,7 +1145,9 @@ Request.prototype.qs = function (q, clobber) { Request.prototype.form = function (form) { var self = this if (form) { - self.setHeader('content-type', 'application/x-www-form-urlencoded') + if (!/^application\/x-www-form-urlencoded\b/.test(self.getHeader('content-type'))) { + self.setHeader('content-type', 'application/x-www-form-urlencoded') + } self.body = (typeof form === 'string') ? self._qs.rfc3986(form.toString('utf8')) : self._qs.stringify(form).toString('utf8') diff --git a/tests/test-form-urlencoded.js b/tests/test-form-urlencoded.js index ae2f17182..2d069933d 100644 --- a/tests/test-form-urlencoded.js +++ b/tests/test-form-urlencoded.js @@ -5,11 +5,15 @@ var http = require('http') , tape = require('tape') -function runTest (t, options) { +function runTest (t, options, index) { var server = http.createServer(function(req, res) { - t.ok(req.headers['content-type'].match(/application\/x-www-form-urlencoded/)) + if (index === 0) { + t.equal(req.headers['content-type'], 'application/x-www-form-urlencoded') + } else { + t.equal(req.headers['content-type'], 'application/x-www-form-urlencoded; charset=UTF-8') + } t.equal(req.headers.accept, 'application/json') var data = '' @@ -45,6 +49,11 @@ var cases = [ form: {some: 'url', encoded: 'data'}, json: true }, + { + headers: {'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'}, + form: {some: 'url', encoded: 'data'}, + json: true + }, { headers: {'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'}, body: 'some=url&encoded=data', @@ -54,6 +63,6 @@ var cases = [ cases.forEach(function (options, index) { tape('application/x-www-form-urlencoded ' + index, function(t) { - runTest(t, options) + runTest(t, options, index) }) }) From 66c0fe9726825550563ed0e3dbfe667ec00a6d92 Mon Sep 17 00:00:00 2001 From: simov Date: Mon, 22 Jun 2015 13:13:05 +0300 Subject: [PATCH 134/490] Preserve HEAD method when using followAllRedirects --- lib/redirect.js | 3 ++- tests/test-redirect.js | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/redirect.js b/lib/redirect.js index 1d4650299..b2d0f613a 100644 --- a/lib/redirect.js +++ b/lib/redirect.js @@ -113,7 +113,8 @@ Redirect.prototype.onResponse = function (response) { , redirectUri: redirectTo } ) - if (self.followAllRedirects && response.statusCode !== 401 && response.statusCode !== 307) { + if (self.followAllRedirects && request.method !== 'HEAD' + && response.statusCode !== 401 && response.statusCode !== 307) { request.method = 'GET' } // request.method = 'GET' // Force all redirects to use GET || commented out fixes #215 diff --git a/tests/test-redirect.js b/tests/test-redirect.js index 096229dba..ee8661889 100644 --- a/tests/test-redirect.js +++ b/tests/test-redirect.js @@ -39,7 +39,7 @@ function createLandingEndpoint(landing) { // Make sure cookies are set properly after redirect assert.equal(req.headers.cookie, 'foo=bar; quux=baz; ham=eggs') hits[landing] = true - res.writeHead(200) + res.writeHead(200, {'x-response': req.method.toUpperCase() + ' ' + landing}) res.end(req.method.toUpperCase() + ' ' + landing) }) } @@ -97,6 +97,25 @@ tape('permanent bounce', function(t) { }) }) +tape('preserve HEAD method when using followAllRedirects', function(t) { + jar.setCookie('quux=baz', s.url) + hits = {} + request({ + method: 'HEAD', + uri: s.url + '/perm', + followAllRedirects: true, + jar: jar, + headers: { cookie: 'foo=bar' } + }, function(err, res, body) { + t.equal(err, null) + t.equal(res.statusCode, 200) + t.ok(hits.perm, 'Original request is to /perm') + t.ok(hits.perm_landing, 'Forward to permanent landing URL') + t.equal(res.headers['x-response'], 'HEAD perm_landing', 'Got permanent landing content') + t.end() + }) +}) + tape('temporary bounce', function(t) { hits = {} request({ From 2127aa3b4395f6b522f9530ac1f79d8343b7d05f Mon Sep 17 00:00:00 2001 From: simov Date: Mon, 22 Jun 2015 20:24:41 +0300 Subject: [PATCH 135/490] Add function for setting up the content-length --- request.js | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/request.js b/request.js index c032ea8f6..aa3ee4960 100644 --- a/request.js +++ b/request.js @@ -430,28 +430,24 @@ Request.prototype.init = function (options) { self.elapsedTime = self.elapsedTime || 0 } - if (self.body) { - var length = 0 - if (!Buffer.isBuffer(self.body)) { - if (Array.isArray(self.body)) { - for (var i = 0; i < self.body.length; i++) { - length += self.body[i].length - } - } else { - self.body = new Buffer(self.body) - length = self.body.length - } - } else { - length = self.body.length + function setContentLength () { + if (!Buffer.isBuffer(self.body) && !Array.isArray(self.body)) { + self.body = new Buffer(self.body) } - if (length) { - if (!self.hasHeader('content-length')) { + 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 + if (length) { self.setHeader('content-length', length) + } else { + self.emit('error', new Error('Argument error, options.body.')) } - } else { - self.emit('error', new Error('Argument error, options.body.')) } } + if (self.body) { + setContentLength() + } if (options.oauth) { self.oauth(options.oauth) @@ -541,6 +537,7 @@ Request.prototype.init = function (options) { self._multipart.body.pipe(self) } if (self.body) { + setContentLength() if (Array.isArray(self.body)) { self.body.forEach(function (part) { self.write(part) From 8baa3306e80b7ba8c78ba47087d2892c372e94b4 Mon Sep 17 00:00:00 2001 From: Dan Nissenbaum Date: Mon, 22 Jun 2015 14:35:08 -0400 Subject: [PATCH 136/490] Update README.md The documentation for the 'encoding : null' argument does not emphasize that this is necessary for binary response data. See http://stackoverflow.com/a/14855016/368896. I've added a parenthetical comment to emphasize this in the documentation. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d033aeb96..e5a686bc6 100644 --- a/README.md +++ b/README.md @@ -766,7 +766,7 @@ The first argument can be either a `url` or an `options` object. The only requir --- -- `encoding` - Encoding to be used on `setEncoding` of response data. If `null`, the `body` is returned as a `Buffer`. Anything else **(including the default value of `undefined`)** will be passed as the [encoding](http://nodejs.org/api/buffer.html#buffer_buffer) parameter to `toString()` (meaning this is effectively `utf8` by default). +- `encoding` - Encoding to be used on `setEncoding` of response data. If `null`, the `body` is returned as a `Buffer`. Anything else **(including the default value of `undefined`)** will be passed as the [encoding](http://nodejs.org/api/buffer.html#buffer_buffer) parameter to `toString()` (meaning this is effectively `utf8` by default). (Warning: This means that if the body of the response is binary data - for example, image data or raw data representing a PDF - you **must** set `encoding: null`.) - `gzip` - If `true`, add an `Accept-Encoding` header to request compressed content encodings from the server (if not already present) and decode supported content encodings in the response. **Note:** Automatic decoding of the response content is performed on the body data returned through `request` (both through the `request` stream and passed to the callback function) but is not performed on the `response` stream (available from the `response` event) which is the unmodified `http.IncomingMessage` object which may contain compressed data. See example below. - `jar` - If `true` and `tough-cookie` is installed, remember cookies for future use (or define your custom cookie jar; see examples section) From 986723e2992e8de83c92ceaa46224780542f3caf Mon Sep 17 00:00:00 2001 From: simov Date: Tue, 23 Jun 2015 11:32:16 +0300 Subject: [PATCH 137/490] Add test for setting up the body via the .form() method --- tests/test-form-urlencoded.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/test-form-urlencoded.js b/tests/test-form-urlencoded.js index 2d069933d..fdb283411 100644 --- a/tests/test-form-urlencoded.js +++ b/tests/test-form-urlencoded.js @@ -9,11 +9,12 @@ function runTest (t, options, index) { var server = http.createServer(function(req, res) { - if (index === 0) { + if (index === 0 || index === 3) { t.equal(req.headers['content-type'], 'application/x-www-form-urlencoded') } else { t.equal(req.headers['content-type'], 'application/x-www-form-urlencoded; charset=UTF-8') } + t.equal(req.headers['content-length'], '21') t.equal(req.headers.accept, 'application/json') var data = '' @@ -33,7 +34,7 @@ function runTest (t, options, index) { server.listen(6767, function() { - request.post('http://localhost:6767', options, function(err, res, body) { + var r = request.post('http://localhost:6767', options, function(err, res, body) { t.equal(err, null) t.equal(res.statusCode, 200) t.equal(body, 'done') @@ -41,6 +42,9 @@ function runTest (t, options, index) { t.end() }) }) + if (!options.form && !options.body) { + r.form({some: 'url', encoded: 'data'}) + } }) } @@ -58,6 +62,10 @@ var cases = [ headers: {'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'}, body: 'some=url&encoded=data', json: true + }, + { + // body set via .form() method + json: true } ] From 9978a480ec17dde8688a1ca6e01b4f130a1cf6de Mon Sep 17 00:00:00 2001 From: Dan Nissenbaum Date: Tue, 23 Jun 2015 09:39:23 -0400 Subject: [PATCH 138/490] Update README.md Consolidated warning about binary data and `encoding: null`. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e5a686bc6..21e6d79dc 100644 --- a/README.md +++ b/README.md @@ -766,7 +766,7 @@ The first argument can be either a `url` or an `options` object. The only requir --- -- `encoding` - Encoding to be used on `setEncoding` of response data. If `null`, the `body` is returned as a `Buffer`. Anything else **(including the default value of `undefined`)** will be passed as the [encoding](http://nodejs.org/api/buffer.html#buffer_buffer) parameter to `toString()` (meaning this is effectively `utf8` by default). (Warning: This means that if the body of the response is binary data - for example, image data or raw data representing a PDF - you **must** set `encoding: null`.) +- `encoding` - Encoding to be used on `setEncoding` of response data. If `null`, the `body` is returned as a `Buffer`. Anything else **(including the default value of `undefined`)** will be passed as the [encoding](http://nodejs.org/api/buffer.html#buffer_buffer) parameter to `toString()` (meaning this is effectively `utf8` by default). (**Note:** if you expect binary data, you should set `encoding: null`.) - `gzip` - If `true`, add an `Accept-Encoding` header to request compressed content encodings from the server (if not already present) and decode supported content encodings in the response. **Note:** Automatic decoding of the response content is performed on the body data returned through `request` (both through the `request` stream and passed to the callback function) but is not performed on the `response` stream (available from the `response` event) which is the unmodified `http.IncomingMessage` object which may contain compressed data. See example below. - `jar` - If `true` and `tough-cookie` is installed, remember cookies for future use (or define your custom cookie jar; see examples section) From 2ca06330c9e8d438b07c9efd9a077303d2e59ec8 Mon Sep 17 00:00:00 2001 From: simov Date: Tue, 30 Jun 2015 10:27:08 +0300 Subject: [PATCH 139/490] Update certificates --- tests/ssl/ca/client-enc.key | 52 ++++++++++++++++++------------------- tests/ssl/ca/client.crt | 22 ++++++++-------- tests/ssl/ca/client.csr | 26 +++++++++---------- tests/ssl/ca/client.key | 50 +++++++++++++++++------------------ tests/ssl/ca/localhost.crt | 22 ++++++++-------- tests/ssl/ca/localhost.csr | 26 +++++++++---------- tests/ssl/ca/localhost.key | 50 +++++++++++++++++------------------ 7 files changed, 124 insertions(+), 124 deletions(-) diff --git a/tests/ssl/ca/client-enc.key b/tests/ssl/ca/client-enc.key index 2e8d7f40d..308f638c3 100644 --- a/tests/ssl/ca/client-enc.key +++ b/tests/ssl/ca/client-enc.key @@ -1,30 +1,30 @@ -----BEGIN RSA PRIVATE KEY----- Proc-Type: 4,ENCRYPTED -DEK-Info: AES-128-CBC,6C31267B8D3AF32D4F73B2E751233B50 +DEK-Info: AES-128-CBC,374F554A54A7BDBAF97E9CDF43F02731 -jOFSbFzYf708vqvNLiBLZiWOdeBRrbH2GU0mNfYvWRqNk/nSqL81A28XpWygzZHk -7xR47ZzEdzdOamam7q0pdZNHfGC5wVOgIBq1LOK97o+Ef1XSLxOAToIvHjAyo1ow -IoYXc68xGRdVq7qIMaTP7VusKwXZiU/ki0+kRNINTMX7Odpug+n8xbumoKpgaSeU -a/0Tz76y7g74md4JeHPTtilhjnTCC02zPR8ehucszkPr6a48E3tLlnOiSyRXnKL2 -O6eXoH5zoFaOOHTQCoW5fFQXZtsjl2vWt0MfZtQbxKOEJvA6cpJBGGPgDv+mHXLv -ywK5w1LE+JI02BK90bDCJ55efVXte4yBFEGy4flz43hE/kpeF5+DL6CwAi9wtIEu -a1CsbCIt9d60NN6HKXrw1UttrbtjHtGssUNfaiIJ8XH/OxAlN6ndKWxmLea3gvEy -8ONrLnJOf9w7T+n4JcAnqM0Av3dDR41hY0gNzXuFxp04cz8fffkHyjb703MkH8i0 -ByzG/9b6wcvbUjfiT68e4ziirkOPlyfASRW4bvznQ/OGVS78mpVNyJq4gd0pAYZ2 -GqfFUKdHM+iM5nUVjjvjkH89IbFmRN1L5BeY6cavHacY8Cz4n2ZGzYz4CUA6068P -Dh7YThpiuMRGGC428afJmS4P+Rmld7MKB4j2eVOIQM0NSjpPMK00hh5NQtaXeA1F -doow9zCNpRcN8KReUafo/mxP68ueDymVHi0N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w4KeeY188fcYkIvxUCQRI3/m4lG/XWRXWxukoFbj +hT/5QVxnCjq47hnnb7spJnfyOFK3U/oFPgT4J25UQU4UuY5MIlcFz9I1wbMNGd+J +pNEmBvjtZiLh/W4o/j1+Qt353ASvGrpVoLPktVJbQxwGBeT9QLrmEZInm6vXKCxt +JmlTI0vWVq3fCNHvANhJALWQfI8IFzpDk7zjo/+QKzAg8H4Sqfi6xYqDbN2nxIjS +/gCZEzuBrKeBIyt+U8ZYta2lCnY2kXeNCYR+NNFd3wgfact+d4yrS+69AShuWwcf +MqAW32QRYKqjOGboly9ByUEHjB5afJmzW1DmowU3kPPja99dANureR20oHsKCza9 -----END RSA PRIVATE KEY----- diff --git a/tests/ssl/ca/client.crt b/tests/ssl/ca/client.crt index fe8610067..7880c55ae 100644 --- a/tests/ssl/ca/client.crt +++ b/tests/ssl/ca/client.crt @@ -3,18 +3,18 @@ MIIDLjCCApcCCQCt9iAWqkDJwzANBgkqhkiG9w0BAQsFADCBojELMAkGA1UEBhMC VVMxCzAJBgNVBAgTAkNBMRAwDgYDVQQHEwdPYWtsYW5kMRAwDgYDVQQKEwdyZXF1 ZXN0MSYwJAYDVQQLEx1yZXF1ZXN0IENlcnRpZmljYXRlIEF1dGhvcml0eTESMBAG A1UEAxMJcmVxdWVzdENBMSYwJAYJKoZIhvcNAQkBFhdtaWtlYWxAbWlrZWFscm9n -ZXJzLmNvbTAeFw0xNTA1MjgwODQwNTVaFw0xNTA2MjcwODQwNTVaMIGPMQswCQYD +ZXJzLmNvbTAeFw0xNTA2MzAwNzI0MzhaFw0xNTA3MzAwNzI0MzhaMIGPMQswCQYD VQQGEwJVUzELMAkGA1UECBMCQ0ExEDAOBgNVBAcTB09ha2xhbmQxEDAOBgNVBAoT B3JlcXVlc3QxGjAYBgNVBAsUEXJlcXVlc3RAbG9jYWxob3N0MRMwEQYDVQQDEwpU ZXN0Q2xpZW50MR4wHAYJKoZIhvcNAQkBFg9kby5ub3RAZW1haWwubWUwggEiMA0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ZpuCQyNfODFRpiityrDT/m0OFFrJeAZbuT0Fv5+ZYPS1pQG +kzdi16Vgez8dsZKYMZgn+VcL/c1ehugM4844y/WesS1x19JAdv1eebuU+gbsNHbB ++Wc= -----END CERTIFICATE----- diff --git a/tests/ssl/ca/client.csr b/tests/ssl/ca/client.csr index ed1df4870..e3580182f 100644 --- a/tests/ssl/ca/client.csr +++ b/tests/ssl/ca/client.csr @@ -2,17 +2,17 @@ MIIC+DCCAeACAQAwgY8xCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJDQTEQMA4GA1UE BxMHT2FrbGFuZDEQMA4GA1UEChMHcmVxdWVzdDEaMBgGA1UECxQRcmVxdWVzdEBs b2NhbGhvc3QxEzARBgNVBAMTClRlc3RDbGllbnQxHjAcBgkqhkiG9w0BCQEWD2Rv -Lm5vdEBlbWFpbC5tZTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMdy -4OyQ4gf7UmtjP2oB/q+lj8O0Y3a2X8/0ZFJBusuEb59d33IT67Wr4zrkak0trpKT -YKdrOWeQQ1wMWVgCgHwZQUgBIbOXruKHH7gPOrK24S0yY8l3PAqYn6AduiXyFBWq -41vHTg71XAA4X+L7vBR/ywaeBuRLeCBVPLW64EA+TPQmSiL5zFh9jkT2HEZW5cl2 -yw/QgXRodh0ZsfWd19aTlB8x1hzNlec6m6s1WctldCu/xNjnmMnSVyPIUsO5Vi9E -E7g7cy52H41XZd8vEdAcbtOf8J+OaX1bKClhIB5iCPj5mxJVIdPQYYlLWSmVMlqo -EVSai7pZODMmGeFxgOcCAwEAAaAjMCEGCSqGSIb3DQEJBzEUExJwYXNzd29yZCBj -aGFsbGVuZ2UwDQYJKoZIhvcNAQELBQADggEBACch/zWTz2YwWKZ3yz9JhGf4prrt -k2OAnpILVCXqe38peZlKYXYoP1H2ulKuyI3y6CZb2nvY/hXUfvDkJI+Xt916f3YM -N0EVKpzIoi5vjooLbyDIHFDtaRDmQJoV7u95bHNu3PL2lZNVXHHpg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ca/client.key b/tests/ssl/ca/client.key index d20b79329..af537fa92 100644 --- a/tests/ssl/ca/client.key +++ b/tests/ssl/ca/client.key @@ -1,27 +1,27 @@ -----BEGIN RSA PRIVATE KEY----- -MIIEowIBAAKCAQEAx3Lg7JDiB/tSa2M/agH+r6WPw7RjdrZfz/RkUkG6y4Rvn13f -chPrtavjOuRqTS2ukpNgp2s5Z5BDXAxZWAKAfBlBSAEhs5eu4ocfuA86srbhLTJj -yXc8CpifoB26JfIUFarjW8dODvVcADhf4vu8FH/LBp4G5Et4IFU8tbrgQD5M9CZK -IvnMWH2ORPYcRlblyXbLD9CBdGh2HRmx9Z3X1pOUHzHWHM2V5zqbqzVZy2V0K7/E -2OeYydJXI8hSw7lWL0QTuDtzLnYfjVdl3y8R0Bxu05/wn45pfVsoKWEgHmII+Pmb -ElUh09BhiUtZKZUyWqgRVJqLulk4MyYZ4XGA5wIDAQABAoIBACyXJmo9Sgt2yMpx -ee/9Wi9y2F1sqwATbgBUJ0msoFJ33WzH0/jxMzV+pGK6RnnSyMDEakuD0WWx/x1J -NYBTrt4P12R9vEcmllbW1uSTow/pixZLubuFCMtlq+pkOwXYxVzCw+n0+SKnAFac -Q/O/TCFZIM7t7aSEquqvo88NZK132ybcftBHMKxOGawfQ8xT8QhCr0vnRuZMfA46 -DtnNebH+mOaJvnQPgb7ev0UFdSa4fHdgy7qFjULglFxkdEcZdPVNuosQz9GRdIj7 -sd9PCmakVkN5myGZh0+k1cfkDVjnoaGJ54u76HRO0OeO76faWTwxqwW9YmOYwJuW -f5Xv6OECgYEA6wrwbqZe6uVtumgAdozP2D8940yh0F3FRW4U16CzrLjG0VEFoDRD -dIRHV964yvonatWrW9wFBOghrduDBiJ6DKF++404DhGh19/atLxMBj+QMz1OK0Kh -v/2zMDkg50t4wURjtX/2T/vXQnS+gk5LwKHbwXG+fY/ClKbJ4jhIdlUCgYEA2Tt5 -jLWZQbGz9co2kyRATWoCQrYjZAtTi+j9N1rrXYPU0UCaaCBYjFf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w6IJM+a +Mi+qR8HeYJ4o++/oIYnA+Zm24y2X9l0XflTg1x7yJ6Xj8tXUaoUID3q1cWBkbiVK +ggIINASJUAYcCNFwMdAyg0pmy8ewHW5+/w3AwQ4UpfkOfoV7lToy9NE= -----END RSA PRIVATE KEY----- diff --git a/tests/ssl/ca/localhost.crt b/tests/ssl/ca/localhost.crt index 920845529..f526649d5 100644 --- a/tests/ssl/ca/localhost.crt +++ b/tests/ssl/ca/localhost.crt @@ -3,18 +3,18 @@ MIIDLTCCApYCCQCt9iAWqkDJwzANBgkqhkiG9w0BAQsFADCBojELMAkGA1UEBhMC VVMxCzAJBgNVBAgTAkNBMRAwDgYDVQQHEwdPYWtsYW5kMRAwDgYDVQQKEwdyZXF1 ZXN0MSYwJAYDVQQLEx1yZXF1ZXN0IENlcnRpZmljYXRlIEF1dGhvcml0eTESMBAG A1UEAxMJcmVxdWVzdENBMSYwJAYJKoZIhvcNAQkBFhdtaWtlYWxAbWlrZWFscm9n -ZXJzLmNvbTAeFw0xNTA1MjgwODQxNDNaFw0xNTA2MjcwODQxNDNaMIGOMQswCQYD +ZXJzLmNvbTAeFw0xNTA2MzAwNzI0NTNaFw0xNTA3MzAwNzI0NTNaMIGOMQswCQYD VQQGEwJVUzELMAkGA1UECBMCQ0ExEDAOBgNVBAcTB09ha2xhbmQxEDAOBgNVBAoT B3JlcXVlc3QxGjAYBgNVBAsUEXJlcXVlc3RAbG9jYWxob3N0MRIwEAYDVQQDEwls b2NhbGhvc3QxHjAcBgkqhkiG9w0BCQEWD2RvLm5vdEBlbWFpbC5tZTCCASIwDQYJ -KoZIhvcNAQEBBQADggEPADCCAQoCggEBANhbOLcJncdyjcKno/YMiPS4jnibv3Yc -caYCgHGeu8K/hJikfI5ExLGb8DV/vjgBKZOtQ2ZqsO2uwqysxBthumq6Dy+iddc/ -b3FxEN+lNnJr7riIg8k9ET5v5tmzg8zWeQgO4rzPjjrfVV4Etm95u3/4b8AD5EmG -iiMSdciNLtOja+csOUz9+kza+/RC9dz/TKTNBLS9bTiA1tH9gdrbDfqdzSxAKObE -JOvNUBM5ll0g26Mg7uoJa4HuMRI8f9ifsEhgEUJKjKNTDTdOEQAj8foeVPkofq2d -ZbLv9DbkjFR8pC0Ax6DaYJEHCI5ixDPPMpTQgAxeHlYO4zSfhSavskcCAwEAATAN -BgkqhkiG9w0BAQsFAAOBgQCgK2mq6rX4C1mdD6kQ/AucqpXivlO2mMqOsp8udWcN -ymFZbjvTYgpUA8fxmiM2xfkdwrSS9ei2u6WVSR0jQdsm6vRnvFx8A+lrbQzvKLSL -pj/5I4e2D9sZruLWw3LCPURSirNObvkE1dKuOauLRlLKSYCeOp33Hfkc+375zQU0 -Pg== +KoZIhvcNAQEBBQADggEPADCCAQoCggEBANOpX00BXKdXYmU69Xhg7YRpg/PmbH1j +yCvc/rhgLUg7zHK2dckdZch5GoQnTMwA7EALgLeFGNSIpeRlaZaqOzy9DCSL8d1D +YmIxBsywk/QCSwOTE2f2CgLNwRAY9568hAVoXdVnBSEPJQaJDK/MHkDYdY4O0Ou1 +wjiaOaze5vf/b1rYvmWxwY46d71/ykIK/6DzVQDrCOOeegsYZAY0FEI23RZqE10X +hxLQg5VJT7nd4FHQw2Y2qmPznjtxQ8dkFCz3JlfClECjG0Z5GTvGRVfAL04k2H12 +aGETbDkkAaAsieNugFkphnbeAgguzfQGDFZjPI6RNSZnRiVIpoSkTa0CAwEAATAN +BgkqhkiG9w0BAQsFAAOBgQAnkyp4oivuflGQYarlXvepZzVnmC2ox8Dwxa/hNVsi +jiJzBdpUEaUqLTlTpYiJr6fEvAfP5WRW1HoLVCIQMvg1ieav+zMfbMf4ftv5zBIe +XwMaQB3NDb+3zzVTdN4J2OWh1tRvVp1/x7wAn3tQKq2+80aUKScTfvguaPUJrUGr +TQ== -----END CERTIFICATE----- diff --git a/tests/ssl/ca/localhost.csr b/tests/ssl/ca/localhost.csr index c3a954346..8a20ca42d 100644 --- a/tests/ssl/ca/localhost.csr +++ b/tests/ssl/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YWlsLm1lMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA06lf +TQFcp1diZTr1eGDthGmD8+ZsfWPIK9z+uGAtSDvMcrZ1yR1lyHkahCdMzADsQAuA +t4UY1Iil5GVplqo7PL0MJIvx3UNiYjEGzLCT9AJLA5MTZ/YKAs3BEBj3nryEBWhd +1WcFIQ8lBokMr8weQNh1jg7Q67XCOJo5rN7m9/9vWti+ZbHBjjp3vX/KQgr/oPNV +AOsI4556CxhkBjQUQjbdFmoTXReHEtCDlUlPud3gUdDDZjaqY/OeO3FDx2QULPcm +V8KUQKMbRnkZO8ZFV8AvTiTYfXZoYRNsOSQBoCyJ426AWSmGdt4CCC7N9AYMVmM8 +jpE1JmdGJUimhKRNrQIDAQABoCMwIQYJKoZIhvcNAQkHMRQTEnBhc3N3b3JkIGNo +YWxsZW5nZTANBgkqhkiG9w0BAQsFAAOCAQEARE+429XzAqsuPZxA2aLEu3SXLsmC +RctPBzlpXlljqwFjt8HmclvP1Y2RfB8OvsTXid0yKqWyn5aIPwXnfsGrb31IfRyy +nZxaREHlkiZzvur2Rks2jB7bjnkOiOk2BnuDNWYrc5waNi7G8gjxp3hMK1RoLtoI +aKZeF+omzGCkcAYhnrdPCnKv6yrmq7akg9CT6V82MAzT+N2I8jGD4GfPmZ77u3F1 +LsqgiW2dcJxlDdyHhqDXgsYjQDvrJWzb81KIHZboFDpB0D0Zu4sA9Y7uWn1y60Uy +TMKhG3FQDOsO+5CJzQh6moOCILWgGgt+H9T4K32Ax7PP7ruYBOUll6ULRw== -----END CERTIFICATE REQUEST----- diff --git a/tests/ssl/ca/localhost.key b/tests/ssl/ca/localhost.key index f4fa70fd4..96119a7fb 100644 --- a/tests/ssl/ca/localhost.key +++ b/tests/ssl/ca/localhost.key @@ -1,27 +1,27 @@ -----BEGIN RSA PRIVATE KEY----- -MIIEowIBAAKCAQEA2Fs4twmdx3KNwqej9gyI9LiOeJu/dhxxpgKAcZ67wr+EmKR8 -jkT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ep 17 00:00:00 2001 From: Deam Date: Sat, 4 Jul 2015 13:03:13 +0200 Subject: [PATCH 140/490] updated dependencies --- package.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 03350096d..e2996666f 100644 --- a/package.json +++ b/package.json @@ -22,20 +22,20 @@ }, "main": "index.js", "dependencies": { - "bl": "~0.9.0", - "caseless": "~0.10.0", - "extend": "~2.0.1", + "bl": "~1.0.0", + "caseless": "~0.11.0", + "extend": "~3.0.0", "forever-agent": "~0.6.0", "form-data": "~1.0.0-rc1", "json-stringify-safe": "~5.0.0", - "mime-types": "~2.0.1", + "mime-types": "~2.1.2", "node-uuid": "~1.4.0", - "qs": "~3.1.0", + "qs": "~4.0.0", "tunnel-agent": "~0.4.0", "tough-cookie": ">=0.12.0", "http-signature": "~0.11.0", "oauth-sign": "~0.8.0", - "hawk": "~2.3.0", + "hawk": "~3.1.0", "aws-sign2": "~0.5.0", "stringstream": "~0.0.4", "combined-stream": "~1.0.1", From 5cdfe8efbb4e54613214555ecfa9d1f7fb28e336 Mon Sep 17 00:00:00 2001 From: simov Date: Fri, 10 Jul 2015 17:30:56 +0300 Subject: [PATCH 141/490] Add tests and docs for using the agent, agentClass and agentOptions Forever option defaults to using http(s).Agent in node 0.12+ --- README.md | 13 +++--- lib/helpers.js | 10 +++++ request.js | 13 +++++- tests/test-agent.js | 99 ++++++++++++++++++++++++++++++++++++++------- 4 files changed, 114 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 21e6d79dc..77e3e1e27 100644 --- a/README.md +++ b/README.md @@ -772,7 +772,11 @@ The first argument can be either a `url` or an `options` object. The only requir --- -- `pool` - An object describing which agents to use for the request. If this option is omitted the request will use the global agent (as long as [your options allow for it](request.js#L747)). Otherwise, request will search the pool for your custom agent. If no custom agent is found, a new agent will be created and added to the pool. +- `agent` - `http(s).Agent` instance to use +- `agentClass` - alternatively specify your agent's class name +- `agentOptions` - and pass its options. **Note:** for HTTPS see [tls API doc for TLS/SSL options](http://nodejs.org/api/tls.html#tls_tls_connect_options_callback) and the [documentation above](#using-optionsagentoptions). +- `forever` - set to `true` to use the [forever-agent](https://github.com/request/forever-agent) **Use only with node 0.10-** +- `pool` - An object describing which agents to use for the request. If this option is omitted the request will use the global agent (as long as your options allow for it). Otherwise, request will search the pool for your custom agent. If no custom agent is found, a new agent will be created and added to the pool. **Note:** `pool` is used only when the `agent` option is not specified. - A `maxSockets` property can also be provided on the `pool` object to set the max number of sockets for all agents created (ex: `pool: {maxSockets: Infinity}`). - Note that if you are sending multiple requests in a loop and creating multiple new `pool` objects, `maxSockets` will not work as intended. To @@ -783,10 +787,12 @@ The first argument can be either a `url` or an `options` object. The only requir 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)). + +--- + - `localAddress` - Local interface to bind for network connections. - `proxy` - An HTTP proxy to be used. Supports proxy Auth with Basic Auth, identical to support for the `url` parameter (by embedding the auth info in the `uri`) - `strictSSL` - If `true`, requires SSL certificates be valid. **Note:** to use your own certificate authority, you need to specify an agent that was created with that CA as an option. -- `agentOptions` - Object containing user agent options. See documentation above. **Note:** [see tls API doc for TLS/SSL options](http://nodejs.org/api/tls.html#tls_tls_connect_options_callback). - `tunnel` - controls the behavior of [HTTP `CONNECT` tunneling](https://en.wikipedia.org/wiki/HTTP_tunnel#HTTP_CONNECT_tunneling) as follows: @@ -803,9 +809,6 @@ The first argument can be either a `url` or an `options` object. The only requir --- - `time` - If `true`, the request-response cycle (including all redirects) is timed at millisecond resolution, and the result provided on the response's `elapsedTime` property. - ---- - - `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)* The callback argument gets 3 arguments: diff --git a/lib/helpers.js b/lib/helpers.js index 5cc79da86..5e8594606 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -54,6 +54,15 @@ function copy (obj) { return o } +function version () { + var numbers = process.version.replace('v', '').split('.') + return { + major: parseInt(numbers[0], 10), + minor: parseInt(numbers[1], 10), + patch: parseInt(numbers[2], 10) + } +} + exports.isFunction = isFunction exports.paramsHaveRequestBody = paramsHaveRequestBody exports.safeStringify = safeStringify @@ -61,4 +70,5 @@ exports.md5 = md5 exports.isReadStream = isReadStream exports.toBase64 = toBase64 exports.copy = copy +exports.version = version exports.defer = deferMethod() diff --git a/request.js b/request.js index e61db5e1b..3664f9ea3 100644 --- a/request.js +++ b/request.js @@ -31,6 +31,7 @@ var safeStringify = helpers.safeStringify , toBase64 = helpers.toBase64 , defer = helpers.defer , copy = helpers.copy + , version = helpers.version , globalCookieJar = cookies.jar() @@ -477,7 +478,17 @@ Request.prototype.init = function (options) { if (options.agentClass) { self.agentClass = options.agentClass } else if (options.forever) { - self.agentClass = protocol === 'http:' ? ForeverAgent : ForeverAgent.SSL + var v = version() + // use ForeverAgent in node 0.10- only + if (v.major === 0 && v.minor <= 10) { + self.agentClass = protocol === 'http:' ? ForeverAgent : ForeverAgent.SSL + } else { + console.warn('The forever option defaults to using http(s).Agent in 0.12+') + self.agent = new self.httpModule.Agent({ + keepAlive: true, + maxSockets: (options.pool && options.pool.maxSockets) || Infinity + }) + } } else { self.agentClass = self.httpModule.Agent } diff --git a/tests/test-agent.js b/tests/test-agent.js index cca03d410..8d18d35c6 100644 --- a/tests/test-agent.js +++ b/tests/test-agent.js @@ -1,34 +1,103 @@ 'use strict' var request = require('../index') - , http = require('http') - , tape = require('tape') + , version = require('../lib/helpers').version + , http = require('http') + , ForeverAgent = require('forever-agent') + , tape = require('tape') -var s = http.createServer(function(req, res) { +var s = http.createServer(function (req, res) { res.statusCode = 200 - res.end('ok') + res.end() }) -tape('setup', function(t) { +tape('setup', function (t) { s.listen(6767, function() { t.end() }) }) -tape('should work with forever agent', function(t) { - var r = request.forever({maxSockets: 1}) +function httpAgent (t, options, req) { + var r = (req || request)(options, function (_err, res, body) { - r({ - url: 'http://localhost:6767', - headers: { 'Connection':'Close' } - }, function(err, resp, body) { - t.equal(err, null) - t.equal(body, 'ok') - t.end() + t.ok(r.agent instanceof http.Agent, 'is http.Agent') + t.equal(r.agent.options.keepAlive, true, 'is keepAlive') + t.equal(Object.keys(r.agent.sockets).length, 1, '1 socket name') + + var name = (typeof r.agent.getName === 'function') + ? r.agent.getName({port:6767}) + : 'localhost:6767' // node 0.10- + t.equal(r.agent.sockets[name].length, 1, '1 open socket') + + var socket = r.agent.sockets[name][0] + socket.on('close', function () { + t.equal(Object.keys(r.agent.sockets).length, 0, '0 open sockets') + t.end() + }) + socket.end() + }) +} + +function foreverAgent (t, options, req) { + var r = (req || request)(options, function (_err, res, body) { + + t.ok(r.agent instanceof ForeverAgent, 'is ForeverAgent') + t.equal(Object.keys(r.agent.sockets).length, 1, '1 socket name') + + var name = 'localhost:6767' // node 0.10- + t.equal(r.agent.sockets[name].length, 1, '1 open socket') + + var socket = r.agent.sockets[name][0] + socket.on('close', function () { + t.equal(Object.keys(r.agent.sockets[name]).length, 0, '0 open sockets') + t.end() + }) + socket.end() + }) +} + +// http.Agent + +tape('options.agent', function (t) { + httpAgent(t, { + uri: 'http://localhost:6767', + agent: new http.Agent({keepAlive: true}) }) }) -tape('cleanup', function(t) { +tape('options.agentClass + options.agentOptions', function (t) { + httpAgent(t, { + uri: 'http://localhost:6767', + agentClass: http.Agent, + agentOptions: {keepAlive: true} + }) +}) + +// forever-agent + +tape('options.forever = true', function (t) { + var v = version() + var options = { + uri: 'http://localhost:6767', + forever: true + } + + if (v.major === 0 && v.minor <= 10) {foreverAgent(t, options)} + else {httpAgent(t, options)} +}) + +tape('forever() method', function (t) { + var v = version() + var options = { + uri: 'http://localhost:6767' + } + var r = request.forever({maxSockets: 1}) + + if (v.major === 0 && v.minor <= 10) {foreverAgent(t, options, r)} + else {httpAgent(t, options, r)} +}) + +tape('cleanup', function (t) { s.close(function() { t.end() }) From 1f4265bd0321008012788b0624576eabc7b8dfb5 Mon Sep 17 00:00:00 2001 From: Joshua Halickman Date: Thu, 16 Jul 2015 13:43:27 -0400 Subject: [PATCH 142/490] When adding realm to the front of the params array do not replace anything in the array. --- lib/oauth.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/oauth.js b/lib/oauth.js index b0f7ab884..c24209b89 100644 --- a/lib/oauth.js +++ b/lib/oauth.js @@ -81,7 +81,7 @@ OAuth.prototype.concatParams = function (oa, sep, wrap) { }).sort() if (oa.realm) { - params.splice(0, 1, 'realm') + params.splice(0, 0, 'realm') } params.push('oauth_signature') From 23cb186cec03e05b4adab02e44e0f8e8a495cdef Mon Sep 17 00:00:00 2001 From: simov Date: Fri, 17 Jul 2015 17:49:37 +0300 Subject: [PATCH 143/490] Fix OAuth tests - add missing key due to #1679 bug --- tests/test-oauth.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test-oauth.js b/tests/test-oauth.js index 940fe0ec3..f27c0a271 100644 --- a/tests/test-oauth.js +++ b/tests/test-oauth.js @@ -427,6 +427,7 @@ tape('query transport_method + form option + url params', function(t) { 'c@': '', a2: 'r b', realm: 'Example', + oauth_consumer_key: '9djdj82h48djs9d2', oauth_nonce: '7d8f3e4a', oauth_signature_method: 'HMAC-SHA1', oauth_timestamp: '137131201', @@ -472,6 +473,7 @@ tape('query transport_method + qs option + url params', function(t) { 'c@': '', c2: '', realm: 'Example', + oauth_consumer_key: '9djdj82h48djs9d2', oauth_nonce: '7d8f3e4a', oauth_signature_method: 'HMAC-SHA1', oauth_timestamp: '137131201', @@ -543,6 +545,7 @@ tape('body transport_method + form option + url params', function(t) { { c2: '', a3: '2 q', realm: 'Example', + oauth_consumer_key: '9djdj82h48djs9d2', oauth_nonce: '7d8f3e4a', oauth_signature_method: 'HMAC-SHA1', oauth_timestamp: '137131201', From 391b80bd3397dcf6125a7aa7f5338ebee8723b54 Mon Sep 17 00:00:00 2001 From: simov Date: Fri, 17 Jul 2015 17:57:37 +0300 Subject: [PATCH 144/490] Remove forever option warning and improve docs --- README.md | 2 +- request.js | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 77e3e1e27..b72276798 100644 --- a/README.md +++ b/README.md @@ -775,7 +775,7 @@ The first argument can be either a `url` or an `options` object. The only requir - `agent` - `http(s).Agent` instance to use - `agentClass` - alternatively specify your agent's class name - `agentOptions` - and pass its options. **Note:** for HTTPS see [tls API doc for TLS/SSL options](http://nodejs.org/api/tls.html#tls_tls_connect_options_callback) and the [documentation above](#using-optionsagentoptions). -- `forever` - set to `true` to use the [forever-agent](https://github.com/request/forever-agent) **Use only with node 0.10-** +- `forever` - set to `true` to use the [forever-agent](https://github.com/request/forever-agent) **Note:** Defaults to `http(s).Agent({keepAlive:true})` in node 0.12+ - `pool` - An object describing which agents to use for the request. If this option is omitted the request will use the global agent (as long as your options allow for it). Otherwise, request will search the pool for your custom agent. If no custom agent is found, a new agent will be created and added to the pool. **Note:** `pool` is used only when the `agent` option is not specified. - A `maxSockets` property can also be provided on the `pool` object to set the max number of sockets for all agents created (ex: `pool: {maxSockets: Infinity}`). - Note that if you are sending multiple requests in a loop and creating diff --git a/request.js b/request.js index 3664f9ea3..6932741c5 100644 --- a/request.js +++ b/request.js @@ -483,7 +483,6 @@ Request.prototype.init = function (options) { if (v.major === 0 && v.minor <= 10) { self.agentClass = protocol === 'http:' ? ForeverAgent : ForeverAgent.SSL } else { - console.warn('The forever option defaults to using http(s).Agent in 0.12+') self.agent = new self.httpModule.Agent({ keepAlive: true, maxSockets: (options.pool && options.pool.maxSockets) || Infinity From 53aebe29f54e9565bbfbc2b71107b66ad64aa7b0 Mon Sep 17 00:00:00 2001 From: simov Date: Mon, 20 Jul 2015 11:46:56 +0300 Subject: [PATCH 145/490] 2.59.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e2996666f..a28e9c387 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.58.1", + "version": "2.59.0", "author": "Mikeal Rogers ", "repository": { "type": "git", From 24015ff407f30c7fe72716c43bb96411fb79bdcf Mon Sep 17 00:00:00 2001 From: simov Date: Mon, 20 Jul 2015 11:49:05 +0300 Subject: [PATCH 146/490] Update changelog --- CHANGELOG.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b3905edb..508efe9c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ ## Change Log +### v2.59.0 (2015/07/20) +- [#1671](https://github.com/request/request/pull/1671) Add tests and docs for using the agent, agentClass, agentOptions and forever options. Forever option defaults to using http(s).Agent in node 0.12+ (@simov) +- [#1679](https://github.com/request/request/pull/1679) Fix - do not remove OAuth param when using OAuth realm (@simov, @jhalickman) +- [#1668](https://github.com/request/request/pull/1668) updated dependencies (@deamme) +- [#1656](https://github.com/request/request/pull/1656) Fix form method (@simov) +- [#1651](https://github.com/request/request/pull/1651) Preserve HEAD method when using followAllRedirects (@simov) +- [#1652](https://github.com/request/request/pull/1652) Update `encoding` option documentation in README.md (@daniel347x) +- [#1650](https://github.com/request/request/pull/1650) Allow content-type overriding when using the `form` option (@simov) +- [#1646](https://github.com/request/request/pull/1646) Clarify the nature of setting `ca` in `agentOptions` (@jeffcharles) + ### v2.58.0 (2015/06/16) - [#1638](https://github.com/request/request/pull/1638) Use the `extend` module to deep extend in the defaults method (@simov) - [#1631](https://github.com/request/request/pull/1631) Move tunnel logic into separate module (@simov) @@ -74,7 +84,7 @@ - [#1392](https://github.com/request/request/pull/1392) Improve `timeout` option description (@watson) ### v2.52.0 (2015/02/02) -- [#1383](https://github.com/request/request/pull/1383) Add missing HTTPS options that were not being passed to tunnel (@brichard19) (@nylen, @brichard19) +- [#1383](https://github.com/request/request/pull/1383) Add missing HTTPS options that were not being passed to tunnel (@brichard19) (@nylen) - [#1388](https://github.com/request/request/pull/1388) Upgrade mime-types package version (@roderickhsiao) - [#1389](https://github.com/request/request/pull/1389) Revise Setup Tunnel Function (@seanstrom) - [#1374](https://github.com/request/request/pull/1374) Allow explicitly disabling tunneling for proxied https destinations (@nylen) @@ -480,7 +490,7 @@ - [#121](https://github.com/request/request/pull/121) Another patch for cookie handling regression (@jhurliman) - [#117](https://github.com/request/request/pull/117) Remove the global `i` (@3rd-Eden) - [#110](https://github.com/request/request/pull/110) Update to Iris Couch URL (@jhs) -- [#86](https://github.com/request/request/pull/86) Can't post binary to multipart requests (@developmentseed) +- [#86](https://github.com/request/request/pull/86) Can't post binary to multipart requests (@kkaefer) - [#105](https://github.com/request/request/pull/105) added test for proxy option. (@dominictarr) - [#102](https://github.com/request/request/pull/102) Implemented cookies - closes issue 82: https://github.com/mikeal/request/issues/82 (@alessioalex) - [#97](https://github.com/request/request/pull/97) Typo in previous pull causes TypeError in non-0.5.11 versions (@isaacs) From 33b15eea26d78496fe3b0f8ee6accbcfa1535023 Mon Sep 17 00:00:00 2001 From: simov Date: Mon, 20 Jul 2015 11:49:49 +0300 Subject: [PATCH 147/490] 2.59.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a28e9c387..f3e3a23f1 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.59.0", + "version": "2.59.1", "author": "Mikeal Rogers ", "repository": { "type": "git", From 3c94b50a8672b4459d592deb4a906d51e924727a Mon Sep 17 00:00:00 2001 From: garymathews Date: Mon, 20 Jul 2015 14:33:31 -0700 Subject: [PATCH 148/490] Fix: setHeader() with undefined value --- request.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/request.js b/request.js index 6932741c5..f3f5dd915 100644 --- a/request.js +++ b/request.js @@ -573,7 +573,7 @@ Request.prototype.init = function (options) { if (self._form && !self.hasHeader('content-length')) { // Before ending the request, we had to compute the length of the whole form, asyncly - self.setHeader(self._form.getHeaders()) + self.setHeader(self._form.getHeaders(), true) self._form.getLength(function (err, length) { if (!err) { self.setHeader('content-length', length) From 27722fe918a74c7c86bbc4f3af10e3a29072bd20 Mon Sep 17 00:00:00 2001 From: simov Date: Tue, 21 Jul 2015 08:14:45 +0300 Subject: [PATCH 149/490] Test request content-type for multipart/form-data --- tests/test-form-data.js | 3 +++ tests/test-form.js | 3 +++ 2 files changed, 6 insertions(+) diff --git a/tests/test-form-data.js b/tests/test-form-data.js index 605d58e32..0c7ca97d9 100644 --- a/tests/test-form-data.js +++ b/tests/test-form-data.js @@ -29,6 +29,9 @@ function runTest(t, options) { } } + t.ok(/multipart\/form-data; boundary=--------------------------\d+/ + .test(req.headers['content-type'])) + // temp workaround var data = '' req.setEncoding('utf8') diff --git a/tests/test-form.js b/tests/test-form.js index 0c4ef3959..6d719409f 100644 --- a/tests/test-form.js +++ b/tests/test-form.js @@ -21,6 +21,9 @@ tape('multipart form append', function(t) { return } + t.ok(/multipart\/form-data; boundary=--------------------------\d+/ + .test(req.headers['content-type'])) + // temp workaround var data = '' req.setEncoding('utf8') From 6e5863853bfb2d631d507753bfc67c123a34851a Mon Sep 17 00:00:00 2001 From: simov Date: Tue, 21 Jul 2015 15:27:22 +0300 Subject: [PATCH 150/490] 2.60.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f3e3a23f1..79dce8fdc 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.59.1", + "version": "2.60.0", "author": "Mikeal Rogers ", "repository": { "type": "git", From af19cef3bc60e9151ffce5015d8ce3c0728d3aca Mon Sep 17 00:00:00 2001 From: simov Date: Tue, 21 Jul 2015 15:29:19 +0300 Subject: [PATCH 151/490] Update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 508efe9c6..4cc1fcbe4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## Change Log +### 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) + ### v2.59.0 (2015/07/20) - [#1671](https://github.com/request/request/pull/1671) Add tests and docs for using the agent, agentClass, agentOptions and forever options. Forever option defaults to using http(s).Agent in node 0.12+ (@simov) - [#1679](https://github.com/request/request/pull/1679) Fix - do not remove OAuth param when using OAuth realm (@simov, @jhalickman) From d4b976170aad29b2ec34a9127defad67f062a4f2 Mon Sep 17 00:00:00 2001 From: simov Date: Tue, 21 Jul 2015 15:29:40 +0300 Subject: [PATCH 152/490] 2.60.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 79dce8fdc..7303c5fae 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.60.0", + "version": "2.60.1", "author": "Mikeal Rogers ", "repository": { "type": "git", From d409a03260616a0e72e3feab49d8040df7ea7e17 Mon Sep 17 00:00:00 2001 From: Phillip Johnsen Date: Mon, 27 Jul 2015 21:57:43 +0200 Subject: [PATCH 153/490] debug() when JSON.parse() on a response body fails. Previously JSON.parse() failures was silently ignored. Although `response.body` would still contain the invalid JSON response body as a string, instead of a JS object, it's valueable to know the JSON was invalid while debugging. --- request.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/request.js b/request.js index f3f5dd915..a4af56a97 100644 --- a/request.js +++ b/request.js @@ -1047,7 +1047,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) From ee643e7848d2f6d6297450b075829a871712ebbe Mon Sep 17 00:00:00 2001 From: Kevin Burke Date: Mon, 3 Aug 2015 09:40:37 -0700 Subject: [PATCH 154/490] Set certificate expiration to August 2, 2018 Updates the gen-* scripts to take a `-days` argument, and set that `days` argument to 3 years from now. I believe without this argument the certificates default to a 30 day expiry. Code lifted from https://github.com/shazow/urllib3/blob/master/dummyserver/certs/README.rst. Generates new SSL certs with a long expiry. --- tests/ssl/ca/client-enc.key | 52 +++++++++++++++++------------------ tests/ssl/ca/client.crt | 28 +++++++++---------- tests/ssl/ca/client.csr | 32 ++++++++++----------- tests/ssl/ca/client.key | 50 ++++++++++++++++----------------- tests/ssl/ca/gen-client.sh | 5 ++-- tests/ssl/ca/gen-localhost.sh | 5 ++-- tests/ssl/ca/localhost.crt | 28 +++++++++---------- tests/ssl/ca/localhost.csr | 32 ++++++++++----------- tests/ssl/ca/localhost.key | 50 ++++++++++++++++----------------- 9 files changed, 142 insertions(+), 140 deletions(-) diff --git a/tests/ssl/ca/client-enc.key b/tests/ssl/ca/client-enc.key index 308f638c3..e0f5348df 100644 --- a/tests/ssl/ca/client-enc.key +++ b/tests/ssl/ca/client-enc.key @@ -1,30 +1,30 @@ -----BEGIN RSA PRIVATE KEY----- Proc-Type: 4,ENCRYPTED -DEK-Info: AES-128-CBC,374F554A54A7BDBAF97E9CDF43F02731 +DEK-Info: AES-128-CBC,DFE9B15161553AFAA662AC7EACFB6D35 -cl1qMhFDUlDtnJ5SkDXhv+PblSuGLfenU74mYUjp+W/Dqc11p3bcRJjUVfdkHBAc -JqkYFZ8Rtn5WNvv6V2AGArZZI8aCGY6gfwzVyLXS1TQem3Xu1stz/R9TJ7bavgaL -FjMBEOLUEUcverl56t/cqJO4vGbGpcGtrEeb3H4+aZGNlYgd0NGj+c05XBoqEYEM -LUv1hJm0evFajKXjAmK0H4ScmWvGnO7K/TXmtOjFV6QEbJtSija9falqPBSRYkmA -EPZypiBuFbBgRYf+jQfbP+YU/HbldXipiQ5wvIMqCidwm1GwdJET4Jw9QOzBnsxo -++adJLyi4h2i+yF3QVc4WBWHTiuEXVytMb5MwsoO/lKZ/dHfuZFG6CR6pMk4z00U -0pgkbOyIKvT3DGKYZRMIW2vtpXC8j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9RPOoVXU7DmSZMYl2Gn6XjwYn +Gn/VTKwyx/+JUTDnDbSgJNbXIBcNJGXFfXa0Pso2XBlX4uP638MQ5Ofdtez6+aPX +fKquJLB2qPfVXyB7yZOKZLA0im3ckp2xS5nKTT7EqKLv7ZZss7tJSWfFAITAhxsk +AeDrcwsEzqi5bdNaoAo+5GWXBCoLB0vvUkXFRQpfctAd+3zVs/Afr3s4j7HOLMZZ +MAQl/ITjSjwNUbsbv/xpoozY75fEfQ5zKR/Buj1yfwWYYTA4/5BswJs9V/Lex/mG +O7IDlzRLQXYOdKI6zT6Zsxfy+oHuLWOt29/N/xoJPRythy8gskjp3R+rDN02NBi8 +x/00ev3P2BQ7/Giiz2lKklOBo8qmyPE+VvW4fmTaAYpaHor6+gxnvtM9FDE5FEGV +PIXuRNPftR9A8N4bUO14bqiIcCwzSb5ncxqVQOiNdC+JhgmF3kcYt2bAhaYN9dQB +F2cloSoQN5oSKFiyRf2tQDB5/VXOf59/UvIVe7Nmsey2JTDCCwTc+S9mjixw0yn5 +BEb2pjWa2C5Bby6LZFu44hpU0cogbYW+dZtqJuDUVsXtfPGIP8R4xnSRIyYrwoQc +tqoxSAvmVC0zEJEmFhLPl+gwYUy5grUZnzR7GSMwC0Sn9i1989jC4XCPrEDS/Y6m -----END RSA PRIVATE KEY----- diff --git a/tests/ssl/ca/client.crt b/tests/ssl/ca/client.crt index 7880c55ae..b5f687042 100644 --- a/tests/ssl/ca/client.crt +++ b/tests/ssl/ca/client.crt @@ -1,20 +1,20 @@ -----BEGIN CERTIFICATE----- -MIIDLjCCApcCCQCt9iAWqkDJwzANBgkqhkiG9w0BAQsFADCBojELMAkGA1UEBhMC +MIIDLjCCApcCCQCt9iAWqkDJwzANBgkqhkiG9w0BAQUFADCBojELMAkGA1UEBhMC VVMxCzAJBgNVBAgTAkNBMRAwDgYDVQQHEwdPYWtsYW5kMRAwDgYDVQQKEwdyZXF1 ZXN0MSYwJAYDVQQLEx1yZXF1ZXN0IENlcnRpZm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+ZYPS1pQG -kzdi16Vgez8dsZKYMZgn+VcL/c1ehugM4844y/WesS1x19JAdv1eebuU+gbsNHbB -+Wc= +CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDYSkr4lssxol4y0Q/1mj9S1FAZ7qZx +9pmK6cqBKmhdULp9RuicYUUG21HbAP6EAatzjR33KAgIlB1jpAfTEt+RqyRrAOdd +jYjBWnVVjjDySvABwBACewAnhpAKquEZupKAShAZtu8G3W2W7XTtZMkyW//6ELu1 +sZojBoZ9M1TH7ENuG7vjLa7DVHd6qqtZyVFD8FjAN/yerfJm57t9K9h6HmZfwv1I +T3PCtytKwEytaxMTDBJuXen68LomszlEXl2KnHnSNoERpoN0NxQIj+4syDf65xTH +kJ5Ev2ZcGWOqMZNKbO+mxJYX5r4uk8GcugtD5I3rIVX8sZNKrQFzpFnBAgMBAAEw +DQYJKoZIhvcNAQEFBQADgYEAKSut5ZyFcEDl4SSUKsnEXV1Z4sfWk1WTnZP8D8qX +L/Mge0Gx36my6OtdJ0JFA1mO9gR3KyS9CDh3OgwWCg9HtoArriqLhBHE0oy7NYa2 +uRFraeLO5fGKk6FKePb3DRF8i9tFMQBhoVAZhX8f6hw+g3Xt5fDAHMumG2qMeuMQ +l4I= -----END CERTIFICATE----- diff --git a/tests/ssl/ca/client.csr b/tests/ssl/ca/client.csr index e3580182f..0bb6f2e10 100644 --- a/tests/ssl/ca/client.csr +++ b/tests/ssl/ca/client.csr @@ -1,18 +1,18 @@ -----BEGIN CERTIFICATE REQUEST----- -MIIC+DCCAeACAQAwgY8xCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJDQTEQMA4GA1UE -BxMHT2FrbGFuZDEQMA4GA1UEChMHcmVxdWVzdDEaMBgGA1UECxQRcmVxdWVzdEBs -b2NhbGhvc3QxEzARBgNVBAMTClRlc3RDbGllbnQxHjAcBgkqhkiG9w0BCQEWD2Rv -Lm5vdEBlbWFpbC5tZTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQ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mYrpyoEqaF1Qun1G6JxhRQbbUdsA/oQBq3ON +HfcoCAiUHWOkB9MS35GrJGsA512NiMFadVWOMPJK8AHAEAJ7ACeGkAqq4Rm6koBK +EBm27wbdbZbtdO1kyTJb//oQu7WxmiMGhn0zVMfsQ24bu+MtrsNUd3qqq1nJUUPw +WMA3/J6t8mbnu30r2HoeZl/C/UhPc8K3K0rATK1rExMMEm5d6frwuiazOUReXYqc +edI2gRGmg3Q3FAiP7izIN/rnFMeQnkS/ZlwZY6oxk0ps76bElhfmvi6TwZy6C0Pk +jeshVfyxk0qtAXOkWcECAwEAAaAjMCEGCSqGSIb3DQEJBzEUDBJwYXNzd29yZCBj +aGFsbGVuZ2UwDQYJKoZIhvcNAQELBQADggEBAADv7KZq1ZxniXFe2SgWbvsvmsLA +5C/8SLH7MB9EQkDGQmyG5nsX98BQtNUR+rXvvXd/1piFBfZD6K/iy26N0ltDxt3H +JLKnWSbJctEKR+A9Nff1NPQsVlWSXEnXyRHqv8+pJlV0o1yl3TtSmTlL6fgVe0Ii +8D8w9QDTX3VT6M53BQtVaXJCpN6B943RvOeeKhOa/zyq0QU2a8+Tqm05qXHGQPCx +ZkcGH861tuQuR/UyPEJLpSpMdVUsstWLuOlpontVZO1pa4kRaWzKONzfDrfX+g58 +tLFyrEl2vRni2tRdQHEXAPs5zvbGQ5wHouF8kp5cvQDmH4HYZAdV2ZSyOlQ= -----END CERTIFICATE REQUEST----- diff --git a/tests/ssl/ca/client.key b/tests/ssl/ca/client.key index af537fa92..4148e25ad 100644 --- a/tests/ssl/ca/client.key +++ b/tests/ssl/ca/client.key @@ -1,27 +1,27 @@ -----BEGIN RSA PRIVATE KEY----- -MIIEpQIBAAKCAQEAyVRKl0I0kzqiS6k2t9CcEh3hoAhEfqsFT14D1drhBn3ObaRl -ZnMqz66PL5OLzy20wO3Iq3+Ph9WtnaHrUIUmzUpMIgt2zl4UXuhh8rvLWvMXXnhH -MQVk/pdzj6EUIvw5PxOGVS1d1VoCSTv1NP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5MkNTiTaU90FnivMrLq/9j2HWJCu8QKwwMHvE4Bv0QJM +UVSFaOkCgYEA/vrs01oXaIpf2bv3uAHmKauIQW7D7+fcvZudq5rvKqnx6eSyI3E1 +CLzLi4EkVTthUojRAPLnEP93EjI32rZr2lr71PZTY2MAEi/NoPTCjj1fjJvPcumS +xfVeJs5RINCk09Cb21FjlSddk7uuGJgVtTrZpX+6qh7LNbjW4wCyuI8CgYEA2SfA +w/Fv8Rsy+Cxwg6RGWDKnKUEJT9Ow2DQXBCGaXFNuidNj3Wv+bEgMTYl++oWA0yML +3uSou4jsjEi6qcKDT/o1ZGOB1RU4JO17h8Jc0BXwjQPkwy5iT9INfUD7tGbp5CHo +XFpu95YPJlSmrDN9lUBcO83xv4KDZMUoNV480K8CgYEAqONplECbOqpU/LJtTVss +qbMtaDHG5JQOeSSnFfBktDymuMa7W5BzkVsD815Rw4a2WuW2kktR08dyhgHvTxX/ +cD1NiuyxpSYA+Qrix9b3OyHZtRfLG5Esn6R7fXaw8+xfENGfOnC5ZiUR7XWlxjKO +RmE5ok5tRJtq/CV3aBqhRm8CgYEA1/ZiDjyaIIX1Tb0cdL82Ola9yhhlA1+7m3lK +fpBQrItI/ocd5UKWt+d7XM1mXA3TjadoEdcEO+Wzotxdz6Cj6TEkUl9n6pt8x7Tq +ypwwo71+CzAZHUeO/GUhhzTOXp6O85QJO3ewrkgtbuh3DgDzXzCvycZKKzTIKbqt +/01mW/8CgYABbHvNMZiaARow1yeKifz0dSEKWuym59VFdqzXKsCvx0iSe2QawKOV +LgFubIgmDZZJ0GwjBEuLv/NMFwHPfUfvNtUm053HAfJSVtk92VyrmUCODIygoOm9 +O2jxpRnIM/KfwszTzge1eWEJGA8xlTmL+Hud/3ofBqXbx/RWrM/hAA== -----END RSA PRIVATE KEY----- diff --git a/tests/ssl/ca/gen-client.sh b/tests/ssl/ca/gen-client.sh index c0f6d3be6..ed2fcfb38 100755 --- a/tests/ssl/ca/gen-client.sh +++ b/tests/ssl/ca/gen-client.sh @@ -8,7 +8,7 @@ openssl genrsa -out client.key 2048 # Create a certificate signing request -openssl req -new -sha256 -key client.key -out client.csr -config client.cnf +openssl req -new -sha256 -key client.key -out client.csr -config client.cnf -days 1095 # Use the CSR and the CA key (previously generated) to create a certificate openssl x509 -req \ @@ -17,7 +17,8 @@ openssl x509 -req \ -CAkey ca.key \ -set_serial 0x`cat ca.srl` \ -passin 'pass:password' \ - -out client.crt + -out client.crt \ + -days 1095 # Encrypt with password openssl rsa -aes128 -in client.key -out client-enc.key -passout 'pass:password' diff --git a/tests/ssl/ca/gen-localhost.sh b/tests/ssl/ca/gen-localhost.sh index 21a1f367b..9c48673c4 100755 --- a/tests/ssl/ca/gen-localhost.sh +++ b/tests/ssl/ca/gen-localhost.sh @@ -8,7 +8,7 @@ openssl genrsa -out localhost.key 2048 # Create a certificate signing request -openssl req -new -sha256 -key localhost.key -out localhost.csr -config localhost.cnf +openssl req -new -sha256 -key localhost.key -out localhost.csr -config localhost.cnf -days 1095 # Use the CSR and the CA key (previously generated) to create a certificate openssl x509 -req \ @@ -17,4 +17,5 @@ openssl x509 -req \ -CAkey ca.key \ -set_serial 0x`cat ca.srl` \ -passin 'pass:password' \ - -out localhost.crt + -out localhost.crt \ + -days 1095 diff --git a/tests/ssl/ca/localhost.crt b/tests/ssl/ca/localhost.crt index f526649d5..8beb1fc3c 100644 --- a/tests/ssl/ca/localhost.crt +++ b/tests/ssl/ca/localhost.crt @@ -1,20 +1,20 @@ -----BEGIN CERTIFICATE----- -MIIDLTCCApYCCQCt9iAWqkDJwzANBgkqhkiG9w0BAQsFADCBojELMAkGA1UEBhMC +MIIDLTCCApYCCQCt9iAWqkDJwzANBgkqhkiG9w0BAQUFADCBojELMAkGA1UEBhMC VVMxCzAJBgNVBAgTAkNBMRAwDgYDVQQHEwdPYWtsYW5kMRAwDgYDVQQKEwdyZXF1 ZXN0MSYwJAYDVQQLEx1yZXF1ZXN0IENlcnRpZmljYXRlIEF1dGhvcml0eTESMBAG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tRvVp1/x7wAn3tQKq2+80aUKScTfvguaPUJrUGr -TQ== +KoZIhvcNAQEBBQADggEPADCCAQoCggEBAK5d+ffEqcykWv/O6OLvsdv3y2h/jK2R +lE4SSgqhCoS2J4X08B6LGHOs+IcMOtGV29dLy/wnMKdqVc/CqGd0KB6zkVERWt0H +mcoT3ATeIcs8kyO+i++LQB+5YNcSbmXZE4he/OoMWLJwLFzbCzSHCZGdutnAO8pl +dV1AWMKYncpDQjxVOL2Ji2sgJFa8Jfl2c6bzpYJxHrW+bdWhq7QjIqM4TtcRkmW4 +NGMmf2sNnTC5pvI6/bFvQSSgYQ5ZjR6ytvFxeyo0cwyW5azTdgkRzXHan2m2Dh4b +kcLu9ReRVuJ6P6fATrUQD91mM85Bb8Qzn+L3rOKSuAcmgx8wrTHyjeUCAwEAATAN +BgkqhkiG9w0BAQUFAAOBgQAFhiBnCVsgk3Gn8kqKoAMqEd4Ckk3w6Fuj+C468lDM +HGrX6e1pPO8UwVNUye1U2nRkVmO92IPsENrnLvIoqbtXR4w6T0DWg+ilRgJsV/Ra +hVZBJxYthAtvyfNBnwd9FV3jC3waEsKRcnLDDkkBOfYtMeUzHuCBAwf5c7vuNC+N +xQ== -----END CERTIFICATE----- diff --git a/tests/ssl/ca/localhost.csr b/tests/ssl/ca/localhost.csr index 8a20ca42d..27036fd03 100644 --- a/tests/ssl/ca/localhost.csr +++ b/tests/ssl/ca/localhost.csr @@ -1,18 +1,18 @@ -----BEGIN CERTIFICATE REQUEST----- -MIIC9zCCAd8CAQAwgY4xCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJDQTEQMA4GA1UE -BxMHT2FrbGFuZDEQMA4GA1UEChMHcmVxdWVzdDEaMBgGA1UECxQRcmVxdWVzdEBs -b2NhbGhvc3QxEjAQBgNVBAMTCWxvY2FsaG9zdDEeMBwGCSqGSIb3DQEJARYPZG8u -bm90QGVtYWlsLm1lMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA06lf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+MrZGUThJKCqEKhLYnhfTwHosYc6z4hww60ZXb10vL +/Ccwp2pVz8KoZ3QoHrORURFa3QeZyhPcBN4hyzyTI76L74tAH7lg1xJuZdkTiF78 +6gxYsnAsXNsLNIcJkZ262cA7ymV1XUBYwpidykNCPFU4vYmLayAkVrwl+XZzpvOl +gnEetb5t1aGrtCMiozhO1xGSZbg0YyZ/aw2dMLmm8jr9sW9BJKBhDlmNHrK28XF7 +KjRzDJblrNN2CRHNcdqfabYOHhuRwu71F5FW4no/p8BOtRAP3WYzzkFvxDOf4ves +4pK4ByaDHzCtMfKN5QIDAQABoCMwIQYJKoZIhvcNAQkHMRQMEnBhc3N3b3JkIGNo +YWxsZW5nZTANBgkqhkiG9w0BAQsFAAOCAQEAZhCYjPuSzKGqXGR+OcbCU+m8VmHA +FpBp04VEYxtStagi+m2m7JUDOsTm+NdMj7lBTMEX5eK6sLadeZjkwS7bZNSiq54b +2g5Yqom29LTQCKACBra+9iH3Y4CUIO0zxmki9QMlMBt5gU9DJEr4m9qk216s1hn+ +FNZ5ytU6756y3eYnGOvJSUfhTKj+AWzljgRtgOsaEhnP/299LTjXrsLirO/5bbm8 +f7qes5FtNWBYlRYx3nejouiquVZVmPYSi663dESLp/R35qV0Bg1Tam+9zGGysTuY +A8IYVUSqik3cpj6Kfu6UBv9KACWeKznjFrvz4dKrDho4YS/K4Zi3cqbEfA== -----END CERTIFICATE REQUEST----- diff --git a/tests/ssl/ca/localhost.key b/tests/ssl/ca/localhost.key index 96119a7fb..260c6a340 100644 --- a/tests/ssl/ca/localhost.key +++ b/tests/ssl/ca/localhost.key @@ -1,27 +1,27 @@ -----BEGIN RSA PRIVATE KEY----- -MIIEowIBAAKCAQEA06lfTQFcp1diZTr1eGDthGmD8+ZsfWPIK9z+uGAtSDvMcrZ1 -yR1lyHkahCdMzADsQAuAt4UY1Iil5GVplqo7PL0MJIvx3UNiYjEGzLCT9AJLA5MT -Z/YKAs3BEBj3nryEBWhd1WcFIQ8lBokMr8weQ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RwyS/6BQt7+rg +F535GSECgYEA1DMv3tKtnFrGA78Htsy6TjtCC0P4jwZw2Xj+pLEu2KInw1JMMSzQ +rpkkFhBOlkg8NhFmEbE9BovR7cS24PDIq+Ya2M3l5VQWYnXEOQZH7MOCv+No4bEA +XGPnKDX3VN0UJblkQJwxfGCcETvJaQra89kybEQZu2JAkypOzRs5r00CgYEA0lur +6vrG85xNwoMns6PNDFWgV9yl6hKoDLZTfECwYh26Znp2gXrGJ/UAY3FcBeQprDzh +T6eKcegqU+kp4v2Hc9WyyluupUlcGWLbCaTTsE2eUgr/0K3LxVqrLg6VF6fG0HZa +sconJx8HhbzHqniVvwjaOyt0A23/g5ivarpFPPkCgYBCuqoGFxhTP9RfHzaMzIqV +yVq2cjR6vZrFOKBTKAjERRHeAUZGfIJPNYc8jPo5lhOhKQ2A6Mx4/4UPkTm1OOLR +87VjkjQGTtAPPFttV0VM9hpqv1efCWtEooHxii7x9+e7CTa2fqetJjBN1xA6QRij +cBzEIRI6c+Y8oSRQqYwVTQKBgQCs/ka7z9CdtwUb2dBko2iVpDVhDExF22HoUmkF +3g0wI1KPxFaA1P7xDUNshGUxUxoSU17XqujoFA37Q9z2l5k1YaDPWeaed14OYoXP +wIV2j96LihAnBUZ23sG39rYV5hxSg4LCg4T/Xz1Idp+dSd2cZSNTVcDqsSNYjdB0 +7QrTwQKBgGTRximBEZj6anNQXxlGUJFd6GZy0UWg4yZf8GH9pCD7PxvDSJNQnVQ1 +nNvdpAFmAcUg6oFP4UTgvf+yGj5L1j5qRicaPiOTT+kDIJ+mRH1lSuMnoTn0Kd0v +/qaX8EqP15UjLfAbUBuz0oQLksGqLidYQOjbGI8xW82/i4mj7V+A -----END RSA PRIVATE KEY----- From ee4cfbbc66dc1bfb7481e79ab7ce51d4e0ba9038 Mon Sep 17 00:00:00 2001 From: Kevin Burke Date: Mon, 3 Aug 2015 05:11:21 -0700 Subject: [PATCH 155/490] Add ability to detect connect timeouts It's valuable to be able to detect whether a timeout occurred on the `connect` syscall or on the `write`/`read` syscall of an HTTP request - the former implies that your client can't reach the server and the latter implies the server might not have responded. For backwards compatibility, and standardization with Unix errno codes, the `code` property of connect timeout errors must remain as 'ETIMEDOUT'. Instead of changing this value, add a new `connect` property on timeout errors, which is set to true if the error occurred on the `connect` attempt. Clients have to opt in to checking it - in the common read timeout case, it will be set to `false`. Updates the documentation around each timeout to clarify what is going on, and what situations can trigger each timeout. Updates the README with more accurate documentation about timeout times in the wild. I tried `time curl http://10.255.255.1` and `time curl http://google.com:81` on four different Linux machines (Heroku, boot2docker, Centos on DigitalOcean, a VPS) and the timeout times ranged from 60 seconds to 120 seconds, much longer than the 20 seconds previously suggested. Updates the README with information on how to detect connection timeout failures. --- .gitignore | 1 + README.md | 38 +++++++++++++++++++++++++++++++++++--- request.js | 16 ++++++++++++++-- tests/test-timeout.js | 29 +++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 98f9955c6..e80332692 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules coverage .idea +npm-debug.log diff --git a/README.md b/README.md index b72276798..d4b407fa3 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/request.js b/request.js index a4af56a97..fe2959302 100644 --- a/request.js +++ b/request.js @@ -804,21 +804,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) } }) diff --git a/tests/test-timeout.js b/tests/test-timeout.js index 9037c8b88..7c4227b50 100644 --- a/tests/test-timeout.js +++ b/tests/test-timeout.js @@ -43,6 +43,19 @@ if (process.env.TRAVIS === 'true') { }) }) + tape('should set connect to false', function(t) { + var shouldTimeout = { + url: s.url + '/timeout', + timeout: 100 + } + + request(shouldTimeout, function(err, res, body) { + checkErrCode(t, err) + t.ok(err.connect === false, 'Read Timeout Error should set \'connect\' property to false') + t.end() + }) + }) + tape('should timeout with events', function(t) { t.plan(3) @@ -109,6 +122,22 @@ if (process.env.TRAVIS === 'true') { }) }) + tape('connect timeout', function(t) { + // We need a destination that will not immediately return a TCP Reset + // packet. StackOverflow suggests this host: + // https://stackoverflow.com/a/904609/329700 + var tarpitHost = 'http://10.255.255.1' + var shouldConnectTimeout = { + url: tarpitHost + '/timeout', + timeout: 100 + } + request(shouldConnectTimeout, function(err) { + checkErrCode(t, err) + t.ok(err.connect === true, 'Connect Timeout Error should set \'connect\' property to true') + t.end() + }) + }) + tape('cleanup', function(t) { s.close(function() { t.end() From ae403dcf92e196991dc1f90a275b794fbf44d260 Mon Sep 17 00:00:00 2001 From: calibr Date: Tue, 4 Aug 2015 16:05:23 +0300 Subject: [PATCH 156/490] fix forever option in node > 0.10 #1709 --- index.js | 2 ++ request.js | 7 ++-- tests/test-pool.js | 82 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 3fe600175..d13ab96b2 100755 --- a/index.js +++ b/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/request.js b/request.js index a4af56a97..4bd5f911f 100644 --- a/request.js +++ b/request.js @@ -483,10 +483,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 diff --git a/tests/test-pool.js b/tests/test-pool.js index b59bd3362..f343081eb 100644 --- a/tests/test-pool.js +++ b/tests/test-pool.js @@ -58,6 +58,88 @@ tape('forever', function(t) { }) }) +tape('forever, should use same agent in sequential requests', function(t) { + var r = request.defaults({ + forever: true + }) + var req1 = r('http://localhost:6767') + var req2 = r('http://localhost:6767/somepath') + req1.abort() + req2.abort() + if (typeof req1.agent.destroy === 'function') { + req1.agent.destroy() + } + if (typeof req2.agent.destroy === 'function') { + req2.agent.destroy() + } + t.equal(req1.agent, req2.agent) + t.end() +}) + +tape('forever, should use same agent in sequential requests(with pool.maxSockets)', function(t) { + var r = request.defaults({ + forever: true, + pool: {maxSockets: 1024} + }) + var req1 = r('http://localhost:6767') + var req2 = r('http://localhost:6767/somepath') + req1.abort() + req2.abort() + if (typeof req1.agent.destroy === 'function') { + req1.agent.destroy() + } + if (typeof req2.agent.destroy === 'function') { + req2.agent.destroy() + } + t.equal(req1.agent.maxSockets, 1024) + t.equal(req1.agent, req2.agent) + t.end() +}) + +tape('forever, should use same agent in request() and request.verb', function(t) { + var r = request.defaults({ + forever: true, + pool: {maxSockets: 1024} + }) + var req1 = r('http://localhost:6767') + var req2 = r.get('http://localhost:6767') + req1.abort() + req2.abort() + if (typeof req1.agent.destroy === 'function') { + req1.agent.destroy() + } + if (typeof req2.agent.destroy === 'function') { + req2.agent.destroy() + } + t.equal(req1.agent.maxSockets, 1024) + t.equal(req1.agent, req2.agent) + t.end() +}) + +tape('should use different agent if pool option specified', function(t) { + var r = request.defaults({ + forever: true, + pool: {maxSockets: 1024} + }) + var req1 = r('http://localhost:6767') + var req2 = r.get({ + url: 'http://localhost:6767', + pool: {maxSockets: 20} + }) + req1.abort() + req2.abort() + if (typeof req1.agent.destroy === 'function') { + req1.agent.destroy() + } + if (typeof req2.agent.destroy === 'function') { + req2.agent.destroy() + } + t.equal(req1.agent.maxSockets, 1024) + t.equal(req2.agent.maxSockets, 20) + t.notEqual(req1.agent, req2.agent) + t.end() +}) + tape('cleanup', function(t) { s.close(function() { t.end() From ea39c231133f4a241ea00c70ef475312f905df5c Mon Sep 17 00:00:00 2001 From: calibr Date: Wed, 5 Aug 2015 12:22:32 +0300 Subject: [PATCH 157/490] do not create Buffer from Object in setContentLength --- request.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/request.js b/request.js index a4af56a97..f4985786a 100644 --- a/request.js +++ b/request.js @@ -432,7 +432,7 @@ Request.prototype.init = function (options) { } function setContentLength () { - if (!Buffer.isBuffer(self.body) && !Array.isArray(self.body)) { + if (!Buffer.isBuffer(self.body) && !Array.isArray(self.body) && typeof self.body !== 'object') { self.body = new Buffer(self.body) } if (!self.hasHeader('content-length')) { From 76bc644506febfb1a0d08792012996541d2c250d Mon Sep 17 00:00:00 2001 From: Arbaaz Date: Sun, 9 Aug 2015 13:29:46 +0530 Subject: [PATCH 158/490] update README.md uri is not defined. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b72276798..d4d5883a6 100644 --- a/README.md +++ b/README.md @@ -1054,8 +1054,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", ...}, ...] }) ``` From 59243bf9687e24d2058f3fd8db9ecb09ed6b93c2 Mon Sep 17 00:00:00 2001 From: Yu-Shih Wang Date: Wed, 12 Aug 2015 20:49:00 +0200 Subject: [PATCH 159/490] Add failing test that shows that agentClass is not used on redirect (mattcg) --- tests/test-redirect.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/test-redirect.js b/tests/test-redirect.js index ee8661889..82278db86 100644 --- a/tests/test-redirect.js +++ b/tests/test-redirect.js @@ -4,6 +4,7 @@ var server = require('./server') , assert = require('assert') , request = require('../index') , tape = require('tape') + , http = require('http') var s = server.createServer() , ss = server.createSSLServer() @@ -365,6 +366,42 @@ tape('should not have a referer when removeRefererHeader is true', function(t) { }) }) +tape('should use same agent class on redirect', function(t) { + var agent + var calls = 0 + var agentOptions = {} + + function FakeAgent(agentOptions) { + var createConnection + + agent = new http.Agent(agentOptions) + createConnection = agent.createConnection + agent.createConnection = function() { + calls++ + return createConnection.apply(agent, arguments) + } + + return agent + } + + hits = {} + request.get({ + uri: s.url + '/temp', + jar: jar, + headers: { cookie: 'foo=bar' }, + agentOptions: agentOptions, + agentClass: FakeAgent + }, function(err, res, body) { + t.equal(err, null) + t.equal(res.statusCode, 200) + t.equal(body, 'GET temp_landing', 'Got temporary landing content') + t.equal(calls, 2) + t.ok(this.agent === agent, 'Reinstantiated the user-specified agent') + t.ok(this.agentOptions === agentOptions, 'Reused agent options') + t.end() + }) +}) + tape('cleanup', function(t) { s.close(function() { ss.close(function() { From 29d4b99d1df51133d92f0d98d4bb3be4fcbef28a Mon Sep 17 00:00:00 2001 From: Paulo McNally Date: Wed, 12 Aug 2015 22:31:34 -0600 Subject: [PATCH 160/490] Update README.md Added , on object --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d4b407fa3..3442dd8f3 100644 --- a/README.md +++ b/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: [ { From 478e0c2766fab310b199c1b0b07d7a2197f070f1 Mon Sep 17 00:00:00 2001 From: Michel Salib Date: Mon, 17 Aug 2015 16:51:36 +0200 Subject: [PATCH 161/490] Avoid useless Buffer transformation --- request.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/request.js b/request.js index d1fe7ed0b..700b9e0a9 100644 --- a/request.js +++ b/request.js @@ -432,13 +432,18 @@ Request.prototype.init = function (options) { } function setContentLength () { - if (!Buffer.isBuffer(self.body) && !Array.isArray(self.body) && typeof self.body !== 'object') { - 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 { From 72bf52a377ea5cd8c10e4b58778e0021f8129133 Mon Sep 17 00:00:00 2001 From: Yu-Shih Wang Date: Tue, 18 Aug 2015 21:06:09 +0200 Subject: [PATCH 162/490] Temp fix redirect agent problem --- lib/redirect.js | 1 - request.js | 63 +++++++------------------------------------------ 2 files changed, 8 insertions(+), 56 deletions(-) diff --git a/lib/redirect.js b/lib/redirect.js index b2d0f613a..d5cc59c91 100644 --- a/lib/redirect.js +++ b/lib/redirect.js @@ -120,7 +120,6 @@ Redirect.prototype.onResponse = function (response) { // request.method = 'GET' // Force all redirects to use GET || commented out fixes #215 delete request.src delete request.req - delete request.agent delete request._started if (response.statusCode !== 401 && response.statusCode !== 307) { // Remove parameters from the previous response, unless this is the second request diff --git a/request.js b/request.js index d1fe7ed0b..1f1efb0bf 100644 --- a/request.js +++ b/request.js @@ -111,6 +111,8 @@ function Request (options) { // call init var self = this + self.options = self.options || options//joshux + self.options = self.options || {}//joshux // start with HAR, then override with additional options if (options.har) { @@ -471,13 +473,13 @@ Request.prototype.init = function (options) { } if (!self.agent) { - if (options.agentOptions) { - self.agentOptions = options.agentOptions + if (self.options.agentOptions) { + self.agentOptions = self.options.agentOptions } - if (options.agentClass) { - self.agentClass = options.agentClass - } else if (options.forever) { + if (self.options.agentClass) { + self.agentClass = self.options.agentClass + } else if (self.options.forever) { var v = version() // use ForeverAgent in node 0.10- only if (v.major === 0 && v.minor <= 10) { @@ -593,56 +595,7 @@ Request.prototype.init = function (options) { // httpModule, Tunneling agent, and/or Forever Agent in use. Request.prototype._updateProtocol = function () { var self = this - var protocol = self.uri.protocol - - if (protocol === 'https:' || self.tunnel) { - // previously was doing http, now doing https - // if it's https, then we might need to tunnel now. - if (self.proxy) { - if (self._tunnel.setup()) { - return - } - } - - self.httpModule = https - switch (self.agentClass) { - case ForeverAgent: - self.agentClass = ForeverAgent.SSL - break - case http.Agent: - self.agentClass = https.Agent - break - default: - // nothing we can do. Just hope for the best. - return - } - - // if there's an agent, we need to get a new one. - if (self.agent) { - self.agent = self.getNewAgent() - } - - } else { - // previously was doing https, now doing http - self.httpModule = http - switch (self.agentClass) { - case ForeverAgent.SSL: - self.agentClass = ForeverAgent - break - case https.Agent: - self.agentClass = http.Agent - break - default: - // nothing we can do. just hope for the best - return - } - - // if there's an agent, then get a new one. - if (self.agent) { - self.agent = null - self.agent = self.getNewAgent() - } - } + delete self.agent } Request.prototype.getNewAgent = function () { From 90799419d3ebb0f8710a6ff1b78a1a086155650f Mon Sep 17 00:00:00 2001 From: simov Date: Wed, 19 Aug 2015 18:37:47 +0300 Subject: [PATCH 163/490] 2.61.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7303c5fae..a6ca5dae9 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.60.1", + "version": "2.61.0", "author": "Mikeal Rogers ", "repository": { "type": "git", From 8492d18add93af1214943ee12e25371f9f9adad3 Mon Sep 17 00:00:00 2001 From: simov Date: Wed, 19 Aug 2015 18:39:26 +0300 Subject: [PATCH 164/490] Update changelog --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4cc1fcbe4..1e1b02c1d 100644 --- a/CHANGELOG.md +++ b/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) From 58e8f53f6272f36aaa3e5915bab027e6da5da22d Mon Sep 17 00:00:00 2001 From: simov Date: Wed, 19 Aug 2015 18:39:55 +0300 Subject: [PATCH 165/490] 2.61.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a6ca5dae9..8b7246488 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.61.0", + "version": "2.61.1", "author": "Mikeal Rogers ", "repository": { "type": "git", From 39e2bb23973928936b45c9f66417979e2b957376 Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 20 Aug 2015 18:05:32 +0300 Subject: [PATCH 166/490] Fix options not being initialized in defaults method --- index.js | 2 ++ tests/test-defaults.js | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/index.js b/index.js index d13ab96b2..4d0c748da 100755 --- a/index.js +++ b/index.js @@ -105,6 +105,8 @@ function wrapRequestMethod (method, options, requester, verb) { request.defaults = function (options, requester) { var self = this + options = options || {} + if (typeof options === 'function') { requester = options options = {} diff --git a/tests/test-defaults.js b/tests/test-defaults.js index 265d5d1fb..5b58304cf 100644 --- a/tests/test-defaults.js +++ b/tests/test-defaults.js @@ -312,6 +312,14 @@ tape('invoke convenience method from defaults', function(t) { }) }) +tape('defaults without options', function(t) { + var d = request.defaults() + d.get(s.url + '/', {json: true}, function (e, r, b) { + t.equal(r.statusCode, 200) + t.end() + }) +}) + tape('cleanup', function(t) { s.close(function() { t.end() From 2efc0f901782f43ecdcef0dcc3eeba37817ce545 Mon Sep 17 00:00:00 2001 From: Nikita Skalkin Date: Tue, 25 Aug 2015 15:24:07 +0300 Subject: [PATCH 167/490] missed comma --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 799811370..ef52cc4d2 100644 --- a/README.md +++ b/README.md @@ -221,7 +221,7 @@ Some variations in different HTTP implementations require a newline/CRLF before, uri: 'http://service.com/upload', multipart: [ { - 'content-type': 'application/json' + 'content-type': 'application/json', body: JSON.stringify({foo: 'bar', _attachments: {'message.txt': {follows: true, length: 18, 'content_type': 'text/plain' }}}) }, { body: 'I am an attachment' }, From 116297acc46e9e7380f3519319119fa551319344 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Loi=CC=88c=20Mahieu?= Date: Sat, 29 Aug 2015 16:10:36 +0200 Subject: [PATCH 168/490] Revert doc about installation of tough-cookie added in #884 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ef52cc4d2..09091c2ac 100644 --- a/README.md +++ b/README.md @@ -768,7 +768,7 @@ The first argument can be either a `url` or an `options` object. The only requir - `encoding` - Encoding to be used on `setEncoding` of response data. If `null`, the `body` is returned as a `Buffer`. Anything else **(including the default value of `undefined`)** will be passed as the [encoding](http://nodejs.org/api/buffer.html#buffer_buffer) parameter to `toString()` (meaning this is effectively `utf8` by default). (**Note:** if you expect binary data, you should set `encoding: null`.) - `gzip` - If `true`, add an `Accept-Encoding` header to request compressed content encodings from the server (if not already present) and decode supported content encodings in the response. **Note:** Automatic decoding of the response content is performed on the body data returned through `request` (both through the `request` stream and passed to the callback function) but is not performed on the `response` stream (available from the `response` event) which is the unmodified `http.IncomingMessage` object which may contain compressed data. See example below. -- `jar` - If `true` and `tough-cookie` is installed, remember cookies for future use (or define your custom cookie jar; see examples section) +- `jar` - If `true`, remember cookies for future use (or define your custom cookie jar; see examples section) --- @@ -1029,7 +1029,7 @@ the server sent a compressed response. }) ``` -Cookies are disabled by default (else, they would be used in subsequent requests). To enable cookies, set `jar` to `true` (either in `defaults` or `options`) and install `tough-cookie`. +Cookies are disabled by default (else, they would be used in subsequent requests). To enable cookies, set `jar` to `true` (either in `defaults` or `options`). ```js var request = request.defaults({jar: true}) From 2423e76df9e7f2f41e890390aa08fbf394678407 Mon Sep 17 00:00:00 2001 From: Josh Vanderwillik Date: Thu, 10 Sep 2015 13:16:20 -0400 Subject: [PATCH 169/490] Query strings now cooperate with unix sockets Fixes issue #1766 --- request.js | 29 ++++++++++++++++++----------- tests/test-unix.js | 13 +++++++++++-- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/request.js b/request.js index 700b9e0a9..dd71c8880 100644 --- a/request.js +++ b/request.js @@ -256,17 +256,7 @@ Request.prototype.init = function (options) { // Support Unix Sockets if (self.uri.host === 'unix') { - // Get the socket & request paths from the URL - var unixParts = self.uri.path.split(':') - , host = unixParts[0] - , path = unixParts[1] - // Apply unix properties to request - self.socketPath = host - self.uri.pathname = path - self.uri.path = path - self.uri.host = host - self.uri.hostname = host - self.uri.isUnix = true + self.enableUnixSocket() } if (self.strictSSL === false) { @@ -1163,6 +1153,10 @@ Request.prototype.qs = function (q, clobber) { self.url = self.uri self.path = self.uri.path + if ( self.uri.host === 'unix' ) { + self.enableUnixSocket() + } + return self } Request.prototype.form = function (form) { @@ -1411,6 +1405,19 @@ Request.prototype.destroy = function () { self.response.destroy() } } +Request.prototype.enableUnixSocket = function () { + // Get the socket & request paths from the URL + var unixParts = this.uri.path.split(':') + , host = unixParts[0] + , path = unixParts[1] + // Apply unix properties to request + this.socketPath = host + this.uri.pathname = path + this.uri.path = path + this.uri.host = host + this.uri.hostname = host + this.uri.isUnix = true +} Request.defaultProxyHeaderWhiteList = Tunnel.defaultProxyHeaderWhiteList.slice() diff --git a/tests/test-unix.js b/tests/test-unix.js index 71395a6bc..14615920b 100644 --- a/tests/test-unix.js +++ b/tests/test-unix.js @@ -6,8 +6,10 @@ var request = require('../index') , rimraf = require('rimraf') , assert = require('assert') , tape = require('tape') + , url = require('url') var path = [null, 'test', 'path'].join('/') + , searchString = '?foo=bar' , socket = [__dirname, 'tmp-socket'].join('/') , expectedBody = 'connected' , statusCode = 200 @@ -15,7 +17,9 @@ var path = [null, 'test', 'path'].join('/') rimraf.sync(socket) var s = http.createServer(function(req, res) { - assert.equal(req.url, path, 'requested path is sent to server') + var incomingUrl = url.parse(req.url) + assert.equal(incomingUrl.pathname, path, 'requested path is sent to server') + assert.equal(incomingUrl.search, searchString, 'query string is sent to server') res.statusCode = statusCode res.end(expectedBody) }) @@ -27,7 +31,12 @@ tape('setup', function(t) { }) tape('unix socket connection', function(t) { - request('http://unix:' + socket + ':' + path, function(err, res, body) { + request({ + uri: 'http://unix:' + socket + ':' + path, + qs: { + foo: 'bar' + } + }, function(err, res, body) { t.equal(err, null, 'no error in connection') t.equal(res.statusCode, statusCode, 'got HTTP 200 OK response') t.equal(body, expectedBody, 'expected response body is received') From cf6df69cd7ed5e3cabf38eed4bbeb908915f0787 Mon Sep 17 00:00:00 2001 From: Josh Vanderwillik Date: Fri, 11 Sep 2015 10:31:15 -0400 Subject: [PATCH 170/490] More tests for unix socket + query string Also brings .enableUnixSocket calls in line with the rest of the code stylistically. --- request.js | 29 +++++++++++++++-------------- tests/test-unix.js | 29 +++++++++++++++++++++++++---- 2 files changed, 40 insertions(+), 18 deletions(-) diff --git a/request.js b/request.js index dd71c8880..af91a11d3 100644 --- a/request.js +++ b/request.js @@ -1153,7 +1153,7 @@ Request.prototype.qs = function (q, clobber) { self.url = self.uri self.path = self.uri.path - if ( self.uri.host === 'unix' ) { + if (self.uri.host === 'unix') { self.enableUnixSocket() } @@ -1240,6 +1240,20 @@ Request.prototype.getHeader = function (name, headers) { }) return result } +Request.prototype.enableUnixSocket = function () { + // Get the socket & request paths from the URL + var unixParts = this.uri.path.split(':') + , host = unixParts[0] + , path = unixParts[1] + // Apply unix properties to request + this.socketPath = host + this.uri.pathname = path + this.uri.path = path + this.uri.host = host + this.uri.hostname = host + this.uri.isUnix = true +} + Request.prototype.auth = function (user, pass, sendImmediately, bearer) { var self = this @@ -1405,19 +1419,6 @@ Request.prototype.destroy = function () { self.response.destroy() } } -Request.prototype.enableUnixSocket = function () { - // Get the socket & request paths from the URL - var unixParts = this.uri.path.split(':') - , host = unixParts[0] - , path = unixParts[1] - // Apply unix properties to request - this.socketPath = host - this.uri.pathname = path - this.uri.path = path - this.uri.host = host - this.uri.hostname = host - this.uri.isUnix = true -} Request.defaultProxyHeaderWhiteList = Tunnel.defaultProxyHeaderWhiteList.slice() diff --git a/tests/test-unix.js b/tests/test-unix.js index 14615920b..7a75023b3 100644 --- a/tests/test-unix.js +++ b/tests/test-unix.js @@ -8,7 +8,8 @@ var request = require('../index') , tape = require('tape') , url = require('url') -var path = [null, 'test', 'path'].join('/') +var rawPath = [null, 'raw', 'path'].join('/') + , queryPath = [null, 'query', 'path'].join('/') , searchString = '?foo=bar' , socket = [__dirname, 'tmp-socket'].join('/') , expectedBody = 'connected' @@ -18,8 +19,19 @@ rimraf.sync(socket) var s = http.createServer(function(req, res) { var incomingUrl = url.parse(req.url) - assert.equal(incomingUrl.pathname, path, 'requested path is sent to server') - assert.equal(incomingUrl.search, searchString, 'query string is sent to server') + switch (incomingUrl.pathname) { + case rawPath: + assert.equal(incomingUrl.pathname, rawPath, 'requested path is sent to server') + break + + case queryPath: + assert.equal(incomingUrl.pathname, queryPath, 'requested path is sent to server') + assert.equal(incomingUrl.search, searchString, 'query string is sent to server') + break + + default: + assert(false, 'A valid path was requested') + } res.statusCode = statusCode res.end(expectedBody) }) @@ -31,8 +43,17 @@ tape('setup', function(t) { }) tape('unix socket connection', function(t) { + request( 'http://unix:' + socket + ':' + rawPath, function(err, res, body) { + t.equal(err, null, 'no error in connection') + t.equal(res.statusCode, statusCode, 'got HTTP 200 OK response') + t.equal(body, expectedBody, 'expected response body is received') + t.end() + }) +}) + +tape('unix socket connection with qs', function(t) { request({ - uri: 'http://unix:' + socket + ':' + path, + uri: 'http://unix:' + socket + ':' + queryPath, qs: { foo: 'bar' } From aaedf8a9d4a6fb48e565193ba64a3355d75ee300 Mon Sep 17 00:00:00 2001 From: simov Date: Mon, 14 Sep 2015 19:13:22 +0300 Subject: [PATCH 171/490] Add node 4.0 to the list of build targets --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 6180cb5d7..d793e7f54 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ language: node_js node_js: + - "4.0" - "io.js" - "0.12" - "0.10" From 60fdf181bce626a378411bcc6c34a0bdbbb83cb3 Mon Sep 17 00:00:00 2001 From: simov Date: Mon, 14 Sep 2015 19:25:19 +0300 Subject: [PATCH 172/490] Bump qs dependency version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8b7246488..1272a91b3 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "json-stringify-safe": "~5.0.0", "mime-types": "~2.1.2", "node-uuid": "~1.4.0", - "qs": "~4.0.0", + "qs": "~5.1.0", "tunnel-agent": "~0.4.0", "tough-cookie": ">=0.12.0", "http-signature": "~0.11.0", From 987f6a3329491d60959aa08f64c3fc7deac4bd6d Mon Sep 17 00:00:00 2001 From: simov Date: Tue, 15 Sep 2015 11:21:38 +0300 Subject: [PATCH 173/490] 2.62.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1272a91b3..9d0c35afb 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.61.1", + "version": "2.62.0", "author": "Mikeal Rogers ", "repository": { "type": "git", From 9cda443b62b33d077dc002aefd19e0b267df9cfa Mon Sep 17 00:00:00 2001 From: simov Date: Tue, 15 Sep 2015 11:23:34 +0300 Subject: [PATCH 174/490] Update changelog --- CHANGELOG.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e1b02c1d..b0ab18d64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ ## Change Log +### v2.62.0 (2015/09/15) +- [#1768](https://github.com/request/request/pull/1768) Add node 4.0 to the list of build targets (@simov) +- [#1767](https://github.com/request/request/pull/1767) Query strings now cooperate with unix sockets (@JoshWillik) +- [#1750](https://github.com/request/request/pull/1750) Revert doc about installation of tough-cookie added in #884 (@LoicMahieu) +- [#1746](https://github.com/request/request/pull/1746) Missed comma in Readme (@vladimirich) +- [#1743](https://github.com/request/request/pull/1743) Fix options not being initialized in defaults method (@simov) + ### 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) @@ -77,9 +84,9 @@ - [#1469](https://github.com/request/request/pull/1469) Feature/base url (@froatsnook) - [#1459](https://github.com/request/request/pull/1459) Add option to time request/response cycle (including rollup of redirects) (@aaron-em) - [#1468](https://github.com/request/request/pull/1468) Re-enable io.js/node 0.12 build (@simov, @mikeal, @BBB) -- [#1442](https://github.com/request/request/pull/1442) Fixed the issue with strictSSL tests on 0.12 & io.js by explicitly setting a cipher that matches the cert. (@BBB, @nicolasmccurdy, @simov, @0x4139) +- [#1442](https://github.com/request/request/pull/1442) Fixed the issue with strictSSL tests on 0.12 & io.js by explicitly setting a cipher that matches the cert. (@BBB, @nicolasmccurdy, @demohi, @simov, @0x4139) - [#1460](https://github.com/request/request/pull/1460) localAddress or proxy config is lost when redirecting (@simov, @0x4139) -- [#1453](https://github.com/request/request/pull/1453) Test on Node.js 0.12 and io.js with allowed failures (@nicolasmccurdy) +- [#1453](https://github.com/request/request/pull/1453) Test on Node.js 0.12 and io.js with allowed failures (@nicolasmccurdy, @demohi) - [#1426](https://github.com/request/request/pull/1426) Fixing tests to pass on io.js and node 0.12 (only test-https.js stiff failing) (@mikeal) - [#1446](https://github.com/request/request/pull/1446) Missing HTTP referer header with redirects Fixes #1038 (@simov, @guimonz) - [#1428](https://github.com/request/request/pull/1428) Deprecate Node v0.8.x (@nylen) From cd928c4e3e51bb5ce54ca00e34f6719c430c9bd6 Mon Sep 17 00:00:00 2001 From: simov Date: Tue, 15 Sep 2015 11:23:51 +0300 Subject: [PATCH 175/490] 2.62.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9d0c35afb..44e2c1acd 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.62.0", + "version": "2.62.1", "author": "Mikeal Rogers ", "repository": { "type": "git", From 5225289165a0fb060c30e5a71f69704c3450103f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rn=20Zaefferer?= Date: Tue, 15 Sep 2015 17:12:25 +0200 Subject: [PATCH 176/490] Set default application/json content-type when using json option Will set the header when using `json: true` without a body. --- request.js | 9 +++------ tests/test-defaults.js | 5 +++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/request.js b/request.js index af91a11d3..61e51fad3 100644 --- a/request.js +++ b/request.js @@ -1198,6 +1198,9 @@ Request.prototype.json = function (val) { } self._json = true + if (!self.hasHeader('content-type')) { + self.setHeader('content-type', 'application/json') + } if (typeof val === 'boolean') { if (self.body !== undefined) { if (!/^application\/x-www-form-urlencoded\b/.test(self.getHeader('content-type'))) { @@ -1205,15 +1208,9 @@ Request.prototype.json = function (val) { } else { self.body = self._qs.rfc3986(self.body) } - if (!self.hasHeader('content-type')) { - self.setHeader('content-type', 'application/json') - } } } else { self.body = safeStringify(val) - if (!self.hasHeader('content-type')) { - self.setHeader('content-type', 'application/json') - } } if (typeof self.jsonReviver === 'function') { diff --git a/tests/test-defaults.js b/tests/test-defaults.js index 5b58304cf..4f8e3c7fe 100644 --- a/tests/test-defaults.js +++ b/tests/test-defaults.js @@ -73,6 +73,7 @@ tape('deep extend', function(t) { }, function (e, r, b) { delete b.headers.host delete b.headers.accept + delete b.headers['content-type'] delete b.headers.connection t.deepEqual(b.headers, { a: '1', b: '3', c: '4' }) t.deepEqual(b.qs, { a: '1', b: '3', c: '4' }) @@ -97,7 +98,7 @@ tape('post(string, object, function)', function(t) { }).post(s.url + '/', { json: true }, function (e, r, b) { t.equal(b.method, 'POST') t.equal(b.headers.foo, 'bar') - t.equal(b.headers['content-type'], undefined) + t.equal(b.headers['content-type'], 'application/json') t.end() }) }) @@ -108,7 +109,7 @@ tape('patch(string, object, function)', function(t) { }).patch(s.url + '/', { json: true }, function (e, r, b) { t.equal(b.method, 'PATCH') t.equal(b.headers.foo, 'bar') - t.equal(b.headers['content-type'], undefined) + t.equal(b.headers['content-type'], 'application/json') t.end() }) }) From fc5c0d6ad9417be48073a9631a94b9020a243a5a Mon Sep 17 00:00:00 2001 From: djchie Date: Thu, 17 Sep 2015 21:15:57 -0700 Subject: [PATCH 177/490] Fix spelling mistake from "recommendend" to "recommended" --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 09091c2ac..e264b88a3 100644 --- a/README.md +++ b/README.md @@ -584,7 +584,7 @@ Note: The `SOCKET` path is assumed to be absolute to the root of the host file s ## TLS/SSL Protocol TLS/SSL Protocol options, such as `cert`, `key` and `passphrase`, can be -set directly in `options` object, in the `agentOptions` property of the `options` object, or even in `https.globalAgent.options`. Keep in mind that, although `agentOptions` allows for a slightly wider range of configurations, the recommendend way is via `options` object directly, as using `agentOptions` or `https.globalAgent.options` would not be applied in the same way in proxied environments (as data travels through a TLS connection instead of an http/https agent). +set directly in `options` object, in the `agentOptions` property of the `options` object, or even in `https.globalAgent.options`. Keep in mind that, although `agentOptions` allows for a slightly wider range of configurations, the recommended way is via `options` object directly, as using `agentOptions` or `https.globalAgent.options` would not be applied in the same way in proxied environments (as data travels through a TLS connection instead of an http/https agent). ```js var fs = require('fs') From d097da73dd04ae405caccf7b05f4c0e49518c635 Mon Sep 17 00:00:00 2001 From: Ryan Wholey Date: Thu, 17 Sep 2015 21:50:14 -0700 Subject: [PATCH 178/490] Changed word 'conjuction' to read 'conjunction' in README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 09091c2ac..00143d17c 100644 --- a/README.md +++ b/README.md @@ -312,7 +312,7 @@ initial request, which will probably cause the request to fail. Bearer authentication is supported, and is activated when the `bearer` value is available. The value may be either a `String` or a `Function` returning a `String`. Using a function to supply the bearer token is particularly useful if -used in conjuction with `defaults` to allow a single function to supply the +used in conjunction with `defaults` to allow a single function to supply the last known token at the time of sending a request, or to compute one on the fly. [back to top](#table-of-contents) From 081246116cd142f60cbea5546645b4424c9dba58 Mon Sep 17 00:00:00 2001 From: simov Date: Mon, 21 Sep 2015 16:59:01 +0300 Subject: [PATCH 179/490] 2.63.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 44e2c1acd..6f471eb52 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.62.1", + "version": "2.63.0", "author": "Mikeal Rogers ", "repository": { "type": "git", From e1c36a0d10cab1466262efddd6cc54f80d88be9c Mon Sep 17 00:00:00 2001 From: simov Date: Mon, 21 Sep 2015 17:00:22 +0300 Subject: [PATCH 180/490] Update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b0ab18d64..16fbf7fbd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## Change Log +### v2.63.0 (2015/09/21) +- [#1772](https://github.com/request/request/pull/1772) Set default application/json content-type when using json option (@jzaefferer) + ### v2.62.0 (2015/09/15) - [#1768](https://github.com/request/request/pull/1768) Add node 4.0 to the list of build targets (@simov) - [#1767](https://github.com/request/request/pull/1767) Query strings now cooperate with unix sockets (@JoshWillik) From 9b37c85d35d75d90e14cf238df8939cd6262d186 Mon Sep 17 00:00:00 2001 From: simov Date: Mon, 21 Sep 2015 17:00:46 +0300 Subject: [PATCH 181/490] 2.63.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6f471eb52..edffeaaf5 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.63.0", + "version": "2.63.1", "author": "Mikeal Rogers ", "repository": { "type": "git", From 65cb53cd9afb1a3c4963c90724f7352270cdfc02 Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 24 Sep 2015 20:27:40 +0300 Subject: [PATCH 182/490] Revert "Set default application/json content-type when using json option" This reverts commit 5225289165a0fb060c30e5a71f69704c3450103f. --- request.js | 9 ++++++--- tests/test-defaults.js | 5 ++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/request.js b/request.js index 61e51fad3..af91a11d3 100644 --- a/request.js +++ b/request.js @@ -1198,9 +1198,6 @@ Request.prototype.json = function (val) { } self._json = true - if (!self.hasHeader('content-type')) { - self.setHeader('content-type', 'application/json') - } if (typeof val === 'boolean') { if (self.body !== undefined) { if (!/^application\/x-www-form-urlencoded\b/.test(self.getHeader('content-type'))) { @@ -1208,9 +1205,15 @@ Request.prototype.json = function (val) { } else { self.body = self._qs.rfc3986(self.body) } + if (!self.hasHeader('content-type')) { + self.setHeader('content-type', 'application/json') + } } } else { self.body = safeStringify(val) + if (!self.hasHeader('content-type')) { + self.setHeader('content-type', 'application/json') + } } if (typeof self.jsonReviver === 'function') { diff --git a/tests/test-defaults.js b/tests/test-defaults.js index 4f8e3c7fe..5b58304cf 100644 --- a/tests/test-defaults.js +++ b/tests/test-defaults.js @@ -73,7 +73,6 @@ tape('deep extend', function(t) { }, function (e, r, b) { delete b.headers.host delete b.headers.accept - delete b.headers['content-type'] delete b.headers.connection t.deepEqual(b.headers, { a: '1', b: '3', c: '4' }) t.deepEqual(b.qs, { a: '1', b: '3', c: '4' }) @@ -98,7 +97,7 @@ tape('post(string, object, function)', function(t) { }).post(s.url + '/', { json: true }, function (e, r, b) { t.equal(b.method, 'POST') t.equal(b.headers.foo, 'bar') - t.equal(b.headers['content-type'], 'application/json') + t.equal(b.headers['content-type'], undefined) t.end() }) }) @@ -109,7 +108,7 @@ tape('patch(string, object, function)', function(t) { }).patch(s.url + '/', { json: true }, function (e, r, b) { t.equal(b.method, 'PATCH') t.equal(b.headers.foo, 'bar') - t.equal(b.headers['content-type'], 'application/json') + t.equal(b.headers['content-type'], undefined) t.end() }) }) From f6b91b55a3b09f3fc2eb4bc9b1b2174016b2961a Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 24 Sep 2015 20:56:55 +0300 Subject: [PATCH 183/490] Add test for missing request body when using json:true --- tests/test-json-request.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test-json-request.js b/tests/test-json-request.js index f45c753d7..e7f39556e 100644 --- a/tests/test-json-request.js +++ b/tests/test-json-request.js @@ -72,6 +72,16 @@ testJSONValueReviver('jsonReviver', -48269.592, function (k, v) { }, 48269.592) testJSONValueReviver('jsonReviverInvalid', -48269.592, 'invalid reviver', -48269.592) +tape('missing body', function (t) { + s.on('/missing-body', function (req, res) { + t.equal(req.headers['content-type'], undefined) + res.end() + }) + request({url:s.url + '/missing-body', json:true}, function () { + t.end() + }) +}) + tape('cleanup', function(t) { s.close(function() { t.end() From abf34d3e6414c8bbf61c6c065dcad40b6ec0791b Mon Sep 17 00:00:00 2001 From: tcme Date: Fri, 25 Sep 2015 10:30:43 +0200 Subject: [PATCH 184/490] npm ignore examples, release.sh and disabled.appveyor.yml --- .npmignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.npmignore b/.npmignore index 53fc9efa9..67fe11cc0 100644 --- a/.npmignore +++ b/.npmignore @@ -1,3 +1,6 @@ coverage tests node_modules +examples +release.sh +disabled.appveyor.yml From e9b7b387a413557604cc55b33d9f033f42a2a74f Mon Sep 17 00:00:00 2001 From: simov Date: Fri, 25 Sep 2015 15:20:10 +0300 Subject: [PATCH 185/490] 2.64.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index edffeaaf5..d621cd0a3 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.63.1", + "version": "2.64.0", "author": "Mikeal Rogers ", "repository": { "type": "git", From ca364485249f13c4810bb9b3952fb0fb886a93ee Mon Sep 17 00:00:00 2001 From: simov Date: Fri, 25 Sep 2015 15:21:08 +0300 Subject: [PATCH 186/490] Update changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16fbf7fbd..a5da7d968 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ ## Change Log +### v2.64.0 (2015/09/25) +- [#1787](https://github.com/request/request/pull/1787) npm ignore examples, release.sh and disabled.appveyor.yml (@thisconnect) +- [#1775](https://github.com/request/request/pull/1775) Fix typo in README.md (@djchie) +- [#1776](https://github.com/request/request/pull/1776) Changed word 'conjuction' to read 'conjunction' in README.md (@ryanwholey) +- [#1785](https://github.com/request/request/pull/1785) Revert: Set default application/json content-type when using json option #1772 (@simov) + ### v2.63.0 (2015/09/21) - [#1772](https://github.com/request/request/pull/1772) Set default application/json content-type when using json option (@jzaefferer) From 51a11d97120d551a55e0c5c19e7588d03d33945d Mon Sep 17 00:00:00 2001 From: simov Date: Fri, 25 Sep 2015 15:21:33 +0300 Subject: [PATCH 187/490] 2.64.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d621cd0a3..e93cb6ec5 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.64.0", + "version": "2.64.1", "author": "Mikeal Rogers ", "repository": { "type": "git", From d3db09e0d5e67b166df228309052b49eae14a31e Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Fri, 25 Sep 2015 16:13:28 +0200 Subject: [PATCH 188/490] chore(package): pinned dependencies http://greenkeeper.io/ --- package.json | 68 ++++++++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/package.json b/package.json index e93cb6ec5..7fe482e47 100644 --- a/package.json +++ b/package.json @@ -22,25 +22,25 @@ }, "main": "index.js", "dependencies": { - "bl": "~1.0.0", - "caseless": "~0.11.0", - "extend": "~3.0.0", - "forever-agent": "~0.6.0", - "form-data": "~1.0.0-rc1", - "json-stringify-safe": "~5.0.0", - "mime-types": "~2.1.2", - "node-uuid": "~1.4.0", - "qs": "~5.1.0", - "tunnel-agent": "~0.4.0", - "tough-cookie": ">=0.12.0", - "http-signature": "~0.11.0", - "oauth-sign": "~0.8.0", - "hawk": "~3.1.0", - "aws-sign2": "~0.5.0", - "stringstream": "~0.0.4", - "combined-stream": "~1.0.1", - "isstream": "~0.1.1", - "har-validator": "^1.6.1" + "bl": "1.0.0", + "caseless": "0.11.0", + "extend": "3.0.0", + "forever-agent": "0.6.1", + "form-data": "1.0.0-rc3", + "json-stringify-safe": "5.0.1", + "mime-types": "2.1.7", + "node-uuid": "1.4.3", + "qs": "5.1.0", + "tunnel-agent": "0.4.1", + "tough-cookie": "2.0.0", + "http-signature": "0.11.0", + "oauth-sign": "0.8.0", + "hawk": "3.1.0", + "aws-sign2": "0.5.0", + "stringstream": "0.0.4", + "combined-stream": "1.0.5", + "isstream": "0.1.2", + "har-validator": "1.8.0" }, "scripts": { "test": "npm run lint && npm run test-ci && npm run test-browser", @@ -50,24 +50,24 @@ "lint": "eslint lib/ *.js tests/ && echo Lint passed." }, "devDependencies": { - "browserify": "~5.9.1", - "browserify-istanbul": "~0.1.3", + "browserify": "5.9.3", + "browserify-istanbul": "0.1.5", "buffer-equal": "0.0.1", - "codecov.io": "~0.1.2", - "coveralls": "~2.11.2", + "codecov.io": "0.1.6", + "coveralls": "2.11.4", "eslint": "0.18.0", - "function-bind": "~1.0.0", - "istanbul": "~0.3.2", - "karma": "~0.12.21", - "karma-browserify": "~3.0.1", + "function-bind": "1.0.2", + "istanbul": "0.3.21", + "karma": "0.12.37", + "karma-browserify": "3.0.3", "karma-cli": "0.0.4", "karma-coverage": "0.2.6", - "karma-phantomjs-launcher": "~0.1.4", - "karma-tap": "~1.0.1", - "rimraf": "~2.2.8", - "server-destroy": "~1.0.0", - "tape": "~3.0.0", - "taper": "~0.4.0", - "bluebird": "~2.9.21" + "karma-phantomjs-launcher": "0.1.4", + "karma-tap": "1.0.3", + "rimraf": "2.2.8", + "server-destroy": "1.0.1", + "tape": "3.0.3", + "taper": "0.4.0", + "bluebird": "2.9.34" } } From 608fd2b23a983151b870e0bc991b9fb72b866d50 Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Fri, 25 Sep 2015 22:07:41 +0200 Subject: [PATCH 189/490] chore(package): updated bluebird to version 2.10.1 http://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e93cb6ec5..b8419ca47 100644 --- a/package.json +++ b/package.json @@ -68,6 +68,6 @@ "server-destroy": "~1.0.0", "tape": "~3.0.0", "taper": "~0.4.0", - "bluebird": "~2.9.21" + "bluebird": "2.10.1" } } From 9f02ff8ffc644deef4425f27c97d6b4a298c2f11 Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Sat, 26 Sep 2015 17:15:14 +0200 Subject: [PATCH 190/490] chore(package): updated karma to version 0.13.10 http://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e93cb6ec5..08e743aec 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "eslint": "0.18.0", "function-bind": "~1.0.0", "istanbul": "~0.3.2", - "karma": "~0.12.21", + "karma": "0.13.10", "karma-browserify": "~3.0.1", "karma-cli": "0.0.4", "karma-coverage": "0.2.6", From 29bd3bdd26ea3db3bde5ba94884bb080c36b3d6f Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Sun, 27 Sep 2015 06:32:37 +0200 Subject: [PATCH 191/490] chore(package): updated browserify to version 11.2.0 http://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e93cb6ec5..1bd6163b0 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "lint": "eslint lib/ *.js tests/ && echo Lint passed." }, "devDependencies": { - "browserify": "~5.9.1", + "browserify": "11.2.0", "browserify-istanbul": "~0.1.3", "buffer-equal": "0.0.1", "codecov.io": "~0.1.2", From 5f4866765f4c7b478d030ef77bae8fb074ed40ef Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Sun, 27 Sep 2015 19:55:58 +0200 Subject: [PATCH 192/490] chore(package): updated karma-cli to version 0.1.1 http://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e93cb6ec5..c678d1f88 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "istanbul": "~0.3.2", "karma": "~0.12.21", "karma-browserify": "~3.0.1", - "karma-cli": "0.0.4", + "karma-cli": "0.1.1", "karma-coverage": "0.2.6", "karma-phantomjs-launcher": "~0.1.4", "karma-tap": "~1.0.1", From dfb70f3827db65fe78cf8d8208711c97cdb363ff Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Tue, 29 Sep 2015 17:59:38 +0200 Subject: [PATCH 193/490] chore(package): update tape to version 4.2.0 http://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a8ab43005..a8b8b7355 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,7 @@ "karma-tap": "1.0.3", "rimraf": "2.2.8", "server-destroy": "1.0.1", - "tape": "3.0.3", + "tape": "4.2.0", "taper": "0.4.0", "bluebird": "2.10.1" } From 7a4feb4b8f93841558c7cacfdcd4dffb0873b1ce Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Wed, 30 Sep 2015 03:38:21 +0200 Subject: [PATCH 194/490] chore(package): update karma-browserify to version 4.4.0 http://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a8ab43005..12ffcd09e 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "eslint": "0.18.0", "function-bind": "1.0.2", "istanbul": "0.3.21", - "karma-browserify": "3.0.3", + "karma-browserify": "4.4.0", "karma": "0.13.10", "karma-cli": "0.1.1", "karma-coverage": "0.2.6", From 03d903bd4a9955bfab22eb5402fc1414a03b3f01 Mon Sep 17 00:00:00 2001 From: simov Date: Wed, 30 Sep 2015 10:06:31 +0300 Subject: [PATCH 195/490] Add caret ranges for devDependencies, except eslint --- package.json | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 450d4b4d5..d81c5b5ba 100644 --- a/package.json +++ b/package.json @@ -50,24 +50,24 @@ "lint": "eslint lib/ *.js tests/ && echo Lint passed." }, "devDependencies": { - "browserify-istanbul": "0.1.5", - "browserify": "11.2.0", - "buffer-equal": "0.0.1", - "codecov.io": "0.1.6", - "coveralls": "2.11.4", + "browserify-istanbul": "^0.1.5", + "browserify": "^11.2.0", + "buffer-equal": "^0.0.1", + "codecov.io": "^0.1.6", + "coveralls": "^2.11.4", "eslint": "0.18.0", - "function-bind": "1.0.2", - "istanbul": "0.3.21", - "karma-browserify": "4.4.0", - "karma": "0.13.10", - "karma-cli": "0.1.1", - "karma-coverage": "0.2.6", - "karma-phantomjs-launcher": "0.1.4", - "karma-tap": "1.0.3", - "rimraf": "2.2.8", - "server-destroy": "1.0.1", - "tape": "4.2.0", - "taper": "0.4.0", - "bluebird": "2.10.1" + "function-bind": "^1.0.2", + "istanbul": "^0.3.21", + "karma-browserify": "^4.4.0", + "karma": "^0.13.10", + "karma-cli": "^0.1.1", + "karma-coverage": "^0.2.6", + "karma-phantomjs-launcher": "^0.1.4", + "karma-tap": "^1.0.3", + "rimraf": "^2.2.8", + "server-destroy": "^1.0.1", + "tape": "^4.2.0", + "taper": "^0.4.0", + "bluebird": "^2.10.1" } } From 4704cfa31410a4f6ec1a4b7adf717845e64baf81 Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Fri, 2 Oct 2015 10:49:10 -0700 Subject: [PATCH 196/490] chore(package): update tough-cookie to version 2.1.0 http://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d81c5b5ba..47cf13e36 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "node-uuid": "1.4.3", "qs": "5.1.0", "tunnel-agent": "0.4.1", - "tough-cookie": "2.0.0", + "tough-cookie": "2.1.0", "http-signature": "0.11.0", "oauth-sign": "0.8.0", "hawk": "3.1.0", From 675794a30fb8e192d37a5867b0e1dc386a4c2bf3 Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Sat, 3 Oct 2015 15:58:48 -0700 Subject: [PATCH 197/490] chore(package): update har-validator to version 2.0.2 http://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 47cf13e36..5a264ba7d 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "stringstream": "0.0.4", "combined-stream": "1.0.5", "isstream": "0.1.2", - "har-validator": "1.8.0" + "har-validator": "2.0.2" }, "scripts": { "test": "npm run lint && npm run test-ci && npm run test-browser", From 12b3bffe49c0b732dc840fdafa69872b679e47aa Mon Sep 17 00:00:00 2001 From: Pierre Voisin Date: Mon, 5 Oct 2015 16:36:08 -0400 Subject: [PATCH 198/490] Extracted the portion of `Request#onRequestResponse` that reads the response's body into `Request#readResponseBody`. Change-Id: I8981efdcf62c7631ca972a4e8e8c1f57a8f02603 --- request.js | 102 ++++++++++++++++++++++++++++------------------------- 1 file changed, 54 insertions(+), 48 deletions(-) diff --git a/request.js b/request.js index af91a11d3..6ea827b0a 100644 --- a/request.js +++ b/request.js @@ -1014,54 +1014,7 @@ Request.prototype.onRequestResponse = function (response) { responseContent.on('close', function () {self.emit('close')}) if (self.callback) { - var buffer = bl() - , strings = [] - - self.on('data', function (chunk) { - if (Buffer.isBuffer(chunk)) { - buffer.append(chunk) - } else { - strings.push(chunk) - } - }) - self.on('end', function () { - debug('end event', self.uri.href) - if (self._aborted) { - debug('aborted', self.uri.href) - return - } - - if (buffer.length) { - debug('has body', self.uri.href, buffer.length) - if (self.encoding === null) { - // response.body = buffer - // can't move to this until https://github.com/rvagg/bl/issues/13 - response.body = buffer.slice() - } else { - response.body = buffer.toString(self.encoding) - } - } else if (strings.length) { - // The UTF8 BOM [0xEF,0xBB,0xBF] is converted to [0xFE,0xFF] in the JS UTC16/UCS2 representation. - // Strip this value out when the encoding is set to 'utf8', as upstream consumers won't expect it and it breaks JSON.parse(). - if (self.encoding === 'utf8' && strings[0].length > 0 && strings[0][0] === '\uFEFF') { - strings[0] = strings[0].substring(1) - } - response.body = strings.join('') - } - - if (self._json) { - try { - response.body = JSON.parse(response.body, self._jsonReviver) - } catch (e) { - debug('invalid JSON received', self.uri.href) - } - } - debug('emitting complete', self.uri.href) - if (typeof response.body === 'undefined' && !self._json) { - response.body = self.encoding === null ? new Buffer(0) : '' - } - self.emit('complete', response, response.body) - }) + self.readResponseBody(response) } //if no callback else { @@ -1077,6 +1030,59 @@ Request.prototype.onRequestResponse = function (response) { debug('finish init function', self.uri.href) } +Request.prototype.readResponseBody = function (response) { + var self = this + debug('reading response\'s body') + var buffer = bl() + , strings = [] + + self.on('data', function (chunk) { + if (Buffer.isBuffer(chunk)) { + buffer.append(chunk) + } else { + strings.push(chunk) + } + }) + self.on('end', function () { + debug('end event', self.uri.href) + if (self._aborted) { + debug('aborted', self.uri.href) + return + } + + if (buffer.length) { + debug('has body', self.uri.href, buffer.length) + if (self.encoding === null) { + // response.body = buffer + // can't move to this until https://github.com/rvagg/bl/issues/13 + response.body = buffer.slice() + } else { + response.body = buffer.toString(self.encoding) + } + } else if (strings.length) { + // The UTF8 BOM [0xEF,0xBB,0xBF] is converted to [0xFE,0xFF] in the JS UTC16/UCS2 representation. + // Strip this value out when the encoding is set to 'utf8', as upstream consumers won't expect it and it breaks JSON.parse(). + if (self.encoding === 'utf8' && strings[0].length > 0 && strings[0][0] === '\uFEFF') { + strings[0] = strings[0].substring(1) + } + response.body = strings.join('') + } + + if (self._json) { + try { + response.body = JSON.parse(response.body, self._jsonReviver) + } catch (e) { + debug('invalid JSON received', self.uri.href) + } + } + debug('emitting complete', self.uri.href) + if (typeof response.body === 'undefined' && !self._json) { + response.body = self.encoding === null ? new Buffer(0) : '' + } + self.emit('complete', response, response.body) + }) +} + Request.prototype.abort = function () { var self = this self._aborted = true From 1a028762d79f51599a16f77d2de5ed848912a0e8 Mon Sep 17 00:00:00 2001 From: Michael Genereux Date: Mon, 5 Oct 2015 17:39:03 -0700 Subject: [PATCH 199/490] Run stringify once Code seems to be running _qs.stringify twice for no reason. --- request.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/request.js b/request.js index af91a11d3..d9f4eecc4 100644 --- a/request.js +++ b/request.js @@ -1143,12 +1143,12 @@ Request.prototype.qs = function (q, clobber) { base[i] = q[i] } - if (self._qs.stringify(base) === '') { + var qs = self._qs.stringify(base) + + if (qs === '') { return self } - var qs = self._qs.stringify(base) - self.uri = url.parse(self.uri.href.split('?')[0] + '?' + qs) self.url = self.uri self.path = self.uri.path From bd51393263919c01b1360e414e141ac5a9fcdaf2 Mon Sep 17 00:00:00 2001 From: Michael Genereux Date: Mon, 5 Oct 2015 18:25:38 -0700 Subject: [PATCH 200/490] Set href as request.js uses it If href was never defined in an original, dynamically generated request options object the rest of the code referencing href fails. --- request.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/request.js b/request.js index af91a11d3..19d5d1644 100644 --- a/request.js +++ b/request.js @@ -247,6 +247,8 @@ Request.prototype.init = function (options) { // If a string URI/URL was given, parse it into a URL object if (typeof self.uri === 'string') { self.uri = url.parse(self.uri) + } else { + self.uri.href = url.format(self.uri) } // DEPRECATED: Warning for users of the old Unix Sockets URL Scheme From 2c1296d7c7154f31af6b88ecd0b7624ffa61567f Mon Sep 17 00:00:00 2001 From: Michael Genereux Date: Tue, 6 Oct 2015 11:06:20 -0700 Subject: [PATCH 201/490] Clarified check and add test. --- request.js | 5 ++++- tests/test-isUrl.js | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/request.js b/request.js index 19d5d1644..a937047d4 100644 --- a/request.js +++ b/request.js @@ -247,7 +247,10 @@ Request.prototype.init = function (options) { // If a string URI/URL was given, parse it into a URL object if (typeof self.uri === 'string') { self.uri = url.parse(self.uri) - } else { + } + + // Some URL objects are not from a URL parsed string and need href added + if (!self.uri.href) { self.uri.href = url.format(self.uri) } diff --git a/tests/test-isUrl.js b/tests/test-isUrl.js index c6b930ddc..0623eac4b 100644 --- a/tests/test-isUrl.js +++ b/tests/test-isUrl.js @@ -94,6 +94,23 @@ tape('hostname and port 3', function(t) { }) }) +tape('hostname and query string', function(t) { + request({ + uri: { + protocol: 'http:', + hostname: 'localhost', + port: 6767 + }, + qs: { + test: 'test' + } + }, function(err, res, body) { + t.equal(err, null) + t.equal(body, 'ok') + t.end() + }) +}) + tape('cleanup', function(t) { s.close(function() { t.end() From c96b5cb8c0196319ebe1ffcd371b4d7dd7b4f626 Mon Sep 17 00:00:00 2001 From: Albert Callarisa Date: Wed, 7 Oct 2015 11:38:45 -0700 Subject: [PATCH 202/490] Updated qs dependency to 5.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5a264ba7d..2ac580442 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "json-stringify-safe": "5.0.1", "mime-types": "2.1.7", "node-uuid": "1.4.3", - "qs": "5.1.0", + "qs": "5.2.0", "tunnel-agent": "0.4.1", "tough-cookie": "2.1.0", "http-signature": "0.11.0", From 488fc477127973dcad30677e0cee053ff036f4d7 Mon Sep 17 00:00:00 2001 From: Sebastian Mayr Date: Sat, 3 Oct 2015 20:00:40 +0200 Subject: [PATCH 203/490] Enable loose cookie parsing in tough-cookie tough-cookie 2.1.0 got a loose cookie mode which is more how browsers actually behave. It implies an empty key for value-only cookies. --- lib/cookies.js | 4 ++-- package.json | 2 +- tests/test-cookies.js | 30 ++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/lib/cookies.js b/lib/cookies.js index adde7c601..412c07d63 100644 --- a/lib/cookies.js +++ b/lib/cookies.js @@ -13,13 +13,13 @@ exports.parse = function(str) { if (typeof str !== 'string') { throw new Error('The cookie function only accepts STRING as param') } - return Cookie.parse(str) + return Cookie.parse(str, {loose: true}) } // Adapt the sometimes-Async api of tough.CookieJar to our requirements function RequestJar(store) { var self = this - self._jar = new CookieJar(store) + self._jar = new CookieJar(store, {looseMode: true}) } RequestJar.prototype.setCookie = function(cookieOrStr, uri, options) { var self = this diff --git a/package.json b/package.json index 47cf13e36..bd23acdef 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "node-uuid": "1.4.3", "qs": "5.1.0", "tunnel-agent": "0.4.1", - "tough-cookie": "2.1.0", + "tough-cookie": "2.2.0", "http-signature": "0.11.0", "oauth-sign": "0.8.0", "hawk": "3.1.0", diff --git a/tests/test-cookies.js b/tests/test-cookies.js index cf8de5cf9..7014935f0 100644 --- a/tests/test-cookies.js +++ b/tests/test-cookies.js @@ -6,11 +6,14 @@ var http = require('http') var validUrl = 'http://localhost:6767/valid' + , malformedUrl = 'http://localhost:6767/malformed' , invalidUrl = 'http://localhost:6767/invalid' var server = http.createServer(function (req, res) { if (req.url === '/valid') { res.setHeader('set-cookie', 'foo=bar') + } else if (req.url === '/malformed') { + res.setHeader('set-cookie', 'foo') } else if (req.url === '/invalid') { res.setHeader('set-cookie', 'foo=bar; Domain=foo.com') } @@ -30,6 +33,13 @@ tape('simple cookie creation', function(t) { t.end() }) +tape('simple malformed cookie creation', function(t) { + var cookie = request.cookie('foo') + t.equals(cookie.key, '') + t.equals(cookie.value, 'foo') + t.end() +}) + tape('after server sends a cookie', function(t) { var jar1 = request.jar() request({ @@ -50,6 +60,26 @@ tape('after server sends a cookie', function(t) { }) }) +tape('after server sends a malformed cookie', function(t) { + var jar = request.jar() + request({ + method: 'GET', + url: malformedUrl, + jar: jar + }, + function (error, response, body) { + t.equal(error, null) + t.equal(jar.getCookieString(malformedUrl), 'foo') + t.equal(body, 'okay') + + var cookies = jar.getCookies(malformedUrl) + t.equal(cookies.length, 1) + t.equal(cookies[0].key, '') + t.equal(cookies[0].value, 'foo') + t.end() + }) +}) + tape('after server sends a cookie for a different domain', function(t) { var jar2 = request.jar() request({ From 033e7fc42a0f40adf5e83644dd329625f32a2192 Mon Sep 17 00:00:00 2001 From: Dennis Keller Date: Mon, 5 Oct 2015 23:37:44 -0400 Subject: [PATCH 204/490] Implement support for 2617 MD5-sess algorithm. Update TODO list Remove challenge.algorithm TODO note --- lib/auth.js | 23 +++++++-- tests/test-digest-auth.js | 99 +++++++++++++++++++++++++++++++++------ 2 files changed, 103 insertions(+), 19 deletions(-) diff --git a/lib/auth.js b/lib/auth.js index 1be1f4258..1cb695216 100644 --- a/lib/auth.js +++ b/lib/auth.js @@ -50,8 +50,6 @@ Auth.prototype.bearer = function (bearer, sendImmediately) { Auth.prototype.digest = function (method, path, authHeader) { // TODO: More complete implementation of RFC 2617. - // - check challenge.algorithm - // - support algorithm="MD5-sess" // - handle challenge.domain // - support qop="auth-int" only // - handle Authentication-Info (not necessarily?) @@ -73,11 +71,28 @@ Auth.prototype.digest = function (method, path, authHeader) { challenge[match[1]] = match[2] || match[3] } - var ha1 = md5(self.user + ':' + challenge.realm + ':' + self.pass) - var ha2 = md5(method + ':' + path) + /** + * RFC 2617: handle both MD5 and MD5-sess algorithms. + * + * If the algorithm directive's value is "MD5" or unspecified, then HA1 is + * HA1=MD5(username:realm:password) + * If the algorithm directive's value is "MD5-sess", then HA1 is + * HA1=MD5(MD5(username:realm:password):nonce:cnonce) + */ + var ha1Compute = function (algorithm, user, realm, pass, nonce, cnonce) { + var ha1 = md5(user + ':' + realm + ':' + pass) + if (algorithm && algorithm.toLowerCase() === 'md5-sess') { + return md5(ha1 + ':' + nonce + ':' + cnonce) + } else { + return ha1 + } + } + var qop = /(^|,)\s*auth\s*($|,)/.test(challenge.qop) && 'auth' var nc = qop && '00000001' var cnonce = qop && uuid().replace(/-/g, '') + var ha1 = ha1Compute(challenge.algorithm, self.user, challenge.realm, self.pass, challenge.nonce, cnonce) + var ha2 = md5(method + ':' + path) var digestResponse = qop ? md5(ha1 + ':' + challenge.nonce + ':' + nc + ':' + cnonce + ':' + qop + ':' + ha2) : md5(ha1 + ':' + challenge.nonce + ':' + ha2) diff --git a/tests/test-digest-auth.js b/tests/test-digest-auth.js index 5ea141ee5..c05fea97d 100644 --- a/tests/test-digest-auth.js +++ b/tests/test-digest-auth.js @@ -3,6 +3,7 @@ var http = require('http') , request = require('../index') , tape = require('tape') + , crypto = require('crypto') function makeHeader() { return [].join.call(arguments, ', ') @@ -12,6 +13,10 @@ function makeHeaderRegex() { return new RegExp('^' + makeHeader.apply(null, arguments) + '$') } +function md5 (str) { + return crypto.createHash('md5').update(str).digest('hex') +} + var digestServer = http.createServer(function(req, res) { var ok , testHeader @@ -19,16 +24,16 @@ var digestServer = http.createServer(function(req, res) { if (req.url === '/test/') { if (req.headers.authorization) { testHeader = makeHeaderRegex( - 'Digest username="test"', - 'realm="Private"', - 'nonce="WpcHS2/TBAA=dffcc0dbd5f96d49a5477166649b7c0ae3866a93"', - 'uri="/test/"', - 'qop=auth', - 'response="[a-f0-9]{32}"', - 'nc=00000001', - 'cnonce="[a-f0-9]{32}"', - 'algorithm=MD5', - 'opaque="5ccc069c403ebaf9f0171e9517f40e41"' + 'Digest username="test"', + 'realm="Private"', + 'nonce="WpcHS2/TBAA=dffcc0dbd5f96d49a5477166649b7c0ae3866a93"', + 'uri="/test/"', + 'qop=auth', + 'response="[a-f0-9]{32}"', + 'nc=00000001', + 'cnonce="[a-f0-9]{32}"', + 'algorithm=MD5', + 'opaque="5ccc069c403ebaf9f0171e9517f40e41"' ) if (testHeader.test(req.headers.authorization)) { ok = true @@ -40,11 +45,53 @@ var digestServer = http.createServer(function(req, res) { // No auth header, send back WWW-Authenticate header ok = false res.setHeader('www-authenticate', makeHeader( - 'Digest realm="Private"', - 'nonce="WpcHS2/TBAA=dffcc0dbd5f96d49a5477166649b7c0ae3866a93"', - 'algorithm=MD5', - 'qop="auth"', - 'opaque="5ccc069c403ebaf9f0171e9517f40e41"' + 'Digest realm="Private"', + 'nonce="WpcHS2/TBAA=dffcc0dbd5f96d49a5477166649b7c0ae3866a93"', + 'algorithm=MD5', + 'qop="auth"', + 'opaque="5ccc069c403ebaf9f0171e9517f40e41"' + )) + } + } else if (req.url === '/test/md5-sess') { // RFC 2716 MD5-sess w/ qop=auth + var user = 'test' + var realm = 'Private' + var pass = 'testing' + var nonce = 'WpcHS2/TBAA=dffcc0dbd5f96d49a5477166649b7c0ae3866a93' + var nonceCount = '00000001' + var qop = 'auth' + var algorithm = 'MD5-sess' + if (req.headers.authorization) { + + //HA1=MD5(MD5(username:realm:password):nonce:cnonce) + //HA2=MD5(method:digestURI) + //response=MD5(HA1:nonce:nonceCount:clientNonce:qop:HA2) + + var cnonce = /cnonce="(.*)"/.exec(req.headers.authorization)[1] + var ha1 = md5(md5(user + ':' + realm + ':' + pass) + ':' + nonce + ':' + cnonce) + var ha2 = md5('GET:/test/md5-sess') + var response = md5(ha1 + ':' + nonce + ':' + nonceCount + ':' + cnonce + ':' + qop + ':' + ha2) + + testHeader = makeHeaderRegex( + 'Digest username="' + user + '"', + 'realm="' + realm + '"', + 'nonce="' + nonce + '"', + 'uri="/test/md5-sess"', + 'qop=' + qop, + 'response="' + response + '"', + 'nc=' + nonceCount, + 'cnonce="' + cnonce + '"', + 'algorithm=' + algorithm + ) + + ok = testHeader.test(req.headers.authorization) + } else { + // No auth header, send back WWW-Authenticate header + ok = false + res.setHeader('www-authenticate', makeHeader( + 'Digest realm="' + realm + '"', + 'nonce="' + nonce + '"', + 'algorithm=' + algorithm, + 'qop="' + qop + '"' )) } } else if (req.url === '/dir/index.html') { @@ -112,6 +159,28 @@ tape('with sendImmediately = false', function(t) { }) }) +tape('with MD5-sess algorithm', function(t) { + var numRedirects = 0 + + request({ + method: 'GET', + uri: 'http://localhost:6767/test/md5-sess', + auth: { + user: 'test', + pass: 'testing', + sendImmediately: false + } + }, function(error, response, body) { + t.equal(error, null) + t.equal(response.statusCode, 200) + t.equal(numRedirects, 1) + t.end() + }).on('redirect', function() { + t.equal(this.response.statusCode, 401) + numRedirects++ + }) +}) + tape('without sendImmediately = false', function(t) { var numRedirects = 0 From 0d921b9f2fb68e074f30edb179eb0e04ee643cbc Mon Sep 17 00:00:00 2001 From: simov Date: Fri, 9 Oct 2015 10:11:40 +0300 Subject: [PATCH 205/490] Bring back tilde ranges for all dependencies --- package.json | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index 2ac580442..3f4555bad 100644 --- a/package.json +++ b/package.json @@ -22,25 +22,25 @@ }, "main": "index.js", "dependencies": { - "bl": "1.0.0", - "caseless": "0.11.0", - "extend": "3.0.0", - "forever-agent": "0.6.1", - "form-data": "1.0.0-rc3", - "json-stringify-safe": "5.0.1", - "mime-types": "2.1.7", - "node-uuid": "1.4.3", - "qs": "5.2.0", - "tunnel-agent": "0.4.1", - "tough-cookie": "2.1.0", - "http-signature": "0.11.0", - "oauth-sign": "0.8.0", - "hawk": "3.1.0", - "aws-sign2": "0.5.0", - "stringstream": "0.0.4", - "combined-stream": "1.0.5", - "isstream": "0.1.2", - "har-validator": "2.0.2" + "bl": "~1.0.0", + "caseless": "~0.11.0", + "extend": "~3.0.0", + "forever-agent": "~0.6.1", + "form-data": "~1.0.0-rc3", + "json-stringify-safe": "~5.0.1", + "mime-types": "~2.1.7", + "node-uuid": "~1.4.3", + "qs": "~5.2.0", + "tunnel-agent": "~0.4.1", + "tough-cookie": "~2.1.0", + "http-signature": "~0.11.0", + "oauth-sign": "~0.8.0", + "hawk": "~3.1.0", + "aws-sign2": "~0.5.0", + "stringstream": "~0.0.4", + "combined-stream": "~1.0.5", + "isstream": "~0.1.2", + "har-validator": "~2.0.2" }, "scripts": { "test": "npm run lint && npm run test-ci && npm run test-browser", From 71b71d947adf715d81cf0122767d40ef1afee167 Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Sun, 11 Oct 2015 10:24:06 -0700 Subject: [PATCH 206/490] chore(package): update aws-sign2 to version 0.6.0 http://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e68c3240f..b4564105d 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "http-signature": "~0.11.0", "oauth-sign": "~0.8.0", "hawk": "~3.1.0", - "aws-sign2": "~0.5.0", + "aws-sign2": "~0.6.0", "stringstream": "~0.0.4", "combined-stream": "~1.0.5", "isstream": "~0.1.2", From 2351a8c54ba701b51d8cbcbaaabbd9d466b7c619 Mon Sep 17 00:00:00 2001 From: simov Date: Sun, 11 Oct 2015 21:03:34 +0300 Subject: [PATCH 207/490] 2.65.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b4564105d..d0e65f6a1 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.64.1", + "version": "2.65.0", "author": "Mikeal Rogers ", "repository": { "type": "git", From 8a7a37835c600f5006a6679aa23a0db504003ecd Mon Sep 17 00:00:00 2001 From: simov Date: Sun, 11 Oct 2015 21:04:41 +0300 Subject: [PATCH 208/490] Update changelog --- CHANGELOG.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5da7d968..a43c6726a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,20 @@ ## Change Log +### v2.65.0 (2015/10/11) +- [#1833](https://github.com/request/request/pull/1833) Update aws-sign2 to version 0.6.0 🚀 (@greenkeeperio-bot) +- [#1811](https://github.com/request/request/pull/1811) Enable loose cookie parsing in tough-cookie (@Sebmaster) +- [#1830](https://github.com/request/request/pull/1830) Bring back tilde ranges for all dependencies (@simov) +- [#1821](https://github.com/request/request/pull/1821) Implement support for RFC 2617 MD5-sess algorithm. (@BigDSK) +- [#1828](https://github.com/request/request/pull/1828) Updated qs dependency to 5.2.0 (@acroca) +- [#1818](https://github.com/request/request/pull/1818) Extract `readResponseBody` method out of `onRequestResponse` (@pvoisin) +- [#1819](https://github.com/request/request/pull/1819) Run stringify once (@mgenereu) +- [#1814](https://github.com/request/request/pull/1814) Updated har-validator to version 2.0.2 (@greenkeeperio-bot) +- [#1807](https://github.com/request/request/pull/1807) Updated tough-cookie to version 2.1.0 (@greenkeeperio-bot) +- [#1800](https://github.com/request/request/pull/1800) Add caret ranges for devDependencies, except eslint (@simov) +- [#1799](https://github.com/request/request/pull/1799) Updated karma-browserify to version 4.4.0 (@greenkeeperio-bot) +- [#1797](https://github.com/request/request/pull/1797) Updated tape to version 4.2.0 (@greenkeeperio-bot) +- [#1788](https://github.com/request/request/pull/1788) Pinned all dependencies (@greenkeeperio-bot) + ### v2.64.0 (2015/09/25) - [#1787](https://github.com/request/request/pull/1787) npm ignore examples, release.sh and disabled.appveyor.yml (@thisconnect) - [#1775](https://github.com/request/request/pull/1775) Fix typo in README.md (@djchie) From d46a4c727ed7368e4625f9204f140904cc3f4478 Mon Sep 17 00:00:00 2001 From: simov Date: Sun, 11 Oct 2015 21:04:58 +0300 Subject: [PATCH 209/490] 2.65.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d0e65f6a1..45aa53a02 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.65.0", + "version": "2.65.1", "author": "Mikeal Rogers ", "repository": { "type": "git", From bf6e7ba157bb7cc1c12bbac08a73b276ea92edb4 Mon Sep 17 00:00:00 2001 From: Jonathan Giroux Date: Tue, 13 Oct 2015 17:20:50 +0200 Subject: [PATCH 210/490] Fix wrong property name --- lib/tunnel.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tunnel.js b/lib/tunnel.js index cf28016e2..9e790aed4 100644 --- a/lib/tunnel.js +++ b/lib/tunnel.js @@ -34,7 +34,7 @@ var defaultProxyHeaderExclusiveList = [ ] function constructProxyHost(uriObject) { - var port = uriObject.portA + var port = uriObject.port , protocol = uriObject.protocol , proxyHost = uriObject.hostname + ':' From e9afbdb12328f67501323285b81ed7482bfad63f Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Thu, 15 Oct 2015 17:11:44 -0700 Subject: [PATCH 211/490] chore(package): update http-signature to version 1.0.2 http://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 45aa53a02..6968b2794 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "qs": "~5.2.0", "tunnel-agent": "~0.4.1", "tough-cookie": "~2.2.0", - "http-signature": "~0.11.0", + "http-signature": "~1.0.2", "oauth-sign": "~0.8.0", "hawk": "~3.1.0", "aws-sign2": "~0.6.0", From 2981ae499289ee3f81471cad63e7177c9b65ef78 Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Fri, 16 Oct 2015 21:34:03 -0700 Subject: [PATCH 212/490] chore(package): update istanbul to version 0.4.0 http://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 45aa53a02..21d049e7b 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "coveralls": "^2.11.4", "eslint": "0.18.0", "function-bind": "^1.0.2", - "istanbul": "^0.3.21", + "istanbul": "^0.4.0", "karma-browserify": "^4.4.0", "karma": "^0.13.10", "karma-cli": "^0.1.1", From e6d51c3c921c8dac3b2326647c58a563fd12c54e Mon Sep 17 00:00:00 2001 From: simov Date: Sat, 17 Oct 2015 12:10:43 +0300 Subject: [PATCH 213/490] Use node's latest version when building --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index d793e7f54..c24c59b5d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,9 @@ language: node_js node_js: - - "4.0" - - "io.js" - - "0.12" - - "0.10" + - node + - io.js + - 0.12 + - 0.10 sudo: false after_script: "npm run test-cov && cat ./coverage/lcov.info | codecov && cat ./coverage/lcov.info | coveralls" From 0e044eb675c531363b10ed96d42db9ec1ad5f8d4 Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Tue, 20 Oct 2015 07:10:38 -0700 Subject: [PATCH 214/490] chore(package): update karma-coverage to version 0.5.3 http://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 07c8f57ab..ff2bea59a 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "karma-browserify": "^4.4.0", "karma": "^0.13.10", "karma-cli": "^0.1.1", - "karma-coverage": "^0.2.6", + "karma-coverage": "^0.5.3", "karma-phantomjs-launcher": "^0.1.4", "karma-tap": "^1.0.3", "rimraf": "^2.2.8", From 727b3054cf6f5f7c40149334db4d05f981a617dc Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Wed, 21 Oct 2015 10:13:06 -0700 Subject: [PATCH 215/490] chore(package): update eslint to version 1.7.3 http://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 07c8f57ab..b2bbfc33d 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,7 @@ "buffer-equal": "^0.0.1", "codecov.io": "^0.1.6", "coveralls": "^2.11.4", - "eslint": "0.18.0", + "eslint": "1.7.3", "function-bind": "^1.0.2", "istanbul": "^0.4.0", "karma-browserify": "^4.4.0", From 84a5ea37cfda1f2a11c12c73b4ed3c06679f4cc1 Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 22 Oct 2015 16:40:44 +0300 Subject: [PATCH 216/490] Remove redundant code introduced in #1736 --- lib/redirect.js | 2 +- request.js | 20 +++++--------------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/lib/redirect.js b/lib/redirect.js index d5cc59c91..bee2ccca9 100644 --- a/lib/redirect.js +++ b/lib/redirect.js @@ -105,7 +105,7 @@ Redirect.prototype.onResponse = function (response) { // handle the case where we change protocol from https to http or vice versa if (request.uri.protocol !== uriPrev.protocol) { - request._updateProtocol() + delete request.agent } self.redirects.push( diff --git a/request.js b/request.js index 1a409b356..b51c32530 100644 --- a/request.js +++ b/request.js @@ -111,8 +111,6 @@ function Request (options) { // call init var self = this - self.options = self.options || options//joshux - self.options = self.options || {}//joshux // start with HAR, then override with additional options if (options.har) { @@ -473,13 +471,13 @@ Request.prototype.init = function (options) { } if (!self.agent) { - if (self.options.agentOptions) { - self.agentOptions = self.options.agentOptions + if (options.agentOptions) { + self.agentOptions = options.agentOptions } - if (self.options.agentClass) { - self.agentClass = self.options.agentClass - } else if (self.options.forever) { + if (options.agentClass) { + self.agentClass = options.agentClass + } else if (options.forever) { var v = version() // use ForeverAgent in node 0.10- only if (v.major === 0 && v.minor <= 10) { @@ -590,14 +588,6 @@ Request.prototype.init = function (options) { } -// Must call this when following a redirect from https to http or vice versa -// Attempts to keep everything as identical as possible, but update the -// httpModule, Tunneling agent, and/or Forever Agent in use. -Request.prototype._updateProtocol = function () { - var self = this - delete self.agent -} - Request.prototype.getNewAgent = function () { var self = this var Agent = self.agentClass From 2d997e50d464985185c3a2f91dcfcaf9addfeed7 Mon Sep 17 00:00:00 2001 From: simov Date: Fri, 23 Oct 2015 11:43:58 +0300 Subject: [PATCH 217/490] Referer header should point to the host name of the original resource when redirecting --- lib/redirect.js | 2 +- tests/test-redirect.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/redirect.js b/lib/redirect.js index bee2ccca9..040dfe0e0 100644 --- a/lib/redirect.js +++ b/lib/redirect.js @@ -140,7 +140,7 @@ Redirect.prototype.onResponse = function (response) { } if (!self.removeRefererHeader) { - request.setHeader('referer', request.uri.href) + request.setHeader('referer', uriPrev.href) } request.emit('redirect') diff --git a/tests/test-redirect.js b/tests/test-redirect.js index 82278db86..d27040b3d 100644 --- a/tests/test-redirect.js +++ b/tests/test-redirect.js @@ -345,7 +345,7 @@ tape('should have the referer when following redirect by default', function(t) { }) .on('redirect', function() { t.notEqual(this.headers.referer, undefined) - t.equal(this.headers.referer.substring(this.headers.referer.lastIndexOf('/')), '/temp_landing') + t.equal(this.headers.referer.substring(this.headers.referer.lastIndexOf('/')), '/temp') }) }) From f97564772698f6b05124c83125ddeccd2321333b Mon Sep 17 00:00:00 2001 From: simov Date: Sat, 24 Oct 2015 09:20:17 +0300 Subject: [PATCH 218/490] Improve referer header tests and docs --- README.md | 2 +- tests/test-redirect.js | 24 ++++++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c18b022ab..17859c933 100644 --- a/README.md +++ b/README.md @@ -762,7 +762,7 @@ The first argument can be either a `url` or an `options` object. The only requir - `followRedirect` - follow HTTP 3xx responses as redirects (default: `true`). This property can also be implemented as function which gets `response` object as a single argument and should return `true` if redirects should continue or `false` otherwise. - `followAllRedirects` - follow non-GET HTTP 3xx responses as redirects (default: `false`) - `maxRedirects` - the maximum number of redirects to follow (default: `10`) -- `removeRefererHeader` - removes the referer header when a redirect happens (default: `false`). +- `removeRefererHeader` - removes the referer header when a redirect happens (default: `false`). **Note:** if true, referer header set in the initial request is preserved during redirect chain. --- diff --git a/tests/test-redirect.js b/tests/test-redirect.js index d27040b3d..882e4398e 100644 --- a/tests/test-redirect.js +++ b/tests/test-redirect.js @@ -332,7 +332,7 @@ tape('http to https redirect', function(t) { }) }) -tape('should have the referer when following redirect by default', function(t) { +tape('should have referer header by default when following redirect', function(t) { request.post({ uri: s.url + '/temp', jar: jar, @@ -344,12 +344,11 @@ tape('should have the referer when following redirect by default', function(t) { t.end() }) .on('redirect', function() { - t.notEqual(this.headers.referer, undefined) - t.equal(this.headers.referer.substring(this.headers.referer.lastIndexOf('/')), '/temp') + t.equal(this.headers.referer, s.url + '/temp') }) }) -tape('should not have a referer when removeRefererHeader is true', function(t) { +tape('should not have referer header when removeRefererHeader is true', function(t) { request.post({ uri: s.url + '/temp', jar: jar, @@ -366,6 +365,23 @@ tape('should not have a referer when removeRefererHeader is true', function(t) { }) }) +tape('should preserve referer header set in the initial request when removeRefererHeader is true', function(t) { + request.post({ + uri: s.url + '/temp', + jar: jar, + followAllRedirects: true, + removeRefererHeader: true, + headers: { cookie: 'foo=bar', referer: 'http://awesome.com' } + }, function(err, res, body) { + t.equal(err, null) + t.equal(res.statusCode, 200) + t.end() + }) + .on('redirect', function() { + t.equal(this.headers.referer, 'http://awesome.com') + }) +}) + tape('should use same agent class on redirect', function(t) { var agent var calls = 0 From 03682b701cbb12001ce0eae9f1e184d74557c8c3 Mon Sep 17 00:00:00 2001 From: Thomas Watson Steen Date: Sat, 24 Oct 2015 11:51:40 +0200 Subject: [PATCH 219/490] Remove redundant call to Stream constructor --- request.js | 1 - 1 file changed, 1 deletion(-) diff --git a/request.js b/request.js index b51c32530..e94e3e214 100644 --- a/request.js +++ b/request.js @@ -122,7 +122,6 @@ function Request (options) { var reserved = Object.keys(Request.prototype) var nonReserved = filterForNonReserved(reserved, options) - stream.Stream.call(self) util._extend(self, nonReserved) options = filterOutReservedFunctions(reserved, options) From d7421173e3b06e9f0982ee88b99c57ef29689e72 Mon Sep 17 00:00:00 2001 From: Miguel Mota Date: Tue, 27 Oct 2015 02:40:46 -0700 Subject: [PATCH 220/490] add missing quotes --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 17859c933..f40a18b6f 100644 --- a/README.md +++ b/README.md @@ -845,7 +845,7 @@ For example: ```js //requests using baseRequest() will set the 'x-token' header var baseRequest = request.defaults({ - headers: {x-token: 'my-token'} + headers: {'x-token': 'my-token'} }) //requests using specialRequest() will include the 'x-token' header set in From 6bfddb141d93e8b1b225a7845eaf3e2ea50e862e Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Wed, 28 Oct 2015 02:55:21 -0700 Subject: [PATCH 221/490] chore(package): update browserify to version 12.0.1 http://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ff2bea59a..be6a50550 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ }, "devDependencies": { "browserify-istanbul": "^0.1.5", - "browserify": "^11.2.0", + "browserify": "^12.0.1", "buffer-equal": "^0.0.1", "codecov.io": "^0.1.6", "coveralls": "^2.11.4", From 6d32949b1bc0bc6b6ae3a68f13050376a0f1b616 Mon Sep 17 00:00:00 2001 From: Greg Walden Date: Wed, 28 Oct 2015 18:18:09 -0400 Subject: [PATCH 222/490] remove typo in README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 17859c933..0a18f0619 100644 --- a/README.md +++ b/README.md @@ -746,7 +746,7 @@ The first argument can be either a `url` or an `options` object. The only requir In non-chunked requests, data items with body streams are not allowed. - `preambleCRLF` - append a newline/CRLF before the boundary of your `multipart/form-data` request. - `postambleCRLF` - append a newline/CRLF at the end of the boundary of your `multipart/form-data` request. -- `json` - sets `body` but to JSON representation of value and adds `Content-type: application/json` header. Additionally, parses the response body as JSON. +- `json` - sets `body` to JSON representation of value and adds `Content-type: application/json` header. Additionally, parses the response body as JSON. - `jsonReviver` - a [reviver function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse) that will be passed to `JSON.parse()` when parsing a JSON response body. --- From 5c179c38d5a0d1dd550519b0f420cf51c7589c6b Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Wed, 28 Oct 2015 23:20:34 -0700 Subject: [PATCH 223/490] chore(package): update bluebird to version 3.0.2 http://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ff2bea59a..d5f9fcef8 100644 --- a/package.json +++ b/package.json @@ -68,6 +68,6 @@ "server-destroy": "^1.0.1", "tape": "^4.2.0", "taper": "^0.4.0", - "bluebird": "^2.10.1" + "bluebird": "^3.0.2" } } From edb4406bc648c2a4aeb2ebb569a5368215f5cb30 Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 29 Oct 2015 08:44:34 +0200 Subject: [PATCH 224/490] Implement loose matching for har mime types --- lib/har.js | 72 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 31 deletions(-) diff --git a/lib/har.js b/lib/har.js index 83453a327..db42c58c2 100644 --- a/lib/har.js +++ b/lib/har.js @@ -60,43 +60,53 @@ Har.prototype.prep = function (data) { } // prep body - switch (data.postData.mimeType) { - case 'multipart/mixed': - case 'multipart/related': - case 'multipart/form-data': - case 'multipart/alternative': - // reset values - data.postData.mimeType = 'multipart/form-data' - break + function some (arr) { + return arr.some(function (type) { + return data.postData.mimeType.indexOf(type) === 0 + }) + } - case 'application/x-www-form-urlencoded': - if (!data.postData.params) { - data.postData.text = '' - } else { - data.postData.paramsObj = data.postData.params.reduce(this.reducer, {}) + if (some([ + 'multipart/mixed', + 'multipart/related', + 'multipart/form-data', + 'multipart/alternative'])) { - // always overwrite - data.postData.text = qs.stringify(data.postData.paramsObj) - } - break + // reset values + data.postData.mimeType = 'multipart/form-data' + } - case 'text/json': - case 'text/x-json': - case 'application/json': - case 'application/x-json': - data.postData.mimeType = 'application/json' + else if (some([ + 'application/x-www-form-urlencoded'])) { - if (data.postData.text) { - try { - data.postData.jsonObj = JSON.parse(data.postData.text) - } catch (e) { - this.request.debug(e) + if (!data.postData.params) { + data.postData.text = '' + } else { + data.postData.paramsObj = data.postData.params.reduce(this.reducer, {}) - // force back to text/plain - data.postData.mimeType = 'text/plain' - } + // always overwrite + data.postData.text = qs.stringify(data.postData.paramsObj) + } + } + + else if (some([ + 'text/json', + 'text/x-json', + 'application/json', + 'application/x-json'])) { + + data.postData.mimeType = 'application/json' + + if (data.postData.text) { + try { + data.postData.jsonObj = JSON.parse(data.postData.text) + } catch (e) { + this.request.debug(e) + + // force back to text/plain + data.postData.mimeType = 'text/plain' } - break + } } return data From ad7360fa5fad2b9ec73b92113f92cd8b57863888 Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 29 Oct 2015 10:23:01 +0200 Subject: [PATCH 225/490] Fix breaking changes in bluebird's promisifier APIs --- tests/test-promise.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test-promise.js b/tests/test-promise.js index d310890db..81507dbe5 100644 --- a/tests/test-promise.js +++ b/tests/test-promise.js @@ -18,7 +18,7 @@ tape('setup', function(t) { tape('promisify convenience method', function(t) { var get = request.get - var p = Promise.promisify(get) + var p = Promise.promisify(get, {multiArgs: true}) p('http://localhost:6767') .then(function (results) { var res = results[0] @@ -28,7 +28,7 @@ tape('promisify convenience method', function(t) { }) tape('promisify request function', function(t) { - var p = Promise.promisify(request) + var p = Promise.promisify(request, {multiArgs: true}) p('http://localhost:6767') .spread(function (res, body) { t.equal(res.statusCode, 200) @@ -37,7 +37,7 @@ tape('promisify request function', function(t) { }) tape('promisify all methods', function(t) { - Promise.promisifyAll(request) + Promise.promisifyAll(request, {multiArgs: true}) request.getAsync('http://localhost:6767') .spread(function (res, body) { t.equal(res.statusCode, 200) From 425a7e8d58106ca148dc649630522c403fca3a6e Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 29 Oct 2015 10:32:28 +0200 Subject: [PATCH 226/490] Improve loose matching for har mime types --- lib/har.js | 77 ++++++++++++++++++++--------------------- tests/fixtures/har.json | 2 +- 2 files changed, 39 insertions(+), 40 deletions(-) diff --git a/lib/har.js b/lib/har.js index db42c58c2..ceb1cd107 100644 --- a/lib/har.js +++ b/lib/har.js @@ -162,51 +162,50 @@ Har.prototype.options = function (options) { options.headers = req.headersObj } - switch (req.postData.mimeType) { - case 'application/x-www-form-urlencoded': - options.form = req.postData.paramsObj - break - - case 'application/json': - if (req.postData.jsonObj) { - options.body = req.postData.jsonObj - options.json = true - } - break - - case 'multipart/form-data': - options.formData = {} + function test (type) { + return req.postData.mimeType.indexOf(type) === 0 + } + if (test('application/x-www-form-urlencoded')) { + options.form = req.postData.paramsObj + } + else if (test('application/json')) { + if (req.postData.jsonObj) { + options.body = req.postData.jsonObj + options.json = true + } + } + else if (test('multipart/form-data')) { + options.formData = {} - req.postData.params.forEach(function (param) { - var attachment = {} + req.postData.params.forEach(function (param) { + var attachment = {} - if (!param.fileName && !param.fileName && !param.contentType) { - options.formData[param.name] = param.value - return - } + if (!param.fileName && !param.fileName && !param.contentType) { + options.formData[param.name] = param.value + return + } - // attempt to read from disk! - if (param.fileName && !param.value) { - attachment.value = fs.createReadStream(param.fileName) - } else if (param.value) { - attachment.value = param.value - } + // attempt to read from disk! + if (param.fileName && !param.value) { + attachment.value = fs.createReadStream(param.fileName) + } else if (param.value) { + attachment.value = param.value + } - if (param.fileName) { - attachment.options = { - filename: param.fileName, - contentType: param.contentType ? param.contentType : null - } + if (param.fileName) { + attachment.options = { + filename: param.fileName, + contentType: param.contentType ? param.contentType : null } - - options.formData[param.name] = attachment - }) - break - - default: - if (req.postData.text) { - options.body = req.postData.text } + + options.formData[param.name] = attachment + }) + } + else { + if (req.postData.text) { + options.body = req.postData.text + } } return options diff --git a/tests/fixtures/har.json b/tests/fixtures/har.json index 49799374c..4864a1b28 100644 --- a/tests/fixtures/har.json +++ b/tests/fixtures/har.json @@ -8,7 +8,7 @@ } ], "postData": { - "mimeType": "application/x-www-form-urlencoded", + "mimeType": "application/x-www-form-urlencoded; charset=UTF-8", "params": [ { "name": "foo", From cceaa6e124c7a16aa0347596810112c4006cbbe9 Mon Sep 17 00:00:00 2001 From: simov Date: Fri, 30 Oct 2015 14:11:00 +0200 Subject: [PATCH 227/490] Fix indentation issues according to eslint@1.7.3 --- .eslintrc | 2 +- tests/test-body.js | 100 ++++++++++++++++++++-------------------- tests/test-https.js | 48 +++++++++---------- tests/test-multipart.js | 10 ++-- tests/test-oauth.js | 72 ++++++++++++++--------------- tests/test-params.js | 54 +++++++++++----------- tests/test-redirect.js | 6 +-- 7 files changed, 146 insertions(+), 146 deletions(-) diff --git a/.eslintrc b/.eslintrc index e79f481f0..6ebc53601 100644 --- a/.eslintrc +++ b/.eslintrc @@ -4,7 +4,7 @@ }, "rules": { // 2-space indentation - "indent": [2, 2], + "indent": [2, 2, {"SwitchCase": 1}], // Disallow semi-colons, unless needed to disambiguate statement "semi": [2, "never"], // Require strings to use single quotes diff --git a/tests/test-body.js b/tests/test-body.js index 77b826d46..031b7a845 100644 --- a/tests/test-body.js +++ b/tests/test-body.js @@ -29,76 +29,76 @@ function addTest(name, data) { } addTest('testGet', { - resp : server.createGetResponse('TESTING!') + resp : server.createGetResponse('TESTING!') , expectBody: 'TESTING!' }) addTest('testGetChunkBreak', { - resp : server.createChunkResponse( - [ new Buffer([239]) - , new Buffer([163]) - , new Buffer([191]) - , new Buffer([206]) - , new Buffer([169]) - , new Buffer([226]) - , new Buffer([152]) - , new Buffer([131]) - ]) + resp : server.createChunkResponse( + [ new Buffer([239]) + , new Buffer([163]) + , new Buffer([191]) + , new Buffer([206]) + , new Buffer([169]) + , new Buffer([226]) + , new Buffer([152]) + , new Buffer([131]) + ]) , expectBody: '\uF8FF\u03A9\u2603' }) addTest('testGetBuffer', { - resp : server.createGetResponse(new Buffer('TESTING!')) + resp : server.createGetResponse(new Buffer('TESTING!')) , encoding: null , expectBody: new Buffer('TESTING!') }) addTest('testGetEncoding', { - resp : server.createGetResponse(new Buffer('efa3bfcea9e29883', 'hex')) + resp : server.createGetResponse(new Buffer('efa3bfcea9e29883', 'hex')) , encoding: 'hex' , expectBody: 'efa3bfcea9e29883' }) addTest('testGetUTF', { - resp: server.createGetResponse(new Buffer([0xEF, 0xBB, 0xBF, 226, 152, 131])) - , encoding: 'utf8' - , expectBody: '\u2603' + resp: server.createGetResponse(new Buffer([0xEF, 0xBB, 0xBF, 226, 152, 131])) + , encoding: 'utf8' + , expectBody: '\u2603' }) addTest('testGetJSON', { - resp : server.createGetResponse('{"test":true}', 'application/json') - , json : true - , expectBody: {'test':true} + resp : server.createGetResponse('{"test":true}', 'application/json') + , json : true + , expectBody: {'test':true} }) addTest('testPutString', { - resp : server.createPostValidator('PUTTINGDATA') + resp : server.createPostValidator('PUTTINGDATA') , method : 'PUT' , body : 'PUTTINGDATA' }) addTest('testPutBuffer', { - resp : server.createPostValidator('PUTTINGDATA') + resp : server.createPostValidator('PUTTINGDATA') , method : 'PUT' , body : new Buffer('PUTTINGDATA') }) addTest('testPutJSON', { - resp : server.createPostValidator(JSON.stringify({foo: 'bar'})) + resp : server.createPostValidator(JSON.stringify({foo: 'bar'})) , method: 'PUT' , json: {foo: 'bar'} }) addTest('testPutMultipart', { - resp: server.createPostValidator( - '--__BOUNDARY__\r\n' + - 'content-type: text/html\r\n' + - '\r\n' + - 'Oh hi.' + - '\r\n--__BOUNDARY__\r\n\r\n' + - 'Oh hi.' + - '\r\n--__BOUNDARY__--' - ) + resp: server.createPostValidator( + '--__BOUNDARY__\r\n' + + 'content-type: text/html\r\n' + + '\r\n' + + 'Oh hi.' + + '\r\n--__BOUNDARY__\r\n\r\n' + + 'Oh hi.' + + '\r\n--__BOUNDARY__--' + ) , method: 'PUT' , multipart: [ {'content-type': 'text/html', 'body': 'Oh hi.'} @@ -107,15 +107,15 @@ addTest('testPutMultipart', { }) addTest('testPutMultipartPreambleCRLF', { - resp: server.createPostValidator( - '\r\n--__BOUNDARY__\r\n' + - 'content-type: text/html\r\n' + - '\r\n' + - 'Oh hi.' + - '\r\n--__BOUNDARY__\r\n\r\n' + - 'Oh hi.' + - '\r\n--__BOUNDARY__--' - ) + resp: server.createPostValidator( + '\r\n--__BOUNDARY__\r\n' + + 'content-type: text/html\r\n' + + '\r\n' + + 'Oh hi.' + + '\r\n--__BOUNDARY__\r\n\r\n' + + 'Oh hi.' + + '\r\n--__BOUNDARY__--' + ) , method: 'PUT' , preambleCRLF: true , multipart: @@ -125,16 +125,16 @@ addTest('testPutMultipartPreambleCRLF', { }) addTest('testPutMultipartPostambleCRLF', { - resp: server.createPostValidator( - '\r\n--__BOUNDARY__\r\n' + - 'content-type: text/html\r\n' + - '\r\n' + - 'Oh hi.' + - '\r\n--__BOUNDARY__\r\n\r\n' + - 'Oh hi.' + - '\r\n--__BOUNDARY__--' + - '\r\n' - ) + resp: server.createPostValidator( + '\r\n--__BOUNDARY__\r\n' + + 'content-type: text/html\r\n' + + '\r\n' + + 'Oh hi.' + + '\r\n--__BOUNDARY__\r\n\r\n' + + 'Oh hi.' + + '\r\n--__BOUNDARY__--' + + '\r\n' + ) , method: 'PUT' , preambleCRLF: true , postambleCRLF: true diff --git a/tests/test-https.js b/tests/test-https.js index dc870df83..74ebb880d 100644 --- a/tests/test-https.js +++ b/tests/test-https.js @@ -50,58 +50,58 @@ function runAllTests(strict, s) { } runTest('testGet', { - resp : server.createGetResponse('TESTING!') + resp : server.createGetResponse('TESTING!') , expectBody: 'TESTING!' }) runTest('testGetChunkBreak', { - resp : server.createChunkResponse( - [ new Buffer([239]) - , new Buffer([163]) - , new Buffer([191]) - , new Buffer([206]) - , new Buffer([169]) - , new Buffer([226]) - , new Buffer([152]) - , new Buffer([131]) - ]) + resp : server.createChunkResponse( + [ new Buffer([239]) + , new Buffer([163]) + , new Buffer([191]) + , new Buffer([206]) + , new Buffer([169]) + , new Buffer([226]) + , new Buffer([152]) + , new Buffer([131]) + ]) , expectBody: '\uf8ff\u03a9\u2603' }) runTest('testGetJSON', { - resp : server.createGetResponse('{"test":true}', 'application/json') + resp : server.createGetResponse('{"test":true}', 'application/json') , json : true , expectBody: {'test':true} }) runTest('testPutString', { - resp : server.createPostValidator('PUTTINGDATA') + resp : server.createPostValidator('PUTTINGDATA') , method : 'PUT' , body : 'PUTTINGDATA' }) runTest('testPutBuffer', { - resp : server.createPostValidator('PUTTINGDATA') + resp : server.createPostValidator('PUTTINGDATA') , method : 'PUT' , body : new Buffer('PUTTINGDATA') }) runTest('testPutJSON', { - resp : server.createPostValidator(JSON.stringify({foo: 'bar'})) + resp : server.createPostValidator(JSON.stringify({foo: 'bar'})) , method: 'PUT' , json: {foo: 'bar'} }) runTest('testPutMultipart', { - resp: server.createPostValidator( - '--__BOUNDARY__\r\n' + - 'content-type: text/html\r\n' + - '\r\n' + - 'Oh hi.' + - '\r\n--__BOUNDARY__\r\n\r\n' + - 'Oh hi.' + - '\r\n--__BOUNDARY__--' - ) + resp: server.createPostValidator( + '--__BOUNDARY__\r\n' + + 'content-type: text/html\r\n' + + '\r\n' + + 'Oh hi.' + + '\r\n--__BOUNDARY__\r\n\r\n' + + 'Oh hi.' + + '\r\n--__BOUNDARY__--' + ) , method: 'PUT' , multipart: [ {'content-type': 'text/html', 'body': 'Oh hi.'} diff --git a/tests/test-multipart.js b/tests/test-multipart.js index fc64c8493..255852b70 100644 --- a/tests/test-multipart.js +++ b/tests/test-multipart.js @@ -72,11 +72,11 @@ function runTest(t, a) { // @NOTE: multipartData properties must be set here so that my_file read stream does not leak in node v0.8 multipartData = [ - {name: 'my_field', body: 'my_value'}, - {name: 'my_buffer', body: new Buffer([1, 2, 3])}, - {name: 'my_file', body: fs.createReadStream(localFile)}, - {name: 'remote_file', body: request('http://localhost:6767/file')} - ] + {name: 'my_field', body: 'my_value'}, + {name: 'my_buffer', body: new Buffer([1, 2, 3])}, + {name: 'my_file', body: fs.createReadStream(localFile)}, + {name: 'remote_file', body: request('http://localhost:6767/file')} + ] var reqOptions = { url: 'http://localhost:6767/upload', diff --git a/tests/test-oauth.js b/tests/test-oauth.js index f27c0a271..3b022abf9 100644 --- a/tests/test-oauth.js +++ b/tests/test-oauth.js @@ -254,19 +254,19 @@ tape('rfc5849 example', function(t) { var rfc5849 = request.post( { url: 'http://example.com/request?b5=%3D%253D&a3=a&c%40=&a2=r%20b' , oauth: - { consumer_key: '9djdj82h48djs9d2' - , nonce: '7d8f3e4a' - , signature_method: 'HMAC-SHA1' - , token: 'kkk9d7dh3k39sjv7' - , timestamp: '137131201' - , consumer_secret: 'j49sk3j29djd' - , token_secret: 'dh893hdasih9' - , realm: 'Example' - } + { consumer_key: '9djdj82h48djs9d2' + , nonce: '7d8f3e4a' + , signature_method: 'HMAC-SHA1' + , token: 'kkk9d7dh3k39sjv7' + , timestamp: '137131201' + , consumer_secret: 'j49sk3j29djd' + , token_secret: 'dh893hdasih9' + , realm: 'Example' + } , form: { - c2: '', - a3: '2 q' - } + c2: '', + a3: '2 q' + } }) process.nextTick(function() { @@ -291,9 +291,9 @@ tape('rfc5849 RSA example', function(t) { , realm: 'Example' } , form: { - c2: '', - a3: '2 q' - } + c2: '', + a3: '2 q' + } }) process.nextTick(function() { @@ -412,9 +412,9 @@ tape('query transport_method + form option + url params', function(t) { , transport_method: 'query' } , form: { - c2: '', - a3: '2 q' - } + c2: '', + a3: '2 q' + } }) process.nextTick(function() { @@ -454,10 +454,10 @@ tape('query transport_method + qs option + url params', function(t) { , transport_method: 'query' } , qs: { - b5: '=%3D', - a3: ['a', '2 q'], - 'c@': '', - c2: '' + b5: '=%3D', + a3: ['a', '2 q'], + 'c@': '', + c2: '' } }) @@ -534,9 +534,9 @@ tape('body transport_method + form option + url params', function(t) { , transport_method: 'body' } , form: { - c2: '', - a3: '2 q' - } + c2: '', + a3: '2 q' + } }) process.nextTick(function() { @@ -639,12 +639,12 @@ tape('refresh oauth_nonce on redirect', function(t) { , token_secret: 'token_secret' } }, function (err, res, body) { - t.equal(err, null) - t.notEqual(oauth_nonce1, oauth_nonce2) - s.close(function () { - t.end() - }) + t.equal(err, null) + t.notEqual(oauth_nonce1, oauth_nonce2) + s.close(function () { + t.end() }) + }) }) }) @@ -668,14 +668,14 @@ tape('no credentials on external redirect', function(t) { , token_secret: 'token_secret' } }, function (err, res, body) { - t.equal(err, null) - t.equal(res.request.headers.Authorization, undefined) - s1.close(function () { - s2.close(function () { - t.end() - }) + t.equal(err, null) + t.equal(res.request.headers.Authorization, undefined) + s1.close(function () { + s2.close(function () { + t.end() }) }) + }) }) }) }) diff --git a/tests/test-params.js b/tests/test-params.js index be19f7be7..70f5e65ce 100644 --- a/tests/test-params.js +++ b/tests/test-params.js @@ -30,64 +30,64 @@ tape('setup', function(t) { }) runTest('testGet', { - resp : server.createGetResponse('TESTING!') + resp : server.createGetResponse('TESTING!') , expectBody: 'TESTING!' }) runTest('testGetChunkBreak', { - resp : server.createChunkResponse( - [ new Buffer([239]) - , new Buffer([163]) - , new Buffer([191]) - , new Buffer([206]) - , new Buffer([169]) - , new Buffer([226]) - , new Buffer([152]) - , new Buffer([131]) - ]) + resp : server.createChunkResponse( + [ new Buffer([239]) + , new Buffer([163]) + , new Buffer([191]) + , new Buffer([206]) + , new Buffer([169]) + , new Buffer([226]) + , new Buffer([152]) + , new Buffer([131]) + ]) , expectBody: '\uf8ff\u03a9\u2603' }) runTest('testGetBuffer', { - resp : server.createGetResponse(new Buffer('TESTING!')) + resp : server.createGetResponse(new Buffer('TESTING!')) , encoding: null , expectBody: new Buffer('TESTING!') }) runTest('testGetJSON', { - resp : server.createGetResponse('{"test":true}', 'application/json') - , json : true - , expectBody: {'test':true} + resp : server.createGetResponse('{"test":true}', 'application/json') + , json : true + , expectBody: {'test':true} }) runTest('testPutString', { - resp : server.createPostValidator('PUTTINGDATA') + resp : server.createPostValidator('PUTTINGDATA') , method : 'PUT' , body : 'PUTTINGDATA' }) runTest('testPutBuffer', { - resp : server.createPostValidator('PUTTINGDATA') + resp : server.createPostValidator('PUTTINGDATA') , method : 'PUT' , body : new Buffer('PUTTINGDATA') }) runTest('testPutJSON', { - resp : server.createPostValidator(JSON.stringify({foo: 'bar'})) + resp : server.createPostValidator(JSON.stringify({foo: 'bar'})) , method: 'PUT' , json: {foo: 'bar'} }) runTest('testPutMultipart', { - resp: server.createPostValidator( - '--__BOUNDARY__\r\n' + - 'content-type: text/html\r\n' + - '\r\n' + - 'Oh hi.' + - '\r\n--__BOUNDARY__\r\n\r\n' + - 'Oh hi.' + - '\r\n--__BOUNDARY__--' - ) + resp: server.createPostValidator( + '--__BOUNDARY__\r\n' + + 'content-type: text/html\r\n' + + '\r\n' + + 'Oh hi.' + + '\r\n--__BOUNDARY__\r\n\r\n' + + 'Oh hi.' + + '\r\n--__BOUNDARY__--' + ) , method: 'PUT' , multipart: [ {'content-type': 'text/html', 'body': 'Oh hi.'} diff --git a/tests/test-redirect.js b/tests/test-redirect.js index ee8661889..bec8f021d 100644 --- a/tests/test-redirect.js +++ b/tests/test-redirect.js @@ -46,9 +46,9 @@ function createLandingEndpoint(landing) { function bouncer(code, label, hops) { var hop, - landing = label + '_landing', - currentLabel, - currentLanding + landing = label + '_landing', + currentLabel, + currentLanding hops = hops || 1 From 5e100550c6b8464cc15361f49329f85b52f3f6c7 Mon Sep 17 00:00:00 2001 From: Mohamad mehdi Kharatizadeh Date: Sat, 31 Oct 2015 16:15:04 +0330 Subject: [PATCH 228/490] Error on initialization should prevent actual HTTP request from being sent --- package.json | 3 ++- request.js | 27 +++++++++++++++++---------- tests/test-bearer-auth.js | 2 +- tests/test-pipes.js | 20 +++++++++++++++++++- 4 files changed, 39 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index dd1cc678b..2d022e903 100644 --- a/package.json +++ b/package.json @@ -68,6 +68,7 @@ "server-destroy": "^1.0.1", "tape": "^4.2.0", "taper": "^0.4.0", - "bluebird": "^3.0.2" + "bluebird": "^3.0.2", + "tape-catch": "^1.0.4" } } diff --git a/request.js b/request.js index e94e3e214..25f9c6b24 100644 --- a/request.js +++ b/request.js @@ -196,7 +196,10 @@ Request.prototype.init = function (options) { self._callbackCalled = true self._callback.apply(self, arguments) } - self.on('error', self.callback.bind()) + self.on('error', function () { + self._aborted = true + return self.callback.bind().apply(this, arguments) + }) self.on('complete', self.callback.bind(self, null)) } @@ -1333,20 +1336,24 @@ Request.prototype.pipe = function (dest, opts) { } Request.prototype.write = function () { var self = this - if (!self._started) { - self.start() + if (!self._aborted) { + if (!self._started) { + self.start() + } + return self.req.write.apply(self.req, arguments) } - return self.req.write.apply(self.req, arguments) } Request.prototype.end = function (chunk) { var self = this - if (chunk) { - self.write(chunk) - } - if (!self._started) { - self.start() + if (!self._aborted) { + if (chunk) { + self.write(chunk) + } + if (!self._started) { + self.start() + } + self.req.end() } - self.req.end() } Request.prototype.pause = function () { var self = this diff --git a/tests/test-bearer-auth.js b/tests/test-bearer-auth.js index 2417fa8f9..3c960cd23 100644 --- a/tests/test-bearer-auth.js +++ b/tests/test-bearer-auth.js @@ -169,7 +169,7 @@ tape('null bearer', function(t) { } }, function(error, res, body) { t.equal(res.statusCode, 401) - t.equal(numBearerRequests, 13) + t.equal(numBearerRequests, 12) t.end() }) }) diff --git a/tests/test-pipes.js b/tests/test-pipes.js index 689ebeb81..1181df6d5 100644 --- a/tests/test-pipes.js +++ b/tests/test-pipes.js @@ -6,7 +6,7 @@ var server = require('./server') , request = require('../index') , path = require('path') , util = require('util') - , tape = require('tape') + , tape = require('tape-catch') var s = server.createServer() @@ -89,6 +89,24 @@ tape('piping to a request object', function(t) { mydata.emit('end') }) +tape('piping to a request object with invalid uri', function(t) { + var mybodydata = new stream.Stream() + mybodydata.readable = true + + var r2 = request.put({ + url: '/bad-uri', + json: true + }, function(err, res, body) { + t.ok(err instanceof Error) + t.equal(err.message, 'Invalid URI "/bad-uri"') + t.end() + }) + mybodydata.pipe(r2) + + mybodydata.emit('data', JSON.stringify({ foo: 'bar' })) + mybodydata.emit('end') +}) + tape('piping to a request object with a json body', function(t) { var obj = {foo: 'bar'} var json = JSON.stringify(obj) From f4e9b0b95cd714ce564c5c61dfda8b266d5cd1bb Mon Sep 17 00:00:00 2001 From: falms Date: Tue, 3 Nov 2015 18:40:42 +0900 Subject: [PATCH 229/490] Fix tunneling after redirection from https in a simple way --- README.md | 3 +-- lib/tunnel.js | 30 ++++++++++++++---------------- request.js | 3 ++- tests/test-tunnel.js | 2 +- 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 7a3659aae..098f9133c 100644 --- a/README.md +++ b/README.md @@ -799,8 +799,7 @@ default in Linux can be anywhere from 20-120 seconds][linux-timeout]). - `tunnel` - controls the behavior of [HTTP `CONNECT` tunneling](https://en.wikipedia.org/wiki/HTTP_tunnel#HTTP_CONNECT_tunneling) as follows: - - `undefined` (default) - `true` if the destination is `https` or a previous - request in the redirect chain used a tunneling proxy, `false` otherwise + - `undefined` (default) - `true` if the destination is `https`, `false` otherwise - `true` - always tunnel to the destination by making a `CONNECT` request to the proxy - `false` - request the destination as a `GET` request. diff --git a/lib/tunnel.js b/lib/tunnel.js index 9e790aed4..f6dc046ae 100644 --- a/lib/tunnel.js +++ b/lib/tunnel.js @@ -111,20 +111,20 @@ function Tunnel (request) { this.proxyHeaderExclusiveList = [] } -Tunnel.prototype.isEnabled = function (options) { - var request = this.request - // Tunnel HTTPS by default, or if a previous request in the redirect chain - // was tunneled. Allow the user to override this setting. - - // If self.tunnel is already set (because this is a redirect), use the - // existing value. - if (typeof request.tunnel !== 'undefined') { - return request.tunnel +Tunnel.prototype.init = function (options) { + if (typeof options.tunnel !== 'undefined') { + this.tunnelOverride = options.tunnel } +} - // If options.tunnel is set (the user specified a value), use it. - if (typeof options.tunnel !== 'undefined') { - return options.tunnel +Tunnel.prototype.isEnabled = function () { + var self = this + , request = self.request + // Tunnel HTTPS by default. Allow the user to override this setting. + + // If self.tunnelOverride is set (the user specified a value), use it. + if (typeof self.tunnelOverride !== 'undefined') { + return self.tunnelOverride } // If the destination is HTTPS, tunnel. @@ -132,10 +132,8 @@ Tunnel.prototype.isEnabled = function (options) { return true } - // Otherwise, leave tunnel unset, because if a later request in the redirect - // chain is HTTPS then that request (and any subsequent ones) should be - // tunneled. - return undefined + // Otherwise, do not use tunnel. + return false } Tunnel.prototype.setup = function (options) { diff --git a/request.js b/request.js index e94e3e214..557d9af86 100644 --- a/request.js +++ b/request.js @@ -288,7 +288,8 @@ Request.prototype.init = function (options) { self.proxy = getProxyFromURI(self.uri) } - self.tunnel = self._tunnel.isEnabled(options) + self._tunnel.init(options) + self.tunnel = self._tunnel.isEnabled() if (self.proxy) { self._tunnel.setup(options) } diff --git a/tests/test-tunnel.js b/tests/test-tunnel.js index cf87731e9..6534fc83e 100644 --- a/tests/test-tunnel.js +++ b/tests/test-tunnel.js @@ -376,7 +376,7 @@ runTest('https->http over http, tunnel=default', { }, [ 'http connect to localhost:' + ss.port, 'https redirect to http', - 'http connect to localhost:' + s.port, + 'http proxy to http', 'http response', '200 http ok' ]) From 7943dce24aaf0b5ecb85148ad8e8c045addc4ed4 Mon Sep 17 00:00:00 2001 From: simov Date: Tue, 3 Nov 2015 13:51:32 +0200 Subject: [PATCH 230/490] Move the tunnel override flag initialization to the ctor --- lib/tunnel.js | 7 ++----- request.js | 1 - 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/tunnel.js b/lib/tunnel.js index f6dc046ae..918aec69a 100644 --- a/lib/tunnel.js +++ b/lib/tunnel.js @@ -109,11 +109,8 @@ function Tunnel (request) { this.request = request this.proxyHeaderWhiteList = defaultProxyHeaderWhiteList this.proxyHeaderExclusiveList = [] -} - -Tunnel.prototype.init = function (options) { - if (typeof options.tunnel !== 'undefined') { - this.tunnelOverride = options.tunnel + if (typeof request.tunnel !== 'undefined') { + this.tunnelOverride = request.tunnel } } diff --git a/request.js b/request.js index 557d9af86..ed9e57d36 100644 --- a/request.js +++ b/request.js @@ -288,7 +288,6 @@ Request.prototype.init = function (options) { self.proxy = getProxyFromURI(self.uri) } - self._tunnel.init(options) self.tunnel = self._tunnel.isEnabled() if (self.proxy) { self._tunnel.setup(options) From 6931cea23ca5cfe3817dc8bb809ecb249921fa3c Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 5 Nov 2015 19:30:28 +0200 Subject: [PATCH 231/490] Improve the write after error fix implemented in #1880 --- package.json | 3 +-- request.js | 32 +++++++++++++++----------------- tests/test-bearer-auth.js | 2 +- tests/test-pipes.js | 2 +- 4 files changed, 18 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index 2d022e903..dd1cc678b 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,6 @@ "server-destroy": "^1.0.1", "tape": "^4.2.0", "taper": "^0.4.0", - "bluebird": "^3.0.2", - "tape-catch": "^1.0.4" + "bluebird": "^3.0.2" } } diff --git a/request.js b/request.js index 25f9c6b24..323348c6d 100644 --- a/request.js +++ b/request.js @@ -196,10 +196,7 @@ Request.prototype.init = function (options) { self._callbackCalled = true self._callback.apply(self, arguments) } - self.on('error', function () { - self._aborted = true - return self.callback.bind().apply(this, arguments) - }) + self.on('error', self.callback.bind()) self.on('complete', self.callback.bind(self, null)) } @@ -284,6 +281,7 @@ Request.prototype.init = function (options) { message += '. This can be caused by a crappy redirection.' } // This error was fatal + self.abort() return self.emit('error', new Error(message)) } @@ -1336,24 +1334,24 @@ Request.prototype.pipe = function (dest, opts) { } Request.prototype.write = function () { var self = this - if (!self._aborted) { - if (!self._started) { - self.start() - } - return self.req.write.apply(self.req, arguments) + if (self._aborted) {return} + + if (!self._started) { + self.start() } + return self.req.write.apply(self.req, arguments) } Request.prototype.end = function (chunk) { var self = this - if (!self._aborted) { - if (chunk) { - self.write(chunk) - } - if (!self._started) { - self.start() - } - self.req.end() + if (self._aborted) {return} + + if (chunk) { + self.write(chunk) + } + if (!self._started) { + self.start() } + self.req.end() } Request.prototype.pause = function () { var self = this diff --git a/tests/test-bearer-auth.js b/tests/test-bearer-auth.js index 3c960cd23..2417fa8f9 100644 --- a/tests/test-bearer-auth.js +++ b/tests/test-bearer-auth.js @@ -169,7 +169,7 @@ tape('null bearer', function(t) { } }, function(error, res, body) { t.equal(res.statusCode, 401) - t.equal(numBearerRequests, 12) + t.equal(numBearerRequests, 13) t.end() }) }) diff --git a/tests/test-pipes.js b/tests/test-pipes.js index 1181df6d5..ec0ea6da8 100644 --- a/tests/test-pipes.js +++ b/tests/test-pipes.js @@ -6,7 +6,7 @@ var server = require('./server') , request = require('../index') , path = require('path') , util = require('util') - , tape = require('tape-catch') + , tape = require('tape') var s = server.createServer() From db7c4eb6b13b2b6819f292b174691b07b52ff7f8 Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Fri, 6 Nov 2015 09:44:27 -0800 Subject: [PATCH 232/490] chore(package): update eslint to version 1.9.0 http://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index dd1cc678b..90eadca55 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,7 @@ "buffer-equal": "^0.0.1", "codecov.io": "^0.1.6", "coveralls": "^2.11.4", - "eslint": "1.7.3", + "eslint": "1.9.0", "function-bind": "^1.0.2", "istanbul": "^0.4.0", "karma-browserify": "^4.4.0", From 86050274b7b573b03885e038a1a254b4c877901a Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Fri, 13 Nov 2015 12:31:32 -0800 Subject: [PATCH 233/490] chore(package): update node-uuid to version 1.4.7 http://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 90eadca55..d16aa2c05 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "form-data": "~1.0.0-rc3", "json-stringify-safe": "~5.0.1", "mime-types": "~2.1.7", - "node-uuid": "~1.4.3", + "node-uuid": "~1.4.7", "qs": "~5.2.0", "tunnel-agent": "~0.4.1", "tough-cookie": "~2.2.0", From cb5b7ac919545c13c03c3e7f00ee2737527d8139 Mon Sep 17 00:00:00 2001 From: simov Date: Mon, 16 Nov 2015 18:38:16 +0200 Subject: [PATCH 234/490] Convert typed arrays into regular buffers --- package.json | 1 + request.js | 5 +++++ tests/test-body.js | 20 ++++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/package.json b/package.json index d16aa2c05..8136b826f 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "stringstream": "~0.0.4", "combined-stream": "~1.0.5", "isstream": "~0.1.2", + "is-typedarray": "~1.0.0", "har-validator": "~2.0.2" }, "scripts": { diff --git a/request.js b/request.js index e1080cafa..19c1b92f3 100644 --- a/request.js +++ b/request.js @@ -15,6 +15,7 @@ var http = require('http') , caseless = require('caseless') , ForeverAgent = require('forever-agent') , FormData = require('form-data') + , isTypedArray = require('is-typedarray').strict , helpers = require('./lib/helpers') , cookies = require('./lib/cookies') , getProxyFromURI = require('./lib/getProxyFromURI') @@ -427,6 +428,10 @@ Request.prototype.init = function (options) { } function setContentLength () { + if (isTypedArray(self.body)) { + self.body = new Buffer(self.body) + } + if (!self.hasHeader('content-length')) { var length if (typeof self.body === 'string') { diff --git a/tests/test-body.js b/tests/test-body.js index 031b7a845..2f52e2c8e 100644 --- a/tests/test-body.js +++ b/tests/test-body.js @@ -3,6 +3,7 @@ var server = require('./server') , request = require('../index') , tape = require('tape') + , http = require('http') var s = server.createServer() @@ -144,6 +145,25 @@ addTest('testPutMultipartPostambleCRLF', { ] }) +tape('typed array', function (t) { + var server = http.createServer() + server.on('request', function (req, res) { + req.pipe(res) + }) + server.listen(6768, function () { + var data = new Uint8Array([1, 2, 3]) + request({ + uri: 'http://localhost:6768', + method: 'POST', + body: data, + encoding: null + }, function (err, res, body) { + t.deepEqual(new Buffer(data), body) + server.close(t.end) + }) + }) +}) + tape('cleanup', function(t) { s.close(function() { t.end() From a1ef680ca857f418c8a20c201fcde17b0e48d023 Mon Sep 17 00:00:00 2001 From: ReadmeCritic Date: Tue, 17 Nov 2015 19:32:29 -0800 Subject: [PATCH 235/490] Update README URLs based on HTTP redirects --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 098f9133c..42781d455 100644 --- a/README.md +++ b/README.md @@ -161,7 +161,7 @@ request.post({url:'http://service.com/upload', form: {key:'value'}}, function(er #### multipart/form-data (Multipart Form Uploads) -For `multipart/form-data` we use the [form-data](https://github.com/felixge/node-form-data) library by [@felixge](https://github.com/felixge). For the most cases, you can pass your upload form data via the `formData` option. +For `multipart/form-data` we use the [form-data](https://github.com/form-data/form-data) library by [@felixge](https://github.com/felixge). For the most cases, you can pass your upload form data via the `formData` option. ```js @@ -179,7 +179,7 @@ var formData = { ], // Pass optional meta-data with an 'options' object with style: {value: DATA, options: OPTIONS} // Use case: for some types of streams, you'll need to provide "file"-related information manually. - // See the `form-data` README for more information about options: https://github.com/felixge/node-form-data + // See the `form-data` README for more information about options: https://github.com/form-data/form-data custom_file: { value: fs.createReadStream('/dev/urandom'), options: { @@ -206,7 +206,7 @@ form.append('my_field', 'my_value'); form.append('my_buffer', new Buffer([1, 2, 3])); form.append('custom_file', fs.createReadStream(__dirname + '/unicycle.jpg'), {filename: 'unicycle.jpg'}); ``` -See the [form-data README](https://github.com/felixge/node-form-data) for more information & examples. +See the [form-data README](https://github.com/form-data/form-data) for more information & examples. #### multipart/related @@ -472,7 +472,7 @@ HTTP/1.1 200 OK At this point, the connection is left open, and the client is communicating directly with the `endpoint-server.com` machine. -See [the wikipedia page on HTTP Tunneling](http://en.wikipedia.org/wiki/HTTP_tunnel) +See [the wikipedia page on HTTP Tunneling](https://en.wikipedia.org/wiki/HTTP_tunnel) for more information. By default, when proxying `http` traffic, request will simply make a @@ -566,7 +566,7 @@ Here's some examples of valid `no_proxy` values: ## UNIX Domain Sockets -`request` supports making requests to [UNIX Domain Sockets](http://en.wikipedia.org/wiki/Unix_domain_socket). To make one, use the following URL scheme: +`request` supports making requests to [UNIX Domain Sockets](https://en.wikipedia.org/wiki/Unix_domain_socket). To make one, use the following URL scheme: ```js /* Pattern */ 'http://unix:SOCKET:PATH' @@ -932,7 +932,7 @@ There are at least three ways to debug the operation of `request`: 2. Set `require('request').debug = true` at any time (this does the same thing as #1). -3. Use the [request-debug module](https://github.com/nylen/request-debug) to +3. Use the [request-debug module](https://github.com/request/request-debug) to view request and response headers and bodies. [back to top](#table-of-contents) @@ -1075,9 +1075,9 @@ request('http://www.google.com', function() { ``` The cookie store must be a -[`tough-cookie`](https://github.com/goinstant/tough-cookie) +[`tough-cookie`](https://github.com/SalesforceEng/tough-cookie) store and it must support synchronous operations; see the -[`CookieStore` API docs](https://github.com/goinstant/tough-cookie/#cookiestore-api) +[`CookieStore` API docs](https://github.com/SalesforceEng/tough-cookie) for details. To inspect your cookie jar after a request: From a30219ad6acb59fae7e3b0dafc916ae25a743a8c Mon Sep 17 00:00:00 2001 From: ReadmeCritic Date: Tue, 17 Nov 2015 19:34:06 -0800 Subject: [PATCH 236/490] Missing anchor --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 42781d455..77e30df58 100644 --- a/README.md +++ b/README.md @@ -1077,7 +1077,7 @@ request('http://www.google.com', function() { The cookie store must be a [`tough-cookie`](https://github.com/SalesforceEng/tough-cookie) store and it must support synchronous operations; see the -[`CookieStore` API docs](https://github.com/SalesforceEng/tough-cookie) +[`CookieStore` API docs](https://github.com/SalesforceEng/tough-cookie#cookiestore-api) for details. To inspect your cookie jar after a request: From ff8b51069fbfb097adbe1ae22389dfd31376c542 Mon Sep 17 00:00:00 2001 From: simov Date: Wed, 18 Nov 2015 12:05:28 +0200 Subject: [PATCH 237/490] 2.66.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8136b826f..573553797 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.65.1", + "version": "2.66.0", "author": "Mikeal Rogers ", "repository": { "type": "git", From 48e505d845d4fa1a9d87b3c94c205e563d91e8b9 Mon Sep 17 00:00:00 2001 From: simov Date: Wed, 18 Nov 2015 12:07:18 +0200 Subject: [PATCH 238/490] Update changelog --- CHANGELOG.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a43c6726a..a88f8600b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,27 @@ ## Change Log +### v2.66.0 (2015/11/18) +- [#1906](https://github.com/request/request/pull/1906) Update README URLs based on HTTP redirects (@ReadmeCritic) +- [#1905](https://github.com/request/request/pull/1905) Convert typed arrays into regular buffers (@simov) +- [#1902](https://github.com/request/request/pull/1902) node-uuid@1.4.7 breaks build 🚨 (@greenkeeperio-bot) +- [#1894](https://github.com/request/request/pull/1894) Fix tunneling after redirection from https (Original: #1881) (@simov, @falms) +- [#1893](https://github.com/request/request/pull/1893) Update eslint to version 1.9.0 🚀 (@greenkeeperio-bot) +- [#1852](https://github.com/request/request/pull/1852) Update eslint to version 1.7.3 🚀 (@simov, @greenkeeperio-bot, @paulomcnally, @michelsalib, @arbaaz, @vladimirich, @LoicMahieu, @JoshWillik, @jzaefferer, @ryanwholey, @djchie, @thisconnect, @mgenereu, @acroca, @Sebmaster, @Bloutiouf) +- [#1876](https://github.com/request/request/pull/1876) Implement loose matching for har mime types (@simov) +- [#1875](https://github.com/request/request/pull/1875) Update bluebird to version 3.0.2 🚀 (@simov, @greenkeeperio-bot) +- [#1871](https://github.com/request/request/pull/1871) Update browserify to version 12.0.1 🚀 (@greenkeeperio-bot) +- [#1866](https://github.com/request/request/pull/1866) Add missing quotes on x-token property in README (@miguelmota) +- [#1874](https://github.com/request/request/pull/1874) Fix typo in README.md (@gswalden) +- [#1860](https://github.com/request/request/pull/1860) Improve referer header tests and docs (@simov) +- [#1861](https://github.com/request/request/pull/1861) Remove redundant call to Stream constructor (@watson) +- [#1857](https://github.com/request/request/pull/1857) Fix Referer header to point to the original host name (@simov) +- [#1850](https://github.com/request/request/pull/1850) Update karma-coverage to version 0.5.3 🚀 (@greenkeeperio-bot) +- [#1847](https://github.com/request/request/pull/1847) Use node's latest version when building (@simov) +- [#1836](https://github.com/request/request/pull/1836) Tunnel: fix wrong property name (@Bloutiouf) +- [#1820](https://github.com/request/request/pull/1820) Set href as request.js uses it (@mgenereu) +- [#1840](https://github.com/request/request/pull/1840) Update http-signature to version 1.0.2 🚀 (@greenkeeperio-bot) +- [#1845](https://github.com/request/request/pull/1845) Update istanbul to version 0.4.0 🚀 (@greenkeeperio-bot) + ### v2.65.0 (2015/10/11) - [#1833](https://github.com/request/request/pull/1833) Update aws-sign2 to version 0.6.0 🚀 (@greenkeeperio-bot) - [#1811](https://github.com/request/request/pull/1811) Enable loose cookie parsing in tough-cookie (@Sebmaster) From 01e51794c3c95c660888890132ee2d7c77d1791a Mon Sep 17 00:00:00 2001 From: simov Date: Wed, 18 Nov 2015 12:07:39 +0200 Subject: [PATCH 239/490] 2.66.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 573553797..299d9cd08 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.66.0", + "version": "2.66.1", "author": "Mikeal Rogers ", "repository": { "type": "git", From 6a9e24cdc9ccf0aa50296ba15eca0038b91c2832 Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Wed, 18 Nov 2015 15:47:56 -0800 Subject: [PATCH 240/490] chore(package): update http-signature to version 1.1.0 http://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 299d9cd08..ae9ebdc33 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "qs": "~5.2.0", "tunnel-agent": "~0.4.1", "tough-cookie": "~2.2.0", - "http-signature": "~1.0.2", + "http-signature": "~1.1.0", "oauth-sign": "~0.8.0", "hawk": "~3.1.0", "aws-sign2": "~0.6.0", From 9b10aec4bdcfcbf03073e63f429b7652a16dd10f Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 19 Nov 2015 09:44:36 +0200 Subject: [PATCH 241/490] 2.67.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ae9ebdc33..91909fdd7 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.66.1", + "version": "2.67.0", "author": "Mikeal Rogers ", "repository": { "type": "git", From 76f0655befbe8b37fa246bdca1107cbf57798d9a Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 19 Nov 2015 09:45:35 +0200 Subject: [PATCH 242/490] Update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a88f8600b..7dc85ea14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## Change Log +### v2.67.0 (2015/11/19) +- [#1913](https://github.com/request/request/pull/1913) Update http-signature to version 1.1.0 🚀 (@greenkeeperio-bot) + ### v2.66.0 (2015/11/18) - [#1906](https://github.com/request/request/pull/1906) Update README URLs based on HTTP redirects (@ReadmeCritic) - [#1905](https://github.com/request/request/pull/1905) Convert typed arrays into regular buffers (@simov) From 777581d5c4fd6d7034ad80d06357f176b14e4495 Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 19 Nov 2015 09:45:52 +0200 Subject: [PATCH 243/490] 2.67.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 91909fdd7..630548317 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.67.0", + "version": "2.67.1", "author": "Mikeal Rogers ", "repository": { "type": "git", From 7990fa61cb46fc3576ef7e0c5a017ef55ddf3a9d Mon Sep 17 00:00:00 2001 From: Yang Xia Date: Thu, 19 Nov 2015 16:40:36 +0800 Subject: [PATCH 244/490] Remove content-length and transfer-encoding headers from defaultProxyHeaderWhiteList --- lib/tunnel.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/tunnel.js b/lib/tunnel.js index 918aec69a..bf96a8fec 100644 --- a/lib/tunnel.js +++ b/lib/tunnel.js @@ -12,7 +12,6 @@ var defaultProxyHeaderWhiteList = [ 'cache-control', 'content-encoding', 'content-language', - 'content-length', 'content-location', 'content-md5', 'content-range', @@ -24,7 +23,6 @@ var defaultProxyHeaderWhiteList = [ 'pragma', 'referer', 'te', - 'transfer-encoding', 'user-agent', 'via' ] From 3848e7b907c326459c1e828c091a4330cd7325b0 Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Fri, 20 Nov 2015 15:05:39 -0800 Subject: [PATCH 245/490] chore(package): update eslint to version 1.10.1 http://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 630548317..2886d32d2 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "buffer-equal": "^0.0.1", "codecov.io": "^0.1.6", "coveralls": "^2.11.4", - "eslint": "1.9.0", + "eslint": "1.10.1", "function-bind": "^1.0.2", "istanbul": "^0.4.0", "karma-browserify": "^4.4.0", From c6c7f85cde03197f8de5118c7938f6e9625fa17c Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Tue, 1 Dec 2015 12:15:33 -0800 Subject: [PATCH 246/490] chore(package): update eslint to version 1.10.3 http://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2886d32d2..daa18004a 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "buffer-equal": "^0.0.1", "codecov.io": "^0.1.6", "coveralls": "^2.11.4", - "eslint": "1.10.1", + "eslint": "1.10.3", "function-bind": "^1.0.2", "istanbul": "^0.4.0", "karma-browserify": "^4.4.0", From 649ae8353e9e6c864fa4f628d9c69529bf46d151 Mon Sep 17 00:00:00 2001 From: simov Date: Wed, 2 Dec 2015 20:01:14 +0200 Subject: [PATCH 247/490] Fix eslint `curly` error --- tests/server.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/server.js b/tests/server.js index 34d9d1ffc..7c2218c33 100644 --- a/tests/server.js +++ b/tests/server.js @@ -51,7 +51,9 @@ exports.createSSLServer = function(port, opts) { , 'cert': path.join(__dirname, 'ssl', 'test.crt') } if (opts) { - for (i in opts) options[i] = opts[i] + for (i in opts) { + options[i] = opts[i] + } } for (i in options) { From ca0d20f89ece366507c30ce72bcc70dad1e0ff2f Mon Sep 17 00:00:00 2001 From: Manas Date: Tue, 8 Dec 2015 20:39:25 +0530 Subject: [PATCH 248/490] Adds example for Tor proxy --- examples/README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/examples/README.md b/examples/README.md index 526d71bba..615a33da5 100644 --- a/examples/README.md +++ b/examples/README.md @@ -113,3 +113,23 @@ fs.createReadStream(TMP_FILE_PATH) .pipe(request.post('http://127.0.0.1:3000')) ; ``` + +# Proxys + +Run tor on the terminal and try the following. (Needs `socks5-http-client` to connect to tor) + +```js +var request = require('../index.js'); +var Agent = require('socks5-http-client/lib/Agent'); + +request.get({ + url: 'http://www.tenreads.io', + agentClass: Agent, + agentOptions: { + socksHost: 'localhost', // Defaults to 'localhost'. + socksPort: 9050 // Defaults to 1080. + } +}, function (err, res) { + console.log(res.body); +}); +``` From f1b59e1c75885ab78fac68ae5e7a1345658a4f1a Mon Sep 17 00:00:00 2001 From: Jong Lee Date: Wed, 9 Dec 2015 13:50:31 -0800 Subject: [PATCH 249/490] check the value of content-length before setting the header when posting a form data. --- request.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/request.js b/request.js index 19c1b92f3..793388abf 100644 --- a/request.js +++ b/request.js @@ -579,7 +579,7 @@ Request.prototype.init = function (options) { // Before ending the request, we had to compute the length of the whole form, asyncly self.setHeader(self._form.getHeaders(), true) self._form.getLength(function (err, length) { - if (!err) { + if (!err && !isNaN(length)) { self.setHeader('content-length', length) } end() From d0b6112690d5a54cecfa1ec61ac9df8cbab8c93c Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 10 Dec 2015 10:31:02 +0200 Subject: [PATCH 250/490] Use IncomingMessage.destroy method --- request.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/request.js b/request.js index 19c1b92f3..19c1918cc 100644 --- a/request.js +++ b/request.js @@ -1044,7 +1044,7 @@ Request.prototype.abort = function () { self.req.abort() } else if (self.response) { - self.response.abort() + self.response.destroy() } self.emit('abort') From 53f5d13af4d5cd7389b255cdf560ca8d2aa1a109 Mon Sep 17 00:00:00 2001 From: Jong Lee Date: Thu, 10 Dec 2015 17:55:43 -0800 Subject: [PATCH 251/490] added a test case for setting content-length header value to NaN when using chunked HTTP response in form data. --- tests/test-form-data-error.js | 40 ++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/tests/test-form-data-error.js b/tests/test-form-data-error.js index 1f3178686..9b7642211 100644 --- a/tests/test-form-data-error.js +++ b/tests/test-form-data-error.js @@ -27,8 +27,46 @@ tape('re-emit formData errors', function(t) { }).form().append('field', ['value1', 'value2']) }) +tape('omit content-length header if the value is set to NaN', function(t) { + + // returns chunked HTTP response which is streamed to the 2nd HTTP request in the form data + s.on('/chunky', server.createChunkResponse( + ['some string', + 'some other string' + ])) + + // accepts form data request + s.on('/stream', function(req, resp) { + req.on('data', function(chunk) { + // consume the request body + }) + req.on('end', function() { + resp.writeHead(200) + resp.end() + }) + }) + + var sendStreamRequest = function(stream) { + request.post({ + uri: s.url + '/stream', + formData: { + param: stream + } + }, function(err, res) { + t.error(err, 'request failed') + t.end() + }) + } + + request.get({ + uri: s.url + '/chunky', + }).on('response', function(res) { + sendStreamRequest(res) + }) +}) + tape('cleanup', function(t) { s.close(function() { t.end() }) -}) +}) \ No newline at end of file From 4dbbf3d70285acf6bfc64a07c2515a2c7ade2880 Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Fri, 1 Jan 2016 18:38:13 -0800 Subject: [PATCH 252/490] chore(package): update buffer-equal to version 1.0.0 http://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index daa18004a..6790cce3f 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "devDependencies": { "browserify-istanbul": "^0.1.5", "browserify": "^12.0.1", - "buffer-equal": "^0.0.1", + "buffer-equal": "^1.0.0", "codecov.io": "^0.1.6", "coveralls": "^2.11.4", "eslint": "1.10.3", From c7db6e54158063801324113ffd6ba2701efb1d67 Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Tue, 12 Jan 2016 02:15:22 -0800 Subject: [PATCH 253/490] chore(package): update browserify to version 13.0.0 http://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6790cce3f..681f125a8 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ }, "devDependencies": { "browserify-istanbul": "^0.1.5", - "browserify": "^12.0.1", + "browserify": "^13.0.0", "buffer-equal": "^1.0.0", "codecov.io": "^0.1.6", "coveralls": "^2.11.4", From 297633984140b3b8a55aa65dc74165a7b94475cb Mon Sep 17 00:00:00 2001 From: simov Date: Wed, 13 Jan 2016 12:31:40 +0200 Subject: [PATCH 254/490] Use the `extend` module instead of util._extend --- lib/har.js | 5 +++-- request.js | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/har.js b/lib/har.js index ceb1cd107..305957487 100644 --- a/lib/har.js +++ b/lib/har.js @@ -3,7 +3,7 @@ var fs = require('fs') var qs = require('querystring') var validate = require('har-validator') -var util = require('util') +var extend = require('extend') function Har (request) { this.request = request @@ -118,7 +118,8 @@ Har.prototype.options = function (options) { return options } - var har = util._extend({}, options.har) + var har = {} + extend(har, options.har) // only process the first entry if (har.log && har.log.entries) { diff --git a/request.js b/request.js index 08785f1cc..9fdd5a630 100644 --- a/request.js +++ b/request.js @@ -15,6 +15,7 @@ var http = require('http') , caseless = require('caseless') , ForeverAgent = require('forever-agent') , FormData = require('form-data') + , extend = require('extend') , isTypedArray = require('is-typedarray').strict , helpers = require('./lib/helpers') , cookies = require('./lib/cookies') @@ -123,7 +124,7 @@ function Request (options) { var reserved = Object.keys(Request.prototype) var nonReserved = filterForNonReserved(reserved, options) - util._extend(self, nonReserved) + extend(self, nonReserved) options = filterOutReservedFunctions(reserved, options) self.readable = true From 8845e130ffd8dc43de5bcf4c14a448e7032d9491 Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Sun, 17 Jan 2016 14:59:47 -0800 Subject: [PATCH 255/490] chore(package): update qs to version 6.0.2 http://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 681f125a8..f264389a1 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "json-stringify-safe": "~5.0.1", "mime-types": "~2.1.7", "node-uuid": "~1.4.7", - "qs": "~5.2.0", + "qs": "~6.0.2", "tunnel-agent": "~0.4.1", "tough-cookie": "~2.2.0", "http-signature": "~1.1.0", From 3d31d4526fa4d4e4f59b89cabe194fb671063cdb Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Tue, 19 Jan 2016 04:54:24 +0100 Subject: [PATCH 256/490] Fix remote memory disclosure in multipart attachments --- lib/multipart.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/multipart.js b/lib/multipart.js index 03618588c..c12817261 100644 --- a/lib/multipart.js +++ b/lib/multipart.js @@ -68,6 +68,9 @@ Multipart.prototype.build = function (parts, chunked) { var body = chunked ? new CombinedStream() : [] function add (part) { + if (typeof part === 'number') { + part = part.toString() + } return chunked ? body.append(part) : body.push(new Buffer(part)) } From 8e98a6e358dd87966df022542fc3354547465876 Mon Sep 17 00:00:00 2001 From: simov Date: Wed, 20 Jan 2016 09:28:31 +0200 Subject: [PATCH 257/490] Test converting of numeric multipart bodies to string --- tests/test-multipart.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/test-multipart.js b/tests/test-multipart.js index 255852b70..4afb87895 100644 --- a/tests/test-multipart.js +++ b/tests/test-multipart.js @@ -41,20 +41,24 @@ function runTest(t, a) { req.on('end', function() { // check for the fields traces - // 1st field : my_field + // my_field t.ok(data.indexOf('name: my_field') !== -1) t.ok(data.indexOf(multipartData[0].body) !== -1) + + // my_number + t.ok(data.indexOf('name: my_number') !== -1) + t.ok(data.indexOf(multipartData[1].body) !== -1) - // 2nd field : my_buffer + // my_buffer t.ok(data.indexOf('name: my_buffer') !== -1) - t.ok(data.indexOf(multipartData[1].body) !== -1) + t.ok(data.indexOf(multipartData[2].body) !== -1) - // 3rd field : my_file + // my_file t.ok(data.indexOf('name: my_file') !== -1) // check for unicycle.jpg traces t.ok(data.indexOf('2005:06:21 01:44:12') !== -1) - // 4th field : remote_file + // remote_file t.ok(data.indexOf('name: remote_file') !== -1) // check for http://localhost:6767/file traces t.ok(data.indexOf('Photoshop ICC') !== -1) @@ -73,6 +77,7 @@ function runTest(t, a) { // @NOTE: multipartData properties must be set here so that my_file read stream does not leak in node v0.8 multipartData = [ {name: 'my_field', body: 'my_value'}, + {name: 'my_number', body: 1000}, {name: 'my_buffer', body: new Buffer([1, 2, 3])}, {name: 'my_file', body: fs.createReadStream(localFile)}, {name: 'remote_file', body: request('http://localhost:6767/file')} From 8a299a09f475aae44e3e89d15e5b53be1c65ba47 Mon Sep 17 00:00:00 2001 From: Tyler Dixon Date: Wed, 20 Jan 2016 11:09:44 -0500 Subject: [PATCH 258/490] Update har-validator dependency for nsp advisory #76 See https://nodesecurity.io/advisories/76 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f264389a1..5d7aa243e 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "combined-stream": "~1.0.5", "isstream": "~0.1.2", "is-typedarray": "~1.0.0", - "har-validator": "~2.0.2" + "har-validator": "~2.0.6" }, "scripts": { "test": "npm run lint && npm run test-ci && npm run test-browser", From 4326b8112a8ca38154776376e8b91f1e6d805e86 Mon Sep 17 00:00:00 2001 From: Mirko Di Serafino Date: Mon, 25 Jan 2016 11:19:05 +0100 Subject: [PATCH 259/490] Added aws-sign4 support added aws-sign4 support added tests Added sign_version parameter doc fixed test fix changes removed changes on CHANGELOG fix fix fix comma --- CHANGELOG.md | 2 +- README.md | 2 +- package.json | 3 +- request.js | 68 +++++++++++++++++++++++++++-------------- tests/test-aws.js | 78 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 127 insertions(+), 26 deletions(-) create mode 100644 tests/test-aws.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 7dc85ea14..300a953ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -70,7 +70,7 @@ - [#1687](https://github.com/request/request/pull/1687) Fix caseless bug - content-type not being set for multipart/form-data (@simov, @garymathews) ### v2.59.0 (2015/07/20) -- [#1671](https://github.com/request/request/pull/1671) Add tests and docs for using the agent, agentClass, agentOptions and forever options. Forever option defaults to using http(s).Agent in node 0.12+ (@simov) +- [#1671](https://github.com/request/request/pull/1671) Add tests and docs for using the agent, agentClass, agentOptions and forever options. - [#1679](https://github.com/request/request/pull/1679) Fix - do not remove OAuth param when using OAuth realm (@simov, @jhalickman) - [#1668](https://github.com/request/request/pull/1668) updated dependencies (@deamme) - [#1656](https://github.com/request/request/pull/1656) Fix form method (@simov) diff --git a/README.md b/README.md index 77e30df58..937836878 100644 --- a/README.md +++ b/README.md @@ -754,7 +754,7 @@ The first argument can be either a `url` or an `options` object. The only requir - `auth` - A hash containing values `user` || `username`, `pass` || `password`, and `sendImmediately` (optional). See documentation above. - `oauth` - Options for OAuth HMAC-SHA1 signing. See documentation above. - `hawk` - Options for [Hawk signing](https://github.com/hueniverse/hawk). The `credentials` key must contain the necessary signing info, [see hawk docs for details](https://github.com/hueniverse/hawk#usage-example). -- `aws` - `object` containing AWS signing information. Should have the properties `key`, `secret`. Also requires the property `bucket`, unless you’re specifying your `bucket` as part of the path, or the request doesn’t use a bucket (i.e. GET Services) +- `aws` - `object` containing AWS signing information. Should have the properties `key`, `secret`. Also requires the property `bucket`, unless you’re specifying your `bucket` as part of the path, or the request doesn’t use a bucket (i.e. GET Services). If you want to use AWS sign version 4 use the parameter `sign_version` with value `4` otherwise the default is version 2. - `httpSignature` - Options for the [HTTP Signature Scheme](https://github.com/joyent/node-http-signature/blob/master/http_signing.md) using [Joyent's library](https://github.com/joyent/node-http-signature). The `keyId` and `key` properties must be specified. See the docs for other options. --- diff --git a/package.json b/package.json index 5d7aa243e..dbb535b10 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,8 @@ "combined-stream": "~1.0.5", "isstream": "~0.1.2", "is-typedarray": "~1.0.0", - "har-validator": "~2.0.6" + "har-validator": "~2.0.6", + "aws4": "^1.2.1" }, "scripts": { "test": "npm run lint && npm run test-ci && npm run test-browser", diff --git a/request.js b/request.js index 9fdd5a630..4ef403ff6 100644 --- a/request.js +++ b/request.js @@ -8,7 +8,8 @@ var http = require('http') , zlib = require('zlib') , bl = require('bl') , hawk = require('hawk') - , aws = require('aws-sign2') + , aws2 = require('aws-sign2') + , aws4 = require('aws4') , httpSignature = require('http-signature') , mime = require('mime-types') , stringstream = require('stringstream') @@ -1229,29 +1230,50 @@ Request.prototype.aws = function (opts, now) { self._aws = opts return self } - var date = new Date() - self.setHeader('date', date.toUTCString()) - var auth = - { key: opts.key - , secret: opts.secret - , verb: self.method.toUpperCase() - , date: date - , contentType: self.getHeader('content-type') || '' - , md5: self.getHeader('content-md5') || '' - , amazonHeaders: aws.canonicalizeHeaders(self.headers) + + if (opts.sign_version == 4 || opts.sign_version == '4') { + // Use aws-sign4 + var options = { + host: self.uri.host, + path: self.uri.path, + method: self.method, + headers: { + 'content-type': self.getHeader('content-type') || '' + }, + body: self.body } - var path = self.uri.path - if (opts.bucket && path) { - auth.resource = '/' + opts.bucket + path - } else if (opts.bucket && !path) { - auth.resource = '/' + opts.bucket - } else if (!opts.bucket && path) { - auth.resource = path - } else if (!opts.bucket && !path) { - auth.resource = '/' - } - auth.resource = aws.canonicalizeResource(auth.resource) - self.setHeader('authorization', aws.authorization(auth)) + var signRes = aws4.sign(options, { + accessKeyId: opts.key, + secretAccessKey: opts.secret + }) + self.setHeader('authorization', signRes.headers.Authorization) + self.setHeader('x-amz-date', signRes.headers['X-Amz-Date']) + } else { + // Default behaviour -> use aws-sign2 + var date = new Date() + self.setHeader('date', date.toUTCString()) + var auth = + { key: opts.key + , secret: opts.secret + , verb: self.method.toUpperCase() + , date: date + , contentType: self.getHeader('content-type') || '' + , md5: self.getHeader('content-md5') || '' + , amazonHeaders: aws2.canonicalizeHeaders(self.headers) + } + var path = self.uri.path + if (opts.bucket && path) { + auth.resource = '/' + opts.bucket + path + } else if (opts.bucket && !path) { + auth.resource = '/' + opts.bucket + } else if (!opts.bucket && path) { + auth.resource = path + } else if (!opts.bucket && !path) { + auth.resource = '/' + } + auth.resource = aws2.canonicalizeResource(auth.resource) + self.setHeader('authorization', aws2.authorization(auth)) + } return self } diff --git a/tests/test-aws.js b/tests/test-aws.js new file mode 100644 index 000000000..b3200cbaa --- /dev/null +++ b/tests/test-aws.js @@ -0,0 +1,78 @@ +'use strict' + +if (process.env.running_under_istanbul) { + // test-agent.js modifies the process state + // causing these tests to fail when running under single process via tape + return +} + +var request = require('../index') + , server = require('./server') + , tape = require('tape') + +var s = server.createServer() + +var path = '/aws.json' + +s.on(path, function(req, res) { + res.writeHead(200, { + 'Content-Type': 'application/json' + }) + res.end(JSON.stringify(req.headers)) +}) + +tape('setup', function(t) { + s.listen(s.port, function() { + t.end() + }) +}) + +tape('default behaviour: aws-sign2 without sign_version key', function(t) { + var aws2_options = { aws: {} } + aws2_options.aws.key = 'my_key' + aws2_options.aws.secret = 'my_secret' + aws2_options.url = s.url + path + aws2_options.json = true + + request(aws2_options, function(err, res, body) { + t.ok(body.authorization) + t.notOk(body['x-amz-date']) + t.end() + }) +}) + +tape('aws-sign2 with sign_version key', function(t) { + var aws2_options = { aws: {} } + aws2_options.aws.key = 'my_key' + aws2_options.aws.secret = 'my_secret' + aws2_options.aws.sign_version = 2 + aws2_options.url = s.url + path + aws2_options.json = true + + request(aws2_options, function(err, res, body) { + t.ok(body.authorization) + t.notOk(body['x-amz-date']) + t.end() + }) +}) + +tape('aws-sign4 options', function(t) { + var aws2_options = { aws: {} } + aws2_options.aws.key = 'my_key' + aws2_options.aws.secret = 'my_secret' + aws2_options.aws.sign_version = 4 + aws2_options.url = s.url + path + aws2_options.json = true + + request(aws2_options, function(err, res, body) { + t.ok(body.authorization) + t.ok(body['x-amz-date']) + t.end() + }) +}) + +tape('cleanup', function(t) { + s.close(function() { + t.end() + }) +}) From 17d7cbc1838ba62089e9a438897c3d1b4427e02f Mon Sep 17 00:00:00 2001 From: simov Date: Tue, 26 Jan 2016 11:35:12 +0200 Subject: [PATCH 260/490] Revert back changelog changes --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 300a953ba..7dc85ea14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -70,7 +70,7 @@ - [#1687](https://github.com/request/request/pull/1687) Fix caseless bug - content-type not being set for multipart/form-data (@simov, @garymathews) ### v2.59.0 (2015/07/20) -- [#1671](https://github.com/request/request/pull/1671) Add tests and docs for using the agent, agentClass, agentOptions and forever options. +- [#1671](https://github.com/request/request/pull/1671) Add tests and docs for using the agent, agentClass, agentOptions and forever options. Forever option defaults to using http(s).Agent in node 0.12+ (@simov) - [#1679](https://github.com/request/request/pull/1679) Fix - do not remove OAuth param when using OAuth realm (@simov, @jhalickman) - [#1668](https://github.com/request/request/pull/1668) updated dependencies (@deamme) - [#1656](https://github.com/request/request/pull/1656) Fix form method (@simov) From f871dfb9b732caa745f74cc799788368dfdd79a3 Mon Sep 17 00:00:00 2001 From: simov Date: Tue, 26 Jan 2016 12:09:30 +0200 Subject: [PATCH 261/490] Improve aws tests --- request.js | 7 +++--- tests/test-aws.js | 55 ++++++++++++++++------------------------------- 2 files changed, 23 insertions(+), 39 deletions(-) diff --git a/request.js b/request.js index 4ef403ff6..8dc900569 100644 --- a/request.js +++ b/request.js @@ -1232,7 +1232,7 @@ Request.prototype.aws = function (opts, now) { } if (opts.sign_version == 4 || opts.sign_version == '4') { - // Use aws-sign4 + // use aws4 var options = { host: self.uri.host, path: self.uri.path, @@ -1248,8 +1248,9 @@ Request.prototype.aws = function (opts, now) { }) self.setHeader('authorization', signRes.headers.Authorization) self.setHeader('x-amz-date', signRes.headers['X-Amz-Date']) - } else { - // Default behaviour -> use aws-sign2 + } + else { + // default: use aws-sign2 var date = new Date() self.setHeader('date', date.toUTCString()) var auth = diff --git a/tests/test-aws.js b/tests/test-aws.js index b3200cbaa..be4314349 100644 --- a/tests/test-aws.js +++ b/tests/test-aws.js @@ -1,11 +1,5 @@ 'use strict' -if (process.env.running_under_istanbul) { - // test-agent.js modifies the process state - // causing these tests to fail when running under single process via tape - return -} - var request = require('../index') , server = require('./server') , tape = require('tape') @@ -28,28 +22,15 @@ tape('setup', function(t) { }) tape('default behaviour: aws-sign2 without sign_version key', function(t) { - var aws2_options = { aws: {} } - aws2_options.aws.key = 'my_key' - aws2_options.aws.secret = 'my_secret' - aws2_options.url = s.url + path - aws2_options.json = true - - request(aws2_options, function(err, res, body) { - t.ok(body.authorization) - t.notOk(body['x-amz-date']) - t.end() - }) -}) - -tape('aws-sign2 with sign_version key', function(t) { - var aws2_options = { aws: {} } - aws2_options.aws.key = 'my_key' - aws2_options.aws.secret = 'my_secret' - aws2_options.aws.sign_version = 2 - aws2_options.url = s.url + path - aws2_options.json = true - - request(aws2_options, function(err, res, body) { + var options = { + url: s.url + path, + aws: { + key: 'my_key', + secret: 'my_secret' + }, + json: true + } + request(options, function(err, res, body) { t.ok(body.authorization) t.notOk(body['x-amz-date']) t.end() @@ -57,14 +38,16 @@ tape('aws-sign2 with sign_version key', function(t) { }) tape('aws-sign4 options', function(t) { - var aws2_options = { aws: {} } - aws2_options.aws.key = 'my_key' - aws2_options.aws.secret = 'my_secret' - aws2_options.aws.sign_version = 4 - aws2_options.url = s.url + path - aws2_options.json = true - - request(aws2_options, function(err, res, body) { + var options = { + url: s.url + path, + aws: { + key: 'my_key', + secret: 'my_secret', + sign_version: 4 + }, + json: true + } + request(options, function(err, res, body) { t.ok(body.authorization) t.ok(body['x-amz-date']) t.end() From cacade52290841e6dd902ee6a71c85eab4d558e8 Mon Sep 17 00:00:00 2001 From: simov Date: Tue, 26 Jan 2016 12:12:35 +0200 Subject: [PATCH 262/490] Use npm to sort the dependencies --- package.json | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index dbb535b10..7aefa7702 100644 --- a/package.json +++ b/package.json @@ -22,27 +22,27 @@ }, "main": "index.js", "dependencies": { + "aws-sign2": "~0.6.0", + "aws4": "^1.2.1", "bl": "~1.0.0", "caseless": "~0.11.0", + "combined-stream": "~1.0.5", "extend": "~3.0.0", "forever-agent": "~0.6.1", "form-data": "~1.0.0-rc3", + "har-validator": "~2.0.6", + "hawk": "~3.1.0", + "http-signature": "~1.1.0", + "is-typedarray": "~1.0.0", + "isstream": "~0.1.2", "json-stringify-safe": "~5.0.1", "mime-types": "~2.1.7", "node-uuid": "~1.4.7", - "qs": "~6.0.2", - "tunnel-agent": "~0.4.1", - "tough-cookie": "~2.2.0", - "http-signature": "~1.1.0", "oauth-sign": "~0.8.0", - "hawk": "~3.1.0", - "aws-sign2": "~0.6.0", + "qs": "~6.0.2", "stringstream": "~0.0.4", - "combined-stream": "~1.0.5", - "isstream": "~0.1.2", - "is-typedarray": "~1.0.0", - "har-validator": "~2.0.6", - "aws4": "^1.2.1" + "tough-cookie": "~2.2.0", + "tunnel-agent": "~0.4.1" }, "scripts": { "test": "npm run lint && npm run test-ci && npm run test-browser", @@ -52,16 +52,17 @@ "lint": "eslint lib/ *.js tests/ && echo Lint passed." }, "devDependencies": { - "browserify-istanbul": "^0.1.5", + "bluebird": "^3.0.2", "browserify": "^13.0.0", + "browserify-istanbul": "^0.1.5", "buffer-equal": "^1.0.0", "codecov.io": "^0.1.6", "coveralls": "^2.11.4", "eslint": "1.10.3", "function-bind": "^1.0.2", "istanbul": "^0.4.0", - "karma-browserify": "^4.4.0", "karma": "^0.13.10", + "karma-browserify": "^4.4.0", "karma-cli": "^0.1.1", "karma-coverage": "^0.5.3", "karma-phantomjs-launcher": "^0.1.4", @@ -69,7 +70,6 @@ "rimraf": "^2.2.8", "server-destroy": "^1.0.1", "tape": "^4.2.0", - "taper": "^0.4.0", - "bluebird": "^3.0.2" + "taper": "^0.4.0" } } From a5101c529f3e795f366d2a8e73bf4f1e1e5aac71 Mon Sep 17 00:00:00 2001 From: simov Date: Wed, 27 Jan 2016 17:36:07 +0200 Subject: [PATCH 263/490] Made aws4 external dependency --- README.md | 2 +- package.json | 2 +- request.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 937836878..6ee45b205 100644 --- a/README.md +++ b/README.md @@ -754,7 +754,7 @@ The first argument can be either a `url` or an `options` object. The only requir - `auth` - A hash containing values `user` || `username`, `pass` || `password`, and `sendImmediately` (optional). See documentation above. - `oauth` - Options for OAuth HMAC-SHA1 signing. See documentation above. - `hawk` - Options for [Hawk signing](https://github.com/hueniverse/hawk). The `credentials` key must contain the necessary signing info, [see hawk docs for details](https://github.com/hueniverse/hawk#usage-example). -- `aws` - `object` containing AWS signing information. Should have the properties `key`, `secret`. Also requires the property `bucket`, unless you’re specifying your `bucket` as part of the path, or the request doesn’t use a bucket (i.e. GET Services). If you want to use AWS sign version 4 use the parameter `sign_version` with value `4` otherwise the default is version 2. +- `aws` - `object` containing AWS signing information. Should have the properties `key`, `secret`. Also requires the property `bucket`, unless you’re specifying your `bucket` as part of the path, or the request doesn’t use a bucket (i.e. GET Services). If you want to use AWS sign version 4 use the parameter `sign_version` with value `4` otherwise the default is version 2. **Note:** you need to `npm install aws4` first. - `httpSignature` - Options for the [HTTP Signature Scheme](https://github.com/joyent/node-http-signature/blob/master/http_signing.md) using [Joyent's library](https://github.com/joyent/node-http-signature). The `keyId` and `key` properties must be specified. See the docs for other options. --- diff --git a/package.json b/package.json index 7aefa7702..aeffc76ed 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,6 @@ "main": "index.js", "dependencies": { "aws-sign2": "~0.6.0", - "aws4": "^1.2.1", "bl": "~1.0.0", "caseless": "~0.11.0", "combined-stream": "~1.0.5", @@ -52,6 +51,7 @@ "lint": "eslint lib/ *.js tests/ && echo Lint passed." }, "devDependencies": { + "aws4": "^1.2.1", "bluebird": "^3.0.2", "browserify": "^13.0.0", "browserify-istanbul": "^0.1.5", diff --git a/request.js b/request.js index 8dc900569..e4a181237 100644 --- a/request.js +++ b/request.js @@ -9,7 +9,6 @@ var http = require('http') , bl = require('bl') , hawk = require('hawk') , aws2 = require('aws-sign2') - , aws4 = require('aws4') , httpSignature = require('http-signature') , mime = require('mime-types') , stringstream = require('stringstream') @@ -1232,6 +1231,7 @@ Request.prototype.aws = function (opts, now) { } if (opts.sign_version == 4 || opts.sign_version == '4') { + var aws4 = require('aws4') // use aws4 var options = { host: self.uri.host, From 7e1fb0e557017666b85d28f3a40ce2718d4234f0 Mon Sep 17 00:00:00 2001 From: simov Date: Wed, 27 Jan 2016 18:18:17 +0200 Subject: [PATCH 264/490] 2.68.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index aeffc76ed..c8274d74c 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.67.1", + "version": "2.68.0", "author": "Mikeal Rogers ", "repository": { "type": "git", From ce6c69faee2dd2a3d2d23f3d20532ff025da3a42 Mon Sep 17 00:00:00 2001 From: simov Date: Wed, 27 Jan 2016 18:20:13 +0200 Subject: [PATCH 265/490] Update changelog --- CHANGELOG.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7dc85ea14..86386a9ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,20 @@ ## Change Log +### v2.68.0 (2016/01/27) +- [#2036](https://github.com/request/request/pull/2036) Add AWS Signature Version 4 (@simov, @mirkods) +- [#2022](https://github.com/request/request/pull/2022) Convert numeric multipart bodies to string (@simov, @feross) +- [#2024](https://github.com/request/request/pull/2024) Update har-validator dependency for nsp advisory #76 (@TylerDixon) +- [#2016](https://github.com/request/request/pull/2016) Update qs to version 6.0.2 🚀 (@greenkeeperio-bot) +- [#2007](https://github.com/request/request/pull/2007) Use the `extend` module instead of util._extend (@simov) +- [#2003](https://github.com/request/request/pull/2003) Update browserify to version 13.0.0 🚀 (@greenkeeperio-bot) +- [#1989](https://github.com/request/request/pull/1989) Update buffer-equal to version 1.0.0 🚀 (@greenkeeperio-bot) +- [#1956](https://github.com/request/request/pull/1956) Check form-data content-length value before setting up the header (@jongyoonlee) +- [#1958](https://github.com/request/request/pull/1958) Use IncomingMessage.destroy method (@simov) +- [#1952](https://github.com/request/request/pull/1952) Adds example for Tor proxy (@prometheansacrifice) +- [#1943](https://github.com/request/request/pull/1943) Update eslint to version 1.10.3 🚀 (@simov, @greenkeeperio-bot) +- [#1924](https://github.com/request/request/pull/1924) Update eslint to version 1.10.1 🚀 (@greenkeeperio-bot) +- [#1915](https://github.com/request/request/pull/1915) Remove content-length and transfer-encoding headers from defaultProxyHeaderWhiteList (@yaxia) + ### v2.67.0 (2015/11/19) - [#1913](https://github.com/request/request/pull/1913) Update http-signature to version 1.1.0 🚀 (@greenkeeperio-bot) @@ -455,7 +470,7 @@ - [#521](https://github.com/request/request/pull/521) Improving test-localAddress.js (@noway421) - [#529](https://github.com/request/request/pull/529) dependencies versions bump (@jodaka) -### v2.17.0 (2013/04/22) +### v2.18.0 (2013/04/22) - [#523](https://github.com/request/request/pull/523) Updating dependencies (@noway421) - [#520](https://github.com/request/request/pull/520) Fixing test-tunnel.js (@noway421) - [#519](https://github.com/request/request/pull/519) Update internal path state on post-creation QS changes (@jblebrun) From 89613204cb6da83373713f4940b22b3a8e3c7dca Mon Sep 17 00:00:00 2001 From: simov Date: Wed, 27 Jan 2016 18:20:33 +0200 Subject: [PATCH 266/490] 2.68.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c8274d74c..adad8203e 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.68.0", + "version": "2.68.1", "author": "Mikeal Rogers ", "repository": { "type": "git", From 08f9b9850934924d3aa5740d2ce1519c0edaa854 Mon Sep 17 00:00:00 2001 From: Ryan Graham Date: Wed, 27 Jan 2016 10:29:29 -0800 Subject: [PATCH 267/490] add aws4 as regular dependency It was moved in #2036 as a devDependency, but is still used in request.js This should fix #2040. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index adad8203e..79e5d5d31 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "main": "index.js", "dependencies": { "aws-sign2": "~0.6.0", + "aws4": "^1.2.1", "bl": "~1.0.0", "caseless": "~0.11.0", "combined-stream": "~1.0.5", @@ -51,7 +52,6 @@ "lint": "eslint lib/ *.js tests/ && echo Lint passed." }, "devDependencies": { - "aws4": "^1.2.1", "bluebird": "^3.0.2", "browserify": "^13.0.0", "browserify-istanbul": "^0.1.5", From 605872aed01079e0645bdd5c69d652131e2d8fcf Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Wed, 3 Feb 2016 22:04:52 -0800 Subject: [PATCH 268/490] chore(package): update qs to version 6.1.0 http://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 79e5d5d31..527f53efb 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "mime-types": "~2.1.7", "node-uuid": "~1.4.7", "oauth-sign": "~0.8.0", - "qs": "~6.0.2", + "qs": "~6.1.0", "stringstream": "~0.0.4", "tough-cookie": "~2.2.0", "tunnel-agent": "~0.4.1" From f672dc503911214257fe48b297949f099ebe44b8 Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 4 Feb 2016 08:44:14 +0200 Subject: [PATCH 269/490] 2.69.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 79e5d5d31..f12b0151f 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.68.1", + "version": "2.69.0", "author": "Mikeal Rogers ", "repository": { "type": "git", From 601a0ce5245bf3e190ec58eed0079a874282692e Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 4 Feb 2016 08:46:13 +0200 Subject: [PATCH 270/490] Update changelog --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 86386a9ae..910eada07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## Change Log +### v2.69.0 (2016/01/27) +- [#2041](https://github.com/request/request/pull/2041) restore aws4 as regular dependency (@rmg) + ### v2.68.0 (2016/01/27) - [#2036](https://github.com/request/request/pull/2036) Add AWS Signature Version 4 (@simov, @mirkods) - [#2022](https://github.com/request/request/pull/2022) Convert numeric multipart bodies to string (@simov, @feross) @@ -470,7 +473,7 @@ - [#521](https://github.com/request/request/pull/521) Improving test-localAddress.js (@noway421) - [#529](https://github.com/request/request/pull/529) dependencies versions bump (@jodaka) -### v2.18.0 (2013/04/22) +### v2.20.0 (2013/04/22) - [#523](https://github.com/request/request/pull/523) Updating dependencies (@noway421) - [#520](https://github.com/request/request/pull/520) Fixing test-tunnel.js (@noway421) - [#519](https://github.com/request/request/pull/519) Update internal path state on post-creation QS changes (@jblebrun) From b2fa11f89d11a7444e9d24208dc0b308b67a8add Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 4 Feb 2016 08:46:19 +0200 Subject: [PATCH 271/490] 2.69.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f12b0151f..d386169ae 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.69.0", + "version": "2.69.1", "author": "Mikeal Rogers ", "repository": { "type": "git", From e5bbcaf767902544e491e1918379f264e0bc6884 Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 4 Feb 2016 10:32:42 +0200 Subject: [PATCH 272/490] Update contributing guidelines --- CONTRIBUTING.md | 45 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 06b1968d9..8aa6999ac 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,19 +1,57 @@ -# This is an OPEN Open Source Project + +# Contributing to Request + +:+1::tada: First off, thanks for taking the time to contribute! :tada::+1: + +The following is a set of guidelines for contributing to Request and its packages, which are hosted in the [Request Organization](https://github.com/request) on GitHub. +These are just guidelines, not rules, use your best judgment and feel free to propose changes to this document in a pull request. + + +## Submitting an Issue + +1. Provide a small self **sufficient** code example to **reproduce** the issue. +2. Run your test code using [request-debug](https://github.com/request/request-debug) and copy/paste the results inside the issue. +3. You should **always** use fenced code blocks when submitting code examples or any other formatted output: +
+  ```js
+  put your javascript code here
+  ```
+
+  ```
+  put any other formatted output here,
+  like for example the one returned from using request-debug
+  ```
+  
+ +If the problem cannot be reliably reproduced, the issue will be marked as `Not enough info (see CONTRIBUTING.md)`. + +If the problem is not related to request the issue will be marked as `Help (please use Stackoverflow)`. + + +## Submitting a Pull Request + +1. In almost all of the cases your PR **needs tests**. Make sure you have any. +2. Run `npm test` locally. Fix any errors before pushing to GitHub. +3. After submitting the PR a build will be triggered on TravisCI. Wait for it to ends and make sure all jobs are passing. + ----------------------------------------- -## What? + +## Becoming a Contributor Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project. + ## Rules There are a few basic ground-rules for contributors: 1. **No `--force` pushes** or modifying the Git history in any way. 1. **Non-master branches** ought to be used for ongoing work. +1. **Any** change should be added through Pull Request. 1. **External API changes and significant modifications** ought to be subject to an **internal pull-request** to solicit feedback from other contributors. 1. Internal pull-requests to solicit feedback are *encouraged* for any other @@ -35,10 +73,9 @@ There are a few basic ground-rules for contributors: Declaring formal releases remains the prerogative of the project maintainer. + ## Changes to this arrangement This is an experiment and feedback is welcome! This document may also be subject to pull-requests or changes by contributors where you believe you have something valuable to add or change. - ------------------------------------------ From 3e63b907d9f1cab9ac51ca673b6922c1dc24503c Mon Sep 17 00:00:00 2001 From: "Eirik S. Morland" Date: Fri, 5 Feb 2016 07:47:17 +0100 Subject: [PATCH 273/490] Upgrade karma-phantomjs-launcher and karma-browserify. Fix browser tests. Fixes #2035. Fixes #2044. Closes #2056 --- package.json | 7 ++++--- tests/browser/test.js | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 6bc4d6eb2..f66349993 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ }, "devDependencies": { "bluebird": "^3.0.2", - "browserify": "^13.0.0", + "browserify": "^12.0.2", "browserify-istanbul": "^0.1.5", "buffer-equal": "^1.0.0", "codecov.io": "^0.1.6", @@ -62,11 +62,12 @@ "function-bind": "^1.0.2", "istanbul": "^0.4.0", "karma": "^0.13.10", - "karma-browserify": "^4.4.0", + "karma-browserify": "^5.0.1", "karma-cli": "^0.1.1", "karma-coverage": "^0.5.3", - "karma-phantomjs-launcher": "^0.1.4", + "karma-phantomjs-launcher": "^1.0.0", "karma-tap": "^1.0.3", + "phantomjs-prebuilt": "^2.1.3", "rimraf": "^2.2.8", "server-destroy": "^1.0.1", "tape": "^4.2.0", diff --git a/tests/browser/test.js b/tests/browser/test.js index 6717ba709..2310195a1 100644 --- a/tests/browser/test.js +++ b/tests/browser/test.js @@ -18,7 +18,7 @@ tape('returns on error', function(t) { uri: 'https://stupid.nonexistent.path:port123/\\<-great-idea', withCredentials: false }, function (error, response) { - t.equal(response.statusCode, 0) + t.equal(typeof error, 'object') t.end() }) }) From 2a1d99c6cbc427d03094369e1602a39612c46bd2 Mon Sep 17 00:00:00 2001 From: simov Date: Fri, 5 Feb 2016 09:11:52 +0200 Subject: [PATCH 274/490] Up bluebird and oauth-sign --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index f66349993..35b3a698f 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "json-stringify-safe": "~5.0.1", "mime-types": "~2.1.7", "node-uuid": "~1.4.7", - "oauth-sign": "~0.8.0", + "oauth-sign": "~0.8.1", "qs": "~6.1.0", "stringstream": "~0.0.4", "tough-cookie": "~2.2.0", @@ -52,7 +52,7 @@ "lint": "eslint lib/ *.js tests/ && echo Lint passed." }, "devDependencies": { - "bluebird": "^3.0.2", + "bluebird": "^3.2.1", "browserify": "^12.0.2", "browserify-istanbul": "^0.1.5", "buffer-equal": "^1.0.0", From af80027d663f01555c1e97504b751701d2f5eaad Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Thu, 11 Feb 2016 19:15:30 -0800 Subject: [PATCH 275/490] chore(package): update bl to version 1.1.2 http://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 35b3a698f..a2d3f794d 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "dependencies": { "aws-sign2": "~0.6.0", "aws4": "^1.2.1", - "bl": "~1.0.0", + "bl": "~1.1.2", "caseless": "~0.11.0", "combined-stream": "~1.0.5", "extend": "~3.0.0", From 9dfecb9cf546b7b48aaa1f291e6026b380a578ed Mon Sep 17 00:00:00 2001 From: simov Date: Mon, 15 Feb 2016 20:43:22 +0200 Subject: [PATCH 276/490] Accept read stream as body option --- README.md | 2 +- request.js | 21 +++++++++++++-------- tests/test-stream.js | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 9 deletions(-) create mode 100644 tests/test-stream.js diff --git a/README.md b/README.md index 6ee45b205..1e346779d 100644 --- a/README.md +++ b/README.md @@ -733,7 +733,7 @@ The first argument can be either a `url` or an `options` object. The only requir --- -- `body` - entity body for PATCH, POST and PUT requests. Must be a `Buffer` or `String`, unless `json` is `true`. If `json` is `true`, then `body` must be a JSON-serializable object. +- `body` - entity body for PATCH, POST and PUT requests. Must be a `Buffer`, `String` or `ReadStream`. If `json` is `true`, then `body` must be a JSON-serializable object. - `form` - when passed an object or a querystring, this sets `body` to a querystring representation of value, and adds `Content-type: application/x-www-form-urlencoded` header. When passed no options, a `FormData` instance is returned (and is piped to request). See "Forms" section above. - `formData` - Data to pass for a `multipart/form-data` request. See [Forms](#forms) section above. diff --git a/request.js b/request.js index e4a181237..cb3862b0e 100644 --- a/request.js +++ b/request.js @@ -16,6 +16,7 @@ var http = require('http') , ForeverAgent = require('forever-agent') , FormData = require('form-data') , extend = require('extend') + , isstream = require('isstream') , isTypedArray = require('is-typedarray').strict , helpers = require('./lib/helpers') , cookies = require('./lib/cookies') @@ -452,7 +453,7 @@ Request.prototype.init = function (options) { } } } - if (self.body) { + if (self.body && !isstream(self.body)) { setContentLength() } @@ -552,15 +553,19 @@ Request.prototype.init = function (options) { self._multipart.body.pipe(self) } if (self.body) { - setContentLength() - if (Array.isArray(self.body)) { - self.body.forEach(function (part) { - self.write(part) - }) + if (isstream(self.body)) { + self.body.pipe(self) } else { - self.write(self.body) + setContentLength() + if (Array.isArray(self.body)) { + self.body.forEach(function (part) { + self.write(part) + }) + } else { + self.write(self.body) + } + self.end() } - self.end() } else if (self.requestBodyStream) { console.warn('options.requestBodyStream is deprecated, please pass the request object to stream.pipe.') self.requestBodyStream.pipe(self) diff --git a/tests/test-stream.js b/tests/test-stream.js new file mode 100644 index 000000000..b1fbfad0f --- /dev/null +++ b/tests/test-stream.js @@ -0,0 +1,34 @@ + +var fs = require('fs') +var path = require('path') +var http = require('http') +var tape = require('tape') +var request = require('../') +var server + + +tape('before', function (t) { + server = http.createServer() + server.on('request', function (req, res) { + req.pipe(res) + }) + server.listen(6767, t.end) +}) + +tape('request body stream', function (t) { + var fpath = path.join(__dirname, 'unicycle.jpg') + var input = fs.createReadStream(fpath, {highWaterMark: 1000}) + request({ + uri: 'http://localhost:6767', + method: 'POST', + body: input, + encoding: null + }, function (err, res, body) { + t.equal(body.length, fs.statSync(fpath).size) + t.end() + }) +}) + +tape('after', function (t) { + server.close(t.end) +}) From ebb2c3b63113d9e7225aacf6a636242c44eae385 Mon Sep 17 00:00:00 2001 From: simov Date: Mon, 22 Feb 2016 14:21:49 +0200 Subject: [PATCH 277/490] Bump hawk --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a2d3f794d..4b273675a 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "forever-agent": "~0.6.1", "form-data": "~1.0.0-rc3", "har-validator": "~2.0.6", - "hawk": "~3.1.0", + "hawk": "~3.1.3", "http-signature": "~1.1.0", "is-typedarray": "~1.0.0", "isstream": "~0.1.2", From 658ff1956fb492a8655a34b36b52b0811ad3bfd5 Mon Sep 17 00:00:00 2001 From: simov Date: Mon, 22 Feb 2016 14:22:19 +0200 Subject: [PATCH 278/490] Add snyk.io badge --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 1e346779d..8de982ad6 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ [![Coverage](https://img.shields.io/codecov/c/github/request/request.svg?style=flat-square)](https://codecov.io/github/request/request?branch=master) [![Coverage](https://img.shields.io/coveralls/request/request.svg?style=flat-square)](https://coveralls.io/r/request/request) [![Dependency Status](https://img.shields.io/david/request/request.svg?style=flat-square)](https://david-dm.org/request/request) +[![Known Vulnerabilities](https://snyk.io/test/npm/request/badge.svg?style=flat-square)](https://snyk.io/test/npm/request) [![Gitter](https://img.shields.io/badge/gitter-join_chat-blue.svg?style=flat-square)](https://gitter.im/request/request?utm_source=badge) From 69bdeee66c67590ffb21f4f81d0debd96afc14e9 Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Tue, 23 Feb 2016 14:45:15 -0800 Subject: [PATCH 279/490] chore(package): update browserify-istanbul to version 1.0.0 http://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a2d3f794d..20669c0ab 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "devDependencies": { "bluebird": "^3.2.1", "browserify": "^12.0.2", - "browserify-istanbul": "^0.1.5", + "browserify-istanbul": "^1.0.0", "buffer-equal": "^1.0.0", "codecov.io": "^0.1.6", "coveralls": "^2.11.4", From 679379596b55051135af49ae7f22aa7ad022ad91 Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Fri, 4 Mar 2016 16:43:09 -0800 Subject: [PATCH 280/490] chore(package): update eslint to version 2.3.0 http://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 14738b826..26109e344 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "buffer-equal": "^1.0.0", "codecov.io": "^0.1.6", "coveralls": "^2.11.4", - "eslint": "1.10.3", + "eslint": "2.3.0", "function-bind": "^1.0.2", "istanbul": "^0.4.0", "karma": "^0.13.10", From 622d61ef381735a9162bebdbccedde71869a173b Mon Sep 17 00:00:00 2001 From: simov Date: Sun, 6 Mar 2016 11:41:27 +0200 Subject: [PATCH 281/490] Update eslint rule --- .eslintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc b/.eslintrc index 6ebc53601..5a5948158 100644 --- a/.eslintrc +++ b/.eslintrc @@ -37,7 +37,7 @@ "no-shadow": 0, // Use if () { } // ^ space - "space-after-keywords": [2, "always"], + "keyword-spacing": [2, {"after": true}], // Use if () { } // ^ space "space-before-blocks": [2, "always"] From 2e4235827d43ccea4602e5953a0993b399fa7eb6 Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Tue, 15 Mar 2016 02:17:59 -0700 Subject: [PATCH 282/490] chore(package): update browserify-istanbul to version 2.0.0 http://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 26109e344..75716c8d1 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "devDependencies": { "bluebird": "^3.2.1", "browserify": "^12.0.2", - "browserify-istanbul": "^1.0.0", + "browserify-istanbul": "^2.0.0", "buffer-equal": "^1.0.0", "codecov.io": "^0.1.6", "coveralls": "^2.11.4", From c163360217597867c2fdacd16e602a55e25a19f1 Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Fri, 25 Mar 2016 15:37:13 -0700 Subject: [PATCH 283/490] chore(package): update eslint to version 2.5.1 http://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 75716c8d1..2d9b7d5cc 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "buffer-equal": "^1.0.0", "codecov.io": "^0.1.6", "coveralls": "^2.11.4", - "eslint": "2.3.0", + "eslint": "2.5.1", "function-bind": "^1.0.2", "istanbul": "^0.4.0", "karma": "^0.13.10", From 397c76bd2fc916b1943a384bed5bfd16de9fe8cf Mon Sep 17 00:00:00 2001 From: Liam O'Boyle Date: Thu, 14 Jan 2016 08:37:58 +1100 Subject: [PATCH 284/490] Support JSON stringify replacer argument. Adds support for the replacer argument of JSON.stringify, in the same way that request already supports the revivier argument for JSON.parse. Change jsonReplacer arg to jsonStringifier. Revert "Change jsonReplacer arg to jsonStringifier." This reverts commit 40c03af35ede54c29ac7cd72aa3a2b50c42a59ff. --- README.md | 1 + lib/helpers.js | 6 +++--- request.js | 8 ++++++-- tests/test-json-request.js | 29 +++++++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 8de982ad6..64c43e742 100644 --- a/README.md +++ b/README.md @@ -749,6 +749,7 @@ The first argument can be either a `url` or an `options` object. The only requir - `postambleCRLF` - append a newline/CRLF at the end of the boundary of your `multipart/form-data` request. - `json` - sets `body` to JSON representation of value and adds `Content-type: application/json` header. Additionally, parses the response body as JSON. - `jsonReviver` - a [reviver function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse) that will be passed to `JSON.parse()` when parsing a JSON response body. +- `jsonReplacer` - a [replacer function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) that will be passed to `JSON.stringify()` when stringifying a JSON request body. --- diff --git a/lib/helpers.js b/lib/helpers.js index 5e8594606..356ff748e 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -24,12 +24,12 @@ function paramsHaveRequestBody(params) { ) } -function safeStringify (obj) { +function safeStringify (obj, replacer) { var ret try { - ret = JSON.stringify(obj) + ret = JSON.stringify(obj, replacer) } catch (e) { - ret = jsonSafeStringify(obj) + ret = jsonSafeStringify(obj, replacer) } return ret } diff --git a/request.js b/request.js index cb3862b0e..6310e0a6b 100644 --- a/request.js +++ b/request.js @@ -1162,11 +1162,15 @@ Request.prototype.json = function (val) { self.setHeader('accept', 'application/json') } + if (typeof self.jsonReplacer === 'function') { + self._jsonReplacer = self.jsonReplacer + } + self._json = true if (typeof val === 'boolean') { if (self.body !== undefined) { if (!/^application\/x-www-form-urlencoded\b/.test(self.getHeader('content-type'))) { - self.body = safeStringify(self.body) + self.body = safeStringify(self.body, self._jsonReplacer) } else { self.body = self._qs.rfc3986(self.body) } @@ -1175,7 +1179,7 @@ Request.prototype.json = function (val) { } } } else { - self.body = safeStringify(val) + self.body = safeStringify(val, self._jsonReplacer) if (!self.hasHeader('content-type')) { self.setHeader('content-type', 'application/json') } diff --git a/tests/test-json-request.js b/tests/test-json-request.js index e7f39556e..aa117e216 100644 --- a/tests/test-json-request.js +++ b/tests/test-json-request.js @@ -51,6 +51,26 @@ function testJSONValueReviver(testId, value, reviver, revivedValue) { }) } +function testJSONValueReplacer(testId, value, replacer, replacedValue) { + tape('test ' + testId, function(t) { + var testUrl = '/' + testId + s.on(testUrl, server.createPostJSONValidator(replacedValue, 'application/json')) + var opts = { + method: 'PUT', + uri: s.url + testUrl, + json: true, + jsonReplacer: replacer, + body: value + } + request(opts, function (err, resp, body) { + t.equal(err, null) + t.equal(resp.statusCode, 200) + t.deepEqual(body, replacedValue) + t.end() + }) + }) +} + testJSONValue('jsonNull', null) testJSONValue('jsonTrue', true) testJSONValue('jsonFalse', false) @@ -72,6 +92,15 @@ testJSONValueReviver('jsonReviver', -48269.592, function (k, v) { }, 48269.592) testJSONValueReviver('jsonReviverInvalid', -48269.592, 'invalid reviver', -48269.592) +testJSONValueReplacer('jsonReplacer', -48269.592, function (k, v) { + return v * -1 +}, 48269.592) +testJSONValueReplacer('jsonReplacerInvalid', -48269.592,'invalid replacer', -48269.592) +testJSONValueReplacer('jsonReplacerObject', {foo: 'bar'}, function (k, v) { + return v.toUpperCase ? v.toUpperCase() : v +}, {foo: 'BAR'}) + + tape('missing body', function (t) { s.on('/missing-body', function (req, res) { t.equal(req.headers['content-type'], undefined) From 77b4783b8c0b22e8c60dc7abef74a101e8beedb8 Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Mon, 28 Mar 2016 11:07:02 -0700 Subject: [PATCH 285/490] chore(package): update eslint to version 2.5.3 http://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2d9b7d5cc..0599114dd 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "buffer-equal": "^1.0.0", "codecov.io": "^0.1.6", "coveralls": "^2.11.4", - "eslint": "2.5.1", + "eslint": "2.5.3", "function-bind": "^1.0.2", "istanbul": "^0.4.0", "karma": "^0.13.10", From 293704a692619dc8bf6b1d3a7585a3a048e1b0a3 Mon Sep 17 00:00:00 2001 From: simov Date: Tue, 29 Mar 2016 10:00:17 +0300 Subject: [PATCH 286/490] Set back the caret range for eslint --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0599114dd..f05464423 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "buffer-equal": "^1.0.0", "codecov.io": "^0.1.6", "coveralls": "^2.11.4", - "eslint": "2.5.3", + "eslint": "^2.5.3", "function-bind": "^1.0.2", "istanbul": "^0.4.0", "karma": "^0.13.10", From 625ba5c2bdcb28d62f12faf4666bd411aa0238da Mon Sep 17 00:00:00 2001 From: simov Date: Tue, 5 Apr 2016 10:08:13 +0300 Subject: [PATCH 287/490] 2.70.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f05464423..8167f1165 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.69.1", + "version": "2.70.0", "author": "Mikeal Rogers ", "repository": { "type": "git", From bc781cb49aafedb057719e8b1eb7850979688a85 Mon Sep 17 00:00:00 2001 From: simov Date: Tue, 5 Apr 2016 13:06:05 +0300 Subject: [PATCH 288/490] Update changelog --- CHANGELOG.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 910eada07..34f8e7325 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,20 @@ ## Change Log +### v2.70.0 (2016/04/05) +- [#2147](https://github.com/request/request/pull/2147) Update eslint to version 2.5.3 🚀 (@simov, @greenkeeperio-bot) +- [#2009](https://github.com/request/request/pull/2009) Support JSON stringify replacer argument. (@elyobo) +- [#2142](https://github.com/request/request/pull/2142) Update eslint to version 2.5.1 🚀 (@greenkeeperio-bot) +- [#2128](https://github.com/request/request/pull/2128) Update browserify-istanbul to version 2.0.0 🚀 (@greenkeeperio-bot) +- [#2115](https://github.com/request/request/pull/2115) Update eslint to version 2.3.0 🚀 (@simov, @greenkeeperio-bot) +- [#2089](https://github.com/request/request/pull/2089) Fix badges (@simov) +- [#2092](https://github.com/request/request/pull/2092) Update browserify-istanbul to version 1.0.0 🚀 (@greenkeeperio-bot) +- [#2079](https://github.com/request/request/pull/2079) Accept read stream as body option (@simov) +- [#2070](https://github.com/request/request/pull/2070) Update bl to version 1.1.2 🚀 (@greenkeeperio-bot) +- [#2063](https://github.com/request/request/pull/2063) Up bluebird and oauth-sign (@simov) +- [#2058](https://github.com/request/request/pull/2058) Karma fixes for latest versions (@eiriksm) +- [#2057](https://github.com/request/request/pull/2057) Update contributing guidelines (@simov) +- [#2054](https://github.com/request/request/pull/2054) Update qs to version 6.1.0 🚀 (@greenkeeperio-bot) + ### v2.69.0 (2016/01/27) - [#2041](https://github.com/request/request/pull/2041) restore aws4 as regular dependency (@rmg) @@ -88,7 +103,8 @@ - [#1687](https://github.com/request/request/pull/1687) Fix caseless bug - content-type not being set for multipart/form-data (@simov, @garymathews) ### v2.59.0 (2015/07/20) -- [#1671](https://github.com/request/request/pull/1671) Add tests and docs for using the agent, agentClass, agentOptions and forever options. Forever option defaults to using http(s).Agent in node 0.12+ (@simov) +- [#1671](https://github.com/request/request/pull/1671) Add tests and docs for using the agent, agentClass, agentOptions and forever options. + Forever option defaults to using http(s).Agent in node 0.12+ (@simov) - [#1679](https://github.com/request/request/pull/1679) Fix - do not remove OAuth param when using OAuth realm (@simov, @jhalickman) - [#1668](https://github.com/request/request/pull/1668) updated dependencies (@deamme) - [#1656](https://github.com/request/request/pull/1656) Fix form method (@simov) From c2224588455b2e9a50199584711dce24f24dc2d2 Mon Sep 17 00:00:00 2001 From: simov Date: Tue, 5 Apr 2016 13:07:36 +0300 Subject: [PATCH 289/490] 2.70.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8167f1165..ebbad58e4 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.70.0", + "version": "2.70.1", "author": "Mikeal Rogers ", "repository": { "type": "git", From 1f0a4577ade88fca1b5630e4f303b8d8c1febd7f Mon Sep 17 00:00:00 2001 From: simov Date: Mon, 11 Apr 2016 15:48:09 +0300 Subject: [PATCH 290/490] Catch errors from the underlying http module --- request.js | 11 +++++++++-- tests/test-headers.js | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/request.js b/request.js index 6310e0a6b..809611d55 100644 --- a/request.js +++ b/request.js @@ -749,7 +749,12 @@ Request.prototype.start = function () { debug('make request', self.uri.href) - self.req = self.httpModule.request(reqOptions) + try { + self.req = self.httpModule.request(reqOptions) + } catch (err) { + self.emit('error', err) + return + } if (self.timing) { self.startTime = new Date().getTime() @@ -1389,7 +1394,9 @@ Request.prototype.end = function (chunk) { if (!self._started) { self.start() } - self.req.end() + if (self.req) { + self.req.end() + } } Request.prototype.pause = function () { var self = this diff --git a/tests/test-headers.js b/tests/test-headers.js index 6ec9dba04..dbd3c4d57 100644 --- a/tests/test-headers.js +++ b/tests/test-headers.js @@ -162,6 +162,21 @@ tape('undefined headers', function(t) { }) }) +tape('catch invalid characters error', function(t) { + request({ + url: s.url + '/headers.json', + headers: { + 'test': 'אבגד' + } + }, function(err, res, body) { + t.equal(err.message, 'The header content contains invalid characters') + }) + .on('error', function (err) { + t.equal(err.message, 'The header content contains invalid characters') + t.end() + }) +}) + tape('cleanup', function(t) { s.close(function() { t.end() From 9aad1597f88a57e8e72af2475778858c2726fa95 Mon Sep 17 00:00:00 2001 From: simov Date: Mon, 11 Apr 2016 16:11:59 +0300 Subject: [PATCH 291/490] Update .travis.yml + drop io.js build target --- .travis.yml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index c24c59b5d..e5d9bde26 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,19 @@ language: node_js + node_js: - node - - io.js - 0.12 - 0.10 -sudo: false -after_script: "npm run test-cov && cat ./coverage/lcov.info | codecov && cat ./coverage/lcov.info | coveralls" +after_script: + - npm run test-cov + - cat ./coverage/lcov.info | codecov + - cat ./coverage/lcov.info | coveralls webhooks: urls: https://webhooks.gitter.im/e/237280ed4796c19cc626 on_success: change # options: [always|never|change] default: always on_failure: always # options: [always|never|change] default: always on_start: false # default: false + +sudo: false From 2b3a8f64161b7802bea409ab569dae8fcb78337f Mon Sep 17 00:00:00 2001 From: simov Date: Tue, 12 Apr 2016 16:04:02 +0300 Subject: [PATCH 292/490] 2.71.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ebbad58e4..395b06b51 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.70.1", + "version": "2.71.0", "author": "Mikeal Rogers ", "repository": { "type": "git", From 25b3ea86c330eb68a68ffe332c4002107a3d6272 Mon Sep 17 00:00:00 2001 From: simov Date: Tue, 12 Apr 2016 16:08:24 +0300 Subject: [PATCH 293/490] Update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 34f8e7325..ac9a0bcd6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## Change Log +### v2.71.0 (2016/04/12) +- [#2164](https://github.com/request/request/pull/2164) Catch errors from the underlying http module (@simov) + ### v2.70.0 (2016/04/05) - [#2147](https://github.com/request/request/pull/2147) Update eslint to version 2.5.3 🚀 (@simov, @greenkeeperio-bot) - [#2009](https://github.com/request/request/pull/2009) Support JSON stringify replacer argument. (@elyobo) From 5777c2ea6ca5b0499682a8d1e6c865b34bb7b1cd Mon Sep 17 00:00:00 2001 From: simov Date: Tue, 12 Apr 2016 16:09:41 +0300 Subject: [PATCH 294/490] 2.71.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 395b06b51..27749df22 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.71.0", + "version": "2.71.1", "author": "Mikeal Rogers ", "repository": { "type": "git", From 1460d0023ac312408d0915fbc65ac9da8a69daf4 Mon Sep 17 00:00:00 2001 From: simov Date: Tue, 12 Apr 2016 19:19:32 +0300 Subject: [PATCH 295/490] Check for self.req existence inside the write method --- request.js | 4 +++- tests/test-headers.js | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/request.js b/request.js index 809611d55..30031605a 100644 --- a/request.js +++ b/request.js @@ -1382,7 +1382,9 @@ Request.prototype.write = function () { if (!self._started) { self.start() } - return self.req.write.apply(self.req, arguments) + if (self.req) { + return self.req.write.apply(self.req, arguments) + } } Request.prototype.end = function (chunk) { var self = this diff --git a/tests/test-headers.js b/tests/test-headers.js index dbd3c4d57..ee893b919 100644 --- a/tests/test-headers.js +++ b/tests/test-headers.js @@ -162,7 +162,7 @@ tape('undefined headers', function(t) { }) }) -tape('catch invalid characters error', function(t) { +tape('catch invalid characters error - GET', function(t) { request({ url: s.url + '/headers.json', headers: { @@ -177,6 +177,23 @@ tape('catch invalid characters error', function(t) { }) }) +tape('catch invalid characters error - POST', function(t) { + request({ + method: 'POST', + url: s.url + '/headers.json', + headers: { + 'test': 'אבגד' + }, + body: 'beep' + }, function(err, res, body) { + t.equal(err.message, 'The header content contains invalid characters') + }) + .on('error', function (err) { + t.equal(err.message, 'The header content contains invalid characters') + t.end() + }) +}) + tape('cleanup', function(t) { s.close(function() { t.end() From 06723fdf204e41d685e1abbe0096f768390a0e14 Mon Sep 17 00:00:00 2001 From: Muhan Zou Date: Tue, 12 Apr 2016 17:11:59 -0400 Subject: [PATCH 296/490] add 'delete' alias for 'del', reduce ternary checking in the meantime --- README.md | 8 ++++++++ index.js | 8 ++++---- tests/test-defaults.js | 11 +++++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 64c43e742..cdffb5ce7 100644 --- a/README.md +++ b/README.md @@ -888,6 +888,14 @@ Same as `request()`, but defaults to `method: "HEAD"`. request.head(url) ``` +### request.delete + +Same as `request()`, but defaults to `method: "DELETE"`. + +```js +request.delete(url) +``` + ### request.del Same as `request()`, but defaults to `method: "DELETE"`. diff --git a/index.js b/index.js index 4d0c748da..f2d710cea 100755 --- a/index.js +++ b/index.js @@ -56,7 +56,7 @@ function request (uri, options, callback) { } function verbFunc (verb) { - var method = verb === 'del' ? 'DELETE' : verb.toUpperCase() + var method = verb.toUpperCase() return function (uri, options, callback) { var params = initParams(uri, options, callback) params.method = method @@ -70,7 +70,7 @@ request.head = verbFunc('head') request.post = verbFunc('post') request.put = verbFunc('put') request.patch = verbFunc('patch') -request.del = verbFunc('del') +request.del = request.delete = verbFunc('delete') request.jar = function (store) { return cookies.jar(store) @@ -91,7 +91,7 @@ function wrapRequestMethod (method, options, requester, verb) { target.pool = params.pool || options.pool if (verb) { - target.method = (verb === 'del' ? 'DELETE' : verb.toUpperCase()) + target.method = verb.toUpperCase() } if (isFunction(requester)) { @@ -114,7 +114,7 @@ request.defaults = function (options, requester) { var defaults = wrapRequestMethod(self, options, requester) - var verbs = ['get', 'head', 'post', 'put', 'patch', 'del'] + var verbs = ['get', 'head', 'post', 'put', 'patch', 'del', 'delete'] verbs.forEach(function(verb) { defaults[verb] = wrapRequestMethod(self[verb], options, requester, verb) }) diff --git a/tests/test-defaults.js b/tests/test-defaults.js index 5b58304cf..afe845e16 100644 --- a/tests/test-defaults.js +++ b/tests/test-defaults.js @@ -138,6 +138,17 @@ tape('del(string, function)', function(t) { }) }) +tape('delete(string, function)', function(t) { + request.defaults({ + headers: {foo: 'bar'}, + json: true + }).delete(s.url + '/', function (e, r, b) { + t.equal(b.method, 'DELETE') + t.equal(b.headers.foo, 'bar') + t.end() + }) +}) + tape('head(object, function)', function(t) { request.defaults({ headers: { foo: 'bar' } From 22a4c8c3e26c71e43dfbd14b35a047254d11e988 Mon Sep 17 00:00:00 2001 From: Alejandro Oviedo Date: Wed, 13 Apr 2016 08:39:21 -0300 Subject: [PATCH 297/490] make travisci badge reference master branch --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 64c43e742..58a9f8fde 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![npm package](https://nodei.co/npm/request.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/request/) -[![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) [![Coverage](https://img.shields.io/coveralls/request/request.svg?style=flat-square)](https://coveralls.io/r/request/request) [![Dependency Status](https://img.shields.io/david/request/request.svg?style=flat-square)](https://david-dm.org/request/request) From 6c32bf4f0591f33e255870fec6af89067b92f841 Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 14 Apr 2016 10:51:24 +0300 Subject: [PATCH 298/490] Add callback option --- README.md | 1 + index.js | 2 +- tests/test-api.js | 30 ++++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 tests/test-api.js diff --git a/README.md b/README.md index 64c43e742..42fbec365 100644 --- a/README.md +++ b/README.md @@ -814,6 +814,7 @@ default in Linux can be anywhere from 20-120 seconds][linux-timeout]). - `time` - If `true`, the request-response cycle (including all redirects) is timed at millisecond resolution, and the result provided on the response's `elapsedTime` property. - `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 The callback argument gets 3 arguments: diff --git a/index.js b/index.js index 4d0c748da..b2b321785 100755 --- a/index.js +++ b/index.js @@ -37,7 +37,7 @@ function initParams(uri, options, callback) { extend(params, uri) } - params.callback = callback + params.callback = callback || params.callback return params } diff --git a/tests/test-api.js b/tests/test-api.js new file mode 100644 index 000000000..a01ee60c2 --- /dev/null +++ b/tests/test-api.js @@ -0,0 +1,30 @@ +'use strict' + +var http = require('http') + , request = require('../index') + , tape = require('tape') + , server + + +tape('setup', function (t) { + server = http.createServer() + server.on('request', function (req, res) { + res.writeHead(202) + req.pipe(res) + }) + server.listen(6767, t.end) +}) + +tape('callback option', function (t) { + request({ + url: 'http://localhost:6767', + callback: function (err, res, body) { + t.equal(res.statusCode, 202) + t.end() + } + }) +}) + +tape('cleanup', function(t) { + server.close(t.end) +}) From 8f2a142a06688b7ae276600add1e5388cb78ab00 Mon Sep 17 00:00:00 2001 From: Eric Millin Date: Thu, 14 Apr 2016 04:03:47 -0400 Subject: [PATCH 299/490] Explicitly destroy request buffer (#2168) * Explicitly destroy response buffer This fixes the issue mentioned in #1723. The lifetime of the `buffer` variable defined in `readResponseBody` is linked to the `Request` object, rather than the enclosing function. This can lead to leaky behavior if references to the request persist in memory. --- request.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/request.js b/request.js index 30031605a..75b184a88 100644 --- a/request.js +++ b/request.js @@ -1011,6 +1011,9 @@ Request.prototype.readResponseBody = function (response) { debug('end event', self.uri.href) if (self._aborted) { 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 } @@ -1023,6 +1026,9 @@ Request.prototype.readResponseBody = function (response) { } else { response.body = buffer.toString(self.encoding) } + // `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) { // The UTF8 BOM [0xEF,0xBB,0xBF] is converted to [0xFE,0xFF] in the JS UTC16/UCS2 representation. // Strip this value out when the encoding is set to 'utf8', as upstream consumers won't expect it and it breaks JSON.parse(). From 865e981f2e36d79ef07a3c44f8e3470e6a7b89f2 Mon Sep 17 00:00:00 2001 From: simov Date: Fri, 15 Apr 2016 12:04:17 +0300 Subject: [PATCH 300/490] Fix support for delete method --- README.md | 11 ++--------- index.js | 3 ++- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index cdffb5ce7..00ac89ba2 100644 --- a/README.md +++ b/README.md @@ -888,20 +888,13 @@ Same as `request()`, but defaults to `method: "HEAD"`. request.head(url) ``` -### request.delete - -Same as `request()`, but defaults to `method: "DELETE"`. - -```js -request.delete(url) -``` - -### request.del +### request.del / request.delete Same as `request()`, but defaults to `method: "DELETE"`. ```js request.del(url) +request.delete(url) ``` ### request.get diff --git a/index.js b/index.js index f2d710cea..716938c1d 100755 --- a/index.js +++ b/index.js @@ -70,7 +70,8 @@ request.head = verbFunc('head') request.post = verbFunc('post') request.put = verbFunc('put') request.patch = verbFunc('patch') -request.del = request.delete = verbFunc('delete') +request.del = verbFunc('delete') +request['delete'] = verbFunc('delete') request.jar = function (store) { return cookies.jar(store) From 750fe8513926769c2e7e7476469b6510d234fd6e Mon Sep 17 00:00:00 2001 From: Aniket Panse Date: Fri, 15 Apr 2016 17:00:14 +0530 Subject: [PATCH 301/490] added support for deflate content encoding --- request.js | 5 ++++- tests/test-gzip.js | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/request.js b/request.js index 75b184a88..eaa866576 100644 --- a/request.js +++ b/request.js @@ -399,7 +399,7 @@ Request.prototype.init = function (options) { } if (self.gzip && !self.hasHeader('accept-encoding')) { - self.setHeader('accept-encoding', 'gzip') + self.setHeader('accept-encoding', 'gzip, deflate') } if (self.uri.auth && !self.hasHeader('authorization')) { @@ -928,6 +928,9 @@ Request.prototype.onRequestResponse = function (response) { if (contentEncoding === 'gzip') { responseContent = zlib.createGunzip() response.pipe(responseContent) + } else if (contentEncoding === 'deflate') { + responseContent = zlib.createInflate() + response.pipe(responseContent) } else { // Since previous versions didn't check for Content-Encoding header, // ignore any invalid values to preserve backwards-compatibility diff --git a/tests/test-gzip.js b/tests/test-gzip.js index fef772055..85870eb4d 100644 --- a/tests/test-gzip.js +++ b/tests/test-gzip.js @@ -31,6 +31,12 @@ var server = http.createServer(function(req, res) { res.end(data) }) } + } else if (/\bdeflate\b/i.test(req.headers['accept-encoding'])) { + res.setHeader('Content-Encoding', 'deflate') + zlib.deflate(testContent, function (err, data) { + assert.equal(err, null) + res.end(data) + }) } else { res.end(testContent) } @@ -209,6 +215,18 @@ tape('pause before streaming from a gzip request object', function(t) { }, 100) }) +tape('transparently supports deflate decoding to callbacks', function(t) { + var options = { url: 'http://localhost:6767/foo', gzip: true, headers: { 'Accept-Encoding': 'deflate' } } + + request.get(options, function(err, res, body) { + t.equal(err, null) + t.equal(res.headers['content-encoding'], 'deflate') + t.equal(body, testContent) + t.end() + }) +}) + + tape('cleanup', function(t) { server.close(function() { t.end() From c9f0cc56bc358f22c25a45fd5868c6cdd11c792d Mon Sep 17 00:00:00 2001 From: simov Date: Sat, 16 Apr 2016 09:37:50 +0300 Subject: [PATCH 302/490] Do not try to pipe HEAD request responses when using gzip --- request.js | 2 +- tests/test-gzip.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/request.js b/request.js index eaa866576..2c83c54b5 100644 --- a/request.js +++ b/request.js @@ -921,7 +921,7 @@ Request.prototype.onRequestResponse = function (response) { }) var responseContent - if (self.gzip) { + if (self.gzip && self.method !== 'HEAD') { var contentEncoding = response.headers['content-encoding'] || 'identity' contentEncoding = contentEncoding.trim().toLowerCase() diff --git a/tests/test-gzip.js b/tests/test-gzip.js index 85870eb4d..0bf3271fe 100644 --- a/tests/test-gzip.js +++ b/tests/test-gzip.js @@ -16,6 +16,12 @@ var server = http.createServer(function(req, res) { res.statusCode = 200 res.setHeader('Content-Type', 'text/plain') + if (req.method === 'HEAD') { + res.setHeader('Content-Encoding', 'gzip') + res.end() + return + } + if (/\bgzip\b/i.test(req.headers['accept-encoding'])) { res.setHeader('Content-Encoding', 'gzip') if (req.url === '/error') { @@ -226,6 +232,16 @@ tape('transparently supports deflate decoding to callbacks', function(t) { }) }) +tape('do not try to pipe HEAD request responses', function(t) { + var options = { method: 'HEAD', url: 'http://localhost:6767/foo', gzip: true } + + request(options, function(err, res, body) { + t.equal(err, null) + t.equal(body, '') + t.end() + }) +}) + tape('cleanup', function(t) { server.close(function() { From 5553f17ffee827a6078b35af76950061a939d95c Mon Sep 17 00:00:00 2001 From: simov Date: Sun, 17 Apr 2016 10:15:38 +0300 Subject: [PATCH 303/490] Do not try to pipe Gzip responses with no body --- request.js | 14 +++++++++++++- tests/test-gzip.js | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/request.js b/request.js index 2c83c54b5..124157e86 100644 --- a/request.js +++ b/request.js @@ -920,8 +920,20 @@ Request.prototype.onRequestResponse = function (response) { self._ended = true }) + 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 && self.method !== 'HEAD') { + if (self.gzip && !noBody(response.statusCode)) { var contentEncoding = response.headers['content-encoding'] || 'identity' contentEncoding = contentEncoding.trim().toLowerCase() diff --git a/tests/test-gzip.js b/tests/test-gzip.js index 0bf3271fe..cf5ce48ad 100644 --- a/tests/test-gzip.js +++ b/tests/test-gzip.js @@ -21,6 +21,14 @@ var server = http.createServer(function(req, res) { res.end() return } + if (req.headers.code) { + res.writeHead(req.headers.code, { + 'Content-Encoding': 'gzip', + code: req.headers.code + }) + res.end() + return + } if (/\bgzip\b/i.test(req.headers['accept-encoding'])) { res.setHeader('Content-Encoding', 'gzip') @@ -242,6 +250,33 @@ tape('do not try to pipe HEAD request responses', function(t) { }) }) +tape('do not try to pipe responses with no body', function(t) { + var options = { url: 'http://localhost:6767/foo', gzip: true } + + options.headers = {code: 105} + request.post(options, function(err, res, body) { + t.equal(err, null) + t.equal(res.headers.code, '105') + t.equal(body, '') + + options.headers = {code: 204} + request.post(options, function(err, res, body) { + t.equal(err, null) + t.equal(res.headers.code, '204') + t.equal(body, '') + + options.headers = {code: 304} + request.post(options, function(err, res, body) { + t.equal(err, null) + t.equal(res.headers.code, '304') + t.equal(body, '') + + t.end() + }) + }) + }) +}) + tape('cleanup', function(t) { server.close(function() { From 9a73a402abe1fab65064c07141ae1da925333dee Mon Sep 17 00:00:00 2001 From: simov Date: Sun, 17 Apr 2016 16:48:12 +0300 Subject: [PATCH 304/490] 2.72.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 27749df22..c8f8d90e5 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.71.1", + "version": "2.72.0", "author": "Mikeal Rogers ", "repository": { "type": "git", From 6dcac13642955577592fdafb5ff3cdc8a6ff1b1b Mon Sep 17 00:00:00 2001 From: simov Date: Sun, 17 Apr 2016 16:53:19 +0300 Subject: [PATCH 305/490] Update changelog --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac9a0bcd6..ce6826f2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ ## 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) - [#2164](https://github.com/request/request/pull/2164) Catch errors from the underlying http module (@simov) From 39688bea3b39ae5b0a754a49c18f7855de5d1cd3 Mon Sep 17 00:00:00 2001 From: simov Date: Sun, 17 Apr 2016 16:53:43 +0300 Subject: [PATCH 306/490] 2.72.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c8f8d90e5..b317a676e 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.72.0", + "version": "2.72.1", "author": "Mikeal Rogers ", "repository": { "type": "git", From e12842012265d8531772ec88191b07b3c51b9293 Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Tue, 3 May 2016 19:28:25 -0700 Subject: [PATCH 307/490] chore(package): update karma-coverage to version 1.0.0 https://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b317a676e..ce5606a49 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,7 @@ "karma": "^0.13.10", "karma-browserify": "^5.0.1", "karma-cli": "^0.1.1", - "karma-coverage": "^0.5.3", + "karma-coverage": "^1.0.0", "karma-phantomjs-launcher": "^1.0.0", "karma-tap": "^1.0.3", "phantomjs-prebuilt": "^2.1.3", From a28ea10c13fbfadbbc5b5933fce20fb4e42f83af Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Tue, 3 May 2016 20:39:47 -0700 Subject: [PATCH 308/490] chore(package): update karma-cli to version 1.0.0 https://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b317a676e..de16a9234 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "istanbul": "^0.4.0", "karma": "^0.13.10", "karma-browserify": "^5.0.1", - "karma-cli": "^0.1.1", + "karma-cli": "^1.0.0", "karma-coverage": "^0.5.3", "karma-phantomjs-launcher": "^1.0.0", "karma-tap": "^1.0.3", From 926ebd87f213e373a843681121d7013cbfdd9246 Mon Sep 17 00:00:00 2001 From: simov Date: Sat, 7 May 2016 20:12:21 +0300 Subject: [PATCH 309/490] Use server-destory to close hanging sockets when running the coverage report (in single process) --- tests/test-httpModule.js | 8 ++++++-- tests/test-redirect-auth.js | 8 ++++++-- tests/test-redirect-complex.js | 8 ++++++-- tests/test-redirect.js | 8 ++++++-- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/tests/test-httpModule.js b/tests/test-httpModule.js index dae4845a7..ee530e6f2 100644 --- a/tests/test-httpModule.js +++ b/tests/test-httpModule.js @@ -2,6 +2,7 @@ var http = require('http') , https = require('https') + , destroyable = require('server-destroy') , server = require('./server') , request = require('../index') , tape = require('tape') @@ -36,6 +37,9 @@ var faux_http = wrap_request('http', http) , plain_server = server.createServer() , https_server = server.createSSLServer() +destroyable(plain_server) +destroyable(https_server) + tape('setup', function(t) { plain_server.listen(plain_server.port, function() { plain_server.on('/plain', function (req, res) { @@ -100,8 +104,8 @@ run_tests('https only', { 'https:': faux_https }) run_tests('http and https', { 'http:': faux_http, 'https:': faux_https }) tape('cleanup', function(t) { - plain_server.close(function() { - https_server.close(function() { + plain_server.destroy(function() { + https_server.destroy(function() { t.end() }) }) diff --git a/tests/test-redirect-auth.js b/tests/test-redirect-auth.js index ecffdbd8b..95eaf04b6 100644 --- a/tests/test-redirect-auth.js +++ b/tests/test-redirect-auth.js @@ -4,10 +4,14 @@ var server = require('./server') , request = require('../index') , util = require('util') , tape = require('tape') + , destroyable = require('server-destroy') var s = server.createServer() , ss = server.createSSLServer() +destroyable(s) +destroyable(ss) + // always send basic auth and allow non-strict SSL request = request.defaults({ auth : { @@ -117,8 +121,8 @@ runTest('different host and protocol', false) tape('cleanup', function(t) { - s.close(function() { - ss.close(function() { + s.destroy(function() { + ss.destroy(function() { t.end() }) }) diff --git a/tests/test-redirect-complex.js b/tests/test-redirect-complex.js index c3ff7a031..b88ef178a 100644 --- a/tests/test-redirect-complex.js +++ b/tests/test-redirect-complex.js @@ -4,11 +4,15 @@ var server = require('./server') , request = require('../index') , events = require('events') , tape = require('tape') + , destroyable = require('server-destroy') var s = server.createServer() , ss = server.createSSLServer() , e = new events.EventEmitter() +destroyable(s) +destroyable(ss) + function bouncy(s, serverUrl) { var redirs = { a: 'b' , b: 'c' @@ -79,8 +83,8 @@ tape('lots of redirects', function(t) { }) tape('cleanup', function(t) { - s.close(function() { - ss.close(function() { + s.destroy(function() { + ss.destroy(function() { t.end() }) }) diff --git a/tests/test-redirect.js b/tests/test-redirect.js index 3c18f85b9..6b9e7ee33 100644 --- a/tests/test-redirect.js +++ b/tests/test-redirect.js @@ -5,12 +5,16 @@ var server = require('./server') , request = require('../index') , tape = require('tape') , http = require('http') + , destroyable = require('server-destroy') var s = server.createServer() , ss = server.createSSLServer() , hits = {} , jar = request.jar() +destroyable(s) +destroyable(ss) + s.on('/ssl', function(req, res) { res.writeHead(302, { location : ss.url + '/' @@ -419,8 +423,8 @@ tape('should use same agent class on redirect', function(t) { }) tape('cleanup', function(t) { - s.close(function() { - ss.close(function() { + s.destroy(function() { + ss.destroy(function() { t.end() }) }) From aff937ad72b66d5ec9e87851958b47c00010f30d Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Sun, 8 May 2016 16:20:06 -0700 Subject: [PATCH 310/490] chore(package): update qs to version 6.2.0 https://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index de16a9234..8eb4c986a 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "mime-types": "~2.1.7", "node-uuid": "~1.4.7", "oauth-sign": "~0.8.1", - "qs": "~6.1.0", + "qs": "~6.2.0", "stringstream": "~0.0.4", "tough-cookie": "~2.2.0", "tunnel-agent": "~0.4.1" From 70cafabcab077b1c2b92115d8ef21e297c443c0b Mon Sep 17 00:00:00 2001 From: simov Date: Mon, 9 May 2016 10:54:27 +0300 Subject: [PATCH 311/490] Move aws4 require statement to the top --- request.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/request.js b/request.js index 124157e86..178a268da 100644 --- a/request.js +++ b/request.js @@ -9,6 +9,7 @@ var http = require('http') , bl = require('bl') , hawk = require('hawk') , aws2 = require('aws-sign2') + , aws4 = require('aws4') , httpSignature = require('http-signature') , mime = require('mime-types') , stringstream = require('stringstream') @@ -1264,10 +1265,9 @@ Request.prototype.aws = function (opts, now) { self._aws = opts return self } - + if (opts.sign_version == 4 || opts.sign_version == '4') { - var aws4 = require('aws4') - // use aws4 + // use aws4 var options = { host: self.uri.host, path: self.uri.path, From dd3fad0ff08e769f35c7b1d47f8a3f9b09d68d69 Mon Sep 17 00:00:00 2001 From: simov Date: Mon, 9 May 2016 13:43:34 +0300 Subject: [PATCH 312/490] Update to form-data RC4 and pass null values to it --- package.json | 2 +- request.js | 2 +- tests/test-form-data-error.js | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e9b47ad8c..2da585d91 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "combined-stream": "~1.0.5", "extend": "~3.0.0", "forever-agent": "~0.6.1", - "form-data": "~1.0.0-rc3", + "form-data": "~1.0.0-rc4", "har-validator": "~2.0.6", "hawk": "~3.1.3", "http-signature": "~1.1.0", diff --git a/request.js b/request.js index 178a268da..bc762d16f 100644 --- a/request.js +++ b/request.js @@ -336,7 +336,7 @@ Request.prototype.init = function (options) { var formData = options.formData var requestForm = self.form() var appendFormValue = function (key, value) { - if (value.hasOwnProperty('value') && value.hasOwnProperty('options')) { + if (value && value.hasOwnProperty('value') && value.hasOwnProperty('options')) { requestForm.append(key, value.value, value.options) } else { requestForm.append(key, value) diff --git a/tests/test-form-data-error.js b/tests/test-form-data-error.js index 9b7642211..7111e033b 100644 --- a/tests/test-form-data-error.js +++ b/tests/test-form-data-error.js @@ -65,6 +65,20 @@ tape('omit content-length header if the value is set to NaN', function(t) { }) }) +// TODO: remove this test after form-data@2.0 starts stringifying null values +tape('form-data should throw on null value', function (t) { + t.throws(function () { + request({ + method: 'POST', + url: 'http://localhost:6767', + formData: { + key: null + } + }) + }, /Cannot read property 'path' of null/) + t.end() +}) + tape('cleanup', function(t) { s.close(function() { t.end() From b7de3a8c4499cb10a3357d69cf56da716e71137e Mon Sep 17 00:00:00 2001 From: simov Date: Sat, 7 May 2016 20:27:29 +0300 Subject: [PATCH 313/490] Add codecov.yml and disable PR comments Use the codecov module instead of codecov.io --- .travis.yml | 4 +++- codecov.yml | 2 ++ package.json | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 codecov.yml diff --git a/.travis.yml b/.travis.yml index e5d9bde26..6f2d753b6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,15 @@ + language: node_js node_js: - node + - 4 - 0.12 - 0.10 after_script: - npm run test-cov - - cat ./coverage/lcov.info | codecov + - codecov - cat ./coverage/lcov.info | coveralls webhooks: diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 000000000..acd3f33ce --- /dev/null +++ b/codecov.yml @@ -0,0 +1,2 @@ + +comment: false diff --git a/package.json b/package.json index de16a9234..fd8404d9f 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "browserify": "^12.0.2", "browserify-istanbul": "^2.0.0", "buffer-equal": "^1.0.0", - "codecov.io": "^0.1.6", + "codecov": "^1.0.1", "coveralls": "^2.11.4", "eslint": "^2.5.3", "function-bind": "^1.0.2", From 3cfbece3b7101fd011f46348539201267a362ec3 Mon Sep 17 00:00:00 2001 From: Ainun Nazieb Date: Fri, 13 May 2016 18:10:32 +0700 Subject: [PATCH 314/490] Doc: Fix link to http.IncomingMessage --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cf9072a21..fb16bcf87 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ Request can also `pipe` to itself. When doing so, `content-type` and `content-le request.get('http://google.com/img.png').pipe(request.put('http://mysite.com/img.png')) ``` -Request emits a "response" event when a response is received. The `response` argument will be an instance of [http.IncomingMessage](http://nodejs.org/api/http.html#http_http_incomingmessage). +Request emits a "response" event when a response is received. The `response` argument will be an instance of [http.IncomingMessage](https://nodejs.org/api/http.html#http_class_http_incomingmessage). ```js request @@ -819,7 +819,7 @@ default in Linux can be anywhere from 20-120 seconds][linux-timeout]). The callback argument gets 3 arguments: 1. An `error` when applicable (usually from [`http.ClientRequest`](http://nodejs.org/api/http.html#http_class_http_clientrequest) object) -2. An [`http.IncomingMessage`](http://nodejs.org/api/http.html#http_http_incomingmessage) object +2. An [`http.IncomingMessage`](https://nodejs.org/api/http.html#http_class_http_incomingmessage) object 3. The third is the `response` body (`String` or `Buffer`, or JSON object if the `json` option is supplied) [back to top](#table-of-contents) From bebcd417a89425743434858a71c83c437bd75f4b Mon Sep 17 00:00:00 2001 From: calamarico Date: Tue, 24 May 2016 12:32:28 +0200 Subject: [PATCH 315/490] Adding a simple Response object reference in argument specification --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fb16bcf87..633dde390 100644 --- a/README.md +++ b/README.md @@ -819,7 +819,7 @@ default in Linux can be anywhere from 20-120 seconds][linux-timeout]). The callback argument gets 3 arguments: 1. An `error` when applicable (usually from [`http.ClientRequest`](http://nodejs.org/api/http.html#http_class_http_clientrequest) object) -2. An [`http.IncomingMessage`](https://nodejs.org/api/http.html#http_class_http_incomingmessage) object +2. An [`http.IncomingMessage`](https://nodejs.org/api/http.html#http_class_http_incomingmessage) object (Response object) 3. The third is the `response` body (`String` or `Buffer`, or JSON object if the `json` option is supplied) [back to top](#table-of-contents) From fcab069367df11c80ea5c9af1ba3274aa9ac05d0 Mon Sep 17 00:00:00 2001 From: Joseph Dykstra Date: Wed, 25 May 2016 22:14:58 -0500 Subject: [PATCH 316/490] Remove extraneous bracket --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index fb16bcf87..81ecac509 100644 --- a/README.md +++ b/README.md @@ -601,7 +601,6 @@ var options = { key: fs.readFileSync(keyFile), passphrase: 'password', ca: fs.readFileSync(caFile) - } }; request.get(options); From bf86f170257de6a0cd7b3342676bb43b63219d9a Mon Sep 17 00:00:00 2001 From: Zach Renner Date: Fri, 10 Jun 2016 10:05:00 -0700 Subject: [PATCH 317/490] Remove connectionErrorHandler to fix #1903 --- request.js | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/request.js b/request.js index bc762d16f..8267c1253 100644 --- a/request.js +++ b/request.js @@ -71,20 +71,6 @@ function filterOutReservedFunctions(reserved, options) { } -// Function for properly handling a connection error -function connectionErrorHandler(error) { - var socket = this - if (socket.res) { - if (socket.res.request) { - socket.res.request.emit('error', error) - } else { - socket.res.emit('error', error) - } - } else { - socket._httpMessage.emit('error', error) - } -} - // Return a simpler request object to allow serialization function requestToJSON() { var self = this @@ -805,11 +791,6 @@ Request.prototype.start = function () { self.emit('socket', socket) }) - self.on('end', function() { - if ( self.req.connection ) { - self.req.connection.removeListener('error', connectionErrorHandler) - } - }) self.emit('request', self.req) } @@ -844,11 +825,6 @@ Request.prototype.onRequestResponse = function (response) { debug('response end', self.uri.href, response.statusCode, response.headers) }) - // The check on response.connection is a workaround for browserify. - if (response.connection && response.connection.listeners('error').indexOf(connectionErrorHandler) === -1) { - response.connection.setMaxListeners(0) - response.connection.once('error', connectionErrorHandler) - } if (self._aborted) { debug('aborted', self.uri.href) response.resume() From 7513bce6deca4f9e62d3dd5b8db92aec7265ef86 Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Thu, 7 Jul 2016 08:36:13 -0700 Subject: [PATCH 318/490] chore(package): update karma to version 1.1.1 https://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2da585d91..03f2c6bd7 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "eslint": "^2.5.3", "function-bind": "^1.0.2", "istanbul": "^0.4.0", - "karma": "^0.13.10", + "karma": "^1.1.1", "karma-browserify": "^5.0.1", "karma-cli": "^1.0.0", "karma-coverage": "^1.0.0", From fba822f058c29b3ba3de9ef7560a65ec45968983 Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Fri, 8 Jul 2016 01:23:27 -0700 Subject: [PATCH 319/490] chore(package): update browserify to version 13.0.1 https://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9db191dfc..1a787d0f9 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ }, "devDependencies": { "bluebird": "^3.2.1", - "browserify": "^12.0.2", + "browserify": "^13.0.1", "browserify-istanbul": "^2.0.0", "buffer-equal": "^1.0.0", "codecov": "^1.0.1", From 6dfb447224484e0ce53f100309f32a5d9a8d45c2 Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Fri, 8 Jul 2016 01:45:20 -0700 Subject: [PATCH 320/490] chore(package): update tape to version 4.6.0 https://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1a787d0f9..74293d308 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "phantomjs-prebuilt": "^2.1.3", "rimraf": "^2.2.8", "server-destroy": "^1.0.1", - "tape": "^4.2.0", + "tape": "^4.6.0", "taper": "^0.4.0" } } From d17b582196bdc8fd4896f9af7c1cbbad4bd3fa5a Mon Sep 17 00:00:00 2001 From: simov Date: Sat, 9 Jul 2016 10:37:21 +0300 Subject: [PATCH 321/490] 2.73.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 74293d308..2b198766c 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.72.1", + "version": "2.73.0", "author": "Mikeal Rogers ", "repository": { "type": "git", From fa46be421b165c737c93672a8f920245cfb090a2 Mon Sep 17 00:00:00 2001 From: simov Date: Sat, 9 Jul 2016 10:42:57 +0300 Subject: [PATCH 322/490] Update changelog --- CHANGELOG.md | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce6826f2f..c7d684fa5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,20 @@ ## Change Log +### v2.73.0 (2016/07/09) +- [#2240](https://github.com/request/request/pull/2240) Remove connectionErrorHandler to fix #1903 (@zarenner) +- [#2251](https://github.com/request/request/pull/2251) tape@4.6.0 breaks build 🚨 (@greenkeeperio-bot) +- [#2225](https://github.com/request/request/pull/2225) Update docs (@ArtskydJ) +- [#2203](https://github.com/request/request/pull/2203) Update browserify to version 13.0.1 🚀 (@greenkeeperio-bot) +- [#2275](https://github.com/request/request/pull/2275) Update karma to version 1.1.1 🚀 (@greenkeeperio-bot) +- [#2204](https://github.com/request/request/pull/2204) Add codecov.yml and disable PR comments (@simov) +- [#2212](https://github.com/request/request/pull/2212) Fix link to http.IncomingMessage documentation (@nazieb) +- [#2208](https://github.com/request/request/pull/2208) Update to form-data RC4 and pass null values to it (@simov) +- [#2207](https://github.com/request/request/pull/2207) Move aws4 require statement to the top (@simov) +- [#2199](https://github.com/request/request/pull/2199) Update karma-coverage to version 1.0.0 🚀 (@greenkeeperio-bot) +- [#2206](https://github.com/request/request/pull/2206) Update qs to version 6.2.0 🚀 (@greenkeeperio-bot) +- [#2205](https://github.com/request/request/pull/2205) Use server-destory to close hanging sockets in tests (@simov) +- [#2200](https://github.com/request/request/pull/2200) Update karma-cli to version 1.0.0 🚀 (@greenkeeperio-bot) + ### 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) @@ -114,8 +129,7 @@ - [#1687](https://github.com/request/request/pull/1687) Fix caseless bug - content-type not being set for multipart/form-data (@simov, @garymathews) ### v2.59.0 (2015/07/20) -- [#1671](https://github.com/request/request/pull/1671) Add tests and docs for using the agent, agentClass, agentOptions and forever options. - Forever option defaults to using http(s).Agent in node 0.12+ (@simov) +- [#1671](https://github.com/request/request/pull/1671) Add tests and docs for using the agent, agentClass, agentOptions and forever options. Forever option defaults to using http(s).Agent in node 0.12+ (@simov) - [#1679](https://github.com/request/request/pull/1679) Fix - do not remove OAuth param when using OAuth realm (@simov, @jhalickman) - [#1668](https://github.com/request/request/pull/1668) updated dependencies (@deamme) - [#1656](https://github.com/request/request/pull/1656) Fix form method (@simov) @@ -182,7 +196,7 @@ - [#1460](https://github.com/request/request/pull/1460) localAddress or proxy config is lost when redirecting (@simov, @0x4139) - [#1453](https://github.com/request/request/pull/1453) Test on Node.js 0.12 and io.js with allowed failures (@nicolasmccurdy, @demohi) - [#1426](https://github.com/request/request/pull/1426) Fixing tests to pass on io.js and node 0.12 (only test-https.js stiff failing) (@mikeal) -- [#1446](https://github.com/request/request/pull/1446) Missing HTTP referer header with redirects Fixes #1038 (@simov, @guimonz) +- [#1446](https://github.com/request/request/pull/1446) Missing HTTP referer header with redirects Fixes #1038 (@simov, @guimon) - [#1428](https://github.com/request/request/pull/1428) Deprecate Node v0.8.x (@nylen) - [#1436](https://github.com/request/request/pull/1436) Add ability to set a requester without setting default options (@tikotzky) - [#1435](https://github.com/request/request/pull/1435) dry up verb methods (@sethpollack) @@ -310,7 +324,7 @@ - [#1131](https://github.com/request/request/pull/1131) Update pool documentation (@FredKSchott) - [#1143](https://github.com/request/request/pull/1143) Rewrite all tests to use tape (@nylen) - [#1137](https://github.com/request/request/pull/1137) Add ability to specifiy querystring lib in options. (@jgrund) -- [#1138](https://github.com/request/request/pull/1138) allow hostname and port in place of host on uri (@cappslock) +- [#1138](https://github.com/request/request/pull/1138) allow hostname and port in place of host on uri (@slimelabs) - [#1134](https://github.com/request/request/pull/1134) Fix multiple redirects and `self.followRedirect` (@blakeembrey) - [#1130](https://github.com/request/request/pull/1130) documentation fix: add note about npm test for contributing (@FredKSchott) - [#1120](https://github.com/request/request/pull/1120) Support/refactor request setup tunnel (@seanstrom) @@ -483,24 +497,18 @@ ### v2.23.0 (2013/07/23) - [#589](https://github.com/request/request/pull/589) Prevent setting headers after they are sent (@geek) - [#587](https://github.com/request/request/pull/587) Global cookie jar disabled by default (@threepointone) - -### v2.22.0 (2013/07/05) - [#544](https://github.com/request/request/pull/544) Update http-signature version. (@davidlehn) - [#581](https://github.com/request/request/pull/581) Fix spelling of "ignoring." (@bigeasy) - [#568](https://github.com/request/request/pull/568) use agentOptions to create agent when specified in request (@SamPlacette) - [#564](https://github.com/request/request/pull/564) Fix redirections (@criloz) - [#541](https://github.com/request/request/pull/541) The exported request function doesn't have an auth method (@tschaub) - [#542](https://github.com/request/request/pull/542) Expose Request class (@regality) - -### v2.21.0 (2013/04/30) - [#536](https://github.com/request/request/pull/536) Allow explicitly empty user field for basic authentication. (@mikeando) - [#532](https://github.com/request/request/pull/532) fix typo (@fredericosilva) - [#497](https://github.com/request/request/pull/497) Added redirect event (@Cauldrath) - [#503](https://github.com/request/request/pull/503) Fix basic auth for passwords that contain colons (@tonistiigi) - [#521](https://github.com/request/request/pull/521) Improving test-localAddress.js (@noway421) - [#529](https://github.com/request/request/pull/529) dependencies versions bump (@jodaka) - -### v2.20.0 (2013/04/22) - [#523](https://github.com/request/request/pull/523) Updating dependencies (@noway421) - [#520](https://github.com/request/request/pull/520) Fixing test-tunnel.js (@noway421) - [#519](https://github.com/request/request/pull/519) Update internal path state on post-creation QS changes (@jblebrun) From bf9a8ef8c5b2d87899cfed30d31118f231c7fffe Mon Sep 17 00:00:00 2001 From: simov Date: Sat, 9 Jul 2016 10:43:32 +0300 Subject: [PATCH 323/490] 2.73.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2b198766c..024254152 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.73.0", + "version": "2.73.1", "author": "Mikeal Rogers ", "repository": { "type": "git", From f53a2068304e6e05264edb3278b09bd54bf57aad Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Mon, 11 Jul 2016 08:23:17 -0700 Subject: [PATCH 324/490] chore(package): update karma-tap to version 2.0.1 https://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 024254152..40317bf12 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,7 @@ "karma-cli": "^1.0.0", "karma-coverage": "^1.0.0", "karma-phantomjs-launcher": "^1.0.0", - "karma-tap": "^1.0.3", + "karma-tap": "^2.0.1", "phantomjs-prebuilt": "^2.1.3", "rimraf": "^2.2.8", "server-destroy": "^1.0.1", From 4f03ea8a8399ef17f1d5c71defd08184d9cbdae3 Mon Sep 17 00:00:00 2001 From: Jeremy Stashewsky Date: Fri, 22 Jul 2016 14:10:44 -0700 Subject: [PATCH 325/490] tough-cookie to 2.3.0 To address https://nodesecurity.io/advisories/130 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 40317bf12..258add029 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "oauth-sign": "~0.8.1", "qs": "~6.2.0", "stringstream": "~0.0.4", - "tough-cookie": "~2.2.0", + "tough-cookie": "~2.3.0", "tunnel-agent": "~0.4.1" }, "scripts": { From ae1fd8e8a9cd970e845f394b773440b71b0cf964 Mon Sep 17 00:00:00 2001 From: simov Date: Sat, 23 Jul 2016 02:43:16 +0300 Subject: [PATCH 326/490] 2.74.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 258add029..4064c35a6 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.73.1", + "version": "2.74.0", "author": "Mikeal Rogers ", "repository": { "type": "git", From 76e82351cbc21049441b1763c6f2bbd504fa8f5a Mon Sep 17 00:00:00 2001 From: simov Date: Sat, 23 Jul 2016 02:44:28 +0300 Subject: [PATCH 327/490] Update changelog --- CHANGELOG.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c7d684fa5..2b5d17765 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## Change Log +### v2.74.0 (2016/07/22) +- [#2295](https://github.com/request/request/pull/2295) Update tough-cookie to 2.3.0 (@stash-sfdc) +- [#2280](https://github.com/request/request/pull/2280) Update karma-tap to version 2.0.1 🚀 (@greenkeeperio-bot) + ### v2.73.0 (2016/07/09) - [#2240](https://github.com/request/request/pull/2240) Remove connectionErrorHandler to fix #1903 (@zarenner) - [#2251](https://github.com/request/request/pull/2251) tape@4.6.0 breaks build 🚨 (@greenkeeperio-bot) @@ -68,7 +72,7 @@ - [#1902](https://github.com/request/request/pull/1902) node-uuid@1.4.7 breaks build 🚨 (@greenkeeperio-bot) - [#1894](https://github.com/request/request/pull/1894) Fix tunneling after redirection from https (Original: #1881) (@simov, @falms) - [#1893](https://github.com/request/request/pull/1893) Update eslint to version 1.9.0 🚀 (@greenkeeperio-bot) -- [#1852](https://github.com/request/request/pull/1852) Update eslint to version 1.7.3 🚀 (@simov, @greenkeeperio-bot, @paulomcnally, @michelsalib, @arbaaz, @vladimirich, @LoicMahieu, @JoshWillik, @jzaefferer, @ryanwholey, @djchie, @thisconnect, @mgenereu, @acroca, @Sebmaster, @Bloutiouf) +- [#1852](https://github.com/request/request/pull/1852) Update eslint to version 1.7.3 🚀 (@simov, @greenkeeperio-bot, @paulomcnally, @michelsalib, @arbaaz, @vladimirich, @LoicMahieu, @JoshWillik, @jzaefferer, @ryanwholey, @djchie, @thisconnect, @mgenereu, @acroca, @Sebmaster, @KoltesDigital) - [#1876](https://github.com/request/request/pull/1876) Implement loose matching for har mime types (@simov) - [#1875](https://github.com/request/request/pull/1875) Update bluebird to version 3.0.2 🚀 (@simov, @greenkeeperio-bot) - [#1871](https://github.com/request/request/pull/1871) Update browserify to version 12.0.1 🚀 (@greenkeeperio-bot) @@ -79,7 +83,7 @@ - [#1857](https://github.com/request/request/pull/1857) Fix Referer header to point to the original host name (@simov) - [#1850](https://github.com/request/request/pull/1850) Update karma-coverage to version 0.5.3 🚀 (@greenkeeperio-bot) - [#1847](https://github.com/request/request/pull/1847) Use node's latest version when building (@simov) -- [#1836](https://github.com/request/request/pull/1836) Tunnel: fix wrong property name (@Bloutiouf) +- [#1836](https://github.com/request/request/pull/1836) Tunnel: fix wrong property name (@KoltesDigital) - [#1820](https://github.com/request/request/pull/1820) Set href as request.js uses it (@mgenereu) - [#1840](https://github.com/request/request/pull/1840) Update http-signature to version 1.0.2 🚀 (@greenkeeperio-bot) - [#1845](https://github.com/request/request/pull/1845) Update istanbul to version 0.4.0 🚀 (@greenkeeperio-bot) @@ -493,8 +497,6 @@ - [#596](https://github.com/request/request/pull/596) Global agent is being used when pool is specified (@Cauldrath) - [#594](https://github.com/request/request/pull/594) Emit complete event when there is no callback (@RomainLK) - [#601](https://github.com/request/request/pull/601) Fixed a small typo (@michalstanko) - -### v2.23.0 (2013/07/23) - [#589](https://github.com/request/request/pull/589) Prevent setting headers after they are sent (@geek) - [#587](https://github.com/request/request/pull/587) Global cookie jar disabled by default (@threepointone) - [#544](https://github.com/request/request/pull/544) Update http-signature version. (@davidlehn) From 9e17ba4819eaf806975540561a336ca620d1b2eb Mon Sep 17 00:00:00 2001 From: simov Date: Sat, 23 Jul 2016 02:44:48 +0300 Subject: [PATCH 328/490] 2.74.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4064c35a6..2202ee1bb 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.74.0", + "version": "2.74.1", "author": "Mikeal Rogers ", "repository": { "type": "git", From 263e16ec89edb8041657edb9280d9b0039146845 Mon Sep 17 00:00:00 2001 From: Thomas Hallock Date: Mon, 18 Apr 2016 13:00:01 -0400 Subject: [PATCH 329/490] using defunctzombie fork of uuid because node-uuid has been abandoned by developer --- lib/auth.js | 2 +- lib/multipart.js | 2 +- lib/oauth.js | 2 +- package.json | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/auth.js b/lib/auth.js index 1cb695216..559ca57be 100644 --- a/lib/auth.js +++ b/lib/auth.js @@ -1,7 +1,7 @@ 'use strict' var caseless = require('caseless') - , uuid = require('node-uuid') + , uuid = require('uuid') , helpers = require('./helpers') var md5 = helpers.md5 diff --git a/lib/multipart.js b/lib/multipart.js index c12817261..3b605bd47 100644 --- a/lib/multipart.js +++ b/lib/multipart.js @@ -1,6 +1,6 @@ 'use strict' -var uuid = require('node-uuid') +var uuid = require('uuid') , CombinedStream = require('combined-stream') , isstream = require('isstream') diff --git a/lib/oauth.js b/lib/oauth.js index c24209b89..56b39b0f5 100644 --- a/lib/oauth.js +++ b/lib/oauth.js @@ -3,7 +3,7 @@ var url = require('url') , qs = require('qs') , caseless = require('caseless') - , uuid = require('node-uuid') + , uuid = require('uuid') , oauth = require('oauth-sign') , crypto = require('crypto') diff --git a/package.json b/package.json index 2202ee1bb..186712245 100644 --- a/package.json +++ b/package.json @@ -37,12 +37,12 @@ "isstream": "~0.1.2", "json-stringify-safe": "~5.0.1", "mime-types": "~2.1.7", - "node-uuid": "~1.4.7", "oauth-sign": "~0.8.1", "qs": "~6.2.0", "stringstream": "~0.0.4", "tough-cookie": "~2.3.0", - "tunnel-agent": "~0.4.1" + "tunnel-agent": "~0.4.1", + "uuid": "^2.0.2" }, "scripts": { "test": "npm run lint && npm run test-ci && npm run test-browser", From a10af07a18bc2925f3a3d4c1d4a0e4d35949682e Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Fri, 26 Aug 2016 05:48:41 -0400 Subject: [PATCH 330/490] chore(package): update form-data to version 1.0.1 https://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2202ee1bb..13a835c30 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "combined-stream": "~1.0.5", "extend": "~3.0.0", "forever-agent": "~0.6.1", - "form-data": "~1.0.0-rc4", + "form-data": "~1.0.1", "har-validator": "~2.0.6", "hawk": "~3.1.3", "http-signature": "~1.1.0", From 1389216fef386846f5bf5b49f81cf93d5be33f20 Mon Sep 17 00:00:00 2001 From: Scott Trinh Date: Fri, 26 Aug 2016 11:48:56 -0400 Subject: [PATCH 331/490] Check error type instead of string Upstream change broke this unit test. --- tests/test-form-data-error.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test-form-data-error.js b/tests/test-form-data-error.js index 7111e033b..09beb317e 100644 --- a/tests/test-form-data-error.js +++ b/tests/test-form-data-error.js @@ -75,7 +75,7 @@ tape('form-data should throw on null value', function (t) { key: null } }) - }, /Cannot read property 'path' of null/) + }, TypeError) t.end() }) @@ -83,4 +83,4 @@ tape('cleanup', function(t) { s.close(function() { t.end() }) -}) \ No newline at end of file +}) From 62712d45aff7d685eb274c78ea69bb0c9c11a7b1 Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Sat, 27 Aug 2016 08:44:33 -0400 Subject: [PATCH 332/490] chore(package): update karma-tap to version 3.0.1 https://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2202ee1bb..0b39e6cd0 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,7 @@ "karma-cli": "^1.0.0", "karma-coverage": "^1.0.0", "karma-phantomjs-launcher": "^1.0.0", - "karma-tap": "^2.0.1", + "karma-tap": "^3.0.1", "phantomjs-prebuilt": "^2.1.3", "rimraf": "^2.2.8", "server-destroy": "^1.0.1", From 33aa74483d676a2a490f3ebe83161f6a6244bf4a Mon Sep 17 00:00:00 2001 From: Paul Irish Date: Sat, 27 Aug 2016 19:44:26 -0700 Subject: [PATCH 333/490] Add responseStartTime timing --- request.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/request.js b/request.js index 8267c1253..96a71b6ed 100644 --- a/request.js +++ b/request.js @@ -958,6 +958,10 @@ Request.prototype.onRequestResponse = function (response) { }) responseContent.on('data', function (chunk) { + if (self.timing && !self.responseStarted) { + self.responseStartTime = (new Date()).getTime() + response.responseStartTime = self.responseStartTime + } self._destdata = true self.emit('data', chunk) }) From ba2d94608887e87319ab50eb1d088adb11f24fb3 Mon Sep 17 00:00:00 2001 From: Paul Irish Date: Sat, 27 Aug 2016 20:04:29 -0700 Subject: [PATCH 334/490] Add tests for responseStartTime --- tests/test-timing.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/test-timing.js b/tests/test-timing.js index 04b13bdcc..754ffab56 100644 --- a/tests/test-timing.js +++ b/tests/test-timing.js @@ -27,21 +27,26 @@ tape('setup', function(t) { tape('non-redirected request is timed', function(t) { var options = {time: true} - request('http://localhost:' + plain_server.port + '/', options, function(err, res, body) { + var r = request('http://localhost:' + plain_server.port + '/', options, function(err, res, body) { t.equal(err, null) t.equal(typeof res.elapsedTime, 'number') + t.equal(typeof res.responseStartTime, 'number') t.equal((res.elapsedTime > 0), true) + t.equal((res.responseStartTime > r.startTime), true) t.end() }) }) tape('redirected request is timed with rollup', function(t) { var options = {time: true} - request('http://localhost:' + plain_server.port + '/redir', options, function(err, res, body) { + var r = request('http://localhost:' + plain_server.port + '/redir', options, function(err, res, body) { t.equal(err, null) t.equal(typeof res.elapsedTime, 'number') + t.equal(typeof res.responseStartTime, 'number') t.equal((res.elapsedTime > 0), true) + t.equal((res.responseStartTime > 0), true) t.equal((res.elapsedTime > redirect_mock_time), true) + t.equal((res.responseStartTime > r.startTime), true) t.end() }) }) From bfb3a469a1c51ebf6a3c1f4be553b43eaafcf47c Mon Sep 17 00:00:00 2001 From: simov Date: Sun, 28 Aug 2016 12:53:46 +0300 Subject: [PATCH 335/490] Update docs to reflect the new time property --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 81ecac509..6eaaa0547 100644 --- a/README.md +++ b/README.md @@ -811,7 +811,7 @@ default in Linux can be anywhere from 20-120 seconds][linux-timeout]). --- -- `time` - If `true`, the request-response cycle (including all redirects) is timed at millisecond resolution, and the result provided on the response's `elapsedTime` property. +- `time` - If `true`, the request-response cycle (including all redirects) is timed at millisecond resolution, and the result provided on the response's `elapsedTime` property. The `responseStartTime` property is also available to indicate the timestamp when the response begins. - `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 From 185f13df1dff4369074ef79c62e7fd4342d851f0 Mon Sep 17 00:00:00 2001 From: simov Date: Sun, 28 Aug 2016 13:13:27 +0300 Subject: [PATCH 336/490] Add greenkeeper ignore packages --- package.json | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/package.json b/package.json index 13a835c30..0c2994f72 100644 --- a/package.json +++ b/package.json @@ -72,5 +72,12 @@ "server-destroy": "^1.0.1", "tape": "^4.6.0", "taper": "^0.4.0" + }, + "greenkeeper": { + "ignore": [ + "eslint", + "hawk", + "har-validator" + ] } } From 212de93e01b2b2d64cf19736808aae3472e40567 Mon Sep 17 00:00:00 2001 From: Jordan Klassen Date: Tue, 6 Sep 2016 18:21:52 -0700 Subject: [PATCH 337/490] Fix typeof check in test-pool.js --- tests/test-pool.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-pool.js b/tests/test-pool.js index f343081eb..0cc33f4a1 100644 --- a/tests/test-pool.js +++ b/tests/test-pool.js @@ -37,7 +37,7 @@ tape('forever', function(t) { pool: {maxSockets: 1024} }, function(err, res, body) { // explicitly shut down the agent - if (r.agent.destroy === typeof 'function') { + if (typeof r.agent.destroy === 'function') { r.agent.destroy() } else { // node < 0.12 From 44a80f3f6f86c20f95652eb8c5ed49e65c957562 Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Sat, 17 Sep 2016 08:15:38 +0200 Subject: [PATCH 338/490] chore(package): update form-data to version 2.0.0 https://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ccf4c2342..9014736a5 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "combined-stream": "~1.0.5", "extend": "~3.0.0", "forever-agent": "~0.6.1", - "form-data": "~1.0.1", + "form-data": "~2.0.0", "har-validator": "~2.0.6", "hawk": "~3.1.3", "http-signature": "~1.1.0", From 5eeafa25097d42d6e2588122158761187d27e6ce Mon Sep 17 00:00:00 2001 From: simov Date: Sun, 18 Sep 2016 01:27:04 +0300 Subject: [PATCH 339/490] Drop support for Node 0.10 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6f2d753b6..9be8247c7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,9 +3,9 @@ language: node_js node_js: - node + - 6 - 4 - 0.12 - - 0.10 after_script: - npm run test-cov From edcdf6446014e41d3c33a15a1ce3ee0af6e783ce Mon Sep 17 00:00:00 2001 From: simov Date: Sun, 18 Sep 2016 01:31:25 +0300 Subject: [PATCH 340/490] 2.75.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9014736a5..350e2bd7f 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.74.1", + "version": "2.75.0", "author": "Mikeal Rogers ", "repository": { "type": "git", From e9f09c2832073858d6d988ba82a2895f36efa92d Mon Sep 17 00:00:00 2001 From: simov Date: Sun, 18 Sep 2016 01:32:49 +0300 Subject: [PATCH 341/490] Update changelog --- CHANGELOG.md | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b5d17765..042c6e526 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ ## Change Log +### v2.75.0 (2016/09/17) +- [#2381](https://github.com/request/request/pull/2381) Drop support for Node 0.10 (@simov) +- [#2377](https://github.com/request/request/pull/2377) Update form-data to version 2.0.0 🚀 (@greenkeeperio-bot) +- [#2353](https://github.com/request/request/pull/2353) Add greenkeeper ignored packages (@simov) +- [#2351](https://github.com/request/request/pull/2351) Update karma-tap to version 3.0.1 🚀 (@greenkeeperio-bot) +- [#2348](https://github.com/request/request/pull/2348) form-data@1.0.1 breaks build 🚨 (@greenkeeperio-bot) +- [#2349](https://github.com/request/request/pull/2349) Check error type instead of string (@scotttrinh) + ### v2.74.0 (2016/07/22) - [#2295](https://github.com/request/request/pull/2295) Update tough-cookie to 2.3.0 (@stash-sfdc) - [#2280](https://github.com/request/request/pull/2280) Update karma-tap to version 2.0.1 🚀 (@greenkeeperio-bot) @@ -196,9 +204,9 @@ - [#1469](https://github.com/request/request/pull/1469) Feature/base url (@froatsnook) - [#1459](https://github.com/request/request/pull/1459) Add option to time request/response cycle (including rollup of redirects) (@aaron-em) - [#1468](https://github.com/request/request/pull/1468) Re-enable io.js/node 0.12 build (@simov, @mikeal, @BBB) -- [#1442](https://github.com/request/request/pull/1442) Fixed the issue with strictSSL tests on 0.12 & io.js by explicitly setting a cipher that matches the cert. (@BBB, @nicolasmccurdy, @demohi, @simov, @0x4139) +- [#1442](https://github.com/request/request/pull/1442) Fixed the issue with strictSSL tests on 0.12 & io.js by explicitly setting a cipher that matches the cert. (@BBB, @nickmccurdy, @demohi, @simov, @0x4139) - [#1460](https://github.com/request/request/pull/1460) localAddress or proxy config is lost when redirecting (@simov, @0x4139) -- [#1453](https://github.com/request/request/pull/1453) Test on Node.js 0.12 and io.js with allowed failures (@nicolasmccurdy, @demohi) +- [#1453](https://github.com/request/request/pull/1453) Test on Node.js 0.12 and io.js with allowed failures (@nickmccurdy, @demohi) - [#1426](https://github.com/request/request/pull/1426) Fixing tests to pass on io.js and node 0.12 (only test-https.js stiff failing) (@mikeal) - [#1446](https://github.com/request/request/pull/1446) Missing HTTP referer header with redirects Fixes #1038 (@simov, @guimon) - [#1428](https://github.com/request/request/pull/1428) Deprecate Node v0.8.x (@nylen) @@ -328,7 +336,7 @@ - [#1131](https://github.com/request/request/pull/1131) Update pool documentation (@FredKSchott) - [#1143](https://github.com/request/request/pull/1143) Rewrite all tests to use tape (@nylen) - [#1137](https://github.com/request/request/pull/1137) Add ability to specifiy querystring lib in options. (@jgrund) -- [#1138](https://github.com/request/request/pull/1138) allow hostname and port in place of host on uri (@slimelabs) +- [#1138](https://github.com/request/request/pull/1138) allow hostname and port in place of host on uri (@cappslock) - [#1134](https://github.com/request/request/pull/1134) Fix multiple redirects and `self.followRedirect` (@blakeembrey) - [#1130](https://github.com/request/request/pull/1130) documentation fix: add note about npm test for contributing (@FredKSchott) - [#1120](https://github.com/request/request/pull/1120) Support/refactor request setup tunnel (@seanstrom) @@ -493,7 +501,7 @@ - [#613](https://github.com/request/request/pull/613) Fixes #583, moved initialization of self.uri.pathname (@lexander) - [#605](https://github.com/request/request/pull/605) Only include ":" + pass in Basic Auth if it's defined (fixes #602) (@bendrucker) -### v2.24.0 (2013/07/23) +### v2.25.0 (2013/07/23) - [#596](https://github.com/request/request/pull/596) Global agent is being used when pool is specified (@Cauldrath) - [#594](https://github.com/request/request/pull/594) Emit complete event when there is no callback (@RomainLK) - [#601](https://github.com/request/request/pull/601) Fixed a small typo (@michalstanko) @@ -559,7 +567,7 @@ - [#343](https://github.com/request/request/pull/343) Allow AWS to work in more situations, added a note in the README on its usage (@nlf) - [#320](https://github.com/request/request/pull/320) request.defaults() doesn't need to wrap jar() (@StuartHarris) - [#322](https://github.com/request/request/pull/322) Fix + test for piped into request bumped into redirect. #321 (@alexindigo) -- [#326](https://github.com/request/request/pull/326) Do not try to remove listener from an undefined connection (@strk) +- [#326](https://github.com/request/request/pull/326) Do not try to remove listener from an undefined connection (@CartoDB) - [#318](https://github.com/request/request/pull/318) Pass servername to tunneling secure socket creation (@isaacs) - [#317](https://github.com/request/request/pull/317) Workaround for #313 (@isaacs) - [#293](https://github.com/request/request/pull/293) Allow parser errors to bubble up to request (@mscdex) From b2ca6353f9fbfb04da84c42e5216440ac7816e61 Mon Sep 17 00:00:00 2001 From: simov Date: Sun, 18 Sep 2016 01:33:33 +0300 Subject: [PATCH 342/490] 2.75.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 350e2bd7f..77a46588c 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.75.0", + "version": "2.75.1", "author": "Mikeal Rogers ", "repository": { "type": "git", From e28fe833f04db3e1289dd28b7167ca438db0a3ae Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Mon, 26 Sep 2016 00:18:26 +0200 Subject: [PATCH 343/490] chore(package): update form-data to version 2.1.0 https://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 77a46588c..dd9adc54e 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "combined-stream": "~1.0.5", "extend": "~3.0.0", "forever-agent": "~0.6.1", - "form-data": "~2.0.0", + "form-data": "~2.1.0", "har-validator": "~2.0.6", "hawk": "~3.1.3", "http-signature": "~1.1.0", From edf29438f8a9c0fd0794b8732fdcaf13439a782b Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Mon, 3 Oct 2016 23:37:21 -0700 Subject: [PATCH 344/490] chore(package): update form-data to version 2.1.1 https://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index dd9adc54e..370580b0f 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "combined-stream": "~1.0.5", "extend": "~3.0.0", "forever-agent": "~0.6.1", - "form-data": "~2.1.0", + "form-data": "~2.1.1", "har-validator": "~2.0.6", "hawk": "~3.1.3", "http-signature": "~1.1.0", From 74e981379cc8eee8523096859edddfa497c65c85 Mon Sep 17 00:00:00 2001 From: Brian White Date: Thu, 13 Oct 2016 22:53:24 -0400 Subject: [PATCH 345/490] Do not pass timeout to http.request() node v6.8.0 supports a `timeout` option now, so we should explicitly delete it in case the value is < 0 (in which case node will throw an error). Handling timeouts manually for now is better for consistency with older node versions. --- request.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/request.js b/request.js index 96a71b6ed..55bcc63f8 100644 --- a/request.js +++ b/request.js @@ -736,6 +736,11 @@ Request.prototype.start = function () { debug('make request', self.uri.href) + // node v6.8.0 now supports a `timeout` value in `http.request()`, but we + // should delete it for now since we handle timeouts manually for better + // consistency with node versions before v6.8.0 + delete reqOptions.timeout + try { self.req = self.httpModule.request(reqOptions) } catch (err) { From 1ef4075f5b649987b52cc71a1c33fdd8111d305c Mon Sep 17 00:00:00 2001 From: Brian White Date: Thu, 13 Oct 2016 22:58:31 -0400 Subject: [PATCH 346/490] Make timeouts more accurate Prior to this commit, the connection timeout could include some amount of time that passes before the socket actually starts its connection attempt. Additionally, this commit only starts the request timeout once a connection is made. This helps to prevent an issue where one kind of timeout is seen instead of another (ETIMEDOUT vs ESOCKETTIMEOUT) while connecting in some situations (depending on OS and possibly node version). --- request.js | 67 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/request.js b/request.js index 55bcc63f8..4ea45b32b 100644 --- a/request.js +++ b/request.js @@ -752,39 +752,9 @@ Request.prototype.start = function () { self.startTime = new Date().getTime() } + var timeout 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) - - 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) - } - }) - } + timeout = self.timeout < 0 ? 0 : self.timeout } self.req.on('response', self.onRequestResponse.bind(self)) @@ -793,6 +763,39 @@ Request.prototype.start = function () { self.emit('drain') }) self.req.on('socket', function(socket) { + if (typeof timeout === 'number') { + socket.once('connect', function() { + clearTimeout(self.timeoutTimer) + self.timeoutTimer = null + // 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 once connected. + // + // 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.abort() + var e = new Error('ESOCKETTIMEDOUT') + e.code = 'ESOCKETTIMEDOUT' + e.connect = false + self.emit('error', e) + } + }) + }) + + // 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 () { + self.abort() + var e = new Error('ETIMEDOUT') + e.code = 'ETIMEDOUT' + e.connect = true + self.emit('error', e) + }, timeout) + } self.emit('socket', socket) }) From bf8b0f73126e1d58af0ef4b848ade4d1d69c573f Mon Sep 17 00:00:00 2001 From: Matt Blair Date: Fri, 14 Oct 2016 10:42:26 -0700 Subject: [PATCH 347/490] change .on to .once, remove possible memory leaks --- request.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/request.js b/request.js index 96a71b6ed..edd824955 100644 --- a/request.js +++ b/request.js @@ -893,7 +893,7 @@ Request.prototype.onRequestResponse = function (response) { } }) - response.on('end', function () { + response.once('end', function () { self._ended = true }) @@ -965,7 +965,7 @@ Request.prototype.onRequestResponse = function (response) { self._destdata = true self.emit('data', chunk) }) - responseContent.on('end', function (chunk) { + responseContent.once('end', function (chunk) { self.emit('end', chunk) }) responseContent.on('error', function (error) { From 6af6261a197c865b6f68af16017c22a55c62e0d1 Mon Sep 17 00:00:00 2001 From: Andres Suarez Date: Sun, 16 Oct 2016 18:57:23 -0400 Subject: [PATCH 348/490] Simplify "defer" helper creation --- lib/helpers.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/helpers.js b/lib/helpers.js index 356ff748e..c9793449b 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -3,13 +3,9 @@ var jsonSafeStringify = require('json-stringify-safe') , crypto = require('crypto') -function deferMethod() { - if (typeof setImmediate === 'undefined') { - return process.nextTick - } - - return setImmediate -} +var defer = typeof setImmediate === 'undefined' + ? process.nextTick + : setImmediate function isFunction(value) { return typeof value === 'function' @@ -71,4 +67,4 @@ exports.isReadStream = isReadStream exports.toBase64 = toBase64 exports.copy = copy exports.version = version -exports.defer = deferMethod() +exports.defer = defer From 092e1e657326626da0b8ac4cfe8752751689313b Mon Sep 17 00:00:00 2001 From: Andres Suarez Date: Sun, 16 Oct 2016 19:07:20 -0400 Subject: [PATCH 349/490] Remove "isFunction" helper in favor of "typeof" check --- index.js | 5 ++--- lib/helpers.js | 5 ----- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 911a90dbb..9ec65ea26 100755 --- a/index.js +++ b/index.js @@ -18,8 +18,7 @@ var extend = require('extend') , cookies = require('./lib/cookies') , helpers = require('./lib/helpers') -var isFunction = helpers.isFunction - , paramsHaveRequestBody = helpers.paramsHaveRequestBody +var paramsHaveRequestBody = helpers.paramsHaveRequestBody // organize params for patch, post, put, head, del @@ -95,7 +94,7 @@ function wrapRequestMethod (method, options, requester, verb) { target.method = verb.toUpperCase() } - if (isFunction(requester)) { + if (typeof requester === 'function') { method = requester } diff --git a/lib/helpers.js b/lib/helpers.js index 356ff748e..668b26307 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -11,10 +11,6 @@ function deferMethod() { return setImmediate } -function isFunction(value) { - return typeof value === 'function' -} - function paramsHaveRequestBody(params) { return ( params.body || @@ -63,7 +59,6 @@ function version () { } } -exports.isFunction = isFunction exports.paramsHaveRequestBody = paramsHaveRequestBody exports.safeStringify = safeStringify exports.md5 = md5 From c343ce9b2a9d96da0b2cae9223fdef3384c6edf1 Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Sun, 16 Oct 2016 17:30:36 -0700 Subject: [PATCH 350/490] chore(package): update qs to version 6.3.0 https://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 370580b0f..fc1cfaf5a 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "mime-types": "~2.1.7", "node-uuid": "~1.4.7", "oauth-sign": "~0.8.1", - "qs": "~6.2.0", + "qs": "~6.3.0", "stringstream": "~0.0.4", "tough-cookie": "~2.3.0", "tunnel-agent": "~0.4.1" From 285d49d2209596b9b71f7dc0c4a88acbd07024ee Mon Sep 17 00:00:00 2001 From: Brian White Date: Fri, 14 Oct 2016 04:17:56 -0400 Subject: [PATCH 351/490] Perform stricter timeout value validation --- request.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/request.js b/request.js index 4ea45b32b..4871d8d9f 100644 --- a/request.js +++ b/request.js @@ -754,7 +754,11 @@ Request.prototype.start = function () { var timeout if (self.timeout && !self.timeoutTimer) { - timeout = self.timeout < 0 ? 0 : self.timeout + if (self.timeout < 0) { + timeout = 0 + } else if (typeof self.timeout === 'number' && isFinite(self.timeout)) { + timeout = self.timeout + } } self.req.on('response', self.onRequestResponse.bind(self)) @@ -763,7 +767,7 @@ Request.prototype.start = function () { self.emit('drain') }) self.req.on('socket', function(socket) { - if (typeof timeout === 'number') { + if (timeout !== undefined) { socket.once('connect', function() { clearTimeout(self.timeoutTimer) self.timeoutTimer = null From f55c5201dd42ee828923be94a10eeece0559b3cc Mon Sep 17 00:00:00 2001 From: Brian White Date: Thu, 13 Oct 2016 23:04:12 -0400 Subject: [PATCH 352/490] Re-enable tests/test-timeout on Travis Recent changes to timeout handling now allow these tests to pass successfully on Travis CI. --- tests/test-timeout.js | 233 +++++++++++++++++++++--------------------- 1 file changed, 116 insertions(+), 117 deletions(-) diff --git a/tests/test-timeout.js b/tests/test-timeout.js index 7c4227b50..43e42fe06 100644 --- a/tests/test-timeout.js +++ b/tests/test-timeout.js @@ -6,141 +6,140 @@ function checkErrCode(t, err) { 'Error ETIMEDOUT or ESOCKETTIMEDOUT') } -if (process.env.TRAVIS === 'true') { - console.error('This test is unreliable on Travis; skipping.') - /*eslint no-process-exit:0*/ -} else { - var server = require('./server') - , request = require('../index') - , tape = require('tape') - - var s = server.createServer() - - // Request that waits for 200ms - s.on('/timeout', function(req, res) { - setTimeout(function() { - res.writeHead(200, {'content-type':'text/plain'}) - res.write('waited') - res.end() - }, 200) +var server = require('./server') + , request = require('../index') + , tape = require('tape') + +var s = server.createServer() + +// Request that waits for 200ms +s.on('/timeout', function(req, res) { + setTimeout(function() { + res.writeHead(200, {'content-type':'text/plain'}) + res.write('waited') + res.end() + }, 200) +}) + +tape('setup', function(t) { + s.listen(s.port, function() { + t.end() }) +}) - tape('setup', function(t) { - s.listen(s.port, function() { - t.end() - }) - }) +tape('should timeout', function(t) { + var shouldTimeout = { + url: s.url + '/timeout', + timeout: 100 + } - tape('should timeout', function(t) { - var shouldTimeout = { - url: s.url + '/timeout', - timeout: 100 - } - - request(shouldTimeout, function(err, res, body) { - checkErrCode(t, err) - t.end() - }) + request(shouldTimeout, function(err, res, body) { + checkErrCode(t, err) + t.end() }) - - tape('should set connect to false', function(t) { - var shouldTimeout = { - url: s.url + '/timeout', - timeout: 100 - } - - request(shouldTimeout, function(err, res, body) { - checkErrCode(t, err) - t.ok(err.connect === false, 'Read Timeout Error should set \'connect\' property to false') - t.end() - }) +}) + +tape('should set connect to false', function(t) { + var shouldTimeout = { + url: s.url + '/timeout', + timeout: 100 + } + + request(shouldTimeout, function(err, res, body) { + checkErrCode(t, err) + t.ok(err.connect === false, 'Read Timeout Error should set \'connect\' property to false') + t.end() }) +}) - tape('should timeout with events', function(t) { - t.plan(3) - - var shouldTimeoutWithEvents = { - url: s.url + '/timeout', - timeout: 100 - } - - var eventsEmitted = 0 - request(shouldTimeoutWithEvents) - .on('error', function(err) { - eventsEmitted++ - t.equal(1, eventsEmitted) - checkErrCode(t, err) - }) - }) +tape('should timeout with events', function(t) { + t.plan(3) - tape('should not timeout', function(t) { - var shouldntTimeout = { - url: s.url + '/timeout', - timeout: 1200 - } + var shouldTimeoutWithEvents = { + url: s.url + '/timeout', + timeout: 100 + } - request(shouldntTimeout, function(err, res, body) { - t.equal(err, null) - t.equal(body, 'waited') - t.end() + var eventsEmitted = 0 + request(shouldTimeoutWithEvents) + .on('error', function(err) { + eventsEmitted++ + t.equal(1, eventsEmitted) + checkErrCode(t, err) }) +}) + +tape('should not timeout', function(t) { + var shouldntTimeout = { + url: s.url + '/timeout', + timeout: 1200 + } + + request(shouldntTimeout, function(err, res, body) { + t.equal(err, null) + t.equal(body, 'waited') + t.end() }) +}) - tape('no timeout', function(t) { - var noTimeout = { - url: s.url + '/timeout' - } +tape('no timeout', function(t) { + var noTimeout = { + url: s.url + '/timeout' + } - request(noTimeout, function(err, res, body) { - t.equal(err, null) - t.equal(body, 'waited') - t.end() - }) + request(noTimeout, function(err, res, body) { + t.equal(err, null) + t.equal(body, 'waited') + t.end() }) - - tape('negative timeout', function(t) { // should be treated a zero or the minimum delay - var negativeTimeout = { - url: s.url + '/timeout', - timeout: -1000 - } - - request(negativeTimeout, function(err, res, body) { +}) + +tape('negative timeout', function(t) { // should be treated a zero or the minimum delay + var negativeTimeout = { + url: s.url + '/timeout', + timeout: -1000 + } + + request(negativeTimeout, function(err, res, body) { + // Only verify error if it is set, since using a timeout value of 0 can lead + // to inconsistent results, depending on a variety of factors + if (err) { checkErrCode(t, err) - t.end() - }) + } + t.end() }) +}) - tape('float timeout', function(t) { // should be rounded by setTimeout anyway - var floatTimeout = { - url: s.url + '/timeout', - timeout: 100.76 - } +tape('float timeout', function(t) { // should be rounded by setTimeout anyway + var floatTimeout = { + url: s.url + '/timeout', + timeout: 100.76 + } - request(floatTimeout, function(err, res, body) { - checkErrCode(t, err) - t.end() - }) + request(floatTimeout, function(err, res, body) { + checkErrCode(t, err) + t.end() }) - - tape('connect timeout', function(t) { - // We need a destination that will not immediately return a TCP Reset - // packet. StackOverflow suggests this host: - // https://stackoverflow.com/a/904609/329700 - var tarpitHost = 'http://10.255.255.1' - var shouldConnectTimeout = { - url: tarpitHost + '/timeout', - timeout: 100 - } - request(shouldConnectTimeout, function(err) { - checkErrCode(t, err) - t.ok(err.connect === true, 'Connect Timeout Error should set \'connect\' property to true') - t.end() - }) +}) + +tape('connect timeout', function(t) { + // We need a destination that will not immediately return a TCP Reset + // packet. StackOverflow suggests this host: + // https://stackoverflow.com/a/904609/329700 + var tarpitHost = 'http://10.255.255.1' + var shouldConnectTimeout = { + url: tarpitHost + '/timeout', + timeout: 100 + } + request(shouldConnectTimeout, function(err) { + checkErrCode(t, err) + t.ok(err.connect === true, 'Connect Timeout Error should set \'connect\' property to true') + t.end() }) +}) - tape('cleanup', function(t) { - s.close(function() { - t.end() - }) +tape('cleanup', function(t) { + s.close(function() { + t.end() }) -} +}) From 95b743f271e021548fccea942a4a9ab3f23ef1f9 Mon Sep 17 00:00:00 2001 From: Brian White Date: Fri, 14 Oct 2016 04:18:24 -0400 Subject: [PATCH 353/490] Use random ports for servers used in tests Not only does this avoid problems with the fixed port already being used on the local system, but it could also avoid cascading test failures and potential race conditions between tests. --- tests/browser/karma.conf.js | 1 + tests/browser/start.js | 8 +- tests/browser/test.js | 2 +- tests/server.js | 34 +- tests/ssl/ca/localhost.js | 36 +- tests/ssl/ca/server.js | 38 +- tests/test-agent.js | 18 +- tests/test-agentOptions.js | 20 +- tests/test-api.js | 7 +- tests/test-aws.js | 2 +- tests/test-baseUrl.js | 91 +++-- tests/test-basic-auth.js | 23 +- tests/test-bearer-auth.js | 22 +- tests/test-body.js | 6 +- tests/test-cookies.js | 12 +- tests/test-defaults.js | 2 +- tests/test-digest-auth.js | 11 +- tests/test-emptyBody.js | 9 +- tests/test-errors.js | 2 +- tests/test-event-forwarding.js | 2 +- tests/test-follow-all-303.js | 5 +- tests/test-follow-all.js | 5 +- tests/test-form-data-error.js | 4 +- tests/test-form-data.js | 10 +- tests/test-form-urlencoded.js | 6 +- tests/test-form.js | 10 +- tests/test-gzip.js | 27 +- tests/test-har.js | 2 +- tests/test-hawk.js | 5 +- tests/test-headers.js | 114 +++--- tests/test-http-signature.js | 7 +- tests/test-httpModule.js | 4 +- tests/test-https.js | 4 +- tests/test-isUrl.js | 20 +- tests/test-json-request.js | 2 +- tests/test-multipart-encoding.js | 5 +- tests/test-multipart.js | 10 +- tests/test-node-debug.js | 12 +- tests/test-oauth.js | 25 +- tests/test-onelineproxy.js | 9 +- tests/test-option-reuse.js | 5 +- tests/test-params.js | 2 +- tests/test-piped-redirect.js | 10 +- tests/test-pipes.js | 2 +- tests/test-pool.js | 23 +- tests/test-promise.js | 9 +- tests/test-proxy-connect.js | 8 +- tests/test-proxy.js | 400 +++++++++--------- tests/test-redirect-auth.js | 80 ++-- tests/test-redirect-complex.js | 6 +- tests/test-redirect.js | 4 +- tests/test-rfc3986.js | 6 +- tests/test-stream.js | 7 +- tests/test-timeout.js | 2 +- tests/test-timing.js | 2 +- tests/test-toJSON.js | 5 +- tests/test-tunnel.js | 678 +++++++++++++++---------------- 57 files changed, 967 insertions(+), 914 deletions(-) diff --git a/tests/browser/karma.conf.js b/tests/browser/karma.conf.js index 6c9311bb0..4c9172471 100644 --- a/tests/browser/karma.conf.js +++ b/tests/browser/karma.conf.js @@ -3,6 +3,7 @@ var istanbul = require('browserify-istanbul') module.exports = function(config) { config.set({ + client: { requestTestUrl: process.argv[4] }, basePath: '../..', frameworks: ['tap', 'browserify'], preprocessors: { diff --git a/tests/browser/start.js b/tests/browser/start.js index 2d8fbeae2..8ada016f8 100644 --- a/tests/browser/start.js +++ b/tests/browser/start.js @@ -4,8 +4,6 @@ var https = require('https') var fs = require('fs') var path = require('path') -var port = 6767 - var server = https.createServer({ key: fs.readFileSync(path.join(__dirname, '/ssl/server.key')), cert: fs.readFileSync(path.join(__dirname, '/ssl/server.crt')), @@ -18,12 +16,14 @@ var server = https.createServer({ res.writeHead(200) res.end('Can you hear the sound of an enormous door slamming in the depths of hell?\n') }) -server.listen(port, function() { +server.listen(0, function() { + var port = this.address().port console.log('Started https server for karma tests on port ' + port) // Spawn process for karma. var c = spawn('karma', [ 'start', - path.join(__dirname, '/karma.conf.js') + path.join(__dirname, '/karma.conf.js'), + 'https://localhost:' + port ]) c.stdout.pipe(process.stdout) c.stderr.pipe(process.stderr) diff --git a/tests/browser/test.js b/tests/browser/test.js index 2310195a1..6ee8f7815 100644 --- a/tests/browser/test.js +++ b/tests/browser/test.js @@ -26,7 +26,7 @@ tape('returns on error', function(t) { tape('succeeds on valid URLs (with https and CORS)', function(t) { t.plan(1) request({ - uri: 'https://localhost:6767', + uri: __karma__.config.requestTestUrl, withCredentials: false }, function (error, response) { t.equal(response.statusCode, 200) diff --git a/tests/server.js b/tests/server.js index 7c2218c33..10a667bc1 100644 --- a/tests/server.js +++ b/tests/server.js @@ -7,22 +7,20 @@ var fs = require('fs') , stream = require('stream') , assert = require('assert') -exports.port = 6767 -exports.portSSL = 16167 - -exports.createServer = function (port) { - port = port || exports.port +exports.createServer = function () { var s = http.createServer(function (req, resp) { s.emit(req.url.replace(/(\?.*)/, ''), req, resp) }) - s.port = port - s.url = 'http://localhost:' + port + s.on('listening', function () { + s.port = this.address().port + s.url = 'http://localhost:' + s.port + }) + s.port = 0 s.protocol = 'http' return s } -exports.createEchoServer = function (port) { - port = port || exports.port +exports.createEchoServer = function () { var s = http.createServer(function (req, resp) { var b = '' req.on('data', function (chunk) {b += chunk}) @@ -37,15 +35,16 @@ exports.createEchoServer = function (port) { resp.end() }) }) - s.port = port - s.url = 'http://localhost:' + port + s.on('listening', function () { + s.port = this.address().port + s.url = 'http://localhost:' + s.port + }) + s.port = 0 s.protocol = 'http' return s } -exports.createSSLServer = function(port, opts) { - port = port || exports.portSSL - +exports.createSSLServer = function(opts) { var i , options = { 'key' : path.join(__dirname, 'ssl', 'test.key') , 'cert': path.join(__dirname, 'ssl', 'test.crt') @@ -65,8 +64,11 @@ exports.createSSLServer = function(port, opts) { var s = https.createServer(options, function (req, resp) { s.emit(req.url, req, resp) }) - s.port = port - s.url = 'https://localhost:' + port + s.on('listening', function () { + s.port = this.address().port + s.url = 'https://localhost:' + s.port + }) + s.port = 0 s.protocol = 'https' return s } diff --git a/tests/ssl/ca/localhost.js b/tests/ssl/ca/localhost.js index c40fb1aa4..8ba3358c6 100644 --- a/tests/ssl/ca/localhost.js +++ b/tests/ssl/ca/localhost.js @@ -10,20 +10,24 @@ var server = https.createServer(options, function (req, res) { res.end() server.close() }) -server.listen(1337) +server.listen(0, function() { + var ca = fs.readFileSync('./ca.crt') + var agent = new https.Agent({ + host: 'localhost', + port: this.address().port, + ca: ca + }) -var ca = fs.readFileSync('./ca.crt') -var agent = new https.Agent({ host: 'localhost', port: 1337, ca: ca }) - -https.request({ host: 'localhost' - , method: 'HEAD' - , port: 1337 - , agent: agent - , ca: [ ca ] - , path: '/' }, function (res) { - if (res.socket.authorized) { - console.log('node test: OK') - } else { - throw new Error(res.socket.authorizationError) - } -}).end() + https.request({ host: 'localhost' + , method: 'HEAD' + , port: this.address().port + , agent: agent + , ca: [ ca ] + , path: '/' }, function (res) { + if (res.socket.authorized) { + console.log('node test: OK') + } else { + throw new Error(res.socket.authorizationError) + } + }).end() +}) diff --git a/tests/ssl/ca/server.js b/tests/ssl/ca/server.js index c47ce4ca5..934554540 100644 --- a/tests/ssl/ca/server.js +++ b/tests/ssl/ca/server.js @@ -10,21 +10,25 @@ var server = https.createServer(options, function (req, res) { res.end() server.close() }) -server.listen(1337) +server.listen(0, function() { + var ca = fs.readFileSync('./ca.crt') + var agent = new https.Agent({ + host: 'localhost', + port: this.address().port, + ca: ca + }) -var ca = fs.readFileSync('./ca.crt') -var agent = new https.Agent({ host: 'localhost', port: 1337, ca: ca }) - -https.request({ host: 'localhost' - , method: 'HEAD' - , port: 1337 - , headers: { host: 'testing.request.mikealrogers.com' } - , agent: agent - , ca: [ ca ] - , path: '/' }, function (res) { - if (res.socket.authorized) { - console.log('node test: OK') - } else { - throw new Error(res.socket.authorizationError) - } -}).end() + https.request({ host: 'localhost' + , method: 'HEAD' + , port: this.address().port + , headers: { host: 'testing.request.mikealrogers.com' } + , agent: agent + , ca: [ ca ] + , path: '/' }, function (res) { + if (res.socket.authorized) { + console.log('node test: OK') + } else { + throw new Error(res.socket.authorizationError) + } + }).end() +}) diff --git a/tests/test-agent.js b/tests/test-agent.js index 8d18d35c6..3bebf446d 100644 --- a/tests/test-agent.js +++ b/tests/test-agent.js @@ -12,7 +12,9 @@ var s = http.createServer(function (req, res) { }) tape('setup', function (t) { - s.listen(6767, function() { + s.listen(0, function() { + s.port = this.address().port + s.url = 'http://localhost:' + s.port t.end() }) }) @@ -25,8 +27,8 @@ function httpAgent (t, options, req) { t.equal(Object.keys(r.agent.sockets).length, 1, '1 socket name') var name = (typeof r.agent.getName === 'function') - ? r.agent.getName({port:6767}) - : 'localhost:6767' // node 0.10- + ? r.agent.getName({port:s.port}) + : 'localhost:' + s.port // node 0.10- t.equal(r.agent.sockets[name].length, 1, '1 open socket') var socket = r.agent.sockets[name][0] @@ -44,7 +46,7 @@ function foreverAgent (t, options, req) { t.ok(r.agent instanceof ForeverAgent, 'is ForeverAgent') t.equal(Object.keys(r.agent.sockets).length, 1, '1 socket name') - var name = 'localhost:6767' // node 0.10- + var name = 'localhost:' + s.port // node 0.10- t.equal(r.agent.sockets[name].length, 1, '1 open socket') var socket = r.agent.sockets[name][0] @@ -60,14 +62,14 @@ function foreverAgent (t, options, req) { tape('options.agent', function (t) { httpAgent(t, { - uri: 'http://localhost:6767', + uri: s.url, agent: new http.Agent({keepAlive: true}) }) }) tape('options.agentClass + options.agentOptions', function (t) { httpAgent(t, { - uri: 'http://localhost:6767', + uri: s.url, agentClass: http.Agent, agentOptions: {keepAlive: true} }) @@ -78,7 +80,7 @@ tape('options.agentClass + options.agentOptions', function (t) { tape('options.forever = true', function (t) { var v = version() var options = { - uri: 'http://localhost:6767', + uri: s.url, forever: true } @@ -89,7 +91,7 @@ tape('options.forever = true', function (t) { tape('forever() method', function (t) { var v = version() var options = { - uri: 'http://localhost:6767' + uri: s.url } var r = request.forever({maxSockets: 1}) diff --git a/tests/test-agentOptions.js b/tests/test-agentOptions.js index 97cf46f6d..28a997c10 100644 --- a/tests/test-agentOptions.js +++ b/tests/test-agentOptions.js @@ -11,22 +11,23 @@ var request = require('../index') , server = require('./server') , tape = require('tape') -var s = server.createServer(function (req, resp) { +var s = server.createServer() + +s.on('/', function (req, resp) { resp.statusCode = 200 resp.end('') }) tape('setup', function(t) { - s.listen(s.port, function() { + s.listen(0, function() { t.end() }) }) tape('without agentOptions should use global agent', function(t) { - var r = request(s.url, function(/*err, res, body*/) { - // TODO: figure out why err.code === 'ECONNREFUSED' on Travis? - //if (err) console.log(err) - //t.equal(err, null) + var r = request(s.url, function(err, res, body) { + t.equal(err, null) + t.equal(res.statusCode, 200) t.deepEqual(r.agent, http.globalAgent) t.equal(Object.keys(r.pool).length, 0) t.end() @@ -36,10 +37,9 @@ tape('without agentOptions should use global agent', function(t) { tape('with agentOptions should apply to new agent in pool', function(t) { var r = request(s.url, { agentOptions: { foo: 'bar' } - }, function(/*err, res, body*/) { - // TODO: figure out why err.code === 'ECONNREFUSED' on Travis? - //if (err) console.log(err) - //t.equal(err, null) + }, function(err, res, body) { + t.equal(err, null) + t.equal(res.statusCode, 200) t.equal(r.agent.options.foo, 'bar') t.equal(Object.keys(r.pool).length, 1) t.end() diff --git a/tests/test-api.js b/tests/test-api.js index a01ee60c2..9471c5fc5 100644 --- a/tests/test-api.js +++ b/tests/test-api.js @@ -12,12 +12,15 @@ tape('setup', function (t) { res.writeHead(202) req.pipe(res) }) - server.listen(6767, t.end) + server.listen(0, function() { + server.url = 'http://localhost:' + this.address().port + t.end() + }) }) tape('callback option', function (t) { request({ - url: 'http://localhost:6767', + url: server.url, callback: function (err, res, body) { t.equal(res.statusCode, 202) t.end() diff --git a/tests/test-aws.js b/tests/test-aws.js index be4314349..cef7c74fb 100644 --- a/tests/test-aws.js +++ b/tests/test-aws.js @@ -16,7 +16,7 @@ s.on(path, function(req, res) { }) tape('setup', function(t) { - s.listen(s.port, function() { + s.listen(0, function() { t.end() }) }) diff --git a/tests/test-baseUrl.js b/tests/test-baseUrl.js index fb523eadd..7b5d034ea 100644 --- a/tests/test-baseUrl.js +++ b/tests/test-baseUrl.js @@ -17,15 +17,52 @@ var s = http.createServer(function(req, res) { res.end('ok') }) +function addTest(baseUrl, uri, expected) { + tape('test baseurl="' + baseUrl + '" uri="' + uri + '"', function(t) { + request(uri, { baseUrl: baseUrl }, function(err, resp, body) { + t.equal(err, null) + t.equal(body, 'ok') + t.equal(resp.headers['x-path'], expected) + t.end() + }) + }) +} + +function addTests() { + addTest(s.url, '', '/') + addTest(s.url + '/', '', '/') + addTest(s.url, '/', '/') + addTest(s.url + '/', '/', '/') + addTest(s.url + '/api', '', '/api') + addTest(s.url + '/api/', '', '/api/') + addTest(s.url + '/api', '/', '/api/') + addTest(s.url + '/api/', '/', '/api/') + addTest(s.url + '/api', 'resource', '/api/resource') + addTest(s.url + '/api/', 'resource', '/api/resource') + addTest(s.url + '/api', '/resource', '/api/resource') + addTest(s.url + '/api/', '/resource', '/api/resource') + addTest(s.url + '/api', 'resource/', '/api/resource/') + addTest(s.url + '/api/', 'resource/', '/api/resource/') + addTest(s.url + '/api', '/resource/', '/api/resource/') + addTest(s.url + '/api/', '/resource/', '/api/resource/') +} + tape('setup', function(t) { - s.listen(6767, function() { + s.listen(0, function() { + s.url = 'http://localhost:' + this.address().port + addTests() + tape('cleanup', function(t) { + s.close(function() { + t.end() + }) + }) t.end() }) }) tape('baseUrl', function(t) { request('resource', { - baseUrl: 'http://localhost:6767' + baseUrl: s.url }, function(err, resp, body) { t.equal(err, null) t.equal(body, 'ok') @@ -35,7 +72,7 @@ tape('baseUrl', function(t) { tape('baseUrl defaults', function(t) { var withDefaults = request.defaults({ - baseUrl: 'http://localhost:6767' + baseUrl: s.url }) withDefaults('resource', function(err, resp, body) { t.equal(err, null) @@ -46,7 +83,7 @@ tape('baseUrl defaults', function(t) { tape('baseUrl and redirects', function(t) { request('/', { - baseUrl: 'http://localhost:6767/redirect' + baseUrl: s.url + '/redirect' }, function(err, resp, body) { t.equal(err, null) t.equal(body, 'ok') @@ -55,37 +92,9 @@ tape('baseUrl and redirects', function(t) { }) }) -function addTest(baseUrl, uri, expected) { - tape('test baseurl="' + baseUrl + '" uri="' + uri + '"', function(t) { - request(uri, { baseUrl: baseUrl }, function(err, resp, body) { - t.equal(err, null) - t.equal(body, 'ok') - t.equal(resp.headers['x-path'], expected) - t.end() - }) - }) -} - -addTest('http://localhost:6767', '', '/') -addTest('http://localhost:6767/', '', '/') -addTest('http://localhost:6767', '/', '/') -addTest('http://localhost:6767/', '/', '/') -addTest('http://localhost:6767/api', '', '/api') -addTest('http://localhost:6767/api/', '', '/api/') -addTest('http://localhost:6767/api', '/', '/api/') -addTest('http://localhost:6767/api/', '/', '/api/') -addTest('http://localhost:6767/api', 'resource', '/api/resource') -addTest('http://localhost:6767/api/', 'resource', '/api/resource') -addTest('http://localhost:6767/api', '/resource', '/api/resource') -addTest('http://localhost:6767/api/', '/resource', '/api/resource') -addTest('http://localhost:6767/api', 'resource/', '/api/resource/') -addTest('http://localhost:6767/api/', 'resource/', '/api/resource/') -addTest('http://localhost:6767/api', '/resource/', '/api/resource/') -addTest('http://localhost:6767/api/', '/resource/', '/api/resource/') - tape('error when baseUrl is not a String', function(t) { request('resource', { - baseUrl: url.parse('http://localhost:6767/path') + baseUrl: url.parse(s.url + '/path') }, function(err, resp, body) { t.notEqual(err, null) t.equal(err.message, 'options.baseUrl must be a string') @@ -95,7 +104,7 @@ tape('error when baseUrl is not a String', function(t) { tape('error when uri is not a String', function(t) { request(url.parse('resource'), { - baseUrl: 'http://localhost:6767/path' + baseUrl: s.url + '/path' }, function(err, resp, body) { t.notEqual(err, null) t.equal(err.message, 'options.uri must be a string when using options.baseUrl') @@ -104,8 +113,8 @@ tape('error when uri is not a String', function(t) { }) tape('error on baseUrl and uri with scheme', function(t) { - request('http://localhost:6767/path/ignoring/baseUrl', { - baseUrl: 'http://localhost:6767/path/' + request(s.url + '/path/ignoring/baseUrl', { + baseUrl: s.url + '/path/' }, function(err, resp, body) { t.notEqual(err, null) t.equal(err.message, 'options.uri must be a path when using options.baseUrl') @@ -114,17 +123,11 @@ tape('error on baseUrl and uri with scheme', function(t) { }) tape('error on baseUrl and uri with scheme-relative url', function(t) { - request('//localhost:6767/path/ignoring/baseUrl', { - baseUrl: 'http://localhost:6767/path/' + request(s.url.slice('http:'.length) + '/path/ignoring/baseUrl', { + baseUrl: s.url + '/path/' }, function(err, resp, body) { t.notEqual(err, null) t.equal(err.message, 'options.uri must be a path when using options.baseUrl') t.end() }) }) - -tape('cleanup', function(t) { - s.close(function() { - t.end() - }) -}) diff --git a/tests/test-basic-auth.js b/tests/test-basic-auth.js index 551092d86..983e3fc54 100644 --- a/tests/test-basic-auth.js +++ b/tests/test-basic-auth.js @@ -7,7 +7,6 @@ var assert = require('assert') var numBasicRequests = 0 , basicServer - , port = 6767 tape('setup', function(t) { basicServer = http.createServer(function (req, res) { @@ -50,7 +49,9 @@ tape('setup', function(t) { res.statusCode = 401 res.end('401') } - }).listen(port, function() { + }).listen(0, function() { + basicServer.port = this.address().port + basicServer.url = 'http://localhost:' + basicServer.port t.end() }) }) @@ -58,7 +59,7 @@ tape('setup', function(t) { tape('sendImmediately - false', function(t) { var r = request({ 'method': 'GET', - 'uri': 'http://localhost:6767/test/', + 'uri': basicServer.url + '/test/', 'auth': { 'user': 'user', 'pass': 'pass', @@ -76,7 +77,7 @@ tape('sendImmediately - true', function(t) { // If we don't set sendImmediately = false, request will send basic auth var r = request({ 'method': 'GET', - 'uri': 'http://localhost:6767/test2/', + 'uri': basicServer.url + '/test2/', 'auth': { 'user': 'user', 'pass': 'pass' @@ -92,7 +93,7 @@ tape('sendImmediately - true', function(t) { tape('credentials in url', function(t) { var r = request({ 'method': 'GET', - 'uri': 'http://user:pass@localhost:6767/test2/' + 'uri': basicServer.url.replace(/:\/\//, '$&user:pass@') + '/test2/' }, function(error, res, body) { t.equal(r._auth.user, 'user') t.equal(res.statusCode, 200) @@ -105,7 +106,7 @@ tape('POST request', function(t) { var r = request({ 'method': 'POST', 'form': { 'key': 'value' }, - 'uri': 'http://localhost:6767/post/', + 'uri': basicServer.url + '/post/', 'auth': { 'user': 'user', 'pass': 'pass', @@ -123,7 +124,7 @@ tape('user - empty string', function(t) { t.doesNotThrow( function() { var r = request({ 'method': 'GET', - 'uri': 'http://localhost:6767/allow_empty_user/', + 'uri': basicServer.url + '/allow_empty_user/', 'auth': { 'user': '', 'pass': 'pass', @@ -142,7 +143,7 @@ tape('pass - undefined', function(t) { t.doesNotThrow( function() { var r = request({ 'method': 'GET', - 'uri': 'http://localhost:6767/allow_undefined_password/', + 'uri': basicServer.url + '/allow_undefined_password/', 'auth': { 'user': 'user', 'pass': undefined, @@ -162,7 +163,7 @@ tape('pass - utf8', function(t) { t.doesNotThrow( function() { var r = request({ 'method': 'GET', - 'uri': 'http://localhost:6767/allow_undefined_password/', + 'uri': basicServer.url + '/allow_undefined_password/', 'auth': { 'user': 'user', 'pass': 'pâss', @@ -180,7 +181,7 @@ tape('pass - utf8', function(t) { tape('auth method', function(t) { var r = request - .get('http://localhost:6767/test/') + .get(basicServer.url + '/test/') .auth('user', '', false) .on('response', function (res) { t.equal(r._auth.user, 'user') @@ -191,7 +192,7 @@ tape('auth method', function(t) { }) tape('get method', function(t) { - var r = request.get('http://localhost:6767/test/', + var r = request.get(basicServer.url + '/test/', { auth: { user: 'user', diff --git a/tests/test-bearer-auth.js b/tests/test-bearer-auth.js index 2417fa8f9..8519c6131 100644 --- a/tests/test-bearer-auth.js +++ b/tests/test-bearer-auth.js @@ -7,7 +7,6 @@ var assert = require('assert') var numBearerRequests = 0 , bearerServer - , port = 6767 tape('setup', function(t) { bearerServer = http.createServer(function (req, res) { @@ -44,7 +43,8 @@ tape('setup', function(t) { res.statusCode = 401 res.end('401') } - }).listen(port, function() { + }).listen(0, function() { + bearerServer.url = 'http://localhost:' + this.address().port t.end() }) }) @@ -52,7 +52,7 @@ tape('setup', function(t) { tape('bearer auth', function(t) { request({ 'method': 'GET', - 'uri': 'http://localhost:6767/test/', + 'uri': bearerServer.url + '/test/', 'auth': { 'bearer': 'theToken', 'sendImmediately': false @@ -68,7 +68,7 @@ tape('bearer auth with default sendImmediately', function(t) { // If we don't set sendImmediately = false, request will send bearer auth request({ 'method': 'GET', - 'uri': 'http://localhost:6767/test2/', + 'uri': bearerServer.url + '/test2/', 'auth': { 'bearer': 'theToken' } @@ -83,7 +83,7 @@ tape('', function(t) { request({ 'method': 'POST', 'form': { 'data_key': 'data_value' }, - 'uri': 'http://localhost:6767/post/', + 'uri': bearerServer.url + '/post/', 'auth': { 'bearer': 'theToken', 'sendImmediately': false @@ -97,7 +97,7 @@ tape('', function(t) { tape('using .auth, sendImmediately = false', function(t) { request - .get('http://localhost:6767/test/') + .get(bearerServer.url + '/test/') .auth(null, null, false, 'theToken') .on('response', function (res) { t.equal(res.statusCode, 200) @@ -108,7 +108,7 @@ tape('using .auth, sendImmediately = false', function(t) { tape('using .auth, sendImmediately = true', function(t) { request - .get('http://localhost:6767/test/') + .get(bearerServer.url + '/test/') .auth(null, null, true, 'theToken') .on('response', function (res) { t.equal(res.statusCode, 200) @@ -120,7 +120,7 @@ tape('using .auth, sendImmediately = true', function(t) { tape('bearer is a function', function(t) { request({ 'method': 'GET', - 'uri': 'http://localhost:6767/test/', + 'uri': bearerServer.url + '/test/', 'auth': { 'bearer': function() { return 'theToken' }, 'sendImmediately': false @@ -136,7 +136,7 @@ tape('bearer is a function, path = test2', function(t) { // If we don't set sendImmediately = false, request will send bearer auth request({ 'method': 'GET', - 'uri': 'http://localhost:6767/test2/', + 'uri': bearerServer.url + '/test2/', 'auth': { 'bearer': function() { return 'theToken' } } @@ -150,7 +150,7 @@ tape('bearer is a function, path = test2', function(t) { tape('no auth method', function(t) { request({ 'method': 'GET', - 'uri': 'http://localhost:6767/test2/', + 'uri': bearerServer.url + '/test2/', 'auth': { 'bearer': undefined } @@ -163,7 +163,7 @@ tape('no auth method', function(t) { tape('null bearer', function(t) { request({ 'method': 'GET', - 'uri': 'http://localhost:6767/test2/', + 'uri': bearerServer.url + '/test2/', 'auth': { 'bearer': null } diff --git a/tests/test-body.js b/tests/test-body.js index 2f52e2c8e..be2a67b59 100644 --- a/tests/test-body.js +++ b/tests/test-body.js @@ -8,7 +8,7 @@ var server = require('./server') var s = server.createServer() tape('setup', function(t) { - s.listen(s.port, function() { + s.listen(0, function() { t.end() }) }) @@ -150,10 +150,10 @@ tape('typed array', function (t) { server.on('request', function (req, res) { req.pipe(res) }) - server.listen(6768, function () { + server.listen(0, function () { var data = new Uint8Array([1, 2, 3]) request({ - uri: 'http://localhost:6768', + uri: 'http://localhost:' + this.address().port, method: 'POST', body: data, encoding: null diff --git a/tests/test-cookies.js b/tests/test-cookies.js index 7014935f0..8a6065927 100644 --- a/tests/test-cookies.js +++ b/tests/test-cookies.js @@ -5,9 +5,9 @@ var http = require('http') , tape = require('tape') -var validUrl = 'http://localhost:6767/valid' - , malformedUrl = 'http://localhost:6767/malformed' - , invalidUrl = 'http://localhost:6767/invalid' +var validUrl + , malformedUrl + , invalidUrl var server = http.createServer(function (req, res) { if (req.url === '/valid') { @@ -21,7 +21,11 @@ var server = http.createServer(function (req, res) { }) tape('setup', function(t) { - server.listen(6767, function() { + server.listen(0, function() { + server.url = 'http://localhost:' + this.address().port + validUrl = server.url + '/valid' + malformedUrl = server.url + '/malformed' + invalidUrl = server.url + '/invalid' t.end() }) }) diff --git a/tests/test-defaults.js b/tests/test-defaults.js index afe845e16..0fc578e7b 100644 --- a/tests/test-defaults.js +++ b/tests/test-defaults.js @@ -8,7 +8,7 @@ var server = require('./server') var s = server.createServer() tape('setup', function(t) { - s.listen(s.port, function() { + s.listen(0, function() { s.on('/', function (req, res) { res.writeHead(200, {'content-type': 'application/json'}) res.end(JSON.stringify({ diff --git a/tests/test-digest-auth.js b/tests/test-digest-auth.js index c05fea97d..b5801ca61 100644 --- a/tests/test-digest-auth.js +++ b/tests/test-digest-auth.js @@ -132,7 +132,8 @@ var digestServer = http.createServer(function(req, res) { }) tape('setup', function(t) { - digestServer.listen(6767, function() { + digestServer.listen(0, function() { + digestServer.url = 'http://localhost:' + this.address().port t.end() }) }) @@ -142,7 +143,7 @@ tape('with sendImmediately = false', function(t) { request({ method: 'GET', - uri: 'http://localhost:6767/test/', + uri: digestServer.url + '/test/', auth: { user: 'test', pass: 'testing', @@ -164,7 +165,7 @@ tape('with MD5-sess algorithm', function(t) { request({ method: 'GET', - uri: 'http://localhost:6767/test/md5-sess', + uri: digestServer.url + '/test/md5-sess', auth: { user: 'test', pass: 'testing', @@ -187,7 +188,7 @@ tape('without sendImmediately = false', function(t) { // If we don't set sendImmediately = false, request will send basic auth request({ method: 'GET', - uri: 'http://localhost:6767/test/', + uri: digestServer.url + '/test/', auth: { user: 'test', pass: 'testing' @@ -208,7 +209,7 @@ tape('with different credentials', function(t) { request({ method: 'GET', - uri: 'http://localhost:6767/dir/index.html', + uri: digestServer.url + '/dir/index.html', auth: { user: 'Mufasa', pass: 'CircleOfLife', diff --git a/tests/test-emptyBody.js b/tests/test-emptyBody.js index 0e4acc55f..412e93229 100644 --- a/tests/test-emptyBody.js +++ b/tests/test-emptyBody.js @@ -10,13 +10,14 @@ var s = http.createServer(function (req, resp) { }) tape('setup', function(t) { - s.listen(6767, function() { + s.listen(0, function() { + s.url = 'http://localhost:' + this.address().port t.end() }) }) tape('empty body with encoding', function(t) { - request('http://localhost:6767', function(err, res, body) { + request(s.url, function(err, res, body) { t.equal(err, null) t.equal(res.statusCode, 200) t.equal(body, '') @@ -26,7 +27,7 @@ tape('empty body with encoding', function(t) { tape('empty body without encoding', function(t) { request({ - url: 'http://localhost:6767', + url: s.url, encoding: null }, function(err, res, body) { t.equal(err, null) @@ -38,7 +39,7 @@ tape('empty body without encoding', function(t) { tape('empty JSON body', function(t) { request({ - url: 'http://localhost:6767', + url: s.url, json: {} }, function(err, res, body) { t.equal(err, null) diff --git a/tests/test-errors.js b/tests/test-errors.js index bfd7c4962..9adc0a0ee 100644 --- a/tests/test-errors.js +++ b/tests/test-errors.js @@ -3,7 +3,7 @@ var request = require('../index') , tape = require('tape') -var local = 'http://localhost:8888/asdf' +var local = 'http://localhost:0/asdf' tape('without uri', function(t) { t.throws(function() { diff --git a/tests/test-event-forwarding.js b/tests/test-event-forwarding.js index ebaad4c0d..3c2086eb3 100644 --- a/tests/test-event-forwarding.js +++ b/tests/test-event-forwarding.js @@ -7,7 +7,7 @@ var server = require('./server') var s = server.createServer() tape('setup', function(t) { - s.listen(s.port, function() { + s.listen(0, function() { s.on('/', function(req, res) { res.writeHead(200, { 'content-type': 'text/plain' }) res.write('waited') diff --git a/tests/test-follow-all-303.js b/tests/test-follow-all-303.js index 5e73db258..2110146fc 100644 --- a/tests/test-follow-all-303.js +++ b/tests/test-follow-all-303.js @@ -15,7 +15,8 @@ var server = http.createServer(function (req, res) { }) tape('setup', function(t) { - server.listen(6767, function() { + server.listen(0, function() { + server.url = 'http://localhost:' + this.address().port t.end() }) }) @@ -24,7 +25,7 @@ tape('followAllRedirects with 303', function(t) { var redirects = 0 request.post({ - url: 'http://localhost:6767/foo', + url: server.url + '/foo', followAllRedirects: true, form: { foo: 'bar' } }, function (err, res, body) { diff --git a/tests/test-follow-all.js b/tests/test-follow-all.js index d6e00d064..e8054cafb 100644 --- a/tests/test-follow-all.js +++ b/tests/test-follow-all.js @@ -26,7 +26,8 @@ var server = http.createServer(function (req, res) { }) tape('setup', function(t) { - server.listen(6767, function() { + server.listen(0, function() { + server.url = 'http://localhost:' + this.address().port t.end() }) }) @@ -35,7 +36,7 @@ tape('followAllRedirects', function(t) { var redirects = 0 request.post({ - url: 'http://localhost:6767/foo', + url: server.url + '/foo', followAllRedirects: true, jar: true, form: { foo: 'bar' } diff --git a/tests/test-form-data-error.js b/tests/test-form-data-error.js index 09beb317e..d5d6f2a5d 100644 --- a/tests/test-form-data-error.js +++ b/tests/test-form-data-error.js @@ -7,7 +7,7 @@ var request = require('../index') var s = server.createServer() tape('setup', function(t) { - s.listen(s.port, function() { + s.listen(0, function() { t.end() }) }) @@ -70,7 +70,7 @@ tape('form-data should throw on null value', function (t) { t.throws(function () { request({ method: 'POST', - url: 'http://localhost:6767', + url: s.url, formData: { key: null } diff --git a/tests/test-form-data.js b/tests/test-form-data.js index 0c7ca97d9..fbfc8c5e2 100644 --- a/tests/test-form-data.js +++ b/tests/test-form-data.js @@ -71,7 +71,7 @@ function runTest(t, options) { t.ok( data.indexOf('form-data; name="batch"') !== -1 ) t.ok( data.match(/form-data; name="batch"/g).length === 2 ) - // check for http://localhost:6767/file traces + // check for http://localhost:nnnn/file traces t.ok( data.indexOf('Photoshop ICC') !== -1 ) t.ok( data.indexOf('Content-Type: ' + mime.lookup(remoteFile) ) !== -1 ) @@ -80,13 +80,13 @@ function runTest(t, options) { }) }) - server.listen(6767, function() { - + server.listen(0, function() { + var url = 'http://localhost:' + this.address().port // @NOTE: multipartFormData properties must be set here so that my_file read stream does not leak in node v0.8 multipartFormData.my_field = 'my_value' multipartFormData.my_buffer = new Buffer([1, 2, 3]) multipartFormData.my_file = fs.createReadStream(localFile) - multipartFormData.remote_file = request('http://localhost:6767/file') + multipartFormData.remote_file = request(url + '/file') multipartFormData.secret_file = { value: fs.createReadStream(localFile), options: { @@ -100,7 +100,7 @@ function runTest(t, options) { ] var reqOptions = { - url: 'http://localhost:6767/upload', + url: url + '/upload', formData: multipartFormData } if (options.json) { diff --git a/tests/test-form-urlencoded.js b/tests/test-form-urlencoded.js index fdb283411..f080a27aa 100644 --- a/tests/test-form-urlencoded.js +++ b/tests/test-form-urlencoded.js @@ -32,9 +32,9 @@ function runTest (t, options, index) { }) }) - server.listen(6767, function() { - - var r = request.post('http://localhost:6767', options, function(err, res, body) { + server.listen(0, function() { + var url = 'http://localhost:' + this.address().port + var r = request.post(url, options, function(err, res, body) { t.equal(err, null) t.equal(res.statusCode, 200) t.equal(body, 'done') diff --git a/tests/test-form.js b/tests/test-form.js index 6d719409f..836ec1dfe 100644 --- a/tests/test-form.js +++ b/tests/test-form.js @@ -58,7 +58,7 @@ tape('multipart form append', function(t) { field = FIELDS.shift() t.ok( data.indexOf('form-data; name="' + field.name + '"') !== -1 ) t.ok( data.indexOf('; filename="' + path.basename(field.value.path) + '"') !== -1 ) - // check for http://localhost:6767/file traces + // check for http://localhost:nnnn/file traces t.ok( data.indexOf('Photoshop ICC') !== -1 ) t.ok( data.indexOf('Content-Type: ' + mime.lookup(remoteFile) ) !== -1 ) @@ -71,16 +71,16 @@ tape('multipart form append', function(t) { }) }) - server.listen(6767, function() { - + server.listen(0, function() { + var url = 'http://localhost:' + this.address().port FIELDS = [ { name: 'my_field', value: 'my_value' }, { name: 'my_buffer', value: new Buffer([1, 2, 3]) }, { name: 'my_file', value: fs.createReadStream(localFile) }, - { name: 'remote_file', value: request('http://localhost:6767/file') } + { name: 'remote_file', value: request(url + '/file') } ] - var req = request.post('http://localhost:6767/upload', function(err, res, body) { + var req = request.post(url + '/upload', function(err, res, body) { t.equal(err, null) t.equal(res.statusCode, 200) t.equal(body, 'done') diff --git a/tests/test-gzip.js b/tests/test-gzip.js index cf5ce48ad..7ade4aee8 100644 --- a/tests/test-gzip.js +++ b/tests/test-gzip.js @@ -78,7 +78,8 @@ tape('setup', function(t) { t.equal(err, null) testContentBigGzip = data2 - server.listen(6767, function() { + server.listen(0, function() { + server.url = 'http://localhost:' + this.address().port t.end() }) }) @@ -86,7 +87,7 @@ tape('setup', function(t) { }) tape('transparently supports gzip decoding to callbacks', function(t) { - var options = { url: 'http://localhost:6767/foo', gzip: true } + var options = { url: server.url + '/foo', gzip: true } request.get(options, function(err, res, body) { t.equal(err, null) t.equal(res.headers['content-encoding'], 'gzip') @@ -96,7 +97,7 @@ tape('transparently supports gzip decoding to callbacks', function(t) { }) tape('transparently supports gzip decoding to pipes', function(t) { - var options = { url: 'http://localhost:6767/foo', gzip: true } + var options = { url: server.url + '/foo', gzip: true } var chunks = [] request.get(options) .on('data', function(chunk) { @@ -114,7 +115,7 @@ tape('transparently supports gzip decoding to pipes', function(t) { tape('does not request gzip if user specifies Accepted-Encodings', function(t) { var headers = { 'Accept-Encoding': null } var options = { - url: 'http://localhost:6767/foo', + url: server.url + '/foo', headers: headers, gzip: true } @@ -128,7 +129,7 @@ tape('does not request gzip if user specifies Accepted-Encodings', function(t) { tape('does not decode user-requested encoding by default', function(t) { var headers = { 'Accept-Encoding': 'gzip' } - var options = { url: 'http://localhost:6767/foo', headers: headers } + var options = { url: server.url + '/foo', headers: headers } request.get(options, function(err, res, body) { t.equal(err, null) t.equal(res.headers['content-encoding'], 'gzip') @@ -140,7 +141,7 @@ tape('does not decode user-requested encoding by default', function(t) { tape('supports character encoding with gzip encoding', function(t) { var headers = { 'Accept-Encoding': 'gzip' } var options = { - url: 'http://localhost:6767/foo', + url: server.url + '/foo', headers: headers, gzip: true, encoding: 'utf8' @@ -161,7 +162,7 @@ tape('supports character encoding with gzip encoding', function(t) { }) tape('transparently supports gzip error to callbacks', function(t) { - var options = { url: 'http://localhost:6767/error', gzip: true } + var options = { url: server.url + '/error', gzip: true } request.get(options, function(err, res, body) { t.equal(err.code, 'Z_DATA_ERROR') t.equal(res, undefined) @@ -171,7 +172,7 @@ tape('transparently supports gzip error to callbacks', function(t) { }) tape('transparently supports gzip error to pipes', function(t) { - var options = { url: 'http://localhost:6767/error', gzip: true } + var options = { url: server.url + '/error', gzip: true } request.get(options) .on('data', function (/*chunk*/) { t.fail('Should not receive data event') @@ -188,7 +189,7 @@ tape('transparently supports gzip error to pipes', function(t) { tape('pause when streaming from a gzip request object', function(t) { var chunks = [] var paused = false - var options = { url: 'http://localhost:6767/chunks', gzip: true } + var options = { url: server.url + '/chunks', gzip: true } request.get(options) .on('data', function(chunk) { var self = this @@ -214,7 +215,7 @@ tape('pause when streaming from a gzip request object', function(t) { tape('pause before streaming from a gzip request object', function(t) { var paused = true - var options = { url: 'http://localhost:6767/foo', gzip: true } + var options = { url: server.url + '/foo', gzip: true } var r = request.get(options) r.pause() r.on('data', function(data) { @@ -230,7 +231,7 @@ tape('pause before streaming from a gzip request object', function(t) { }) tape('transparently supports deflate decoding to callbacks', function(t) { - var options = { url: 'http://localhost:6767/foo', gzip: true, headers: { 'Accept-Encoding': 'deflate' } } + var options = { url: server.url + '/foo', gzip: true, headers: { 'Accept-Encoding': 'deflate' } } request.get(options, function(err, res, body) { t.equal(err, null) @@ -241,7 +242,7 @@ tape('transparently supports deflate decoding to callbacks', function(t) { }) tape('do not try to pipe HEAD request responses', function(t) { - var options = { method: 'HEAD', url: 'http://localhost:6767/foo', gzip: true } + var options = { method: 'HEAD', url: server.url + '/foo', gzip: true } request(options, function(err, res, body) { t.equal(err, null) @@ -251,7 +252,7 @@ tape('do not try to pipe HEAD request responses', function(t) { }) tape('do not try to pipe responses with no body', function(t) { - var options = { url: 'http://localhost:6767/foo', gzip: true } + var options = { url: server.url + '/foo', gzip: true } options.headers = {code: 105} request.post(options, function(err, res, body) { diff --git a/tests/test-har.js b/tests/test-har.js index f0dca791c..61f0d7d63 100644 --- a/tests/test-har.js +++ b/tests/test-har.js @@ -9,7 +9,7 @@ var server = require('./server') var s = server.createEchoServer() tape('setup', function (t) { - s.listen(s.port, function () { + s.listen(0, function () { t.end() }) }) diff --git a/tests/test-hawk.js b/tests/test-hawk.js index bd0ac1d2e..f0aa1d56b 100644 --- a/tests/test-hawk.js +++ b/tests/test-hawk.js @@ -26,7 +26,8 @@ var server = http.createServer(function(req, res) { }) tape('setup', function(t) { - server.listen(6767, function() { + server.listen(0, function() { + server.url = 'http://localhost:' + this.address().port t.end() }) }) @@ -37,7 +38,7 @@ tape('hawk', function(t) { algorithm: 'sha256', id: 'dh37fgj492je' } - request('http://localhost:6767', { + request(server.url, { hawk: { credentials: creds } }, function(err, res, body) { t.equal(err, null) diff --git a/tests/test-headers.js b/tests/test-headers.js index ee893b919..53b7cb033 100644 --- a/tests/test-headers.js +++ b/tests/test-headers.js @@ -26,12 +26,6 @@ s.on('/headers.json', function(req, res) { res.end(JSON.stringify(req.headers)) }) -tape('setup', function(t) { - s.listen(s.port, function() { - t.end() - }) -}) - function runTest(name, path, requestObj, serverAssertFn) { tape(name, function(t) { s.on('/' + path, function(req, res) { @@ -48,54 +42,68 @@ function runTest(name, path, requestObj, serverAssertFn) { }) } -runTest( - '#125: headers.cookie with no cookie jar', - 'no-jar', - {headers: {cookie: 'foo=bar'}}, - function(t, req, res) { - t.equal(req.headers.cookie, 'foo=bar') - }) +function addTests() { + runTest( + '#125: headers.cookie with no cookie jar', + 'no-jar', + {headers: {cookie: 'foo=bar'}}, + function(t, req, res) { + t.equal(req.headers.cookie, 'foo=bar') + }) -var jar = request.jar() -jar.setCookie('quux=baz', s.url) -runTest( - '#125: headers.cookie + cookie jar', - 'header-and-jar', - {jar: jar, headers: {cookie: 'foo=bar'}}, - function(t, req, res) { - t.equal(req.headers.cookie, 'foo=bar; quux=baz') - }) + var jar = request.jar() + jar.setCookie('quux=baz', s.url) + runTest( + '#125: headers.cookie + cookie jar', + 'header-and-jar', + {jar: jar, headers: {cookie: 'foo=bar'}}, + function(t, req, res) { + t.equal(req.headers.cookie, 'foo=bar; quux=baz') + }) -var jar2 = request.jar() -jar2.setCookie('quux=baz; Domain=foo.bar.com', s.url, {ignoreError: true}) -runTest( - '#794: ignore cookie parsing and domain errors', - 'ignore-errors', - {jar: jar2, headers: {cookie: 'foo=bar'}}, - function(t, req, res) { - t.equal(req.headers.cookie, 'foo=bar') - }) + var jar2 = request.jar() + jar2.setCookie('quux=baz; Domain=foo.bar.com', s.url, {ignoreError: true}) + runTest( + '#794: ignore cookie parsing and domain errors', + 'ignore-errors', + {jar: jar2, headers: {cookie: 'foo=bar'}}, + function(t, req, res) { + t.equal(req.headers.cookie, 'foo=bar') + }) -runTest( - '#784: override content-type when json is used', - 'json', - { - json: true, - method: 'POST', - headers: { 'content-type': 'application/json; charset=UTF-8' }, - body: { hello: 'my friend' }}, - function(t, req, res) { - t.equal(req.headers['content-type'], 'application/json; charset=UTF-8') - } -) - -runTest( - 'neither headers.cookie nor a cookie jar is specified', - 'no-cookie', - {}, - function(t, req, res) { - t.equal(req.headers.cookie, undefined) + runTest( + '#784: override content-type when json is used', + 'json', + { + json: true, + method: 'POST', + headers: { 'content-type': 'application/json; charset=UTF-8' }, + body: { hello: 'my friend' }}, + function(t, req, res) { + t.equal(req.headers['content-type'], 'application/json; charset=UTF-8') + } + ) + + runTest( + 'neither headers.cookie nor a cookie jar is specified', + 'no-cookie', + {}, + function(t, req, res) { + t.equal(req.headers.cookie, undefined) + }) +} + +tape('setup', function(t) { + s.listen(0, function() { + addTests() + tape('cleanup', function(t) { + s.close(function() { + t.end() + }) + }) + t.end() }) +}) tape('upper-case Host header and redirect', function(t) { // Horrible hack to observe the raw data coming to the server (before Node @@ -193,9 +201,3 @@ tape('catch invalid characters error - POST', function(t) { t.end() }) }) - -tape('cleanup', function(t) { - s.close(function() { - t.end() - }) -}) diff --git a/tests/test-http-signature.js b/tests/test-http-signature.js index 1ad96bafa..b5679beba 100644 --- a/tests/test-http-signature.js +++ b/tests/test-http-signature.js @@ -69,7 +69,8 @@ var server = http.createServer(function (req, res) { }) tape('setup', function(t) { - server.listen(6767, function() { + server.listen(0, function() { + server.url = 'http://localhost:' + this.address().port t.end() }) }) @@ -81,7 +82,7 @@ tape('correct key', function(t) { key: privateKeyPEMs['key-1'] } } - request('http://localhost:6767', options, function(err, res, body) { + request(server.url, options, function(err, res, body) { t.equal(err, null) t.equal(200, res.statusCode) t.end() @@ -95,7 +96,7 @@ tape('incorrect key', function(t) { key: privateKeyPEMs['key-1'] } } - request('http://localhost:6767', options, function(err, res, body) { + request(server.url, options, function(err, res, body) { t.equal(err, null) t.equal(400, res.statusCode) t.end() diff --git a/tests/test-httpModule.js b/tests/test-httpModule.js index ee530e6f2..9acf80c0e 100644 --- a/tests/test-httpModule.js +++ b/tests/test-httpModule.js @@ -41,7 +41,7 @@ destroyable(plain_server) destroyable(https_server) tape('setup', function(t) { - plain_server.listen(plain_server.port, function() { + plain_server.listen(0, function() { plain_server.on('/plain', function (req, res) { res.writeHead(200) res.end('plain') @@ -51,7 +51,7 @@ tape('setup', function(t) { res.end() }) - https_server.listen(https_server.port, function() { + https_server.listen(0, function() { https_server.on('/https', function (req, res) { res.writeHead(200) res.end('https') diff --git a/tests/test-https.js b/tests/test-https.js index 74ebb880d..c298f7d54 100644 --- a/tests/test-https.js +++ b/tests/test-https.js @@ -17,13 +17,13 @@ var s = server.createSSLServer() key: path.resolve(__dirname, 'ssl/ca/server.key'), cert: path.resolve(__dirname, 'ssl/ca/server.crt') } - , sStrict = server.createSSLServer(s.port + 1, opts) + , sStrict = server.createSSLServer(opts) function runAllTests(strict, s) { var strictMsg = (strict ? 'strict ' : 'relaxed ') tape(strictMsg + 'setup', function(t) { - s.listen(s.port, function() { + s.listen(0, function() { t.end() }) }) diff --git a/tests/test-isUrl.js b/tests/test-isUrl.js index 0623eac4b..cbdd246df 100644 --- a/tests/test-isUrl.js +++ b/tests/test-isUrl.js @@ -10,13 +10,15 @@ var s = http.createServer(function(req, res) { }) tape('setup', function(t) { - s.listen(6767, function() { + s.listen(0, function() { + s.port = this.address().port + s.url = 'http://localhost:' + s.port t.end() }) }) tape('lowercase', function(t) { - request('http://localhost:6767', function(err, resp, body) { + request(s.url, function(err, resp, body) { t.equal(err, null) t.equal(body, 'ok') t.end() @@ -24,7 +26,7 @@ tape('lowercase', function(t) { }) tape('uppercase', function(t) { - request('HTTP://localhost:6767', function(err, resp, body) { + request(s.url.replace('http', 'HTTP'), function(err, resp, body) { t.equal(err, null) t.equal(body, 'ok') t.end() @@ -32,7 +34,7 @@ tape('uppercase', function(t) { }) tape('mixedcase', function(t) { - request('HtTp://localhost:6767', function(err, resp, body) { + request(s.url.replace('http', 'HtTp'), function(err, resp, body) { t.equal(err, null) t.equal(body, 'ok') t.end() @@ -44,7 +46,7 @@ tape('hostname and port', function(t) { uri: { protocol: 'http:', hostname: 'localhost', - port: 6767 + port: s.port } }, function(err, res, body) { t.equal(err, null) @@ -58,7 +60,7 @@ tape('hostname and port 1', function(t) { uri: { protocol: 'http:', hostname: 'localhost', - port: 6767 + port: s.port } }, function(err, res, body) { t.equal(err, null) @@ -71,7 +73,7 @@ tape('hostname and port 2', function(t) { request({ protocol: 'http:', hostname: 'localhost', - port: 6767 + port: s.port }, { // need this empty options object, otherwise request thinks no uri was set }, function(err, res, body) { @@ -85,7 +87,7 @@ tape('hostname and port 3', function(t) { request({ protocol: 'http:', hostname: 'localhost', - port: 6767 + port: s.port }, function(err, res, body) { t.notEqual(err, null) t.equal(err.message, 'options.uri is a required argument') @@ -99,7 +101,7 @@ tape('hostname and query string', function(t) { uri: { protocol: 'http:', hostname: 'localhost', - port: 6767 + port: s.port }, qs: { test: 'test' diff --git a/tests/test-json-request.js b/tests/test-json-request.js index aa117e216..b89e254e2 100644 --- a/tests/test-json-request.js +++ b/tests/test-json-request.js @@ -7,7 +7,7 @@ var server = require('./server') var s = server.createServer() tape('setup', function(t) { - s.listen(s.port, function() { + s.listen(0, function() { t.end() }) }) diff --git a/tests/test-multipart-encoding.js b/tests/test-multipart-encoding.js index 4c8383489..8691f1f76 100644 --- a/tests/test-multipart-encoding.js +++ b/tests/test-multipart-encoding.js @@ -124,7 +124,8 @@ function runTest(t, test) { }) }) - server.listen(6767, function() { + server.listen(0, function() { + var url = 'http://localhost:' + this.address().port // @NOTE: multipartData properties must be set here // so that file read stream does not leak in node v0.8 var parts = test.options.multipart.data || test.options.multipart @@ -132,7 +133,7 @@ function runTest(t, test) { parts[0].body = fs.createReadStream(localFile) } - request.post('http://localhost:6767', test.options, function (err, res, body) { + request.post(url, test.options, function (err, res, body) { t.equal(err, null) t.equal(res.statusCode, 200) server.close(function () { diff --git a/tests/test-multipart.js b/tests/test-multipart.js index 4afb87895..c1bf26d23 100644 --- a/tests/test-multipart.js +++ b/tests/test-multipart.js @@ -60,7 +60,7 @@ function runTest(t, a) { // remote_file t.ok(data.indexOf('name: remote_file') !== -1) - // check for http://localhost:6767/file traces + // check for http://localhost:nnnn/file traces t.ok(data.indexOf('Photoshop ICC') !== -1) if (a.header && a.header.indexOf('boundary=XXX') !== -1) { @@ -72,19 +72,19 @@ function runTest(t, a) { }) }) - server.listen(6767, function() { - + server.listen(0, function() { + var url = 'http://localhost:' + this.address().port // @NOTE: multipartData properties must be set here so that my_file read stream does not leak in node v0.8 multipartData = [ {name: 'my_field', body: 'my_value'}, {name: 'my_number', body: 1000}, {name: 'my_buffer', body: new Buffer([1, 2, 3])}, {name: 'my_file', body: fs.createReadStream(localFile)}, - {name: 'remote_file', body: request('http://localhost:6767/file')} + {name: 'remote_file', body: request(url + '/file')} ] var reqOptions = { - url: 'http://localhost:6767/upload', + url: url + '/upload', multipart: multipartData } if (a.header) { diff --git a/tests/test-node-debug.js b/tests/test-node-debug.js index 4d4e5ac0a..2291bf9c1 100644 --- a/tests/test-node-debug.js +++ b/tests/test-node-debug.js @@ -18,7 +18,8 @@ tape('setup', function(t) { stderr.push(string) } - s.listen(6767, function() { + s.listen(0, function() { + s.url = 'http://localhost:' + this.address().port t.end() }) }) @@ -29,14 +30,15 @@ tape('a simple request should not fail with debugging enabled', function(t) { t.equal(request.debug, true, 'request.debug gets request.Request.debug') stderr = [] - request('http://localhost:6767', function(err, res, body) { + request(s.url, function(err, res, body) { t.ifError(err, 'the request did not fail') t.ok(res, 'the request did not fail') t.ok(stderr.length, 'stderr has some messages') + var url = s.url.replace(/\//g, '\\/') var patterns = [ /^REQUEST { uri: /, - /^REQUEST make request http:\/\/localhost:6767\/\n$/, + new RegExp('^REQUEST make request ' + url + '\/\n$'), /^REQUEST onRequestResponse /, /^REQUEST finish init /, /^REQUEST response end /, @@ -61,7 +63,7 @@ tape('there should be no further lookups on process.env', function(t) { process.env.NODE_DEBUG = '' stderr = [] - request('http://localhost:6767', function(err, res, body) { + request(s.url, function(err, res, body) { t.ifError(err, 'the request did not fail') t.ok(res, 'the request did not fail') t.equal(stderr.length, prevStderrLen, 'env.NODE_DEBUG is not retested') @@ -75,7 +77,7 @@ tape('it should be possible to disable debugging at runtime', function(t) { t.equal(request.debug, false, 'request.debug gets request.Request.debug') stderr = [] - request('http://localhost:6767', function(err, res, body) { + request(s.url, function(err, res, body) { t.ifError(err, 'the request did not fail') t.ok(res, 'the request did not fail') t.equal(stderr.length, 0, 'debugging can be disabled') diff --git a/tests/test-oauth.js b/tests/test-oauth.js index 3b022abf9..dd994f07d 100644 --- a/tests/test-oauth.js +++ b/tests/test-oauth.js @@ -617,11 +617,11 @@ tape('body_hash PLAINTEXT signature_method', function(t) { }) tape('refresh oauth_nonce on redirect', function(t) { - var oauth_nonce1, oauth_nonce2 + var oauth_nonce1, oauth_nonce2, url var s = http.createServer(function (req, res) { if (req.url === '/redirect') { oauth_nonce1 = req.headers.authorization.replace(/.*oauth_nonce="([^"]+)".*/, '$1') - res.writeHead(302, {location:'http://localhost:6767/response'}) + res.writeHead(302, {location:url + '/response'}) res.end() } else if (req.url === '/response') { oauth_nonce2 = req.headers.authorization.replace(/.*oauth_nonce="([^"]+)".*/, '$1') @@ -629,9 +629,10 @@ tape('refresh oauth_nonce on redirect', function(t) { res.end() } }) - s.listen(6767, function () { + s.listen(0, function () { + url = 'http://localhost:' + this.address().port request.get( - { url: 'http://localhost:6767/redirect' + { url: url + '/redirect' , oauth: { consumer_key: 'consumer_key' , consumer_secret: 'consumer_secret' @@ -649,18 +650,20 @@ tape('refresh oauth_nonce on redirect', function(t) { }) tape('no credentials on external redirect', function(t) { - var s1 = http.createServer(function (req, res) { - res.writeHead(302, {location:'http://127.0.0.1:6768'}) - res.end() - }) var s2 = http.createServer(function (req, res) { res.writeHead(200, {'content-type':'text/plain'}) res.end() }) - s1.listen(6767, function () { - s2.listen(6768, function () { + var s1 = http.createServer(function (req, res) { + res.writeHead(302, {location:s2.url}) + res.end() + }) + s1.listen(0, function () { + s1.url = 'http://localhost:' + this.address().port + s2.listen(0, function () { + s2.url = 'http://127.0.0.1:' + this.address().port request.get( - { url: 'http://localhost:6767' + { url: s1.url , oauth: { consumer_key: 'consumer_key' , consumer_secret: 'consumer_secret' diff --git a/tests/test-onelineproxy.js b/tests/test-onelineproxy.js index 73a0ae8a3..5732f0512 100644 --- a/tests/test-onelineproxy.js +++ b/tests/test-onelineproxy.js @@ -28,24 +28,25 @@ var server = http.createServer(function(req, resp) { } if (req.url === '/proxy') { assert.equal(req.method, 'PUT') - req.pipe(request('http://localhost:6767/put')).pipe(resp) + req.pipe(request(server.url + '/put')).pipe(resp) return } if (req.url === '/test') { - request('http://localhost:6767/get').pipe(request.put('http://localhost:6767/proxy')).pipe(resp) + request(server.url + '/get').pipe(request.put(server.url + '/proxy')).pipe(resp) return } throw new Error('Unknown url', req.url) }) tape('setup', function(t) { - server.listen(6767, function() { + server.listen(0, function() { + server.url = 'http://localhost:' + this.address().port t.end() }) }) tape('chained one-line proxying', function(t) { - request('http://localhost:6767/test', function(err, res, body) { + request(server.url + '/test', function(err, res, body) { t.equal(err, null) t.equal(res.statusCode, 200) t.equal(body, 'success') diff --git a/tests/test-option-reuse.js b/tests/test-option-reuse.js index c2dcf63c6..706b121a9 100644 --- a/tests/test-option-reuse.js +++ b/tests/test-option-reuse.js @@ -17,13 +17,14 @@ var s = http.createServer(function(req, res) { }) tape('setup', function(t) { - s.listen(6767, function() { + s.listen(0, function() { + s.url = 'http://localhost:' + this.address().port t.end() }) }) tape('options object is not mutated', function(t) { - var url = 'http://localhost:6767' + var url = s.url var options = { url: url } request.head(options, function(err, resp, body) { diff --git a/tests/test-params.js b/tests/test-params.js index 70f5e65ce..6cd0a99f2 100644 --- a/tests/test-params.js +++ b/tests/test-params.js @@ -24,7 +24,7 @@ function runTest(name, test) { } tape('setup', function(t) { - s.listen(s.port, function() { + s.listen(0, function() { t.end() }) }) diff --git a/tests/test-piped-redirect.js b/tests/test-piped-redirect.js index fecb21d3c..d669c0923 100644 --- a/tests/test-piped-redirect.js +++ b/tests/test-piped-redirect.js @@ -4,8 +4,8 @@ var http = require('http') , request = require('../index') , tape = require('tape') -var port1 = 6767 - , port2 = 6768 +var port1 + , port2 var s1 = http.createServer(function(req, resp) { if (req.url === '/original') { @@ -29,8 +29,10 @@ var s2 = http.createServer(function(req, resp) { }) tape('setup', function(t) { - s1.listen(port1, function() { - s2.listen(port2, function() { + s1.listen(0, function() { + port1 = this.address().port + s2.listen(0, function() { + port2 = this.address().port t.end() }) }) diff --git a/tests/test-pipes.js b/tests/test-pipes.js index ec0ea6da8..41d82232f 100644 --- a/tests/test-pipes.js +++ b/tests/test-pipes.js @@ -64,7 +64,7 @@ ValidationStream.prototype.end = function(chunk) { tape('setup', function(t) { - s.listen(s.port, function() { + s.listen(0, function() { t.end() }) }) diff --git a/tests/test-pool.js b/tests/test-pool.js index f343081eb..183939f72 100644 --- a/tests/test-pool.js +++ b/tests/test-pool.js @@ -10,14 +10,15 @@ var s = http.createServer(function (req, res) { }) tape('setup', function(t) { - s.listen(6767, function() { + s.listen(0, function() { + s.url = 'http://localhost:' + this.address().port t.end() }) }) tape('pool', function(t) { request({ - url: 'http://localhost:6767', + url: s.url, pool: false }, function(err, res, body) { t.equal(err, null) @@ -32,7 +33,7 @@ tape('pool', function(t) { tape('forever', function(t) { var r = request({ - url: 'http://localhost:6767', + url: s.url, forever: true, pool: {maxSockets: 1024} }, function(err, res, body) { @@ -62,8 +63,8 @@ tape('forever, should use same agent in sequential requests', function(t) { var r = request.defaults({ forever: true }) - var req1 = r('http://localhost:6767') - var req2 = r('http://localhost:6767/somepath') + var req1 = r(s.url) + var req2 = r(s.url + '/somepath') req1.abort() req2.abort() if (typeof req1.agent.destroy === 'function') { @@ -81,8 +82,8 @@ tape('forever, should use same agent in sequential requests(with pool.maxSockets forever: true, pool: {maxSockets: 1024} }) - var req1 = r('http://localhost:6767') - var req2 = r('http://localhost:6767/somepath') + var req1 = r(s.url) + var req2 = r(s.url + '/somepath') req1.abort() req2.abort() if (typeof req1.agent.destroy === 'function') { @@ -101,8 +102,8 @@ tape('forever, should use same agent in request() and request.verb', function(t) forever: true, pool: {maxSockets: 1024} }) - var req1 = r('http://localhost:6767') - var req2 = r.get('http://localhost:6767') + var req1 = r(s.url) + var req2 = r.get(s.url) req1.abort() req2.abort() if (typeof req1.agent.destroy === 'function') { @@ -121,9 +122,9 @@ tape('should use different agent if pool option specified', function(t) { forever: true, pool: {maxSockets: 1024} }) - var req1 = r('http://localhost:6767') + var req1 = r(s.url) var req2 = r.get({ - url: 'http://localhost:6767', + url: s.url, pool: {maxSockets: 20} }) req1.abort() diff --git a/tests/test-promise.js b/tests/test-promise.js index 81507dbe5..f5343cf46 100644 --- a/tests/test-promise.js +++ b/tests/test-promise.js @@ -11,7 +11,8 @@ var s = http.createServer(function(req, res) { }) tape('setup', function(t) { - s.listen(6767, function() { + s.listen(0, function() { + s.url = 'http://localhost:' + this.address().port t.end() }) }) @@ -19,7 +20,7 @@ tape('setup', function(t) { tape('promisify convenience method', function(t) { var get = request.get var p = Promise.promisify(get, {multiArgs: true}) - p('http://localhost:6767') + p(s.url) .then(function (results) { var res = results[0] t.equal(res.statusCode, 200) @@ -29,7 +30,7 @@ tape('promisify convenience method', function(t) { tape('promisify request function', function(t) { var p = Promise.promisify(request, {multiArgs: true}) - p('http://localhost:6767') + p(s.url) .spread(function (res, body) { t.equal(res.statusCode, 200) t.end() @@ -38,7 +39,7 @@ tape('promisify request function', function(t) { tape('promisify all methods', function(t) { Promise.promisifyAll(request, {multiArgs: true}) - request.getAsync('http://localhost:6767') + request.getAsync(s.url) .spread(function (res, body) { t.equal(res.statusCode, 200) t.end() diff --git a/tests/test-proxy-connect.js b/tests/test-proxy-connect.js index f8aeba4ce..084e19fee 100644 --- a/tests/test-proxy-connect.js +++ b/tests/test-proxy-connect.js @@ -3,8 +3,7 @@ var request = require('../index') , tape = require('tape') -var port = 6768 - , called = false +var called = false , proxiedHost = 'google.com' , data = '' @@ -28,7 +27,8 @@ var s = require('net').createServer(function(sock) { }) tape('setup', function(t) { - s.listen(port, function() { + s.listen(0, function() { + s.url = 'http://localhost:' + this.address().port t.end() }) }) @@ -37,7 +37,7 @@ tape('proxy', function(t) { request({ tunnel: true, url: 'http://' + proxiedHost, - proxy: 'http://localhost:' + port, + proxy: s.url, headers: { 'Proxy-Authorization' : 'Basic dXNlcjpwYXNz', 'authorization' : 'Token deadbeef', diff --git a/tests/test-proxy.js b/tests/test-proxy.js index eec0b0c35..dd5cefbcb 100644 --- a/tests/test-proxy.js +++ b/tests/test-proxy.js @@ -79,228 +79,228 @@ function runTest(name, options, responseHandler) { }) } -tape('setup', function(t) { - s.listen(s.port, function() { - t.end() - }) -}) - +function addTests() { + // If the `runTest` function is changed, run the following command and make + // sure both of these tests fail: + // + // TEST_PROXY_HARNESS=y node tests/test-proxy.js -// If the `runTest` function is changed, run the following command and make -// sure both of these tests fail: -// -// TEST_PROXY_HARNESS=y node tests/test-proxy.js + if (process.env.TEST_PROXY_HARNESS) { -if (process.env.TEST_PROXY_HARNESS) { + runTest('should fail with "proxy response should not be called"', { + proxy : s.url + }, false) - runTest('should fail with "proxy response should not be called"', { - proxy : s.url - }, false) + runTest('should fail with "proxy response should be called"', { + proxy : null + }, true) - runTest('should fail with "proxy response should be called"', { - proxy : null - }, true) + } else { + // Run the real tests -} else { - // Run the real tests - - runTest('basic proxy', { - proxy : s.url, - headers : { - 'proxy-authorization': 'Token Fooblez' - } - }, function(t, req, res) { - t.equal(req.headers['proxy-authorization'], 'Token Fooblez') - }) + runTest('basic proxy', { + proxy : s.url, + headers : { + 'proxy-authorization': 'Token Fooblez' + } + }, function(t, req, res) { + t.equal(req.headers['proxy-authorization'], 'Token Fooblez') + }) - runTest('proxy auth without uri auth', { - proxy : 'http://user:pass@localhost:' + s.port - }, function(t, req, res) { - t.equal(req.headers['proxy-authorization'], 'Basic dXNlcjpwYXNz') - }) + runTest('proxy auth without uri auth', { + proxy : 'http://user:pass@localhost:' + s.port + }, function(t, req, res) { + t.equal(req.headers['proxy-authorization'], 'Basic dXNlcjpwYXNz') + }) - // http: urls and basic proxy settings - - runTest('HTTP_PROXY environment variable and http: url', { - env : { HTTP_PROXY : s.url } - }, true) - - runTest('http_proxy environment variable and http: url', { - env : { http_proxy : s.url } - }, true) - - runTest('HTTPS_PROXY environment variable and http: url', { - env : { HTTPS_PROXY : s.url } - }, false) - - runTest('https_proxy environment variable and http: url', { - env : { https_proxy : s.url } - }, false) - - // https: urls and basic proxy settings - - runTest('HTTP_PROXY environment variable and https: url', { - env : { HTTP_PROXY : s.url }, - url : 'https://google.com', - tunnel : false, - pool : false - }, true) - - runTest('http_proxy environment variable and https: url', { - env : { http_proxy : s.url }, - url : 'https://google.com', - tunnel : false - }, true) - - runTest('HTTPS_PROXY environment variable and https: url', { - env : { HTTPS_PROXY : s.url }, - url : 'https://google.com', - tunnel : false - }, true) - - runTest('https_proxy environment variable and https: url', { - env : { https_proxy : s.url }, - url : 'https://google.com', - tunnel : false - }, true) - - runTest('multiple environment variables and https: url', { - env : { - HTTPS_PROXY : s.url, - HTTP_PROXY : 'http://localhost:4/' - }, - url : 'https://google.com', - tunnel : false - }, true) - - // no_proxy logic - - runTest('NO_PROXY hostnames are case insensitive', { - env : { - HTTP_PROXY : s.url, - NO_PROXY : 'GOOGLE.COM' - } - }, false) + // http: urls and basic proxy settings + + runTest('HTTP_PROXY environment variable and http: url', { + env : { HTTP_PROXY : s.url } + }, true) + + runTest('http_proxy environment variable and http: url', { + env : { http_proxy : s.url } + }, true) + + runTest('HTTPS_PROXY environment variable and http: url', { + env : { HTTPS_PROXY : s.url } + }, false) + + runTest('https_proxy environment variable and http: url', { + env : { https_proxy : s.url } + }, false) + + // https: urls and basic proxy settings + + runTest('HTTP_PROXY environment variable and https: url', { + env : { HTTP_PROXY : s.url }, + url : 'https://google.com', + tunnel : false, + pool : false + }, true) + + runTest('http_proxy environment variable and https: url', { + env : { http_proxy : s.url }, + url : 'https://google.com', + tunnel : false + }, true) + + runTest('HTTPS_PROXY environment variable and https: url', { + env : { HTTPS_PROXY : s.url }, + url : 'https://google.com', + tunnel : false + }, true) + + runTest('https_proxy environment variable and https: url', { + env : { https_proxy : s.url }, + url : 'https://google.com', + tunnel : false + }, true) + + runTest('multiple environment variables and https: url', { + env : { + HTTPS_PROXY : s.url, + HTTP_PROXY : 'http://localhost:0/' + }, + url : 'https://google.com', + tunnel : false + }, true) + + // no_proxy logic + + runTest('NO_PROXY hostnames are case insensitive', { + env : { + HTTP_PROXY : s.url, + NO_PROXY : 'GOOGLE.COM' + } + }, false) - runTest('NO_PROXY hostnames are case insensitive 2', { - env : { - http_proxy : s.url, - NO_PROXY : 'GOOGLE.COM' - } - }, false) + runTest('NO_PROXY hostnames are case insensitive 2', { + env : { + http_proxy : s.url, + NO_PROXY : 'GOOGLE.COM' + } + }, false) - runTest('NO_PROXY hostnames are case insensitive 3', { - env : { - HTTP_PROXY : s.url, - no_proxy : 'GOOGLE.COM' - } - }, false) + runTest('NO_PROXY hostnames are case insensitive 3', { + env : { + HTTP_PROXY : s.url, + no_proxy : 'GOOGLE.COM' + } + }, false) - runTest('NO_PROXY ignored with explicit proxy passed', { - env : { NO_PROXY : '*' }, - proxy : s.url - }, true) + runTest('NO_PROXY ignored with explicit proxy passed', { + env : { NO_PROXY : '*' }, + proxy : s.url + }, true) - runTest('NO_PROXY overrides HTTP_PROXY for specific hostname', { - env : { - HTTP_PROXY : s.url, - NO_PROXY : 'google.com' - } - }, false) + runTest('NO_PROXY overrides HTTP_PROXY for specific hostname', { + env : { + HTTP_PROXY : s.url, + NO_PROXY : 'google.com' + } + }, false) - runTest('no_proxy overrides HTTP_PROXY for specific hostname', { - env : { - HTTP_PROXY : s.url, - no_proxy : 'google.com' - } - }, false) + runTest('no_proxy overrides HTTP_PROXY for specific hostname', { + env : { + HTTP_PROXY : s.url, + no_proxy : 'google.com' + } + }, false) - runTest('NO_PROXY does not override HTTP_PROXY if no hostnames match', { - env : { - HTTP_PROXY : s.url, - NO_PROXY : 'foo.bar,bar.foo' - } - }, true) + runTest('NO_PROXY does not override HTTP_PROXY if no hostnames match', { + env : { + HTTP_PROXY : s.url, + NO_PROXY : 'foo.bar,bar.foo' + } + }, true) - runTest('NO_PROXY overrides HTTP_PROXY if a hostname matches', { - env : { - HTTP_PROXY : s.url, - NO_PROXY : 'foo.bar,google.com' - } - }, false) + runTest('NO_PROXY overrides HTTP_PROXY if a hostname matches', { + env : { + HTTP_PROXY : s.url, + NO_PROXY : 'foo.bar,google.com' + } + }, false) - runTest('NO_PROXY allows an explicit port', { - env : { - HTTP_PROXY : s.url, - NO_PROXY : 'google.com:80' - } - }, false) + runTest('NO_PROXY allows an explicit port', { + env : { + HTTP_PROXY : s.url, + NO_PROXY : 'google.com:80' + } + }, false) - runTest('NO_PROXY only overrides HTTP_PROXY if the port matches', { - env : { - HTTP_PROXY : s.url, - NO_PROXY : 'google.com:1234' - } - }, true) + runTest('NO_PROXY only overrides HTTP_PROXY if the port matches', { + env : { + HTTP_PROXY : s.url, + NO_PROXY : 'google.com:1234' + } + }, true) - runTest('NO_PROXY=* should override HTTP_PROXY for all hosts', { - env : { - HTTP_PROXY : s.url, - NO_PROXY : '*' - } - }, false) - - runTest('NO_PROXY should override HTTP_PROXY for all subdomains', { - env : { - HTTP_PROXY : s.url, - NO_PROXY : 'google.com' - }, - headers : { host : 'www.google.com' } - }, false) - - runTest('NO_PROXY should not override HTTP_PROXY for partial domain matches', { - env : { - HTTP_PROXY : s.url, - NO_PROXY : 'oogle.com' - } - }, true) + runTest('NO_PROXY=* should override HTTP_PROXY for all hosts', { + env : { + HTTP_PROXY : s.url, + NO_PROXY : '*' + } + }, false) + + runTest('NO_PROXY should override HTTP_PROXY for all subdomains', { + env : { + HTTP_PROXY : s.url, + NO_PROXY : 'google.com' + }, + headers : { host : 'www.google.com' } + }, false) + + runTest('NO_PROXY should not override HTTP_PROXY for partial domain matches', { + env : { + HTTP_PROXY : s.url, + NO_PROXY : 'oogle.com' + } + }, true) - runTest('NO_PROXY with port should not override HTTP_PROXY for partial domain matches', { - env : { - HTTP_PROXY : s.url, - NO_PROXY : 'oogle.com:80' - } - }, true) + runTest('NO_PROXY with port should not override HTTP_PROXY for partial domain matches', { + env : { + HTTP_PROXY : s.url, + NO_PROXY : 'oogle.com:80' + } + }, true) - // misc + // misc - // this fails if the check 'isMatchedAt > -1' in lib/getProxyFromURI.js is - // missing or broken - runTest('http_proxy with length of one more than the URL', { - env : { - HTTP_PROXY : s.url, - NO_PROXY : 'elgoog1.com' // one more char than google.com - } - }, true) - - runTest('proxy: null should override HTTP_PROXY', { - env : { HTTP_PROXY : s.url }, - proxy : null, - timeout : 500 - }, false) - - runTest('uri auth without proxy auth', { - url : 'http://user:pass@google.com', - proxy : s.url - }, function(t, req, res) { - t.equal(req.headers['proxy-authorization'], undefined) - t.equal(req.headers.authorization, 'Basic dXNlcjpwYXNz') - }) + // this fails if the check 'isMatchedAt > -1' in lib/getProxyFromURI.js is + // missing or broken + runTest('http_proxy with length of one more than the URL', { + env : { + HTTP_PROXY : s.url, + NO_PROXY : 'elgoog1.com' // one more char than google.com + } + }, true) + + runTest('proxy: null should override HTTP_PROXY', { + env : { HTTP_PROXY : s.url }, + proxy : null, + timeout : 500 + }, false) + + runTest('uri auth without proxy auth', { + url : 'http://user:pass@google.com', + proxy : s.url + }, function(t, req, res) { + t.equal(req.headers['proxy-authorization'], undefined) + t.equal(req.headers.authorization, 'Basic dXNlcjpwYXNz') + }) + } } - -tape('cleanup', function(t) { - s.close(function() { +tape('setup', function(t) { + s.listen(0, function() { + addTests() + tape('cleanup', function(t) { + s.close(function() { + t.end() + }) + }) t.end() }) }) diff --git a/tests/test-redirect-auth.js b/tests/test-redirect-auth.js index 95eaf04b6..400ad5429 100644 --- a/tests/test-redirect-auth.js +++ b/tests/test-redirect-auth.js @@ -66,30 +66,6 @@ function handleRequests(srv) { handleRequests(s) handleRequests(ss) -tape('setup', function(t) { - s.listen(s.port, function() { - ss.listen(ss.port, function() { - t.end() - }) - }) -}) - -tape('redirect URL helper', function(t) { - t.deepEqual( - redirect.from('http', 'localhost').to('https', '127.0.0.1'), - { - src : util.format('http://localhost:%d/to/https/127.0.0.1', s.port), - dst : util.format('https://127.0.0.1:%d/from/http/localhost', ss.port) - }) - t.deepEqual( - redirect.from('https', 'localhost').to('http', 'localhost'), - { - src : util.format('https://localhost:%d/to/http/localhost', ss.port), - dst : util.format('http://localhost:%d/from/https/localhost', s.port) - }) - t.end() -}) - function runTest(name, redir, expectAuth) { tape('redirect to ' + name, function(t) { request(redir.src, function(err, res, body) { @@ -104,26 +80,52 @@ function runTest(name, redir, expectAuth) { }) } -runTest('same host and protocol', - redirect.from('http', 'localhost').to('http', 'localhost'), - true) +function addTests() { + runTest('same host and protocol', + redirect.from('http', 'localhost').to('http', 'localhost'), + true) -runTest('same host different protocol', - redirect.from('http', 'localhost').to('https', 'localhost'), - true) + runTest('same host different protocol', + redirect.from('http', 'localhost').to('https', 'localhost'), + true) -runTest('different host same protocol', - redirect.from('https', '127.0.0.1').to('https', 'localhost'), - false) + runTest('different host same protocol', + redirect.from('https', '127.0.0.1').to('https', 'localhost'), + false) -runTest('different host and protocol', - redirect.from('http', 'localhost').to('https', '127.0.0.1'), - false) + runTest('different host and protocol', + redirect.from('http', 'localhost').to('https', '127.0.0.1'), + false) +} -tape('cleanup', function(t) { - s.destroy(function() { - ss.destroy(function() { +tape('setup', function(t) { + s.listen(0, function() { + ss.listen(0, function() { + addTests() + tape('cleanup', function(t) { + s.destroy(function() { + ss.destroy(function() { + t.end() + }) + }) + }) t.end() }) }) }) + +tape('redirect URL helper', function(t) { + t.deepEqual( + redirect.from('http', 'localhost').to('https', '127.0.0.1'), + { + src : util.format('http://localhost:%d/to/https/127.0.0.1', s.port), + dst : util.format('https://127.0.0.1:%d/from/http/localhost', ss.port) + }) + t.deepEqual( + redirect.from('https', 'localhost').to('http', 'localhost'), + { + src : util.format('https://localhost:%d/to/http/localhost', ss.port), + dst : util.format('http://localhost:%d/from/https/localhost', s.port) + }) + t.end() +}) diff --git a/tests/test-redirect-complex.js b/tests/test-redirect-complex.js index b88ef178a..4f11ab56b 100644 --- a/tests/test-redirect-complex.js +++ b/tests/test-redirect-complex.js @@ -47,9 +47,9 @@ function bouncy(s, serverUrl) { } tape('setup', function(t) { - s.listen(s.port, function() { - bouncy(s, ss.url) - ss.listen(ss.port, function() { + s.listen(0, function() { + ss.listen(0, function() { + bouncy(s, ss.url) bouncy(ss, s.url) t.end() }) diff --git a/tests/test-redirect.js b/tests/test-redirect.js index 6b9e7ee33..1f49182fb 100644 --- a/tests/test-redirect.js +++ b/tests/test-redirect.js @@ -72,8 +72,8 @@ function bouncer(code, label, hops) { } tape('setup', function(t) { - s.listen(s.port, function() { - ss.listen(ss.port, function() { + s.listen(0, function() { + ss.listen(0, function() { bouncer(301, 'temp') bouncer(301, 'double', 2) bouncer(301, 'treble', 3) diff --git a/tests/test-rfc3986.js b/tests/test-rfc3986.js index 50868ab47..a48bd31db 100644 --- a/tests/test-rfc3986.js +++ b/tests/test-rfc3986.js @@ -27,9 +27,9 @@ function runTest (t, options) { }) }) - server.listen(6767, function() { - - request.post('http://localhost:6767', options, function(err, res, body) { + server.listen(0, function() { + var port = this.address().port + request.post('http://localhost:' + port, options, function(err, res, body) { t.equal(err, null) server.close(function() { t.end() diff --git a/tests/test-stream.js b/tests/test-stream.js index b1fbfad0f..88142f030 100644 --- a/tests/test-stream.js +++ b/tests/test-stream.js @@ -12,14 +12,17 @@ tape('before', function (t) { server.on('request', function (req, res) { req.pipe(res) }) - server.listen(6767, t.end) + server.listen(0, function() { + server.url = 'http://localhost:' + this.address().port + t.end() + }) }) tape('request body stream', function (t) { var fpath = path.join(__dirname, 'unicycle.jpg') var input = fs.createReadStream(fpath, {highWaterMark: 1000}) request({ - uri: 'http://localhost:6767', + uri: server.url, method: 'POST', body: input, encoding: null diff --git a/tests/test-timeout.js b/tests/test-timeout.js index 43e42fe06..1f2944e43 100644 --- a/tests/test-timeout.js +++ b/tests/test-timeout.js @@ -22,7 +22,7 @@ s.on('/timeout', function(req, res) { }) tape('setup', function(t) { - s.listen(s.port, function() { + s.listen(0, function() { t.end() }) }) diff --git a/tests/test-timing.js b/tests/test-timing.js index 754ffab56..5a3636d76 100644 --- a/tests/test-timing.js +++ b/tests/test-timing.js @@ -8,7 +8,7 @@ var plain_server = server.createServer() , redirect_mock_time = 10 tape('setup', function(t) { - plain_server.listen(plain_server.port, function() { + plain_server.listen(0, function() { plain_server.on('/', function (req, res) { res.writeHead(200) res.end('plain') diff --git a/tests/test-toJSON.js b/tests/test-toJSON.js index 431600a1b..4549844d4 100644 --- a/tests/test-toJSON.js +++ b/tests/test-toJSON.js @@ -10,14 +10,15 @@ var s = http.createServer(function (req, resp) { }) tape('setup', function(t) { - s.listen(6767, function() { + s.listen(0, function() { + s.url = 'http://localhost:' + this.address().port t.end() }) }) tape('request().toJSON()', function(t) { var r = request({ - url: 'http://localhost:6767', + url: s.url, headers: { foo: 'bar' } }, function(err, res) { var json_r = JSON.parse(JSON.stringify(r)) diff --git a/tests/test-tunnel.js b/tests/test-tunnel.js index 6534fc83e..75847345a 100644 --- a/tests/test-tunnel.js +++ b/tests/test-tunnel.js @@ -36,8 +36,8 @@ httpsOpts.ca = httpsOpts.ca || [] httpsOpts.ca.push(ca) var s = server.createServer() - , ss = server.createSSLServer(null, sslOpts) - , ss2 = server.createSSLServer(ss.port + 1, mutualSSLOpts) + , ss = server.createSSLServer(sslOpts) + , ss2 = server.createSSLServer(mutualSSLOpts) // XXX when tunneling https over https, connections get left open so the server // doesn't want to close normally (and same issue with http server on v0.8.x) @@ -101,16 +101,6 @@ setListeners(s, 'http') setListeners(ss, 'https') setListeners(ss2, 'https') -tape('setup', function(t) { - s.listen(s.port, function() { - ss.listen(ss.port, function() { - ss2.listen(ss2.port, 'localhost', function() { - t.end() - }) - }) - }) -}) - // monkey-patch since you can't set a custom certificate authority for the // proxy in tunnel-agent (this is necessary for "* over https" tests) var customCaCount = 0 @@ -138,334 +128,344 @@ function runTest(name, opts, expected) { }) } +function addTests() { + // HTTP OVER HTTP + + runTest('http over http, tunnel=true', { + url : s.url, + proxy : s.url, + tunnel : true + }, [ + 'http connect to localhost:' + s.port, + 'http response', + '200 http ok' + ]) + + runTest('http over http, tunnel=false', { + url : s.url, + proxy : s.url, + tunnel : false + }, [ + 'http proxy to http', + 'http response', + '200 http ok' + ]) + + runTest('http over http, tunnel=default', { + url : s.url, + proxy : s.url + }, [ + 'http proxy to http', + 'http response', + '200 http ok' + ]) + + + // HTTP OVER HTTPS + + runTest('http over https, tunnel=true', { + url : s.url, + proxy : ss.url, + tunnel : true + }, [ + 'https connect to localhost:' + s.port, + 'http response', + '200 http ok' + ]) + + runTest('http over https, tunnel=false', { + url : s.url, + proxy : ss.url, + tunnel : false + }, [ + 'https proxy to http', + 'http response', + '200 http ok' + ]) + + runTest('http over https, tunnel=default', { + url : s.url, + proxy : ss.url + }, [ + 'https proxy to http', + 'http response', + '200 http ok' + ]) + + + // HTTPS OVER HTTP + + runTest('https over http, tunnel=true', { + url : ss.url, + proxy : s.url, + tunnel : true + }, [ + 'http connect to localhost:' + ss.port, + 'https response', + '200 https ok' + ]) + + runTest('https over http, tunnel=false', { + url : ss.url, + proxy : s.url, + tunnel : false + }, [ + 'http proxy to https', + 'https response', + '200 https ok' + ]) + + runTest('https over http, tunnel=default', { + url : ss.url, + proxy : s.url + }, [ + 'http connect to localhost:' + ss.port, + 'https response', + '200 https ok' + ]) + + + // HTTPS OVER HTTPS + + runTest('https over https, tunnel=true', { + url : ss.url, + proxy : ss.url, + tunnel : true + }, [ + 'https connect to localhost:' + ss.port, + 'https response', + '200 https ok' + ]) + + runTest('https over https, tunnel=false', { + url : ss.url, + proxy : ss.url, + tunnel : false, + pool : false // must disable pooling here or Node.js hangs + }, [ + 'https proxy to https', + 'https response', + '200 https ok' + ]) + + runTest('https over https, tunnel=default', { + url : ss.url, + proxy : ss.url + }, [ + 'https connect to localhost:' + ss.port, + 'https response', + '200 https ok' + ]) + + + // HTTP->HTTP OVER HTTP + + runTest('http->http over http, tunnel=true', { + url : s.url + '/redirect/http', + proxy : s.url, + tunnel : true + }, [ + 'http connect to localhost:' + s.port, + 'http redirect to http', + 'http connect to localhost:' + s.port, + 'http response', + '200 http ok' + ]) + + runTest('http->http over http, tunnel=false', { + url : s.url + '/redirect/http', + proxy : s.url, + tunnel : false + }, [ + 'http proxy to http->http', + 'http redirect to http', + 'http proxy to http', + 'http response', + '200 http ok' + ]) + + runTest('http->http over http, tunnel=default', { + url : s.url + '/redirect/http', + proxy : s.url + }, [ + 'http proxy to http->http', + 'http redirect to http', + 'http proxy to http', + 'http response', + '200 http ok' + ]) + + + // HTTP->HTTPS OVER HTTP + + runTest('http->https over http, tunnel=true', { + url : s.url + '/redirect/https', + proxy : s.url, + tunnel : true + }, [ + 'http connect to localhost:' + s.port, + 'http redirect to https', + 'http connect to localhost:' + ss.port, + 'https response', + '200 https ok' + ]) + + runTest('http->https over http, tunnel=false', { + url : s.url + '/redirect/https', + proxy : s.url, + tunnel : false + }, [ + 'http proxy to http->https', + 'http redirect to https', + 'http proxy to https', + 'https response', + '200 https ok' + ]) + + runTest('http->https over http, tunnel=default', { + url : s.url + '/redirect/https', + proxy : s.url + }, [ + 'http proxy to http->https', + 'http redirect to https', + 'http connect to localhost:' + ss.port, + 'https response', + '200 https ok' + ]) + + + // HTTPS->HTTP OVER HTTP + + runTest('https->http over http, tunnel=true', { + url : ss.url + '/redirect/http', + proxy : s.url, + tunnel : true + }, [ + 'http connect to localhost:' + ss.port, + 'https redirect to http', + 'http connect to localhost:' + s.port, + 'http response', + '200 http ok' + ]) + + runTest('https->http over http, tunnel=false', { + url : ss.url + '/redirect/http', + proxy : s.url, + tunnel : false + }, [ + 'http proxy to https->http', + 'https redirect to http', + 'http proxy to http', + 'http response', + '200 http ok' + ]) + + runTest('https->http over http, tunnel=default', { + url : ss.url + '/redirect/http', + proxy : s.url + }, [ + 'http connect to localhost:' + ss.port, + 'https redirect to http', + 'http proxy to http', + 'http response', + '200 http ok' + ]) + + + // HTTPS->HTTPS OVER HTTP + + runTest('https->https over http, tunnel=true', { + url : ss.url + '/redirect/https', + proxy : s.url, + tunnel : true + }, [ + 'http connect to localhost:' + ss.port, + 'https redirect to https', + 'http connect to localhost:' + ss.port, + 'https response', + '200 https ok' + ]) + + runTest('https->https over http, tunnel=false', { + url : ss.url + '/redirect/https', + proxy : s.url, + tunnel : false + }, [ + 'http proxy to https->https', + 'https redirect to https', + 'http proxy to https', + 'https response', + '200 https ok' + ]) + + runTest('https->https over http, tunnel=default', { + url : ss.url + '/redirect/https', + proxy : s.url + }, [ + 'http connect to localhost:' + ss.port, + 'https redirect to https', + 'http connect to localhost:' + ss.port, + 'https response', + '200 https ok' + ]) + + + // MUTUAL HTTPS OVER HTTP + + runTest('mutual https over http, tunnel=true', { + url : ss2.url, + proxy : s.url, + tunnel : true, + cert : clientCert, + key : clientKey, + passphrase : clientPassword + }, [ + 'http connect to localhost:' + ss2.port, + 'https response', + '200 https ok' + ]) + + // XXX causes 'Error: socket hang up' + // runTest('mutual https over http, tunnel=false', { + // url : ss2.url, + // proxy : s.url, + // tunnel : false, + // cert : clientCert, + // key : clientKey, + // passphrase : clientPassword + // }, [ + // 'http connect to localhost:' + ss2.port, + // 'https response', + // '200 https ok' + // ]) + + runTest('mutual https over http, tunnel=default', { + url : ss2.url, + proxy : s.url, + cert : clientCert, + key : clientKey, + passphrase : clientPassword + }, [ + 'http connect to localhost:' + ss2.port, + 'https response', + '200 https ok' + ]) +} -// HTTP OVER HTTP - -runTest('http over http, tunnel=true', { - url : s.url, - proxy : s.url, - tunnel : true -}, [ - 'http connect to localhost:' + s.port, - 'http response', - '200 http ok' -]) - -runTest('http over http, tunnel=false', { - url : s.url, - proxy : s.url, - tunnel : false -}, [ - 'http proxy to http', - 'http response', - '200 http ok' -]) - -runTest('http over http, tunnel=default', { - url : s.url, - proxy : s.url -}, [ - 'http proxy to http', - 'http response', - '200 http ok' -]) - - -// HTTP OVER HTTPS - -runTest('http over https, tunnel=true', { - url : s.url, - proxy : ss.url, - tunnel : true -}, [ - 'https connect to localhost:' + s.port, - 'http response', - '200 http ok' -]) - -runTest('http over https, tunnel=false', { - url : s.url, - proxy : ss.url, - tunnel : false -}, [ - 'https proxy to http', - 'http response', - '200 http ok' -]) - -runTest('http over https, tunnel=default', { - url : s.url, - proxy : ss.url -}, [ - 'https proxy to http', - 'http response', - '200 http ok' -]) - - -// HTTPS OVER HTTP - -runTest('https over http, tunnel=true', { - url : ss.url, - proxy : s.url, - tunnel : true -}, [ - 'http connect to localhost:' + ss.port, - 'https response', - '200 https ok' -]) - -runTest('https over http, tunnel=false', { - url : ss.url, - proxy : s.url, - tunnel : false -}, [ - 'http proxy to https', - 'https response', - '200 https ok' -]) - -runTest('https over http, tunnel=default', { - url : ss.url, - proxy : s.url -}, [ - 'http connect to localhost:' + ss.port, - 'https response', - '200 https ok' -]) - - -// HTTPS OVER HTTPS - -runTest('https over https, tunnel=true', { - url : ss.url, - proxy : ss.url, - tunnel : true -}, [ - 'https connect to localhost:' + ss.port, - 'https response', - '200 https ok' -]) - -runTest('https over https, tunnel=false', { - url : ss.url, - proxy : ss.url, - tunnel : false, - pool : false // must disable pooling here or Node.js hangs -}, [ - 'https proxy to https', - 'https response', - '200 https ok' -]) - -runTest('https over https, tunnel=default', { - url : ss.url, - proxy : ss.url -}, [ - 'https connect to localhost:' + ss.port, - 'https response', - '200 https ok' -]) - - -// HTTP->HTTP OVER HTTP - -runTest('http->http over http, tunnel=true', { - url : s.url + '/redirect/http', - proxy : s.url, - tunnel : true -}, [ - 'http connect to localhost:' + s.port, - 'http redirect to http', - 'http connect to localhost:' + s.port, - 'http response', - '200 http ok' -]) - -runTest('http->http over http, tunnel=false', { - url : s.url + '/redirect/http', - proxy : s.url, - tunnel : false -}, [ - 'http proxy to http->http', - 'http redirect to http', - 'http proxy to http', - 'http response', - '200 http ok' -]) - -runTest('http->http over http, tunnel=default', { - url : s.url + '/redirect/http', - proxy : s.url -}, [ - 'http proxy to http->http', - 'http redirect to http', - 'http proxy to http', - 'http response', - '200 http ok' -]) - - -// HTTP->HTTPS OVER HTTP - -runTest('http->https over http, tunnel=true', { - url : s.url + '/redirect/https', - proxy : s.url, - tunnel : true -}, [ - 'http connect to localhost:' + s.port, - 'http redirect to https', - 'http connect to localhost:' + ss.port, - 'https response', - '200 https ok' -]) - -runTest('http->https over http, tunnel=false', { - url : s.url + '/redirect/https', - proxy : s.url, - tunnel : false -}, [ - 'http proxy to http->https', - 'http redirect to https', - 'http proxy to https', - 'https response', - '200 https ok' -]) - -runTest('http->https over http, tunnel=default', { - url : s.url + '/redirect/https', - proxy : s.url -}, [ - 'http proxy to http->https', - 'http redirect to https', - 'http connect to localhost:' + ss.port, - 'https response', - '200 https ok' -]) - - -// HTTPS->HTTP OVER HTTP - -runTest('https->http over http, tunnel=true', { - url : ss.url + '/redirect/http', - proxy : s.url, - tunnel : true -}, [ - 'http connect to localhost:' + ss.port, - 'https redirect to http', - 'http connect to localhost:' + s.port, - 'http response', - '200 http ok' -]) - -runTest('https->http over http, tunnel=false', { - url : ss.url + '/redirect/http', - proxy : s.url, - tunnel : false -}, [ - 'http proxy to https->http', - 'https redirect to http', - 'http proxy to http', - 'http response', - '200 http ok' -]) - -runTest('https->http over http, tunnel=default', { - url : ss.url + '/redirect/http', - proxy : s.url -}, [ - 'http connect to localhost:' + ss.port, - 'https redirect to http', - 'http proxy to http', - 'http response', - '200 http ok' -]) - - -// HTTPS->HTTPS OVER HTTP - -runTest('https->https over http, tunnel=true', { - url : ss.url + '/redirect/https', - proxy : s.url, - tunnel : true -}, [ - 'http connect to localhost:' + ss.port, - 'https redirect to https', - 'http connect to localhost:' + ss.port, - 'https response', - '200 https ok' -]) - -runTest('https->https over http, tunnel=false', { - url : ss.url + '/redirect/https', - proxy : s.url, - tunnel : false -}, [ - 'http proxy to https->https', - 'https redirect to https', - 'http proxy to https', - 'https response', - '200 https ok' -]) - -runTest('https->https over http, tunnel=default', { - url : ss.url + '/redirect/https', - proxy : s.url -}, [ - 'http connect to localhost:' + ss.port, - 'https redirect to https', - 'http connect to localhost:' + ss.port, - 'https response', - '200 https ok' -]) - - -// MUTUAL HTTPS OVER HTTP - -runTest('mutual https over http, tunnel=true', { - url : ss2.url, - proxy : s.url, - tunnel : true, - cert : clientCert, - key : clientKey, - passphrase : clientPassword -}, [ - 'http connect to localhost:' + ss2.port, - 'https response', - '200 https ok' -]) - -// XXX causes 'Error: socket hang up' -// runTest('mutual https over http, tunnel=false', { -// url : ss2.url, -// proxy : s.url, -// tunnel : false, -// cert : clientCert, -// key : clientKey, -// passphrase : clientPassword -// }, [ -// 'http connect to localhost:' + ss2.port, -// 'https response', -// '200 https ok' -// ]) - -runTest('mutual https over http, tunnel=default', { - url : ss2.url, - proxy : s.url, - cert : clientCert, - key : clientKey, - passphrase : clientPassword -}, [ - 'http connect to localhost:' + ss2.port, - 'https response', - '200 https ok' -]) - - -tape('cleanup', function(t) { - s.destroy(function() { - ss.destroy(function() { - ss2.destroy(function() { +tape('setup', function(t) { + s.listen(0, function() { + ss.listen(0, function() { + ss2.listen(0, 'localhost', function() { + addTests() + tape('cleanup', function(t) { + s.destroy(function() { + ss.destroy(function() { + ss2.destroy(function() { + t.end() + }) + }) + }) + }) t.end() }) }) From 3804428a723b5dc4ae15b92169d576b2d9466840 Mon Sep 17 00:00:00 2001 From: Brian White Date: Fri, 14 Oct 2016 06:21:14 -0400 Subject: [PATCH 354/490] Don't end response early in tests/test-pipes --- tests/test-pipes.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/test-pipes.js b/tests/test-pipes.js index 41d82232f..f1498e17d 100644 --- a/tests/test-pipes.js +++ b/tests/test-pipes.js @@ -210,7 +210,7 @@ tape('pause before piping from a request object', function(t) { }, 100) }) -var fileContents = fs.readFileSync(__filename).toString() +var fileContents = fs.readFileSync(__filename) function testPipeFromFile(testName, hasContentLength) { tape(testName, function(t) { s.once('/pushjs', function(req, res) { @@ -220,13 +220,16 @@ function testPipeFromFile(testName, hasContentLength) { req.headers['content-length'], (hasContentLength ? '' + fileContents.length : undefined)) var body = '' + req.setEncoding('utf8') req.on('data', function(data) { body += data }) req.on('end', function() { - t.equal(body, fileContents) + res.end() + t.equal(body, fileContents.toString()) t.end() }) + } else { res.end() } }) From 5c93d8c4dbb9e7a2745cd285e98140cdc2e25f15 Mon Sep 17 00:00:00 2001 From: Brian White Date: Thu, 13 Oct 2016 20:37:52 -0400 Subject: [PATCH 355/490] Improve test-timeout reliability --- tests/test-timeout.js | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/tests/test-timeout.js b/tests/test-timeout.js index 1f2944e43..7dd1d39e5 100644 --- a/tests/test-timeout.js +++ b/tests/test-timeout.js @@ -122,16 +122,30 @@ tape('float timeout', function(t) { // should be rounded by setTimeout anyway }) }) -tape('connect timeout', function(t) { - // We need a destination that will not immediately return a TCP Reset - // packet. StackOverflow suggests this host: - // https://stackoverflow.com/a/904609/329700 - var tarpitHost = 'http://10.255.255.1' +// We need a destination that will not immediately return a TCP Reset +// packet. StackOverflow suggests these hosts: +// (https://stackoverflow.com/a/904609/329700) +var nonRoutable = [ + '10.255.255.1', + '10.0.0.0', + '192.168.0.0', + '192.168.255.255', + '172.16.0.0', + '172.31.255.255' +] +tape('connect timeout', function tryConnect(t) { + var tarpitHost = 'http://' + nonRoutable.shift() var shouldConnectTimeout = { url: tarpitHost + '/timeout', timeout: 100 } request(shouldConnectTimeout, function(err) { + if (err.code === 'ENETUNREACH' && nonRoutable.length) { + // With some network configurations, some addresses will be reported as + // unreachable immediately (before the timeout occurs). In those cases, + // try other non-routable addresses before giving up. + return tryConnect(t) + } checkErrCode(t, err) t.ok(err.connect === true, 'Connect Timeout Error should set \'connect\' property to true') t.end() From 0d27170e8a96437758694aa7ed10af432ea8d9e6 Mon Sep 17 00:00:00 2001 From: Andres Suarez Date: Sun, 16 Oct 2016 18:31:57 -0400 Subject: [PATCH 356/490] Handle buffers directly instead of using "bl" --- package.json | 1 - request.js | 30 +++++++++++++++--------------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index fc1cfaf5a..a3214931d 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,6 @@ "dependencies": { "aws-sign2": "~0.6.0", "aws4": "^1.2.1", - "bl": "~1.1.2", "caseless": "~0.11.0", "combined-stream": "~1.0.5", "extend": "~3.0.0", diff --git a/request.js b/request.js index fe70a6ed2..8ed57b7f0 100644 --- a/request.js +++ b/request.js @@ -6,7 +6,6 @@ var http = require('http') , util = require('util') , stream = require('stream') , zlib = require('zlib') - , bl = require('bl') , hawk = require('hawk') , aws2 = require('aws-sign2') , aws4 = require('aws4') @@ -1005,14 +1004,16 @@ Request.prototype.onRequestResponse = function (response) { Request.prototype.readResponseBody = function (response) { var self = this debug('reading response\'s body') - var buffer = bl() + var buffers = [] + , bufferLength = 0 , strings = [] self.on('data', function (chunk) { - if (Buffer.isBuffer(chunk)) { - buffer.append(chunk) - } else { + if (!Buffer.isBuffer(chunk)) { strings.push(chunk) + } else if (chunk.length) { + bufferLength += chunk.length + buffers.push(chunk) } }) self.on('end', function () { @@ -1021,22 +1022,21 @@ Request.prototype.readResponseBody = function (response) { 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() + buffers = [] + bufferLength = 0 return } - if (buffer.length) { - debug('has body', self.uri.href, buffer.length) - if (self.encoding === null) { - // response.body = buffer - // can't move to this until https://github.com/rvagg/bl/issues/13 - response.body = buffer.slice() - } else { - response.body = buffer.toString(self.encoding) + if (bufferLength) { + debug('has body', self.uri.href, bufferLength) + response.body = Buffer.concat(buffers, bufferLength) + if (self.encoding !== null) { + response.body = response.body.toString(self.encoding) } // `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() + buffers = [] + bufferLength = 0 } else if (strings.length) { // The UTF8 BOM [0xEF,0xBB,0xBF] is converted to [0xFE,0xFF] in the JS UTC16/UCS2 representation. // Strip this value out when the encoding is set to 'utf8', as upstream consumers won't expect it and it breaks JSON.parse(). From d9b8d4882dfcc7386fc9390419c34d5847aedb14 Mon Sep 17 00:00:00 2001 From: kirrg001 Date: Tue, 25 Oct 2016 10:13:42 +0200 Subject: [PATCH 357/490] Add followOriginalHttpMethod to redirect to original HTTP method closes #2118 - added test - updated readme --- README.md | 1 + lib/redirect.js | 6 +++++- tests/test-redirect.js | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6eaaa0547..a0b6c84d0 100644 --- a/README.md +++ b/README.md @@ -762,6 +762,7 @@ The first argument can be either a `url` or an `options` object. The only requir - `followRedirect` - follow HTTP 3xx responses as redirects (default: `true`). This property can also be implemented as function which gets `response` object as a single argument and should return `true` if redirects should continue or `false` otherwise. - `followAllRedirects` - follow non-GET HTTP 3xx responses as redirects (default: `false`) +- `followOriginalHttpMethod` - by default we redirect to HTTP method GET. you can enable this property to redirect to the original HTTP method (default: `false`) - `maxRedirects` - the maximum number of redirects to follow (default: `10`) - `removeRefererHeader` - removes the referer header when a redirect happens (default: `false`). **Note:** if true, referer header set in the initial request is preserved during redirect chain. diff --git a/lib/redirect.js b/lib/redirect.js index 040dfe0e0..f8604491f 100644 --- a/lib/redirect.js +++ b/lib/redirect.js @@ -8,6 +8,7 @@ function Redirect (request) { this.followRedirect = true this.followRedirects = true this.followAllRedirects = false + this.followOriginalHttpMethod = false this.allowRedirect = function () {return true} this.maxRedirects = 10 this.redirects = [] @@ -36,6 +37,9 @@ Redirect.prototype.onRequest = function (options) { if (options.removeRefererHeader !== undefined) { self.removeRefererHeader = options.removeRefererHeader } + if (options.followOriginalHttpMethod !== undefined) { + self.followOriginalHttpMethod = options.followOriginalHttpMethod + } } Redirect.prototype.redirectTo = function (response) { @@ -115,7 +119,7 @@ Redirect.prototype.onResponse = function (response) { ) if (self.followAllRedirects && request.method !== 'HEAD' && response.statusCode !== 401 && response.statusCode !== 307) { - request.method = 'GET' + request.method = self.followOriginalHttpMethod ? request.method : 'GET' } // request.method = 'GET' // Force all redirects to use GET || commented out fixes #215 delete request.src diff --git a/tests/test-redirect.js b/tests/test-redirect.js index 1f49182fb..decfd2602 100644 --- a/tests/test-redirect.js +++ b/tests/test-redirect.js @@ -186,6 +186,24 @@ tape('should follow post redirects when followallredirects true', function(t) { }) }) +tape('should follow post redirects when followallredirects true and followOriginalHttpMethod is enabled', function(t) { + hits = {} + request.post({ + uri: s.url + '/temp', + followAllRedirects: true, + followOriginalHttpMethod: true, + jar: jar, + headers: { cookie: 'foo=bar' } + }, function(err, res, body) { + t.equal(err, null) + t.equal(res.statusCode, 200) + t.ok(hits.temp, 'Original request is to /temp') + t.ok(hits.temp_landing, 'Forward to temporary landing URL') + t.equal(body, 'POST temp_landing', 'Got temporary landing content') + t.end() + }) +}) + tape('should not follow post redirects when followallredirects false', function(t) { hits = {} request.post({ From a29f1f8b4dbc68e3b5e21e9db776663537beaa79 Mon Sep 17 00:00:00 2001 From: simov Date: Tue, 25 Oct 2016 11:56:23 +0300 Subject: [PATCH 358/490] 2.76.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a3214931d..73d867575 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.75.1", + "version": "2.76.0", "author": "Mikeal Rogers ", "repository": { "type": "git", From 7e873863803817d321dbc994d3eff943cde42ac7 Mon Sep 17 00:00:00 2001 From: simov Date: Tue, 25 Oct 2016 11:57:32 +0300 Subject: [PATCH 359/490] Update changelog --- CHANGELOG.md | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 042c6e526..c8f4545a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ ## Change Log +### v2.76.0 (2016/10/25) +- [#2424](https://github.com/request/request/pull/2424) Handle buffers directly instead of using "bl" (@zertosh) +- [#2415](https://github.com/request/request/pull/2415) Re-enable timeout tests on Travis + other fixes (@mscdex) +- [#2431](https://github.com/request/request/pull/2431) Improve timeouts accuracy and node v6.8.0+ compatibility (@mscdex, @greenkeeperio-bot) +- [#2428](https://github.com/request/request/pull/2428) Update qs to version 6.3.0 🚀 (@greenkeeperio-bot) +- [#2420](https://github.com/request/request/pull/2420) change .on to .once, remove possible memory leaks (@duereg) +- [#2426](https://github.com/request/request/pull/2426) Remove "isFunction" helper in favor of "typeof" check (@zertosh) +- [#2425](https://github.com/request/request/pull/2425) Simplify "defer" helper creation (@zertosh) +- [#2402](https://github.com/request/request/pull/2402) form-data@2.1.1 breaks build 🚨 (@greenkeeperio-bot) +- [#2393](https://github.com/request/request/pull/2393) Update form-data to version 2.1.0 🚀 (@greenkeeperio-bot) + ### v2.75.0 (2016/09/17) - [#2381](https://github.com/request/request/pull/2381) Drop support for Node 0.10 (@simov) - [#2377](https://github.com/request/request/pull/2377) Update form-data to version 2.0.0 🚀 (@greenkeeperio-bot) @@ -500,8 +511,6 @@ ### v2.26.0 (2013/08/07) - [#613](https://github.com/request/request/pull/613) Fixes #583, moved initialization of self.uri.pathname (@lexander) - [#605](https://github.com/request/request/pull/605) Only include ":" + pass in Basic Auth if it's defined (fixes #602) (@bendrucker) - -### v2.25.0 (2013/07/23) - [#596](https://github.com/request/request/pull/596) Global agent is being used when pool is specified (@Cauldrath) - [#594](https://github.com/request/request/pull/594) Emit complete event when there is no callback (@RomainLK) - [#601](https://github.com/request/request/pull/601) Fixed a small typo (@michalstanko) @@ -574,7 +583,7 @@ - [#290](https://github.com/request/request/pull/290) A test for #289 (@isaacs) - [#280](https://github.com/request/request/pull/280) Like in node.js print options if NODE_DEBUG contains the word request (@Filirom1) - [#207](https://github.com/request/request/pull/207) Fix #206 Change HTTP/HTTPS agent when redirecting between protocols (@isaacs) -- [#214](https://github.com/request/request/pull/214) documenting additional behavior of json option (@jphaas) +- [#214](https://github.com/request/request/pull/214) documenting additional behavior of json option (@jphaas, @vpulim) - [#272](https://github.com/request/request/pull/272) Boundary begins with CRLF? (@elspoono, @timshadel, @naholyr, @nanodocumet, @TehShrike) - [#284](https://github.com/request/request/pull/284) Remove stray `console.log()` call in multipart generator. (@bcherry) - [#241](https://github.com/request/request/pull/241) Composability updates suggested by issue #239 (@polotek) @@ -592,10 +601,10 @@ - [#246](https://github.com/request/request/pull/246) Fixing the set-cookie header (@jeromegn) - [#243](https://github.com/request/request/pull/243) Dynamic boundary (@zephrax) - [#240](https://github.com/request/request/pull/240) don't error when null is passed for options (@polotek) -- [#211](https://github.com/request/request/pull/211) Replace all occurrences of special chars in RFC3986 (@chriso) +- [#211](https://github.com/request/request/pull/211) Replace all occurrences of special chars in RFC3986 (@chriso, @vpulim) - [#224](https://github.com/request/request/pull/224) Multipart content-type change (@janjongboom) - [#217](https://github.com/request/request/pull/217) need to use Authorization (titlecase) header with Tumblr OAuth (@visnup) -- [#203](https://github.com/request/request/pull/203) Fix cookie and redirect bugs and add auth support for HTTPS tunnel (@milewise) +- [#203](https://github.com/request/request/pull/203) Fix cookie and redirect bugs and add auth support for HTTPS tunnel (@vpulim) - [#199](https://github.com/request/request/pull/199) Tunnel (@isaacs) - [#198](https://github.com/request/request/pull/198) Bugfix on forever usage of util.inherits (@isaacs) - [#197](https://github.com/request/request/pull/197) Make ForeverAgent work with HTTPS (@isaacs) From 53b78317f47e8c1d4e4c046966b476fc6672be70 Mon Sep 17 00:00:00 2001 From: simov Date: Tue, 25 Oct 2016 11:58:00 +0300 Subject: [PATCH 360/490] 2.76.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 73d867575..e82329eb1 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.76.0", + "version": "2.76.1", "author": "Mikeal Rogers ", "repository": { "type": "git", From 001eae3d479a13350b06b8d3f8182b2060a2c60d Mon Sep 17 00:00:00 2001 From: Brian White Date: Wed, 26 Oct 2016 11:46:27 -0400 Subject: [PATCH 361/490] Fix socket 'connect' listener handling This commit ensures that both a 'connect' timer only starts when a new socket is being used for a request and that the 'connect' timer is stopped in more places. Fixes: https://github.com/request/request/issues/2438 --- request.js | 18 +++++++++++++++-- tests/test-timeout.js | 47 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/request.js b/request.js index 8ed57b7f0..035385d45 100644 --- a/request.js +++ b/request.js @@ -766,8 +766,15 @@ Request.prototype.start = function () { self.emit('drain') }) self.req.on('socket', function(socket) { - if (timeout !== undefined) { - socket.once('connect', function() { + // `._connecting` was the old property which was made public in node v6.1.0 + var isConnecting = socket._connecting || socket.connecting + // Only start the connection timer if we're actually connecting a new + // socket, otherwise if we're already connected (because this is a + // keep-alive connection) do not bother. This is important since we won't + // get a 'connect' event for an already connected socket. + if (timeout !== undefined && isConnecting) { + var onReqSockConnect = function() { + socket.removeListener('connect', onReqSockConnect) clearTimeout(self.timeoutTimer) self.timeoutTimer = null // Set an additional timeout on the socket, via the `setsockopt` syscall. @@ -785,6 +792,12 @@ Request.prototype.start = function () { self.emit('error', e) } }) + } + + socket.on('connect', onReqSockConnect) + + self.req.on('error', function(err) { + socket.removeListener('connect', onReqSockConnect) }) // Set a timeout in memory - this block will throw if the server takes more @@ -792,6 +805,7 @@ Request.prototype.start = function () { // 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 () { + socket.removeListener('connect', onReqSockConnect) self.abort() var e = new Error('ETIMEDOUT') e.code = 'ETIMEDOUT' diff --git a/tests/test-timeout.js b/tests/test-timeout.js index 1f2944e43..ddcb9e1eb 100644 --- a/tests/test-timeout.js +++ b/tests/test-timeout.js @@ -6,6 +6,19 @@ function checkErrCode(t, err) { 'Error ETIMEDOUT or ESOCKETTIMEDOUT') } +function checkEventHandlers(t, socket) { + var connectListeners = socket.listeners('connect') + var found = false + for (var i = 0; i < connectListeners.length; ++i) { + var fn = connectListeners[i] + if (typeof fn === 'function' && fn.name === 'onReqSockConnect') { + found = true + break + } + } + t.ok(!found, 'Connect listener should not exist') +} + var server = require('./server') , request = require('../index') , tape = require('tape') @@ -75,10 +88,14 @@ tape('should not timeout', function(t) { timeout: 1200 } + var socket request(shouldntTimeout, function(err, res, body) { t.equal(err, null) t.equal(body, 'waited') + checkEventHandlers(t, socket) t.end() + }).on('socket', function(socket_) { + socket = socket_ }) }) @@ -131,10 +148,40 @@ tape('connect timeout', function(t) { url: tarpitHost + '/timeout', timeout: 100 } + var socket request(shouldConnectTimeout, function(err) { checkErrCode(t, err) t.ok(err.connect === true, 'Connect Timeout Error should set \'connect\' property to true') + checkEventHandlers(t, socket) t.end() + }).on('socket', function(socket_) { + socket = socket_ + }) +}) + +tape('connect timeout with non-timeout error', function(t) { + // We need a destination that will not immediately return a TCP Reset + // packet. StackOverflow suggests this host: + // https://stackoverflow.com/a/904609/329700 + var tarpitHost = 'http://10.255.255.1' + var shouldConnectTimeout = { + url: tarpitHost + '/timeout', + timeout: 1000 + } + var socket + request(shouldConnectTimeout, function(err) { + t.notEqual(err, null) + // Delay the check since the 'connect' handler is removed in a separate + // 'error' handler which gets triggered after this callback + setImmediate(function() { + checkEventHandlers(t, socket) + t.end() + }) + }).on('socket', function(socket_) { + socket = socket_ + setImmediate(function() { + socket.emit('error', new Error('Fake Error')) + }) }) }) From 01aefdd87cdd9cc44af6828c55fe5ef9c7e205d7 Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Mon, 31 Oct 2016 15:10:22 -0700 Subject: [PATCH 362/490] chore: drop support for Node.js 0.10 BREAKING CHANGE: This module no longer supports Node.js 0.10 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e82329eb1..fcc235e60 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ }, "license": "Apache-2.0", "engines": { - "node": ">=0.8.0" + "node": ">= 4" }, "main": "index.js", "dependencies": { From 4c4557faabf415a01ce2d8a7c3473311c126f69b Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 3 Nov 2016 13:15:58 +0200 Subject: [PATCH 363/490] Drop 0.12 build target --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9be8247c7..643e6551b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,6 @@ node_js: - node - 6 - 4 - - 0.12 after_script: - npm run test-cov From 22ecf67769f3cca15ebc4724500117b3359e8195 Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 3 Nov 2016 13:16:19 +0200 Subject: [PATCH 364/490] 2.77.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index fcc235e60..4ef0afb2d 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.76.1", + "version": "2.77.0", "author": "Mikeal Rogers ", "repository": { "type": "git", From 8d534217a9411053e40885120696515c1bee0673 Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 3 Nov 2016 13:17:46 +0200 Subject: [PATCH 365/490] Update changelog --- CHANGELOG.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c8f4545a2..3e0d19bb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ ## Change Log +### v2.77.0 (2016/11/03) +- [#2439](https://github.com/request/request/pull/2439) Fix socket 'connect' listener handling (@mscdex) +- [#2442](https://github.com/request/request/pull/2442) 👻😱 Node.js 0.10 is unmaintained 😱👻 (@greenkeeperio-bot) +- [#2435](https://github.com/request/request/pull/2435) Add followOriginalHttpMethod to redirect to original HTTP method (@kirrg001) +- [#2414](https://github.com/request/request/pull/2414) Improve test-timeout reliability (@mscdex) + ### v2.76.0 (2016/10/25) - [#2424](https://github.com/request/request/pull/2424) Handle buffers directly instead of using "bl" (@zertosh) - [#2415](https://github.com/request/request/pull/2415) Re-enable timeout tests on Travis + other fixes (@mscdex) @@ -507,8 +513,6 @@ ### v2.27.0 (2013/08/15) - [#619](https://github.com/request/request/pull/619) decouple things a bit (@joaojeronimo) - -### v2.26.0 (2013/08/07) - [#613](https://github.com/request/request/pull/613) Fixes #583, moved initialization of self.uri.pathname (@lexander) - [#605](https://github.com/request/request/pull/605) Only include ":" + pass in Basic Auth if it's defined (fixes #602) (@bendrucker) - [#596](https://github.com/request/request/pull/596) Global agent is being used when pool is specified (@Cauldrath) From 7228f1328523b4dd8f0be652104a6a41e1fc9395 Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 3 Nov 2016 13:18:01 +0200 Subject: [PATCH 366/490] 2.77.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4ef0afb2d..ed853b55a 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.77.0", + "version": "2.77.1", "author": "Mikeal Rogers ", "repository": { "type": "git", From 82da8b857050a7078a40b7e0f2781077c13abea7 Mon Sep 17 00:00:00 2001 From: Brian White Date: Thu, 3 Nov 2016 08:05:38 -0400 Subject: [PATCH 367/490] Always set request timeout on keep-alive connections 001eae3d479 would erroneously only set http request timeout if a new socket was being used for the request. This commit ensures the http request timeout is always set, even on keep-alive connections. --- request.js | 89 +++++++++++++++++++++++-------------------- tests/test-timeout.js | 29 ++++++++++++++ 2 files changed, 77 insertions(+), 41 deletions(-) diff --git a/request.js b/request.js index 035385d45..9528b5662 100644 --- a/request.js +++ b/request.js @@ -766,52 +766,59 @@ Request.prototype.start = function () { self.emit('drain') }) self.req.on('socket', function(socket) { + var setReqTimeout = function() { + // This timeout sets the amount of time to wait *between* bytes sent + // from the server once connected. + // + // 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.abort() + var e = new Error('ESOCKETTIMEDOUT') + e.code = 'ESOCKETTIMEDOUT' + e.connect = false + self.emit('error', e) + } + }) + } // `._connecting` was the old property which was made public in node v6.1.0 var isConnecting = socket._connecting || socket.connecting - // Only start the connection timer if we're actually connecting a new - // socket, otherwise if we're already connected (because this is a - // keep-alive connection) do not bother. This is important since we won't - // get a 'connect' event for an already connected socket. - if (timeout !== undefined && isConnecting) { - var onReqSockConnect = function() { - socket.removeListener('connect', onReqSockConnect) - clearTimeout(self.timeoutTimer) - self.timeoutTimer = null - // 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 once connected. - // - // 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.abort() - var e = new Error('ESOCKETTIMEDOUT') - e.code = 'ESOCKETTIMEDOUT' - e.connect = false - self.emit('error', e) - } - }) - } + if (timeout !== undefined) { + // Only start the connection timer if we're actually connecting a new + // socket, otherwise if we're already connected (because this is a + // keep-alive connection) do not bother. This is important since we won't + // get a 'connect' event for an already connected socket. + if (isConnecting) { + var onReqSockConnect = function() { + socket.removeListener('connect', onReqSockConnect) + clearTimeout(self.timeoutTimer) + self.timeoutTimer = null + setReqTimeout() + } - socket.on('connect', onReqSockConnect) + socket.on('connect', onReqSockConnect) - self.req.on('error', function(err) { - socket.removeListener('connect', onReqSockConnect) - }) + self.req.on('error', function(err) { + socket.removeListener('connect', onReqSockConnect) + }) - // 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 () { - socket.removeListener('connect', onReqSockConnect) - self.abort() - var e = new Error('ETIMEDOUT') - e.code = 'ETIMEDOUT' - e.connect = true - self.emit('error', e) - }, 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 () { + socket.removeListener('connect', onReqSockConnect) + self.abort() + var e = new Error('ETIMEDOUT') + e.code = 'ETIMEDOUT' + e.connect = true + self.emit('error', e) + }, timeout) + } else { + // We're already connected + setReqTimeout() + } } self.emit('socket', socket) }) diff --git a/tests/test-timeout.js b/tests/test-timeout.js index f2016b0b4..4eb6bc0cd 100644 --- a/tests/test-timeout.js +++ b/tests/test-timeout.js @@ -199,6 +199,35 @@ tape('connect timeout with non-timeout error', function(t) { }) }) +tape('request timeout with keep-alive connection', function(t) { + var agent = new require('http').Agent({ keepAlive: true }) + var firstReq = { + url: s.url + '/timeout', + agent: agent + } + request(firstReq, function(err) { + // We should now still have a socket open. For the second request we should + // see a request timeout on the active socket ... + t.equal(err, null) + var shouldReqTimeout = { + url: s.url + '/timeout', + timeout: 100, + agent: agent + } + request(shouldReqTimeout, function(err) { + checkErrCode(t, err) + t.ok(err.connect === false, 'Error should have been a request timeout error') + t.end() + }).on('socket', function(socket) { + var isConnecting = socket._connecting || socket.connecting + t.ok(isConnecting !== true, 'Socket should already be connected') + }) + }).on('socket', function(socket) { + var isConnecting = socket._connecting || socket.connecting + t.ok(isConnecting === true, 'Socket should be new') + }) +}) + tape('cleanup', function(t) { s.close(function() { t.end() From 4cb1487e7ca806aab65391b9212e82d1eb2ac391 Mon Sep 17 00:00:00 2001 From: Brian White Date: Thu, 3 Nov 2016 08:36:30 -0400 Subject: [PATCH 368/490] Make other connect timeout test more reliable too --- tests/test-timeout.js | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/tests/test-timeout.js b/tests/test-timeout.js index f2016b0b4..e53165a92 100644 --- a/tests/test-timeout.js +++ b/tests/test-timeout.js @@ -150,15 +150,25 @@ var nonRoutable = [ '172.16.0.0', '172.31.255.255' ] +var nrIndex = 0 +function getNonRoutable() { + var ip = nonRoutable[nrIndex] + if (!ip) { + throw new Error('No more non-routable addresses') + } + ++nrIndex + return ip +} tape('connect timeout', function tryConnect(t) { - var tarpitHost = 'http://' + nonRoutable.shift() + var tarpitHost = 'http://' + getNonRoutable() var shouldConnectTimeout = { url: tarpitHost + '/timeout', timeout: 100 } var socket request(shouldConnectTimeout, function(err) { - if (err.code === 'ENETUNREACH' && nonRoutable.length) { + t.notEqual(err, null) + if (err.code === 'ENETUNREACH' && nrIndex < nonRoutable.length) { // With some network configurations, some addresses will be reported as // unreachable immediately (before the timeout occurs). In those cases, // try other non-routable addresses before giving up. @@ -167,17 +177,15 @@ tape('connect timeout', function tryConnect(t) { checkErrCode(t, err) t.ok(err.connect === true, 'Connect Timeout Error should set \'connect\' property to true') checkEventHandlers(t, socket) + nrIndex = 0 t.end() }).on('socket', function(socket_) { socket = socket_ }) }) -tape('connect timeout with non-timeout error', function(t) { - // We need a destination that will not immediately return a TCP Reset - // packet. StackOverflow suggests this host: - // https://stackoverflow.com/a/904609/329700 - var tarpitHost = 'http://10.255.255.1' +tape('connect timeout with non-timeout error', function tryConnect(t) { + var tarpitHost = 'http://' + getNonRoutable() var shouldConnectTimeout = { url: tarpitHost + '/timeout', timeout: 1000 @@ -185,10 +193,17 @@ tape('connect timeout with non-timeout error', function(t) { var socket request(shouldConnectTimeout, function(err) { t.notEqual(err, null) + if (err.code === 'ENETUNREACH' && nrIndex < nonRoutable.length) { + // With some network configurations, some addresses will be reported as + // unreachable immediately (before the timeout occurs). In those cases, + // try other non-routable addresses before giving up. + return tryConnect(t) + } // Delay the check since the 'connect' handler is removed in a separate // 'error' handler which gets triggered after this callback setImmediate(function() { checkEventHandlers(t, socket) + nrIndex = 0 t.end() }) }).on('socket', function(socket_) { From 7cc16575a3e5a47cdd362ccd1b508e253f37a4bb Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 3 Nov 2016 15:36:28 +0200 Subject: [PATCH 369/490] 2.78.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ed853b55a..88e6ba920 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.77.1", + "version": "2.78.0", "author": "Mikeal Rogers ", "repository": { "type": "git", From d4a68e9b64979f388c204f5d957e366878262340 Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 3 Nov 2016 15:37:56 +0200 Subject: [PATCH 370/490] Update changelog --- CHANGELOG.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e0d19bb9..be7949cea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## Change Log +### v2.78.0 (2016/11/03) +- [#2447](https://github.com/request/request/pull/2447) Always set request timeout on keep-alive connections (@mscdex) + ### v2.77.0 (2016/11/03) - [#2439](https://github.com/request/request/pull/2439) Fix socket 'connect' listener handling (@mscdex) - [#2442](https://github.com/request/request/pull/2442) 👻😱 Node.js 0.10 is unmaintained 😱👻 (@greenkeeperio-bot) @@ -510,8 +513,6 @@ - [#662](https://github.com/request/request/pull/662) option.tunnel to explicitly disable tunneling (@seanmonstar) - [#659](https://github.com/request/request/pull/659) fix failure when running with NODE_DEBUG=request, and a test for that (@jrgm) - [#630](https://github.com/request/request/pull/630) Send random cnonce for HTTP Digest requests (@wprl) - -### v2.27.0 (2013/08/15) - [#619](https://github.com/request/request/pull/619) decouple things a bit (@joaojeronimo) - [#613](https://github.com/request/request/pull/613) Fixes #583, moved initialization of self.uri.pathname (@lexander) - [#605](https://github.com/request/request/pull/605) Only include ":" + pass in Basic Auth if it's defined (fixes #602) (@bendrucker) From 6739fe78759204ced0eb917f578c608f5f5f560b Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 3 Nov 2016 15:38:08 +0200 Subject: [PATCH 371/490] 2.78.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 88e6ba920..2645565c5 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.78.0", + "version": "2.78.1", "author": "Mikeal Rogers ", "repository": { "type": "git", From c5243d0a584a2251c1407099667d6614f616886e Mon Sep 17 00:00:00 2001 From: Nic Jansma Date: Sat, 5 Nov 2016 21:23:01 -0400 Subject: [PATCH 372/490] Adds .timings array with dns, tcp, request and response times --- README.md | 12 +++++++++++- package.json | 1 + request.js | 37 +++++++++++++++++++++++++++++++++++-- tests/test-timing.js | 11 +++++++++++ 4 files changed, 58 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a0b6c84d0..e1b31f6ae 100644 --- a/README.md +++ b/README.md @@ -812,7 +812,17 @@ default in Linux can be anywhere from 20-120 seconds][linux-timeout]). --- -- `time` - If `true`, the request-response cycle (including all redirects) is timed at millisecond resolution, and the result provided on the response's `elapsedTime` property. The `responseStartTime` property is also available to indicate the timestamp when the response begins. +- `time` - If `true`, the request-response cycle (including all redirects) is timed at millisecond resolution, and the result provided on the response's `elapsedTime` property. The `responseStartTime` property is also available to indicate the timestamp when the response begins. In addition, there is a `.timings` object available with the following properties: + - `start`: Timestamp when `request()` was initialized + - `socket` Timestamp when the [`http`](https://nodejs.org/api/http.html#http_event_socket) module's `socket` event fires. This happens when the socket is assigned to the request (after DNS has been resolved). + - `connect`: Timestamp when the [`http`](https://nodejs.org/api/http.html#http_event_connect) module's `connect` event fires. This happens when the server acknowledges the TCP connection. + - `response`: Timestamp when the [`http`](https://nodejs.org/api/http.html#http_event_response) module's `response` event fires. This happens when the first bytes are received from the server. + - `end`: Timestamp when the last bytes of the response are received. + - `dns`: Duration of DNS lookup (`timings.socket` - `timings.start`) + - `tcp`: Duration of TCP connection (`timings.connect` - `timings.socket`) + - `download`: Duration HTTP fetch (`timings.end` - `timings.response`) + - `total`: Duration entire HTTP round-trip (`timings.end` - `timings.start`) + - `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 diff --git a/package.json b/package.json index 2645565c5..c47bcd217 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "mime-types": "~2.1.7", "node-uuid": "~1.4.7", "oauth-sign": "~0.8.1", + "performance-now": "^0.2.0", "qs": "~6.3.0", "stringstream": "~0.0.4", "tough-cookie": "~2.3.0", diff --git a/request.js b/request.js index 9528b5662..39d2b37fd 100644 --- a/request.js +++ b/request.js @@ -28,6 +28,7 @@ var http = require('http') , Multipart = require('./lib/multipart').Multipart , Redirect = require('./lib/redirect').Redirect , Tunnel = require('./lib/tunnel').Tunnel + , now = require('performance-now') var safeStringify = helpers.safeStringify , isReadStream = helpers.isReadStream @@ -713,6 +714,10 @@ Request.prototype.start = function () { // this is usually called on the first write(), end() or on nextTick() var self = this + if (self.timing) { + var startTime = now() + } + if (self._aborted) { return } @@ -749,6 +754,9 @@ Request.prototype.start = function () { if (self.timing) { self.startTime = new Date().getTime() + self.timings = { + start: startTime + } } var timeout @@ -766,6 +774,13 @@ Request.prototype.start = function () { self.emit('drain') }) self.req.on('socket', function(socket) { + if (self.timing) { + self.timings.socket = now() + socket.on('connect', function() { + self.timings.connect = now() + }) + } + var setReqTimeout = function() { // This timeout sets the amount of time to wait *between* bytes sent // from the server once connected. @@ -847,12 +862,30 @@ Request.prototype.onRequestError = function (error) { Request.prototype.onRequestResponse = function (response) { var self = this + + if (self.timing) { + self.timings.response = now() + } + debug('onRequestResponse', self.uri.href, response.statusCode, response.headers) response.on('end', function() { if (self.timing) { - self.elapsedTime += (new Date().getTime() - self.startTime) - debug('elapsed time', self.elapsedTime) + self.timings.end = now() + + self.timings.dns = self.timings.socket - self.timings.start + self.timings.tcp = self.timings.connect - self.timings.socket + self.timings.firstByte = self.timings.response - self.timings.connect + self.timings.download = self.timings.end - self.timings.response + self.timings.total = self.timings.end - self.timings.start + + debug('elapsed time', self.timings.total) + + // elapsedTime includes all redirects + self.elapsedTime += Math.round(self.timings.total) response.elapsedTime = self.elapsedTime + + // timings is just for the final fetch + response.timings = self.timings } debug('response end', self.uri.href, response.statusCode, response.headers) }) diff --git a/tests/test-timing.js b/tests/test-timing.js index 5a3636d76..0e9a7cdf9 100644 --- a/tests/test-timing.js +++ b/tests/test-timing.js @@ -31,8 +31,19 @@ tape('non-redirected request is timed', function(t) { t.equal(err, null) t.equal(typeof res.elapsedTime, 'number') t.equal(typeof res.responseStartTime, 'number') + t.equal(typeof res.timings, 'object') t.equal((res.elapsedTime > 0), true) t.equal((res.responseStartTime > r.startTime), true) + t.equal((res.timings.start > 0), true) + t.equal((res.timings.socket >= res.timings.start), true) + t.equal((res.timings.connect >= res.timings.socket), true) + t.equal((res.timings.response >= res.timings.connect), true) + t.equal((res.timings.end >= res.timings.response), true) + t.equal((res.timings.dns >= 0), true) + t.equal((res.timings.tcp > 0), true) + t.equal((res.timings.firstByte > 0), true) + t.equal((res.timings.download > 0), true) + t.equal((res.timings.total > 0), true) t.end() }) }) From 17095d5984393907a55924d79f2b7fab7a121c7b Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Tue, 8 Nov 2016 19:16:06 -0800 Subject: [PATCH 373/490] chore(package): update taper to version 0.5.0 https://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2645565c5..9494d0053 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "rimraf": "^2.2.8", "server-destroy": "^1.0.1", "tape": "^4.6.0", - "taper": "^0.4.0" + "taper": "^0.5.0" }, "greenkeeper": { "ignore": [ From 33700bd058242d42cf81b50f4bd39b37af4fa408 Mon Sep 17 00:00:00 2001 From: OwnageIsMagic Date: Sat, 12 Nov 2016 15:10:31 +0300 Subject: [PATCH 374/490] Fix wrong MIME type in example --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a0b6c84d0..5e82b92b5 100644 --- a/README.md +++ b/README.md @@ -185,7 +185,7 @@ var formData = { value: fs.createReadStream('/dev/urandom'), options: { filename: 'topsecret.jpg', - contentType: 'image/jpg' + contentType: 'image/jpeg' } } }; From 9122f4359d36d6d2024cabbd0bfa59bd669d4ba2 Mon Sep 17 00:00:00 2001 From: Christopher Phillips Date: Thu, 17 Nov 2016 10:43:09 -0500 Subject: [PATCH 375/490] Fixing requests/requests issue #2462 - AWS support does not include the use of session tokens for temporary credentials --- README.md | 2 +- request.js | 6 +++++- tests/test-aws.js | 20 ++++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a0b6c84d0..2ddfe72c5 100644 --- a/README.md +++ b/README.md @@ -755,7 +755,7 @@ The first argument can be either a `url` or an `options` object. The only requir - `auth` - A hash containing values `user` || `username`, `pass` || `password`, and `sendImmediately` (optional). See documentation above. - `oauth` - Options for OAuth HMAC-SHA1 signing. See documentation above. - `hawk` - Options for [Hawk signing](https://github.com/hueniverse/hawk). The `credentials` key must contain the necessary signing info, [see hawk docs for details](https://github.com/hueniverse/hawk#usage-example). -- `aws` - `object` containing AWS signing information. Should have the properties `key`, `secret`. Also requires the property `bucket`, unless you’re specifying your `bucket` as part of the path, or the request doesn’t use a bucket (i.e. GET Services). If you want to use AWS sign version 4 use the parameter `sign_version` with value `4` otherwise the default is version 2. **Note:** you need to `npm install aws4` first. +- `aws` - `object` containing AWS signing information. Should have the properties `key`, `secret`, and optionally `session` (note that this only works for services that require session as part of the canonical string). Also requires the property `bucket`, unless you’re specifying your `bucket` as part of the path, or the request doesn’t use a bucket (i.e. GET Services). If you want to use AWS sign version 4 use the parameter `sign_version` with value `4` otherwise the default is version 2. **Note:** you need to `npm install aws4` first. - `httpSignature` - Options for the [HTTP Signature Scheme](https://github.com/joyent/node-http-signature/blob/master/http_signing.md) using [Joyent's library](https://github.com/joyent/node-http-signature). The `keyId` and `key` properties must be specified. See the docs for other options. --- diff --git a/request.js b/request.js index 9528b5662..618edacc9 100644 --- a/request.js +++ b/request.js @@ -1292,10 +1292,14 @@ Request.prototype.aws = function (opts, now) { } var signRes = aws4.sign(options, { accessKeyId: opts.key, - secretAccessKey: opts.secret + secretAccessKey: opts.secret, + sessionToken: opts.session ? opts.session : undefined }) self.setHeader('authorization', signRes.headers.Authorization) self.setHeader('x-amz-date', signRes.headers['X-Amz-Date']) + if (signRes.headers['X-Amz-Security-Token']) { + self.setHeader('x-amz-security-token', signRes.headers['X-Amz-Security-Token']) + } } else { // default: use aws-sign2 diff --git a/tests/test-aws.js b/tests/test-aws.js index cef7c74fb..af854c8cb 100644 --- a/tests/test-aws.js +++ b/tests/test-aws.js @@ -50,6 +50,26 @@ tape('aws-sign4 options', function(t) { request(options, function(err, res, body) { t.ok(body.authorization) t.ok(body['x-amz-date']) + t.notok(body['x-amz-security-token']) + t.end() + }) +}) + +tape('aws-sign4 options with session token', function(t) { + var options = { + url: s.url + path, + aws: { + key: 'my_key', + secret: 'my_secret', + session: 'session', + sign_version: 4 + }, + json: true + } + request(options, function(err, res, body) { + t.ok(body.authorization) + t.ok(body['x-amz-date']) + t.ok(body['x-amz-security-token']) t.end() }) }) From 39350edecf29a4996225974908a175f8a7759b76 Mon Sep 17 00:00:00 2001 From: simov Date: Fri, 18 Nov 2016 14:27:03 +0200 Subject: [PATCH 376/490] Bump uuid --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b99284229..f6e0b65cc 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "stringstream": "~0.0.4", "tough-cookie": "~2.3.0", "tunnel-agent": "~0.4.1", - "uuid": "^2.0.2" + "uuid": "^3.0.0" }, "scripts": { "test": "npm run lint && npm run test-ci && npm run test-browser", From 7532634b090a01a4bc75f298f39e5eb9ed51d63f Mon Sep 17 00:00:00 2001 From: simov Date: Fri, 18 Nov 2016 18:54:16 +0200 Subject: [PATCH 377/490] Remove redundant code --- request.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/request.js b/request.js index 618edacc9..26f70c208 100644 --- a/request.js +++ b/request.js @@ -1293,7 +1293,7 @@ Request.prototype.aws = function (opts, now) { var signRes = aws4.sign(options, { accessKeyId: opts.key, secretAccessKey: opts.secret, - sessionToken: opts.session ? opts.session : undefined + sessionToken: opts.session }) self.setHeader('authorization', signRes.headers.Authorization) self.setHeader('x-amz-date', signRes.headers['X-Amz-Date']) From d05c86c46a79928c5e64488d6067dc9c31ee0fce Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Mon, 26 Sep 2016 13:29:37 +0200 Subject: [PATCH 378/490] Use `files` in package.json --- .npmignore | 6 ------ package.json | 5 +++++ 2 files changed, 5 insertions(+), 6 deletions(-) delete mode 100644 .npmignore diff --git a/.npmignore b/.npmignore deleted file mode 100644 index 67fe11cc0..000000000 --- a/.npmignore +++ /dev/null @@ -1,6 +0,0 @@ -coverage -tests -node_modules -examples -release.sh -disabled.appveyor.yml diff --git a/package.json b/package.json index dd9adc54e..d8ac08b47 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,11 @@ "node": ">=0.8.0" }, "main": "index.js", + "files": [ + "lib/", + "index.js", + "request.js" + ], "dependencies": { "aws-sign2": "~0.6.0", "aws4": "^1.2.1", From 3a98820b38b2656c47c8ad55fdb6190d35c5fe6f Mon Sep 17 00:00:00 2001 From: simov Date: Fri, 18 Nov 2016 19:18:30 +0200 Subject: [PATCH 379/490] 2.79.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d25387684..4e7372ff5 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.78.1", + "version": "2.79.0", "author": "Mikeal Rogers ", "repository": { "type": "git", From ff729c6f1a87237060d075908563ce13386395ac Mon Sep 17 00:00:00 2001 From: simov Date: Fri, 18 Nov 2016 19:20:57 +0200 Subject: [PATCH 380/490] Update changelog --- CHANGELOG.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be7949cea..7a9b2abf9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ ## Change Log +### v2.79.0 (2016/11/18) +- [#2368](https://github.com/request/request/pull/2368) Fix typeof check in test-pool.js (@forivall) +- [#2394](https://github.com/request/request/pull/2394) Use `files` in package.json (@SimenB) +- [#2463](https://github.com/request/request/pull/2463) AWS support for session tokens for temporary credentials (@simov) +- [#2467](https://github.com/request/request/pull/2467) Migrate to uuid (@simov, @antialias) +- [#2459](https://github.com/request/request/pull/2459) Update taper to version 0.5.0 🚀 (@greenkeeperio-bot) +- [#2448](https://github.com/request/request/pull/2448) Make other connect timeout test more reliable too (@mscdex) + ### v2.78.0 (2016/11/03) - [#2447](https://github.com/request/request/pull/2447) Always set request timeout on keep-alive connections (@mscdex) @@ -496,7 +504,6 @@ ### v2.29.0 (2013/12/06) - [#727](https://github.com/request/request/pull/727) fix requester bug (@jchris) - ### v2.28.0 (2013/12/04) - [#724](https://github.com/request/request/pull/724) README.md: add custom HTTP Headers example. (@tcort) - [#719](https://github.com/request/request/pull/719) Made a comment gender neutral. (@unsetbit) From b628cab739fdd0e29a47f69b8b08ea3bdeb1598d Mon Sep 17 00:00:00 2001 From: simov Date: Fri, 18 Nov 2016 19:21:11 +0200 Subject: [PATCH 381/490] 2.79.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4e7372ff5..cd1bad9ff 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.79.0", + "version": "2.79.1", "author": "Mikeal Rogers ", "repository": { "type": "git", From c7c9431f1fadaf4b700e82218c3df9e0f2e96646 Mon Sep 17 00:00:00 2001 From: Nic Jansma Date: Sun, 4 Dec 2016 09:35:28 -0500 Subject: [PATCH 382/490] Addresses feedback --- README.md | 5 +++-- package.json | 1 - request.js | 34 ++++++++++++++++++++++++++++------ tests/test-timing.js | 2 +- 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index e1b31f6ae..c52efd72e 100644 --- a/README.md +++ b/README.md @@ -812,7 +812,7 @@ default in Linux can be anywhere from 20-120 seconds][linux-timeout]). --- -- `time` - If `true`, the request-response cycle (including all redirects) is timed at millisecond resolution, and the result provided on the response's `elapsedTime` property. The `responseStartTime` property is also available to indicate the timestamp when the response begins. In addition, there is a `.timings` object available with the following properties: +- `time` - If `true`, the request-response cycle (including all redirects) is timed at millisecond resolution, and the result provided on the response's `elapsedTime` property. The `responseStartTime` property is also available to indicate the timestamp when the response begins. In addition, there is a `.timings` object available with the following properties: - `start`: Timestamp when `request()` was initialized - `socket` Timestamp when the [`http`](https://nodejs.org/api/http.html#http_event_socket) module's `socket` event fires. This happens when the socket is assigned to the request (after DNS has been resolved). - `connect`: Timestamp when the [`http`](https://nodejs.org/api/http.html#http_event_connect) module's `connect` event fires. This happens when the server acknowledges the TCP connection. @@ -820,7 +820,8 @@ default in Linux can be anywhere from 20-120 seconds][linux-timeout]). - `end`: Timestamp when the last bytes of the response are received. - `dns`: Duration of DNS lookup (`timings.socket` - `timings.start`) - `tcp`: Duration of TCP connection (`timings.connect` - `timings.socket`) - - `download`: Duration HTTP fetch (`timings.end` - `timings.response`) + - `firstByte`: Duration of HTTP server response (`timings.response` - `timings.connect`) + - `download`: Duration of HTTP download (`timings.end` - `timings.response`) - `total`: Duration entire HTTP round-trip (`timings.end` - `timings.start`) - `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)* diff --git a/package.json b/package.json index c47bcd217..2645565c5 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,6 @@ "mime-types": "~2.1.7", "node-uuid": "~1.4.7", "oauth-sign": "~0.8.1", - "performance-now": "^0.2.0", "qs": "~6.3.0", "stringstream": "~0.0.4", "tough-cookie": "~2.3.0", diff --git a/request.js b/request.js index 39d2b37fd..1ea024119 100644 --- a/request.js +++ b/request.js @@ -28,7 +28,6 @@ var http = require('http') , Multipart = require('./lib/multipart').Multipart , Redirect = require('./lib/redirect').Redirect , Tunnel = require('./lib/tunnel').Tunnel - , now = require('performance-now') var safeStringify = helpers.safeStringify , isReadStream = helpers.isReadStream @@ -37,6 +36,7 @@ var safeStringify = helpers.safeStringify , copy = helpers.copy , version = helpers.version , globalCookieJar = cookies.jar() + , hrTimeStart var globalPool = {} @@ -92,6 +92,28 @@ function responseToJSON() { } } +function getHrTime() { + if (typeof process === 'undefined' || !process.hrtime) { + return 0 + } + + var hr = process.hrtime() + // convert to nanoseconds + return hr[0] * 1e9 + hr[1] +} + +hrTimeStart = getHrTime() + +function getTimeFromStart() { + // in the browser, use performance.now() + if (typeof performance !== 'undefined' && performance.now) { + return performance.now() + } + + // in nodejs, use process.hrtime() (converting back to milliseconds) + return (getHrTime() - hrTimeStart) / 1e6 +} + function Request (options) { // if given the method property in options, set property explicitMethod to true @@ -715,7 +737,7 @@ Request.prototype.start = function () { var self = this if (self.timing) { - var startTime = now() + var startTime = getTimeFromStart() } if (self._aborted) { @@ -775,9 +797,9 @@ Request.prototype.start = function () { }) self.req.on('socket', function(socket) { if (self.timing) { - self.timings.socket = now() + self.timings.socket = getTimeFromStart() socket.on('connect', function() { - self.timings.connect = now() + self.timings.connect = getTimeFromStart() }) } @@ -864,13 +886,13 @@ Request.prototype.onRequestResponse = function (response) { var self = this if (self.timing) { - self.timings.response = now() + self.timings.response = getTimeFromStart() } debug('onRequestResponse', self.uri.href, response.statusCode, response.headers) response.on('end', function() { if (self.timing) { - self.timings.end = now() + self.timings.end = getTimeFromStart() self.timings.dns = self.timings.socket - self.timings.start self.timings.tcp = self.timings.connect - self.timings.socket diff --git a/tests/test-timing.js b/tests/test-timing.js index 0e9a7cdf9..6cbed5f1b 100644 --- a/tests/test-timing.js +++ b/tests/test-timing.js @@ -40,7 +40,7 @@ tape('non-redirected request is timed', function(t) { t.equal((res.timings.response >= res.timings.connect), true) t.equal((res.timings.end >= res.timings.response), true) t.equal((res.timings.dns >= 0), true) - t.equal((res.timings.tcp > 0), true) + t.equal((res.timings.tcp >= 0), true) t.equal((res.timings.firstByte > 0), true) t.equal((res.timings.download > 0), true) t.equal((res.timings.total > 0), true) From 76eb485b4109ebece8e83bf026351f35dbf996e4 Mon Sep 17 00:00:00 2001 From: Ahmad Nassri Date: Mon, 5 Dec 2016 03:47:02 -0500 Subject: [PATCH 383/490] dependency(har-validator): update to ~v4.2.0 dependency(har-validator): update to ~v4.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cd1bad9ff..f0eaf6c01 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "extend": "~3.0.0", "forever-agent": "~0.6.1", "form-data": "~2.1.1", - "har-validator": "~2.0.6", + "har-validator": "~4.2.0", "hawk": "~3.1.3", "http-signature": "~1.1.0", "is-typedarray": "~1.0.0", From 47523a2eb29ede4c7b5726a3540b7b756f2bb493 Mon Sep 17 00:00:00 2001 From: Nic Jansma Date: Tue, 6 Dec 2016 09:02:18 -0500 Subject: [PATCH 384/490] Removed double-spaces after period --- README.md | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index c52efd72e..88c2e3c93 100644 --- a/README.md +++ b/README.md @@ -287,13 +287,13 @@ The method form takes parameters `auth(username, password, sendImmediately, bearer)`. `sendImmediately` defaults to `true`, which causes a basic or bearer -authentication header to be sent. If `sendImmediately` is `false`, then +authentication header to be sent. If `sendImmediately` is `false`, then `request` will retry with a proper authentication header after receiving a `401` response from the server (which must contain a `WWW-Authenticate` header indicating the required authentication method). Note that you can also specify basic authentication using the URL itself, as -detailed in [RFC 1738](http://www.ietf.org/rfc/rfc1738.txt). Simply pass the +detailed in [RFC 1738](http://www.ietf.org/rfc/rfc1738.txt). Simply pass the `user:password` before the host with an `@` sign: ```js @@ -358,7 +358,7 @@ request(options, callback); ## OAuth Signing -[OAuth version 1.0](https://tools.ietf.org/html/rfc5849) is supported. The +[OAuth version 1.0](https://tools.ietf.org/html/rfc5849) is supported. The default signing algorithm is [HMAC-SHA1](https://tools.ietf.org/html/rfc5849#section-3.4.2): @@ -477,7 +477,7 @@ See [the wikipedia page on HTTP Tunneling](https://en.wikipedia.org/wiki/HTTP_tu for more information. By default, when proxying `http` traffic, request will simply make a -standard proxied `http` request. This is done by making the `url` +standard proxied `http` request. This is done by making the `url` section of the initial line of the request a fully qualified url to the endpoint. @@ -493,7 +493,7 @@ request body or whatever Because a pure "http over http" tunnel offers no additional security or other features, it is generally simpler to go with a -straightforward HTTP proxy in this case. However, if you would like +straightforward HTTP proxy in this case. However, if you would like to force a tunneling proxy, you may set the `tunnel` option to `true`. You can also make a standard proxied `http` request by explicitly setting @@ -717,7 +717,7 @@ a validation step will check if the HAR Request format matches the latest spec ( The first argument can be either a `url` or an `options` object. The only required option is `uri`; all others are optional. - `uri` || `url` - fully qualified uri or a parsed url object from `url.parse()` -- `baseUrl` - fully qualified uri string used as the base url. Most useful with `request.defaults`, for example when you want to do many requests to the same domain. If `baseUrl` is `https://example.com/api/`, then requesting `/end/point?test=true` will fetch `https://example.com/api/end/point?test=true`. When `baseUrl` is given, `uri` must also be a string. +- `baseUrl` - fully qualified uri string used as the base url. Most useful with `request.defaults`, for example when you want to do many requests to the same domain. If `baseUrl` is `https://example.com/api/`, then requesting `/end/point?test=true` will fetch `https://example.com/api/end/point?test=true`. When `baseUrl` is given, `uri` must also be a string. - `method` - http method (default: `"GET"`) - `headers` - http headers (default: `{}`) @@ -727,7 +727,7 @@ The first argument can be either a `url` or an `options` object. The only requir - `qsParseOptions` - object containing options to pass to the [qs.parse](https://github.com/hapijs/qs#parsing-objects) method. Alternatively pass options to the [querystring.parse](https://nodejs.org/docs/v0.12.0/api/querystring.html#querystring_querystring_parse_str_sep_eq_options) method using this format `{sep:';', eq:':', options:{}}` - `qsStringifyOptions` - object containing options to pass to the [qs.stringify](https://github.com/hapijs/qs#stringifying) method. Alternatively pass options to the [querystring.stringify](https://nodejs.org/docs/v0.12.0/api/querystring.html#querystring_querystring_stringify_obj_sep_eq_options) method using this format `{sep:';', eq:':', options:{}}`. For example, to change the way arrays are converted to query strings using the `qs` module pass the `arrayFormat` option with one of `indices|brackets|repeat` - `useQuerystring` - If true, use `querystring` to stringify and parse - querystrings, otherwise use `qs` (default: `false`). Set this option to + querystrings, otherwise use `qs` (default: `false`). Set this option to `true` if you need arrays to be serialized as `foo=bar&foo=baz` instead of the default `foo[0]=bar&foo[1]=baz`. @@ -746,13 +746,13 @@ The first argument can be either a `url` or an `options` object. The only requir In non-chunked requests, data items with body streams are not allowed. - `preambleCRLF` - append a newline/CRLF before the boundary of your `multipart/form-data` request. - `postambleCRLF` - append a newline/CRLF at the end of the boundary of your `multipart/form-data` request. -- `json` - sets `body` to JSON representation of value and adds `Content-type: application/json` header. Additionally, parses the response body as JSON. +- `json` - sets `body` to JSON representation of value and adds `Content-type: application/json` header. Additionally, parses the response body as JSON. - `jsonReviver` - a [reviver function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse) that will be passed to `JSON.parse()` when parsing a JSON response body. - `jsonReplacer` - a [replacer function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) that will be passed to `JSON.stringify()` when stringifying a JSON request body. --- -- `auth` - A hash containing values `user` || `username`, `pass` || `password`, and `sendImmediately` (optional). See documentation above. +- `auth` - A hash containing values `user` || `username`, `pass` || `password`, and `sendImmediately` (optional). See documentation above. - `oauth` - Options for OAuth HMAC-SHA1 signing. See documentation above. - `hawk` - Options for [Hawk signing](https://github.com/hueniverse/hawk). The `credentials` key must contain the necessary signing info, [see hawk docs for details](https://github.com/hueniverse/hawk#usage-example). - `aws` - `object` containing AWS signing information. Should have the properties `key`, `secret`. Also requires the property `bucket`, unless you’re specifying your `bucket` as part of the path, or the request doesn’t use a bucket (i.e. GET Services). If you want to use AWS sign version 4 use the parameter `sign_version` with value `4` otherwise the default is version 2. **Note:** you need to `npm install aws4` first. @@ -769,7 +769,7 @@ The first argument can be either a `url` or an `options` object. The only requir --- - `encoding` - Encoding to be used on `setEncoding` of response data. If `null`, the `body` is returned as a `Buffer`. Anything else **(including the default value of `undefined`)** will be passed as the [encoding](http://nodejs.org/api/buffer.html#buffer_buffer) parameter to `toString()` (meaning this is effectively `utf8` by default). (**Note:** if you expect binary data, you should set `encoding: null`.) -- `gzip` - If `true`, add an `Accept-Encoding` header to request compressed content encodings from the server (if not already present) and decode supported content encodings in the response. **Note:** Automatic decoding of the response content is performed on the body data returned through `request` (both through the `request` stream and passed to the callback function) but is not performed on the `response` stream (available from the `response` event) which is the unmodified `http.IncomingMessage` object which may contain compressed data. See example below. +- `gzip` - If `true`, add an `Accept-Encoding` header to request compressed content encodings from the server (if not already present) and decode supported content encodings in the response. **Note:** Automatic decoding of the response content is performed on the body data returned through `request` (both through the `request` stream and passed to the callback function) but is not performed on the `response` stream (available from the `response` event) which is the unmodified `http.IncomingMessage` object which may contain compressed data. See example below. - `jar` - If `true`, remember cookies for future use (or define your custom cookie jar; see examples section) --- @@ -781,7 +781,7 @@ The first argument can be either a `url` or an `options` object. The only requir - `pool` - An object describing which agents to use for the request. If this option is omitted the request will use the global agent (as long as your options allow for it). Otherwise, request will search the pool for your custom agent. If no custom agent is found, a new agent will be created and added to the pool. **Note:** `pool` is used only when the `agent` option is not specified. - A `maxSockets` property can also be provided on the `pool` object to set the max number of sockets for all agents created (ex: `pool: {maxSockets: Infinity}`). - Note that if you are sending multiple requests in a loop and creating - multiple new `pool` objects, `maxSockets` will not work as intended. To + multiple new `pool` objects, `maxSockets` will not work as intended. To work around this, either use [`request.defaults`](#requestdefaultsoptions) with your pool options or create the pool object with the `maxSockets` property outside of the loop. @@ -814,9 +814,9 @@ default in Linux can be anywhere from 20-120 seconds][linux-timeout]). - `time` - If `true`, the request-response cycle (including all redirects) is timed at millisecond resolution, and the result provided on the response's `elapsedTime` property. The `responseStartTime` property is also available to indicate the timestamp when the response begins. In addition, there is a `.timings` object available with the following properties: - `start`: Timestamp when `request()` was initialized - - `socket` Timestamp when the [`http`](https://nodejs.org/api/http.html#http_event_socket) module's `socket` event fires. This happens when the socket is assigned to the request (after DNS has been resolved). - - `connect`: Timestamp when the [`http`](https://nodejs.org/api/http.html#http_event_connect) module's `connect` event fires. This happens when the server acknowledges the TCP connection. - - `response`: Timestamp when the [`http`](https://nodejs.org/api/http.html#http_event_response) module's `response` event fires. This happens when the first bytes are received from the server. + - `socket` Timestamp when the [`http`](https://nodejs.org/api/http.html#http_event_socket) module's `socket` event fires. This happens when the socket is assigned to the request (after DNS has been resolved). + - `connect`: Timestamp when the [`http`](https://nodejs.org/api/http.html#http_event_connect) module's `connect` event fires. This happens when the server acknowledges the TCP connection. + - `response`: Timestamp when the [`http`](https://nodejs.org/api/http.html#http_event_response) module's `response` event fires. This happens when the first bytes are received from the server. - `end`: Timestamp when the last bytes of the response are received. - `dns`: Duration of DNS lookup (`timings.socket` - `timings.start`) - `tcp`: Duration of TCP connection (`timings.connect` - `timings.socket`) @@ -1013,7 +1013,7 @@ request.get('http://10.255.255.1', {timeout: 1500}, function(err) { ``` For backwards-compatibility, response compression is not supported by default. -To accept gzip-compressed responses, set the `gzip` option to `true`. Note +To accept gzip-compressed responses, set the `gzip` option to `true`. Note that the body data passed through `request` is automatically decompressed while the response object is unmodified and will contain compressed data if the server sent a compressed response. From 21e315d9080200278002441943aec0c4a17f57c3 Mon Sep 17 00:00:00 2001 From: Nic Jansma Date: Wed, 7 Dec 2016 23:24:59 -0500 Subject: [PATCH 385/490] Removed extra space --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 88c2e3c93..a02f40bb2 100644 --- a/README.md +++ b/README.md @@ -815,7 +815,7 @@ default in Linux can be anywhere from 20-120 seconds][linux-timeout]). - `time` - If `true`, the request-response cycle (including all redirects) is timed at millisecond resolution, and the result provided on the response's `elapsedTime` property. The `responseStartTime` property is also available to indicate the timestamp when the response begins. In addition, there is a `.timings` object available with the following properties: - `start`: Timestamp when `request()` was initialized - `socket` Timestamp when the [`http`](https://nodejs.org/api/http.html#http_event_socket) module's `socket` event fires. This happens when the socket is assigned to the request (after DNS has been resolved). - - `connect`: Timestamp when the [`http`](https://nodejs.org/api/http.html#http_event_connect) module's `connect` event fires. This happens when the server acknowledges the TCP connection. + - `connect`: Timestamp when the [`http`](https://nodejs.org/api/http.html#http_event_connect) module's `connect` event fires. This happens when the server acknowledges the TCP connection. - `response`: Timestamp when the [`http`](https://nodejs.org/api/http.html#http_event_response) module's `response` event fires. This happens when the first bytes are received from the server. - `end`: Timestamp when the last bytes of the response are received. - `dns`: Duration of DNS lookup (`timings.socket` - `timings.start`) From 71081b64ac939b74eaf7a510fee45ab27d4669a1 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Wed, 21 Dec 2016 07:21:38 +0100 Subject: [PATCH 386/490] More lenient gzip decompression MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Be explicitly lenient with gzip decompression by always requesting `zlib` to flush the input data and never explicitly ending the `zlib` input. The behavioural difference is that on Node ≥ 6, which has a slightly stricter gzip decoding process than previous Node versions, malformed but otherwise acceptable server responses are still properly decompressed (the most common example being a missing checksum at the stream end). This aligns behaviour with cURL, which always uses the `Z_SYNC_FLUSH` flag for decompression. On the downside, accidental truncation of a response is no longer detected on the compression layer. Ref: https://github.com/nodejs/node/issues/8701#issuecomment-268224481 Fixes: https://github.com/request/request/issues/2482 --- request.js | 13 +++++++++++-- tests/test-gzip.js | 16 ++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/request.js b/request.js index 26f70c208..d9ade74c9 100644 --- a/request.js +++ b/request.js @@ -946,11 +946,20 @@ Request.prototype.onRequestResponse = function (response) { var contentEncoding = response.headers['content-encoding'] || 'identity' contentEncoding = contentEncoding.trim().toLowerCase() + // Be more lenient with decoding compressed responses, since (very rarely) + // servers send slightly invalid gzip responses that are still accepted + // by common browsers. + // Always using Z_SYNC_FLUSH is what cURL does. + var zlibOptions = { + flush: zlib.Z_SYNC_FLUSH + , finishFlush: zlib.Z_SYNC_FLUSH + } + if (contentEncoding === 'gzip') { - responseContent = zlib.createGunzip() + responseContent = zlib.createGunzip(zlibOptions) response.pipe(responseContent) } else if (contentEncoding === 'deflate') { - responseContent = zlib.createInflate() + responseContent = zlib.createInflate(zlibOptions) response.pipe(responseContent) } else { // Since previous versions didn't check for Content-Encoding header, diff --git a/tests/test-gzip.js b/tests/test-gzip.js index 7ade4aee8..ac523a8d7 100644 --- a/tests/test-gzip.js +++ b/tests/test-gzip.js @@ -39,6 +39,12 @@ var server = http.createServer(function(req, res) { res.writeHead(200) res.write(testContentBigGzip.slice(0, 4096)) setTimeout(function() { res.end(testContentBigGzip.slice(4096)) }, 10) + } else if (req.url === '/just-slightly-truncated') { + zlib.gzip(testContent, function(err, data) { + assert.equal(err, null) + // truncate the CRC checksum and size check at the end of the stream + res.end(data.slice(0, data.length-8)) + }) } else { zlib.gzip(testContent, function(err, data) { assert.equal(err, null) @@ -96,6 +102,16 @@ tape('transparently supports gzip decoding to callbacks', function(t) { }) }) +tape('supports slightly invalid gzip content', function(t) { + var options = { url: server.url + '/just-slightly-truncated', gzip: true } + request.get(options, function(err, res, body) { + t.equal(err, null) + t.equal(res.headers['content-encoding'], 'gzip') + t.equal(body, testContent) + t.end() + }) +}) + tape('transparently supports gzip decoding to pipes', function(t) { var options = { url: server.url + '/foo', gzip: true } var chunks = [] From 4901f968ce0462f38b0cf3c6fbb008ad58414773 Mon Sep 17 00:00:00 2001 From: "David Humphrey (:humph) david.humphrey@senecacollege.ca" Date: Mon, 16 Jan 2017 16:55:18 -0500 Subject: [PATCH 387/490] Change tags to keywords in package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f0eaf6c01..834d0e08c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "request", "description": "Simplified HTTP request client.", - "tags": [ + "keywords": [ "http", "simple", "util", From dfd777aa2fdae96242910f651fffad65e49b61c4 Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Thu, 26 Jan 2017 13:41:34 -0800 Subject: [PATCH 388/490] chore(package): update caseless to version 0.12.0 https://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f0eaf6c01..96587f91f 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "dependencies": { "aws-sign2": "~0.6.0", "aws4": "^1.2.1", - "caseless": "~0.11.0", + "caseless": "~0.12.0", "combined-stream": "~1.0.5", "extend": "~3.0.0", "forever-agent": "~0.6.1", From a60be68ddad2877aa17b0ce79391fc3d327afa5e Mon Sep 17 00:00:00 2001 From: "Fred K. Schott" Date: Mon, 13 Feb 2017 16:06:33 -0800 Subject: [PATCH 389/490] Create PULL_REQUEST_TEMPLATE.md --- PULL_REQUEST_TEMPLATE.md | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 PULL_REQUEST_TEMPLATE.md diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 000000000..e4aaab68a --- /dev/null +++ b/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,11 @@ + + + + +#### PR Checklist: + + +- [ ] If this is a major change, an issue has already been created where the problem / solution was discussed: [ADD LINK TO GITHUB ISSUE HERE] +- [ ] I have run `npm test` locally and all tests are passing. +- [ ] I have added tests for any new behavior. + From d9e8c3d5b4ccb98cb9c51d1775bd8c668f51e655 Mon Sep 17 00:00:00 2001 From: Nic Jansma Date: Fri, 17 Feb 2017 10:06:10 -0500 Subject: [PATCH 390/490] Added deprecated notes --- request.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/request.js b/request.js index 1ea024119..d13609d0b 100644 --- a/request.js +++ b/request.js @@ -435,6 +435,8 @@ Request.prototype.init = function (options) { if (options.time) { self.timing = true + + // NOTE: elapsedTime is deprecated in favor of .timings self.elapsedTime = self.elapsedTime || 0 } @@ -904,6 +906,8 @@ Request.prototype.onRequestResponse = function (response) { // elapsedTime includes all redirects self.elapsedTime += Math.round(self.timings.total) + + // NOTE: elapsedTime is deprecated in favor of .timings response.elapsedTime = self.elapsedTime // timings is just for the final fetch @@ -1047,6 +1051,8 @@ Request.prototype.onRequestResponse = function (response) { responseContent.on('data', function (chunk) { if (self.timing && !self.responseStarted) { self.responseStartTime = (new Date()).getTime() + + // NOTE: responseStartTime is deprecated in favor of .timings response.responseStartTime = self.responseStartTime } self._destdata = true From a9ad38a3f7c4bc388af8af353b54fc05cfb81f63 Mon Sep 17 00:00:00 2001 From: Nic Jansma Date: Fri, 17 Feb 2017 10:06:22 -0500 Subject: [PATCH 391/490] Ensure only the properties we expect are there --- tests/test-timing.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test-timing.js b/tests/test-timing.js index 6cbed5f1b..0623195f6 100644 --- a/tests/test-timing.js +++ b/tests/test-timing.js @@ -44,6 +44,17 @@ tape('non-redirected request is timed', function(t) { t.equal((res.timings.firstByte > 0), true) t.equal((res.timings.download > 0), true) t.equal((res.timings.total > 0), true) + + // validate there are no unexpected properties + var propNames = [] + for (var propName in res.timings) { + if (res.timings.hasOwnProperty(propName)) { + propNames.push(propName) + } + } + t.deepEqual(propNames, ['start', 'socket', 'connect', 'response', 'end', 'dns', + 'tcp', 'firstByte', 'download', 'total']) + t.end() }) }) From 3f57975212976c88fc006e9e7b3e2cb5b53a2ddf Mon Sep 17 00:00:00 2001 From: Nic Jansma Date: Fri, 17 Feb 2017 10:10:34 -0500 Subject: [PATCH 392/490] Use performance-now instead of custom solution --- package.json | 1 + request.js | 34 ++++++---------------------------- 2 files changed, 7 insertions(+), 28 deletions(-) diff --git a/package.json b/package.json index 2645565c5..c47bcd217 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "mime-types": "~2.1.7", "node-uuid": "~1.4.7", "oauth-sign": "~0.8.1", + "performance-now": "^0.2.0", "qs": "~6.3.0", "stringstream": "~0.0.4", "tough-cookie": "~2.3.0", diff --git a/request.js b/request.js index d13609d0b..74435bd16 100644 --- a/request.js +++ b/request.js @@ -28,6 +28,7 @@ var http = require('http') , Multipart = require('./lib/multipart').Multipart , Redirect = require('./lib/redirect').Redirect , Tunnel = require('./lib/tunnel').Tunnel + , now = require('performance-now') var safeStringify = helpers.safeStringify , isReadStream = helpers.isReadStream @@ -36,7 +37,6 @@ var safeStringify = helpers.safeStringify , copy = helpers.copy , version = helpers.version , globalCookieJar = cookies.jar() - , hrTimeStart var globalPool = {} @@ -92,28 +92,6 @@ function responseToJSON() { } } -function getHrTime() { - if (typeof process === 'undefined' || !process.hrtime) { - return 0 - } - - var hr = process.hrtime() - // convert to nanoseconds - return hr[0] * 1e9 + hr[1] -} - -hrTimeStart = getHrTime() - -function getTimeFromStart() { - // in the browser, use performance.now() - if (typeof performance !== 'undefined' && performance.now) { - return performance.now() - } - - // in nodejs, use process.hrtime() (converting back to milliseconds) - return (getHrTime() - hrTimeStart) / 1e6 -} - function Request (options) { // if given the method property in options, set property explicitMethod to true @@ -739,7 +717,7 @@ Request.prototype.start = function () { var self = this if (self.timing) { - var startTime = getTimeFromStart() + var startTime = now() } if (self._aborted) { @@ -799,9 +777,9 @@ Request.prototype.start = function () { }) self.req.on('socket', function(socket) { if (self.timing) { - self.timings.socket = getTimeFromStart() + self.timings.socket = now() socket.on('connect', function() { - self.timings.connect = getTimeFromStart() + self.timings.connect = now() }) } @@ -888,13 +866,13 @@ Request.prototype.onRequestResponse = function (response) { var self = this if (self.timing) { - self.timings.response = getTimeFromStart() + self.timings.response = now() } debug('onRequestResponse', self.uri.href, response.statusCode, response.headers) response.on('end', function() { if (self.timing) { - self.timings.end = getTimeFromStart() + self.timings.end = now() self.timings.dns = self.timings.socket - self.timings.start self.timings.tcp = self.timings.connect - self.timings.socket From fec1f2b724f4be27125e7b435a75b3df3b2c2a45 Mon Sep 17 00:00:00 2001 From: "Fred K. Schott" Date: Sun, 19 Feb 2017 14:11:04 -0800 Subject: [PATCH 393/490] reorder PULL_REQUEST_TEMPLATE sections --- PULL_REQUEST_TEMPLATE.md | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md index e4aaab68a..069c80d9b 100644 --- a/PULL_REQUEST_TEMPLATE.md +++ b/PULL_REQUEST_TEMPLATE.md @@ -1,11 +1,13 @@ - - - +## PR Checklist: +- [ ] I have run `npm test` locally and all tests are passing. +- [ ] I have added/updated tests for any new behavior. + +- [ ] An issue has already been created where the problem / solution was discussed: [N/A, or add link to issue here] + -#### PR Checklist: - -- [ ] If this is a major change, an issue has already been created where the problem / solution was discussed: [ADD LINK TO GITHUB ISSUE HERE] -- [ ] I have run `npm test` locally and all tests are passing. -- [ ] I have added tests for any new behavior. - +## PR Description + From 256deeae1487d5d7a488b3c50505775b0a1be510 Mon Sep 17 00:00:00 2001 From: "Fred K. Schott" Date: Sun, 19 Feb 2017 13:57:39 -0800 Subject: [PATCH 394/490] add ISSUE_TEMPLATE, move PR template --- .github/ISSUE_TEMPLATE.md | 54 +++++++++++++++++++ .../PULL_REQUEST_TEMPLATE.md | 0 2 files changed, 54 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE.md rename PULL_REQUEST_TEMPLATE.md => .github/PULL_REQUEST_TEMPLATE.md (100%) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 000000000..70e7521ee --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,54 @@ + + + + +### Request Options + + +```js +request({ + url: 'http://example.com', // a public URL that we can hit to reproduce, if possible + more: { 'options': 'here' } +}, +``` + +### Expected Behavior + + + + +### Current Behavior + + + +### Possible Solution + + + +### Context + + + +### Your Environment + + +| software | version +| ---------------- | ------- +| request | +| node | +| npm | +| Operating System | diff --git a/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md similarity index 100% rename from PULL_REQUEST_TEMPLATE.md rename to .github/PULL_REQUEST_TEMPLATE.md From 921ebeedb6689f53a113be2c902ea52dbf8d26d2 Mon Sep 17 00:00:00 2001 From: "Fred K. Schott" Date: Sun, 19 Feb 2017 14:13:37 -0800 Subject: [PATCH 395/490] small change to template wording --- .github/ISSUE_TEMPLATE.md | 6 ++++-- .github/PULL_REQUEST_TEMPLATE.md | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 70e7521ee..f036dc9a5 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -5,7 +5,7 @@ Please search open/closed issues before submitting since someone might have aske If you have a support request or question please submit them to one of this resources: -* StackOverflow: http://stackoverflow.com/questions/tagged/request+node.js using the tags `node.js` & `request` +* Stack Overflow: http://stackoverflow.com/questions/tagged/request+node.js using the tags `node.js` & `request` * Gitter community: https://gitter.im/request/request?utm_source=newissue * Also have a look at the Readme for more information on how to get support: https://github.com/request/request/blob/master/README.md @@ -14,13 +14,15 @@ Issues on GitHub are only related to problems of request itself and we cannot an support questions here. --> +### Summary -### Request Options +### Simplest Example to Reproduce ```js request({ + method: 'GET', url: 'http://example.com', // a public URL that we can hit to reproduce, if possible more: { 'options': 'here' } }, diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 069c80d9b..0cb35f040 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -3,10 +3,10 @@ - [ ] I have added/updated tests for any new behavior. -- [ ] An issue has already been created where the problem / solution was discussed: [N/A, or add link to issue here] +- [ ] If this is a significant change, an issue has already been created where the problem / solution was discussed: [N/A, or add link to issue here] + please create an issue to discuss those changes and gather + feedback BEFORE submitting your PR. --> ## PR Description From 8d78bd0333b09fc75bb642aa1d8b3954c8f8ca55 Mon Sep 17 00:00:00 2001 From: "Fred K. Schott" Date: Tue, 21 Feb 2017 15:44:21 -0800 Subject: [PATCH 396/490] Update README.md example snippet --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e47dd6c49..c1a201e86 100644 --- a/README.md +++ b/README.md @@ -18,10 +18,10 @@ Request is designed to be the simplest way possible to make http calls. It suppo ```js var request = require('request'); request('http://www.google.com', function (error, response, body) { - if (!error && response.statusCode == 200) { - console.log(body) // Show the HTML for the Google homepage. - } -}) + console.log('error:', error); // Print the error if one occurred + console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received + console.log('body:', body); // Print the HTML for the Google homepage. +}); ``` From ff6d6c6e7a3b2c36618b5d1db662e10c929696e3 Mon Sep 17 00:00:00 2001 From: "James M. Greene" Date: Fri, 3 Mar 2017 20:30:35 -0600 Subject: [PATCH 397/490] Correctly format the Host header for IPv6 addresses Fixes #2292 --- request.js | 11 ++++------- tests/test-headers.js | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/request.js b/request.js index a683a590b..008df9810 100644 --- a/request.js +++ b/request.js @@ -289,13 +289,10 @@ Request.prototype.init = function (options) { self.setHost = false if (!self.hasHeader('host')) { var hostHeaderName = self.originalHostHeaderName || 'host' - self.setHeader(hostHeaderName, self.uri.hostname) - if (self.uri.port) { - if ( !(self.uri.port === 80 && self.uri.protocol === 'http:') && - !(self.uri.port === 443 && self.uri.protocol === 'https:') ) { - self.setHeader(hostHeaderName, self.getHeader('host') + (':' + self.uri.port) ) - } - } + // When used with an IPv6 address, `host` will provide + // the correct bracketed format, unlike using `hostname` and + // optionally adding the `port` when necessary. + self.setHeader(hostHeaderName, self.uri.host) self.setHost = true } diff --git a/tests/test-headers.js b/tests/test-headers.js index 53b7cb033..91abd25ef 100644 --- a/tests/test-headers.js +++ b/tests/test-headers.js @@ -4,6 +4,7 @@ var server = require('./server') , request = require('../index') , util = require('util') , tape = require('tape') + , url = require('url') var s = server.createServer() @@ -201,3 +202,42 @@ tape('catch invalid characters error - POST', function(t) { t.end() }) }) + +tape('IPv6 Host header', function(t) { + // Horrible hack to observe the raw data coming to the server + var rawData = '' + + s.on('connection', function(socket) { + if (socket.ondata) { + var ondata = socket.ondata + } + function handledata (d, start, end) { + if (ondata) { + rawData += d.slice(start, end).toString() + return ondata.apply(this, arguments) + } else { + rawData += d + } + } + socket.on('data', handledata) + socket.ondata = handledata + }) + + function checkHostHeader(host) { + t.ok( + new RegExp('^Host: ' + host + '$', 'im').test(rawData), + util.format( + 'Expected "Host: %s" in data "%s"', + host, rawData.trim().replace(/\r?\n/g, '\\n'))) + rawData = '' + } + + request({ + url : s.url.replace(url.parse(s.url).hostname, '[::1]') + '/headers.json' + }, function(err, res, body) { + t.equal(err, null) + t.equal(res.statusCode, 200) + checkHostHeader('\\[::1\\]:' + s.port) + t.end() + }) +}) From f422111e0bc44e065a7b15e243748b59d5e99e33 Mon Sep 17 00:00:00 2001 From: Mikeal Rogers Date: Fri, 3 Mar 2017 20:42:39 -0800 Subject: [PATCH 398/490] 2.80.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a5cd27bf3..12d9de0b0 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.79.1", + "version": "2.80.0", "author": "Mikeal Rogers ", "repository": { "type": "git", From 7b9ceefe590b5879600b02e1245d12aadde5a16f Mon Sep 17 00:00:00 2001 From: Mikeal Rogers Date: Fri, 3 Mar 2017 20:42:43 -0800 Subject: [PATCH 399/490] 2.80.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 12d9de0b0..d387eb3aa 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.80.0", + "version": "2.80.1", "author": "Mikeal Rogers ", "repository": { "type": "git", From 095ec7997e6970195ad78d9fbe2517b4e165baf9 Mon Sep 17 00:00:00 2001 From: Ahmad Nassri Date: Sat, 4 Mar 2017 09:13:01 -0500 Subject: [PATCH 400/490] fixes #2572 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d387eb3aa..a1b30014b 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "extend": "~3.0.0", "forever-agent": "~0.6.1", "form-data": "~2.1.1", - "har-validator": "~4.2.0", + "har-validator": "~4.2.1", "hawk": "~3.1.3", "http-signature": "~1.1.0", "is-typedarray": "~1.0.0", From f11325385a7392b930ed8b61a97a956a22e7b0be Mon Sep 17 00:00:00 2001 From: Mikeal Rogers Date: Sat, 4 Mar 2017 11:34:48 -0800 Subject: [PATCH 401/490] Migrating to safe-buffer for improved security. --- lib/helpers.js | 1 + lib/multipart.js | 1 + lib/oauth.js | 1 + package.json | 3 ++- request.js | 1 + 5 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/helpers.js b/lib/helpers.js index f9d727e38..9e2d2ad34 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -2,6 +2,7 @@ var jsonSafeStringify = require('json-stringify-safe') , crypto = require('crypto') + , Buffer = require('safe-buffer').Buffer var defer = typeof setImmediate === 'undefined' ? process.nextTick diff --git a/lib/multipart.js b/lib/multipart.js index 3b605bd47..4bb15325f 100644 --- a/lib/multipart.js +++ b/lib/multipart.js @@ -3,6 +3,7 @@ var uuid = require('uuid') , CombinedStream = require('combined-stream') , isstream = require('isstream') + , Buffer = require('safe-buffer').Buffer function Multipart (request) { diff --git a/lib/oauth.js b/lib/oauth.js index 56b39b0f5..402c89ff5 100644 --- a/lib/oauth.js +++ b/lib/oauth.js @@ -6,6 +6,7 @@ var url = require('url') , uuid = require('uuid') , oauth = require('oauth-sign') , crypto = require('crypto') + , Buffer = require('safe-buffer').Buffer function OAuth (request) { diff --git a/package.json b/package.json index d387eb3aa..feaa3ea4e 100644 --- a/package.json +++ b/package.json @@ -44,9 +44,10 @@ "oauth-sign": "~0.8.1", "performance-now": "^0.2.0", "qs": "~6.3.0", + "safe-buffer": "^5.0.1", "stringstream": "~0.0.4", "tough-cookie": "~2.3.0", - "tunnel-agent": "~0.4.1", + "tunnel-agent": "^0.5.0", "uuid": "^3.0.0" }, "scripts": { diff --git a/request.js b/request.js index 008df9810..5af242207 100644 --- a/request.js +++ b/request.js @@ -29,6 +29,7 @@ var http = require('http') , Redirect = require('./lib/redirect').Redirect , Tunnel = require('./lib/tunnel').Tunnel , now = require('performance-now') + , Buffer = require('safe-buffer').Buffer var safeStringify = helpers.safeStringify , isReadStream = helpers.isReadStream From 2e70b7477b7ad39f0626d5eff2ea8bb9e7600403 Mon Sep 17 00:00:00 2001 From: Nic Jansma Date: Sat, 4 Mar 2017 18:53:21 -0500 Subject: [PATCH 402/490] Timings: Tracks 'lookup', adds 'wait' time, fixes connection re-use (#2566) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Timings: Tracks 'lookup', adds 'wait' time, fixes connection re-use * Don’t re-add event listeners on Keep-Alive, run only .once(), and cleanup on error * Fixed documentation --- README.md | 28 +++++++++------ request.js | 84 +++++++++++++++++++++++++++++++++----------- tests/test-timing.js | 35 ++++++++++++------ 3 files changed, 106 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index a716c2337..231739114 100644 --- a/README.md +++ b/README.md @@ -812,17 +812,23 @@ default in Linux can be anywhere from 20-120 seconds][linux-timeout]). --- -- `time` - If `true`, the request-response cycle (including all redirects) is timed at millisecond resolution, and the result provided on the response's `elapsedTime` property. The `responseStartTime` property is also available to indicate the timestamp when the response begins. In addition, there is a `.timings` object available with the following properties: - - `start`: Timestamp when `request()` was initialized - - `socket` Timestamp when the [`http`](https://nodejs.org/api/http.html#http_event_socket) module's `socket` event fires. This happens when the socket is assigned to the request (after DNS has been resolved). - - `connect`: Timestamp when the [`http`](https://nodejs.org/api/http.html#http_event_connect) module's `connect` event fires. This happens when the server acknowledges the TCP connection. - - `response`: Timestamp when the [`http`](https://nodejs.org/api/http.html#http_event_response) module's `response` event fires. This happens when the first bytes are received from the server. - - `end`: Timestamp when the last bytes of the response are received. - - `dns`: Duration of DNS lookup (`timings.socket` - `timings.start`) - - `tcp`: Duration of TCP connection (`timings.connect` - `timings.socket`) - - `firstByte`: Duration of HTTP server response (`timings.response` - `timings.connect`) - - `download`: Duration of HTTP download (`timings.end` - `timings.response`) - - `total`: Duration entire HTTP round-trip (`timings.end` - `timings.start`) +- `time` - If `true`, the request-response cycle (including all redirects) is timed at millisecond resolution. When set, the following properties are added to the response object: + - `elapsedTime` Duration of the entire request/response in milliseconds (*deprecated*). + - `responseStartTime` Timestamp when the response began (in Unix Epoch milliseconds) (*deprecated*). + - `timingStart` Timestamp of the start of the request (in Unix Epoch milliseconds). + - `timings` Contains event timestamps in millisecond resolution relative to `timingStart`. If there were redirects, the properties reflect the timings of the final request in the redirect chain: + - `socket` Relative timestamp when the [`http`](https://nodejs.org/api/http.html#http_event_socket) module's `socket` event fires. This happens when the socket is assigned to the request. + - `lookup` Relative timestamp when the [`net`](https://nodejs.org/api/net.html#net_event_lookup) module's `lookup` event fires. This happens when the DNS has been resolved. + - `connect`: Relative timestamp when the [`net`](https://nodejs.org/api/net.html#net_event_connect) module's `connect` event fires. This happens when the server acknowledges the TCP connection. + - `response`: Relative timestamp when the [`http`](https://nodejs.org/api/http.html#http_event_response) module's `response` event fires. This happens when the first bytes are received from the server. + - `end`: Relative timestamp when the last bytes of the response are received. + - `timingPhases` Contains the durations of each request phase. If there were redirects, the properties reflect the timings of the final request in the redirect chain: + - `wait`: Duration of socket initialization (`timings.socket`) + - `dns`: Duration of DNS lookup (`timings.lookup` - `timings.socket`) + - `tcp`: Duration of TCP connection (`timings.connect` - `timings.socket`) + - `firstByte`: Duration of HTTP server response (`timings.response` - `timings.connect`) + - `download`: Duration of HTTP download (`timings.end` - `timings.response`) + - `total`: Duration entire HTTP round-trip (`timings.end`) - `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 diff --git a/request.js b/request.js index 5af242207..089d52813 100644 --- a/request.js +++ b/request.js @@ -715,7 +715,13 @@ Request.prototype.start = function () { var self = this if (self.timing) { - var startTime = now() + // All timings will be relative to this request's startTime. In order to do this, + // we need to capture the wall-clock start time (via Date), immediately followed + // by the high-resolution timer (via now()). While these two won't be set + // at the _exact_ same time, they should be close enough to be able to calculate + // high-resolution, monotonically non-decreasing timestamps relative to startTime. + var startTime = new Date().getTime() + var startTimeNow = now() } if (self._aborted) { @@ -753,10 +759,12 @@ Request.prototype.start = function () { } if (self.timing) { - self.startTime = new Date().getTime() - self.timings = { - start: startTime - } + self.startTime = startTime + self.startTimeNow = startTimeNow + + // Timing values will all be relative to startTime (by comparing to startTimeNow + // so we have an accurate clock) + self.timings = {} } var timeout @@ -774,11 +782,29 @@ Request.prototype.start = function () { self.emit('drain') }) self.req.on('socket', function(socket) { + // `._connecting` was the old property which was made public in node v6.1.0 + var isConnecting = socket._connecting || socket.connecting if (self.timing) { - self.timings.socket = now() - socket.on('connect', function() { - self.timings.connect = now() - }) + self.timings.socket = now() - self.startTimeNow + + if (isConnecting) { + var onLookupTiming = function() { + self.timings.lookup = now() - self.startTimeNow + } + + var onConnectTiming = function() { + self.timings.connect = now() - self.startTimeNow + } + + socket.once('lookup', onLookupTiming) + socket.once('connect', onConnectTiming) + + // clean up timing event listeners if needed on error + self.req.once('error', function() { + socket.removeListener('lookup', onLookupTiming) + socket.removeListener('connect', onConnectTiming) + }) + } } var setReqTimeout = function() { @@ -797,8 +823,6 @@ Request.prototype.start = function () { } }) } - // `._connecting` was the old property which was made public in node v6.1.0 - var isConnecting = socket._connecting || socket.connecting if (timeout !== undefined) { // Only start the connection timer if we're actually connecting a new // socket, otherwise if we're already connected (because this is a @@ -864,30 +888,50 @@ Request.prototype.onRequestResponse = function (response) { var self = this if (self.timing) { - self.timings.response = now() + self.timings.response = now() - self.startTimeNow } debug('onRequestResponse', self.uri.href, response.statusCode, response.headers) response.on('end', function() { if (self.timing) { - self.timings.end = now() + self.timings.end = now() - self.startTimeNow + response.timingStart = self.startTime - self.timings.dns = self.timings.socket - self.timings.start - self.timings.tcp = self.timings.connect - self.timings.socket - self.timings.firstByte = self.timings.response - self.timings.connect - self.timings.download = self.timings.end - self.timings.response - self.timings.total = self.timings.end - self.timings.start + // fill in the blanks for any periods that didn't trigger, such as + // no lookup or connect due to keep alive + if (!self.timings.socket) { + self.timings.socket = 0 + } + if (!self.timings.lookup) { + self.timings.lookup = self.timings.socket + } + if (!self.timings.connect) { + self.timings.connect = self.timings.lookup + } + if (!self.timings.response) { + self.timings.response = self.timings.connect + } - debug('elapsed time', self.timings.total) + debug('elapsed time', self.timings.end) // elapsedTime includes all redirects - self.elapsedTime += Math.round(self.timings.total) + self.elapsedTime += Math.round(self.timings.end) // NOTE: elapsedTime is deprecated in favor of .timings response.elapsedTime = self.elapsedTime // timings is just for the final fetch response.timings = self.timings + + // pre-calculate phase timings as well + response.timingPhases = { + wait: self.timings.socket, + dns: self.timings.lookup - self.timings.socket, + tcp: self.timings.connect - self.timings.lookup, + firstByte: self.timings.response - self.timings.connect, + download: self.timings.end - self.timings.response, + total: self.timings.end + } } debug('response end', self.uri.href, response.statusCode, response.headers) }) diff --git a/tests/test-timing.js b/tests/test-timing.js index 0623195f6..bc68774a6 100644 --- a/tests/test-timing.js +++ b/tests/test-timing.js @@ -27,23 +27,31 @@ tape('setup', function(t) { tape('non-redirected request is timed', function(t) { var options = {time: true} + var start = new Date().getTime() var r = request('http://localhost:' + plain_server.port + '/', options, function(err, res, body) { + var end = new Date().getTime() t.equal(err, null) t.equal(typeof res.elapsedTime, 'number') t.equal(typeof res.responseStartTime, 'number') + t.equal(typeof res.timingStart, 'number') + t.equal((res.timingStart >= start), true) t.equal(typeof res.timings, 'object') t.equal((res.elapsedTime > 0), true) + t.equal((res.elapsedTime <= (end - start)), true) t.equal((res.responseStartTime > r.startTime), true) - t.equal((res.timings.start > 0), true) - t.equal((res.timings.socket >= res.timings.start), true) - t.equal((res.timings.connect >= res.timings.socket), true) + t.equal((res.timings.socket >= 0), true) + t.equal((res.timings.lookup >= res.timings.socket), true) + t.equal((res.timings.connect >= res.timings.lookup), true) t.equal((res.timings.response >= res.timings.connect), true) t.equal((res.timings.end >= res.timings.response), true) - t.equal((res.timings.dns >= 0), true) - t.equal((res.timings.tcp >= 0), true) - t.equal((res.timings.firstByte > 0), true) - t.equal((res.timings.download > 0), true) - t.equal((res.timings.total > 0), true) + t.equal(typeof res.timingPhases, 'object') + t.equal((res.timingPhases.wait >= 0), true) + t.equal((res.timingPhases.dns >= 0), true) + t.equal((res.timingPhases.tcp >= 0), true) + t.equal((res.timingPhases.firstByte > 0), true) + t.equal((res.timingPhases.download > 0), true) + t.equal((res.timingPhases.total > 0), true) + t.equal((res.timingPhases.total <= (end - start)), true) // validate there are no unexpected properties var propNames = [] @@ -52,8 +60,15 @@ tape('non-redirected request is timed', function(t) { propNames.push(propName) } } - t.deepEqual(propNames, ['start', 'socket', 'connect', 'response', 'end', 'dns', - 'tcp', 'firstByte', 'download', 'total']) + t.deepEqual(propNames, ['socket', 'lookup', 'connect', 'response', 'end']) + + propNames = [] + for (var propName in res.timingPhases) { + if (res.timingPhases.hasOwnProperty(propName)) { + propNames.push(propName) + } + } + t.deepEqual(propNames, ['wait', 'dns', 'tcp', 'firstByte', 'download', 'total']) t.end() }) From 6d62d8e5f1dea4d167dbd627092652edf7f9a2e0 Mon Sep 17 00:00:00 2001 From: Mikeal Rogers Date: Sat, 4 Mar 2017 16:35:23 -0800 Subject: [PATCH 403/490] safe-buffer doesn't zero-fill by default, its just a polyfill. --- lib/helpers.js | 2 +- lib/multipart.js | 2 +- lib/oauth.js | 2 +- package.json | 2 +- request.js | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/helpers.js b/lib/helpers.js index 9e2d2ad34..05c77a0bd 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -36,7 +36,7 @@ function isReadStream (rs) { } function toBase64 (str) { - return (new Buffer(str || '', 'utf8')).toString('base64') + return Buffer.from(str || '', 'utf8').toString('base64') } function copy (obj) { diff --git a/lib/multipart.js b/lib/multipart.js index 4bb15325f..fc7b50276 100644 --- a/lib/multipart.js +++ b/lib/multipart.js @@ -72,7 +72,7 @@ Multipart.prototype.build = function (parts, chunked) { if (typeof part === 'number') { part = part.toString() } - return chunked ? body.append(part) : body.push(new Buffer(part)) + return chunked ? body.append(part) : body.push(Buffer.from(part)) } if (self.request.preambleCRLF) { diff --git a/lib/oauth.js b/lib/oauth.js index 402c89ff5..13b693773 100644 --- a/lib/oauth.js +++ b/lib/oauth.js @@ -71,7 +71,7 @@ OAuth.prototype.buildBodyHash = function(_oauth, body) { shasum.update(body || '') var sha1 = shasum.digest('hex') - return new Buffer(sha1).toString('base64') + return Buffer.from(sha1).toString('base64') } OAuth.prototype.concatParams = function (oa, sep, wrap) { diff --git a/package.json b/package.json index feaa3ea4e..4e1799dbb 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "safe-buffer": "^5.0.1", "stringstream": "~0.0.4", "tough-cookie": "~2.3.0", - "tunnel-agent": "^0.5.0", + "tunnel-agent": "^0.6.0", "uuid": "^3.0.0" }, "scripts": { diff --git a/request.js b/request.js index 5af242207..3606ce273 100644 --- a/request.js +++ b/request.js @@ -418,7 +418,7 @@ Request.prototype.init = function (options) { function setContentLength () { if (isTypedArray(self.body)) { - self.body = new Buffer(self.body) + self.body = Buffer.from(self.body) } if (!self.hasHeader('content-length')) { @@ -1122,7 +1122,7 @@ Request.prototype.readResponseBody = function (response) { } debug('emitting complete', self.uri.href) if (typeof response.body === 'undefined' && !self._json) { - response.body = self.encoding === null ? new Buffer(0) : '' + response.body = self.encoding === null ? Buffer.alloc(0) : '' } self.emit('complete', response, response.body) }) From fa48e67578a3c43f83c9e4e9339440e8dbbcf6f5 Mon Sep 17 00:00:00 2001 From: Mikeal Rogers Date: Sat, 4 Mar 2017 17:39:10 -0800 Subject: [PATCH 404/490] safe-buffer doesn't zero-fill by default, its just a polyfill. (#2578) --- lib/helpers.js | 2 +- lib/multipart.js | 2 +- lib/oauth.js | 2 +- package.json | 2 +- request.js | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/helpers.js b/lib/helpers.js index 9e2d2ad34..05c77a0bd 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -36,7 +36,7 @@ function isReadStream (rs) { } function toBase64 (str) { - return (new Buffer(str || '', 'utf8')).toString('base64') + return Buffer.from(str || '', 'utf8').toString('base64') } function copy (obj) { diff --git a/lib/multipart.js b/lib/multipart.js index 4bb15325f..fc7b50276 100644 --- a/lib/multipart.js +++ b/lib/multipart.js @@ -72,7 +72,7 @@ Multipart.prototype.build = function (parts, chunked) { if (typeof part === 'number') { part = part.toString() } - return chunked ? body.append(part) : body.push(new Buffer(part)) + return chunked ? body.append(part) : body.push(Buffer.from(part)) } if (self.request.preambleCRLF) { diff --git a/lib/oauth.js b/lib/oauth.js index 402c89ff5..13b693773 100644 --- a/lib/oauth.js +++ b/lib/oauth.js @@ -71,7 +71,7 @@ OAuth.prototype.buildBodyHash = function(_oauth, body) { shasum.update(body || '') var sha1 = shasum.digest('hex') - return new Buffer(sha1).toString('base64') + return Buffer.from(sha1).toString('base64') } OAuth.prototype.concatParams = function (oa, sep, wrap) { diff --git a/package.json b/package.json index e64da627d..74c47ff6c 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "safe-buffer": "^5.0.1", "stringstream": "~0.0.4", "tough-cookie": "~2.3.0", - "tunnel-agent": "^0.5.0", + "tunnel-agent": "^0.6.0", "uuid": "^3.0.0" }, "scripts": { diff --git a/request.js b/request.js index 089d52813..467524ba4 100644 --- a/request.js +++ b/request.js @@ -418,7 +418,7 @@ Request.prototype.init = function (options) { function setContentLength () { if (isTypedArray(self.body)) { - self.body = new Buffer(self.body) + self.body = Buffer.from(self.body) } if (!self.hasHeader('content-length')) { @@ -1166,7 +1166,7 @@ Request.prototype.readResponseBody = function (response) { } debug('emitting complete', self.uri.href) if (typeof response.body === 'undefined' && !self._json) { - response.body = self.encoding === null ? new Buffer(0) : '' + response.body = self.encoding === null ? Buffer.alloc(0) : '' } self.emit('complete', response, response.body) }) From 34d1ea5a67e2c0a340cff97307a910a16e72b720 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergej=20M=C3=BCller?= Date: Mon, 6 Mar 2017 16:12:12 +0100 Subject: [PATCH 405/490] Upgrade qs to version 6.4.0 Fix vulnerability alert, see the recommendation https://snyk.io/vuln/npm%3Aqs%3A20170213 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 74c47ff6c..39dd7a722 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "mime-types": "~2.1.7", "oauth-sign": "~0.8.1", "performance-now": "^0.2.0", - "qs": "~6.3.0", + "qs": "~6.4.0", "safe-buffer": "^5.0.1", "stringstream": "~0.0.4", "tough-cookie": "~2.3.0", From 44ba9df460c9d902bde0734fe222792c5f419a5b Mon Sep 17 00:00:00 2001 From: odykyi Date: Tue, 7 Mar 2017 15:56:18 +0200 Subject: [PATCH 406/490] fix tabulation on request example README.MD --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 231739114..3eaec064f 100644 --- a/README.md +++ b/README.md @@ -1036,7 +1036,8 @@ the server sent a compressed response. console.log('server encoded the data as: ' + (response.headers['content-encoding'] || 'identity')) console.log('the decoded data is: ' + body) } - ).on('data', function(data) { + ) + .on('data', function(data) { // decompressed data as it is received console.log('decoded chunk: ' + data) }) From eb5d89d86430f8bacbdf559e52c08c5f6a1701c4 Mon Sep 17 00:00:00 2001 From: Nic Jansma Date: Thu, 9 Mar 2017 09:30:52 -0500 Subject: [PATCH 407/490] Adds test-timing keepAlive test --- tests/test-timing.js | 47 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/tests/test-timing.js b/tests/test-timing.js index bc68774a6..a7da6d6a2 100644 --- a/tests/test-timing.js +++ b/tests/test-timing.js @@ -88,6 +88,53 @@ tape('redirected request is timed with rollup', function(t) { }) }) +tape('keepAlive is timed', function(t) { + var agent = new require('http').Agent({ keepAlive: true }) + var options = { time: true, agent: agent } + var start1 = new Date().getTime() + request('http://localhost:' + plain_server.port + '/', options, function(err1, res1, body1) { + var end1 = new Date().getTime() + + // ensure the first request's timestamps look ok + t.equal((res1.timingStart >= start1), true) + t.equal((start1 <= end1), true) + + t.equal((res1.timings.socket >= 0), true) + t.equal((res1.timings.lookup >= res1.timings.socket), true) + t.equal((res1.timings.connect >= res1.timings.lookup), true) + t.equal((res1.timings.response >= res1.timings.connect), true) + + var start2 = new Date().getTime() + request('http://localhost:' + plain_server.port + '/', options, function(err2, res2, body2) { + var end2 = new Date().getTime() + + // ensure the second request's timestamps look ok + t.equal((res2.timingStart >= start2), true) + t.equal((start2 <= end2), true) + + // ensure socket==lookup==connect for the second request + t.equal((res2.timings.socket >= 0), true) + t.equal((res2.timings.lookup == res2.timings.socket), true) + t.equal((res2.timings.connect == res2.timings.lookup), true) + t.equal((res2.timings.response >= res2.timings.connect), true) + + // explicitly shut down the agent + if (typeof agent.destroy === 'function') { + agent.destroy() + } else { + // node < 0.12 + Object.keys(agent.sockets).forEach(function (name) { + agent.sockets[name].forEach(function (socket) { + socket.end() + }) + }) + } + + t.end() + }) + }) +}) + tape('cleanup', function(t) { plain_server.close(function() { t.end() From f2f54fa5e420f143a661f497c9f568632676016a Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 9 Mar 2017 17:54:56 +0200 Subject: [PATCH 408/490] 2.81.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 39dd7a722..6516b5b00 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.80.1", + "version": "2.81.0", "author": "Mikeal Rogers ", "repository": { "type": "git", From a0cdc704c19e63e6f1740e173bb003c51eef524c Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 9 Mar 2017 17:56:33 +0200 Subject: [PATCH 409/490] Update changelog --- CHANGELOG.md | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a9b2abf9..af76719b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,22 @@ ## Change Log +### v2.81.0 (2017/03/09) +- [#2584](https://github.com/request/request/pull/2584) Security issue: Upgrade qs to version 6.4.0 (@sergejmueller) +- [#2574](https://github.com/request/request/pull/2574) Migrating to safe-buffer for improved security. (@mikeal) +- [#2573](https://github.com/request/request/pull/2573) fixes #2572 (@ahmadnassri) + +### v2.80.0 (2017/03/04) +- [#2571](https://github.com/request/request/pull/2571) Correctly format the Host header for IPv6 addresses (@JamesMGreene) +- [#2558](https://github.com/request/request/pull/2558) Update README.md example snippet (@FredKSchott) +- [#2221](https://github.com/request/request/pull/2221) Adding a simple Response object reference in argument specification (@calamarico) +- [#2452](https://github.com/request/request/pull/2452) Adds .timings array with DNC, TCP, request and response times (@nicjansma) +- [#2553](https://github.com/request/request/pull/2553) add ISSUE_TEMPLATE, move PR template (@FredKSchott) +- [#2539](https://github.com/request/request/pull/2539) Create PULL_REQUEST_TEMPLATE.md (@FredKSchott) +- [#2524](https://github.com/request/request/pull/2524) Update caseless to version 0.12.0 🚀 (@greenkeeperio-bot) +- [#2460](https://github.com/request/request/pull/2460) Fix wrong MIME type in example (@OwnageIsMagic) +- [#2514](https://github.com/request/request/pull/2514) Change tags to keywords in package.json (@humphd) +- [#2492](https://github.com/request/request/pull/2492) More lenient gzip decompression (@addaleax) + ### v2.79.0 (2016/11/18) - [#2368](https://github.com/request/request/pull/2368) Fix typeof check in test-pool.js (@forivall) - [#2394](https://github.com/request/request/pull/2394) Use `files` in package.json (@SimenB) @@ -108,7 +125,7 @@ - [#1902](https://github.com/request/request/pull/1902) node-uuid@1.4.7 breaks build 🚨 (@greenkeeperio-bot) - [#1894](https://github.com/request/request/pull/1894) Fix tunneling after redirection from https (Original: #1881) (@simov, @falms) - [#1893](https://github.com/request/request/pull/1893) Update eslint to version 1.9.0 🚀 (@greenkeeperio-bot) -- [#1852](https://github.com/request/request/pull/1852) Update eslint to version 1.7.3 🚀 (@simov, @greenkeeperio-bot, @paulomcnally, @michelsalib, @arbaaz, @vladimirich, @LoicMahieu, @JoshWillik, @jzaefferer, @ryanwholey, @djchie, @thisconnect, @mgenereu, @acroca, @Sebmaster, @KoltesDigital) +- [#1852](https://github.com/request/request/pull/1852) Update eslint to version 1.7.3 🚀 (@simov, @greenkeeperio-bot, @paulomcnally, @michelsalib, @arbaaz, @nsklkn, @LoicMahieu, @JoshWillik, @jzaefferer, @ryanwholey, @djchie, @thisconnect, @mgenereu, @acroca, @Sebmaster, @KoltesDigital) - [#1876](https://github.com/request/request/pull/1876) Implement loose matching for har mime types (@simov) - [#1875](https://github.com/request/request/pull/1875) Update bluebird to version 3.0.2 🚀 (@simov, @greenkeeperio-bot) - [#1871](https://github.com/request/request/pull/1871) Update browserify to version 12.0.1 🚀 (@greenkeeperio-bot) @@ -152,7 +169,7 @@ - [#1768](https://github.com/request/request/pull/1768) Add node 4.0 to the list of build targets (@simov) - [#1767](https://github.com/request/request/pull/1767) Query strings now cooperate with unix sockets (@JoshWillik) - [#1750](https://github.com/request/request/pull/1750) Revert doc about installation of tough-cookie added in #884 (@LoicMahieu) -- [#1746](https://github.com/request/request/pull/1746) Missed comma in Readme (@vladimirich) +- [#1746](https://github.com/request/request/pull/1746) Missed comma in Readme (@nsklkn) - [#1743](https://github.com/request/request/pull/1743) Fix options not being initialized in defaults method (@simov) ### v2.61.0 (2015/08/19) @@ -430,7 +447,7 @@ - [#1006](https://github.com/request/request/pull/1006) Migrate to caseless, fixes #1001 (@mikeal) - [#995](https://github.com/request/request/pull/995) Fix parsing array of objects (@sjonnet19) - [#999](https://github.com/request/request/pull/999) Fix fallback for browserify for optional modules. (@eiriksm) -- [#996](https://github.com/request/request/pull/996) Wrong oauth signature when multiple same param keys exist [updated] (@bengl, @hyjin) +- [#996](https://github.com/request/request/pull/996) Wrong oauth signature when multiple same param keys exist [updated] (@bengl) ### v2.40.0 (2014/08/06) - [#992](https://github.com/request/request/pull/992) Fix security vulnerability. Update qs (@poeticninja) @@ -496,15 +513,10 @@ - [#742](https://github.com/request/request/pull/742) Add note about JSON output body type (@iansltx) - [#741](https://github.com/request/request/pull/741) README example is using old cookie jar api (@emkay) - [#736](https://github.com/request/request/pull/736) Fix callback arguments documentation (@mmalecki) - -### v2.30.0 (2013/12/13) - [#732](https://github.com/request/request/pull/732) JSHINT: Creating global 'for' variable. Should be 'for (var ...'. (@Fritz-Lium) - [#730](https://github.com/request/request/pull/730) better HTTP DIGEST support (@dai-shi) - [#728](https://github.com/request/request/pull/728) Fix TypeError when calling request.cookie (@scarletmeow) - -### v2.29.0 (2013/12/06) - [#727](https://github.com/request/request/pull/727) fix requester bug (@jchris) -### v2.28.0 (2013/12/04) - [#724](https://github.com/request/request/pull/724) README.md: add custom HTTP Headers example. (@tcort) - [#719](https://github.com/request/request/pull/719) Made a comment gender neutral. (@unsetbit) - [#715](https://github.com/request/request/pull/715) Request.multipart no longer crashes when header 'Content-type' present (@pastaclub) @@ -538,10 +550,10 @@ - [#532](https://github.com/request/request/pull/532) fix typo (@fredericosilva) - [#497](https://github.com/request/request/pull/497) Added redirect event (@Cauldrath) - [#503](https://github.com/request/request/pull/503) Fix basic auth for passwords that contain colons (@tonistiigi) -- [#521](https://github.com/request/request/pull/521) Improving test-localAddress.js (@noway421) +- [#521](https://github.com/request/request/pull/521) Improving test-localAddress.js (@noway) - [#529](https://github.com/request/request/pull/529) dependencies versions bump (@jodaka) -- [#523](https://github.com/request/request/pull/523) Updating dependencies (@noway421) -- [#520](https://github.com/request/request/pull/520) Fixing test-tunnel.js (@noway421) +- [#523](https://github.com/request/request/pull/523) Updating dependencies (@noway) +- [#520](https://github.com/request/request/pull/520) Fixing test-tunnel.js (@noway) - [#519](https://github.com/request/request/pull/519) Update internal path state on post-creation QS changes (@jblebrun) - [#510](https://github.com/request/request/pull/510) Add HTTP Signature support. (@davidlehn) - [#502](https://github.com/request/request/pull/502) Fix POST (and probably other) requests that are retried after 401 Unauthorized (@nylen) From c57fb7258788888e42fcfa2b6d54c8150517cabe Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 9 Mar 2017 17:56:51 +0200 Subject: [PATCH 410/490] 2.81.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6516b5b00..e8f5fd25e 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.81.0", + "version": "2.81.1", "author": "Mikeal Rogers ", "repository": { "type": "git", From 51806f8ad32ec8fc3050a58467d5c2ac8742468b Mon Sep 17 00:00:00 2001 From: Ahmad Nassri Date: Tue, 14 Mar 2017 17:01:50 -0400 Subject: [PATCH 411/490] chore(dependencies): har-validator to 5.x [removes babel dep] a simple `npm i request` resulted in a `babel` install due to usage as a `devDependency` in `har-validator`, so `har-validator` is now refactored to remove that dependency entirely, making `request` lighter to install _(if only slightly)_ :) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e8f5fd25e..475dd10bd 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "extend": "~3.0.0", "forever-agent": "~0.6.1", "form-data": "~2.1.1", - "har-validator": "~4.2.1", + "har-validator": "~5.0.0", "hawk": "~3.1.3", "http-signature": "~1.1.0", "is-typedarray": "~1.0.0", From 21b1112831702c5e4e8ebd0eb3e5d5bee94b5c9a Mon Sep 17 00:00:00 2001 From: Ahmad Nassri Date: Tue, 14 Mar 2017 17:14:28 -0400 Subject: [PATCH 412/490] chore(dependencies): har-validator -> 5.0.1 addresses browser concerns. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 475dd10bd..68a5e8253 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "extend": "~3.0.0", "forever-agent": "~0.6.1", "form-data": "~2.1.1", - "har-validator": "~5.0.0", + "har-validator": "~5.0.1", "hawk": "~3.1.3", "http-signature": "~1.1.0", "is-typedarray": "~1.0.0", From baf9c1f2a6e3b0a78f017caa0e64259a5ecf40b5 Mon Sep 17 00:00:00 2001 From: Ahmad Nassri Date: Tue, 14 Mar 2017 17:36:59 -0400 Subject: [PATCH 413/490] chore(dependencies): har-validator -> 5.0.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 68a5e8253..128595e1d 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "extend": "~3.0.0", "forever-agent": "~0.6.1", "form-data": "~2.1.1", - "har-validator": "~5.0.1", + "har-validator": "~5.0.2", "hawk": "~3.1.3", "http-signature": "~1.1.0", "is-typedarray": "~1.0.0", From 0951f47782829204bb705e0d921c17db7192fb0e Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Thu, 16 Mar 2017 01:47:56 -0700 Subject: [PATCH 414/490] chore(package): update codecov to version 2.0.2 https://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e8f5fd25e..c4a815ad3 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,7 @@ "browserify": "^13.0.1", "browserify-istanbul": "^2.0.0", "buffer-equal": "^1.0.0", - "codecov": "^1.0.1", + "codecov": "^2.0.2", "coveralls": "^2.11.4", "eslint": "^2.5.3", "function-bind": "^1.0.2", From dd5c02c2d6861e6d44b27ea013cdb09d5f820717 Mon Sep 17 00:00:00 2001 From: Nic Jansma Date: Thu, 16 Mar 2017 19:22:33 -0400 Subject: [PATCH 415/490] Updated comment --- tests/test-timing.js | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test-timing.js b/tests/test-timing.js index a7da6d6a2..4e87afcee 100644 --- a/tests/test-timing.js +++ b/tests/test-timing.js @@ -104,6 +104,7 @@ tape('keepAlive is timed', function(t) { t.equal((res1.timings.connect >= res1.timings.lookup), true) t.equal((res1.timings.response >= res1.timings.connect), true) + // open a second request with the same agent so we re-use the same connection var start2 = new Date().getTime() request('http://localhost:' + plain_server.port + '/', options, function(err2, res2, body2) { var end2 = new Date().getTime() From b12a6245d9acdb1e13c6486d427801e123fdafae Mon Sep 17 00:00:00 2001 From: Ahmad Nassri Date: Thu, 16 Mar 2017 20:47:57 -0400 Subject: [PATCH 416/490] refactor(lint): replace eslint with standard (#2579) * refactor(lint): replace eslint with standard Fixes #2577 * refactor(lint): standard lint one additional standard lint error after merging with upstream * refactor(lint): error must be handled avoid using the `err` var name if we have no use for it * refactor(lint): keep oauth_* variable names in snakecase remain consistent with OAuth standard, as per @mikeal recommendation * chore(.eslintrc) remove, no longer needed --- .eslintrc | 45 -- index.js | 26 +- lib/auth.js | 11 +- lib/cookies.js | 15 +- lib/getProxyFromURI.js | 36 +- lib/har.js | 20 +- lib/helpers.js | 20 +- lib/multipart.js | 13 +- lib/oauth.js | 42 +- lib/querystring.js | 5 +- lib/redirect.js | 17 +- lib/tunnel.js | 51 ++- package.json | 5 +- request.js | 215 +++++----- tests/browser/karma.conf.js | 2 +- tests/browser/start.js | 4 +- tests/browser/test.js | 13 +- tests/server.js | 34 +- tests/ssl/ca/localhost.js | 18 +- tests/ssl/ca/server.js | 20 +- tests/test-agent.js | 22 +- tests/test-agentOptions.js | 84 ++-- tests/test-api.js | 12 +- tests/test-aws.js | 31 +- tests/test-baseUrl.js | 54 +-- tests/test-basic-auth.js | 70 +-- tests/test-bearer-auth.js | 60 +-- tests/test-body.js | 111 ++--- tests/test-cookies.js | 89 ++-- tests/test-defaults.js | 120 +++--- tests/test-digest-auth.js | 111 +++-- tests/test-emptyBody.js | 24 +- tests/test-errors.js | 46 +- tests/test-event-forwarding.js | 20 +- tests/test-follow-all-303.js | 16 +- tests/test-follow-all.js | 16 +- tests/test-form-data-error.js | 35 +- tests/test-form-data.js | 69 ++- tests/test-form-urlencoded.js | 21 +- tests/test-form.js | 63 ++- tests/test-gzip.js | 117 +++-- tests/test-hawk.js | 26 +- tests/test-headers.js | 80 ++-- tests/test-http-signature.js | 22 +- tests/test-httpModule.js | 96 ++--- tests/test-https.js | 92 ++-- tests/test-isUrl.js | 46 +- tests/test-json-request.js | 29 +- tests/test-localAddress.js | 4 +- tests/test-multipart-encoding.js | 23 +- tests/test-multipart.js | 35 +- tests/test-node-debug.js | 36 +- tests/test-oauth.js | 708 +++++++++++++++---------------- tests/test-onelineproxy.js | 24 +- tests/test-option-reuse.js | 20 +- tests/test-params.js | 85 ++-- tests/test-piped-redirect.js | 26 +- tests/test-pipes.js | 137 +++--- tests/test-pool.js | 28 +- tests/test-promise.js | 22 +- tests/test-proxy-connect.js | 32 +- tests/test-proxy.js | 192 +++++---- tests/test-qs.js | 96 ++--- tests/test-redirect-auth.js | 70 +-- tests/test-redirect-complex.js | 54 +-- tests/test-redirect.js | 146 +++---- tests/test-rfc3986.js | 45 +- tests/test-stream.js | 5 +- tests/test-timeout.js | 83 ++-- tests/test-timing.js | 54 +-- tests/test-toJSON.js | 32 +- tests/test-tunnel.js | 263 ++++++------ tests/test-unix.js | 42 +- 73 files changed, 2158 insertions(+), 2298 deletions(-) delete mode 100644 .eslintrc diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 5a5948158..000000000 --- a/.eslintrc +++ /dev/null @@ -1,45 +0,0 @@ -{ - "env": { - "node": true - }, - "rules": { - // 2-space indentation - "indent": [2, 2, {"SwitchCase": 1}], - // Disallow semi-colons, unless needed to disambiguate statement - "semi": [2, "never"], - // Require strings to use single quotes - "quotes": [2, "single"], - // Require curly braces for all control statements - "curly": 2, - // Disallow using variables and functions before they've been defined - "no-use-before-define": 2, - // Allow any case for variable naming - "camelcase": 0, - // Disallow unused variables, except as function arguments - "no-unused-vars": [2, {"args":"none"}], - // Allow leading underscores for method names - // REASON: we use underscores to denote private methods - "no-underscore-dangle": 0, - // Allow multi spaces around operators since they are - // used for alignment. This is not consistent in the - // code. - "no-multi-spaces": 0, - // Style rule is: most objects use { beforeColon: false, afterColon: true }, unless aligning which uses: - // - // { - // beforeColon : true, - // afterColon : true - // } - // - // eslint can't handle this, so the check is disabled. - "key-spacing": 0, - // Allow shadowing vars in outer scope (needs discussion) - "no-shadow": 0, - // Use if () { } - // ^ space - "keyword-spacing": [2, {"after": true}], - // Use if () { } - // ^ space - "space-before-blocks": [2, "always"] - } -} diff --git a/index.js b/index.js index 9ec65ea26..979260db8 100755 --- a/index.js +++ b/index.js @@ -14,15 +14,14 @@ 'use strict' -var extend = require('extend') - , cookies = require('./lib/cookies') - , helpers = require('./lib/helpers') +var extend = require('extend') +var cookies = require('./lib/cookies') +var helpers = require('./lib/helpers') var paramsHaveRequestBody = helpers.paramsHaveRequestBody - // organize params for patch, post, put, head, del -function initParams(uri, options, callback) { +function initParams (uri, options, callback) { if (typeof options === 'function') { callback = options } @@ -81,7 +80,6 @@ request.cookie = function (str) { } function wrapRequestMethod (method, options, requester, verb) { - return function (uri, opts, callback) { var params = initParams(uri, opts, callback) @@ -112,15 +110,15 @@ request.defaults = function (options, requester) { options = {} } - var defaults = wrapRequestMethod(self, options, requester) + var defaults = wrapRequestMethod(self, options, requester) var verbs = ['get', 'head', 'post', 'put', 'patch', 'del', 'delete'] - verbs.forEach(function(verb) { - defaults[verb] = wrapRequestMethod(self[verb], options, requester, verb) + verbs.forEach(function (verb) { + defaults[verb] = wrapRequestMethod(self[verb], options, requester, verb) }) - defaults.cookie = wrapRequestMethod(self.cookie, options, requester) - defaults.jar = self.jar + defaults.cookie = wrapRequestMethod(self.cookie, options, requester) + defaults.jar = self.jar defaults.defaults = self.defaults return defaults } @@ -146,11 +144,11 @@ request.initParams = initParams // Backwards compatibility for request.debug Object.defineProperty(request, 'debug', { - enumerable : true, - get : function() { + enumerable: true, + get: function () { return request.Request.debug }, - set : function(debug) { + set: function (debug) { request.Request.debug = debug } }) diff --git a/lib/auth.js b/lib/auth.js index 559ca57be..42f9adaec 100644 --- a/lib/auth.js +++ b/lib/auth.js @@ -1,12 +1,11 @@ 'use strict' var caseless = require('caseless') - , uuid = require('uuid') - , helpers = require('./helpers') +var uuid = require('uuid') +var helpers = require('./helpers') var md5 = helpers.md5 - , toBase64 = helpers.toBase64 - +var toBase64 = helpers.toBase64 function Auth (request) { // define all public properties here @@ -126,7 +125,7 @@ Auth.prototype.digest = function (method, path, authHeader) { Auth.prototype.onRequest = function (user, pass, sendImmediately, bearer) { var self = this - , request = self.request + var request = self.request var authHeader if (bearer === undefined && user === undefined) { @@ -143,7 +142,7 @@ Auth.prototype.onRequest = function (user, pass, sendImmediately, bearer) { Auth.prototype.onResponse = function (response) { var self = this - , request = self.request + var request = self.request if (!self.hasAuth || self.sentAuth) { return null } diff --git a/lib/cookies.js b/lib/cookies.js index 412c07d63..bd5d46bea 100644 --- a/lib/cookies.js +++ b/lib/cookies.js @@ -3,10 +3,9 @@ var tough = require('tough-cookie') var Cookie = tough.Cookie - , CookieJar = tough.CookieJar +var CookieJar = tough.CookieJar - -exports.parse = function(str) { +exports.parse = function (str) { if (str && str.uri) { str = str.uri } @@ -17,23 +16,23 @@ exports.parse = function(str) { } // Adapt the sometimes-Async api of tough.CookieJar to our requirements -function RequestJar(store) { +function RequestJar (store) { var self = this self._jar = new CookieJar(store, {looseMode: true}) } -RequestJar.prototype.setCookie = function(cookieOrStr, uri, options) { +RequestJar.prototype.setCookie = function (cookieOrStr, uri, options) { var self = this return self._jar.setCookieSync(cookieOrStr, uri, options || {}) } -RequestJar.prototype.getCookieString = function(uri) { +RequestJar.prototype.getCookieString = function (uri) { var self = this return self._jar.getCookieStringSync(uri) } -RequestJar.prototype.getCookies = function(uri) { +RequestJar.prototype.getCookies = function (uri) { var self = this return self._jar.getCookiesSync(uri) } -exports.jar = function(store) { +exports.jar = function (store) { return new RequestJar(store) } diff --git a/lib/getProxyFromURI.js b/lib/getProxyFromURI.js index c2013a6e1..4633ba5f6 100644 --- a/lib/getProxyFromURI.js +++ b/lib/getProxyFromURI.js @@ -1,33 +1,33 @@ 'use strict' -function formatHostname(hostname) { +function formatHostname (hostname) { // canonicalize the hostname, so that 'oogle.com' won't match 'google.com' return hostname.replace(/^\.*/, '.').toLowerCase() } -function parseNoProxyZone(zone) { +function parseNoProxyZone (zone) { zone = zone.trim().toLowerCase() var zoneParts = zone.split(':', 2) - , zoneHost = formatHostname(zoneParts[0]) - , zonePort = zoneParts[1] - , hasPort = zone.indexOf(':') > -1 + var zoneHost = formatHostname(zoneParts[0]) + var zonePort = zoneParts[1] + var hasPort = zone.indexOf(':') > -1 return {hostname: zoneHost, port: zonePort, hasPort: hasPort} } -function uriInNoProxy(uri, noProxy) { +function uriInNoProxy (uri, noProxy) { var port = uri.port || (uri.protocol === 'https:' ? '443' : '80') - , hostname = formatHostname(uri.hostname) - , noProxyList = noProxy.split(',') + var hostname = formatHostname(uri.hostname) + var noProxyList = noProxy.split(',') // iterate through the noProxyList until it finds a match. - return noProxyList.map(parseNoProxyZone).some(function(noProxyZone) { + return noProxyList.map(parseNoProxyZone).some(function (noProxyZone) { var isMatchedAt = hostname.indexOf(noProxyZone.hostname) - , hostnameMatched = ( - isMatchedAt > -1 && - (isMatchedAt === hostname.length - noProxyZone.hostname.length) - ) + var hostnameMatched = ( + isMatchedAt > -1 && + (isMatchedAt === hostname.length - noProxyZone.hostname.length) + ) if (noProxyZone.hasPort) { return (port === noProxyZone.port) && hostnameMatched @@ -37,7 +37,7 @@ function uriInNoProxy(uri, noProxy) { }) } -function getProxyFromURI(uri) { +function getProxyFromURI (uri) { // Decide the proper request proxy to use based on the request URI object and the // environmental variables (NO_PROXY, HTTP_PROXY, etc.) // respect NO_PROXY environment variables (see: http://lynx.isc.org/current/breakout/lynx_help/keystrokes/environments.html) @@ -60,14 +60,14 @@ function getProxyFromURI(uri) { if (uri.protocol === 'http:') { return process.env.HTTP_PROXY || - process.env.http_proxy || null + process.env.http_proxy || null } if (uri.protocol === 'https:') { return process.env.HTTPS_PROXY || - process.env.https_proxy || - process.env.HTTP_PROXY || - process.env.http_proxy || null + process.env.https_proxy || + process.env.HTTP_PROXY || + process.env.http_proxy || null } // if none of that works, return null diff --git a/lib/har.js b/lib/har.js index 305957487..2f660309d 100644 --- a/lib/har.js +++ b/lib/har.js @@ -71,14 +71,10 @@ Har.prototype.prep = function (data) { 'multipart/related', 'multipart/form-data', 'multipart/alternative'])) { - // reset values data.postData.mimeType = 'multipart/form-data' - } - - else if (some([ + } else if (some([ 'application/x-www-form-urlencoded'])) { - if (!data.postData.params) { data.postData.text = '' } else { @@ -87,14 +83,11 @@ Har.prototype.prep = function (data) { // always overwrite data.postData.text = qs.stringify(data.postData.paramsObj) } - } - - else if (some([ + } else if (some([ 'text/json', 'text/x-json', 'application/json', 'application/x-json'])) { - data.postData.mimeType = 'application/json' if (data.postData.text) { @@ -168,14 +161,12 @@ Har.prototype.options = function (options) { } if (test('application/x-www-form-urlencoded')) { options.form = req.postData.paramsObj - } - else if (test('application/json')) { + } else if (test('application/json')) { if (req.postData.jsonObj) { options.body = req.postData.jsonObj options.json = true } - } - else if (test('multipart/form-data')) { + } else if (test('multipart/form-data')) { options.formData = {} req.postData.params.forEach(function (param) { @@ -202,8 +193,7 @@ Har.prototype.options = function (options) { options.formData[param.name] = attachment }) - } - else { + } else { if (req.postData.text) { options.body = req.postData.text } diff --git a/lib/helpers.js b/lib/helpers.js index 05c77a0bd..8b2a7e6eb 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -1,14 +1,14 @@ 'use strict' var jsonSafeStringify = require('json-stringify-safe') - , crypto = require('crypto') - , Buffer = require('safe-buffer').Buffer +var crypto = require('crypto') +var Buffer = require('safe-buffer').Buffer var defer = typeof setImmediate === 'undefined' ? process.nextTick : setImmediate -function paramsHaveRequestBody(params) { +function paramsHaveRequestBody (params) { return ( params.body || params.requestBodyStream || @@ -57,10 +57,10 @@ function version () { } exports.paramsHaveRequestBody = paramsHaveRequestBody -exports.safeStringify = safeStringify -exports.md5 = md5 -exports.isReadStream = isReadStream -exports.toBase64 = toBase64 -exports.copy = copy -exports.version = version -exports.defer = defer +exports.safeStringify = safeStringify +exports.md5 = md5 +exports.isReadStream = isReadStream +exports.toBase64 = toBase64 +exports.copy = copy +exports.version = version +exports.defer = defer diff --git a/lib/multipart.js b/lib/multipart.js index fc7b50276..d6b981277 100644 --- a/lib/multipart.js +++ b/lib/multipart.js @@ -1,10 +1,9 @@ 'use strict' var uuid = require('uuid') - , CombinedStream = require('combined-stream') - , isstream = require('isstream') - , Buffer = require('safe-buffer').Buffer - +var CombinedStream = require('combined-stream') +var isstream = require('isstream') +var Buffer = require('safe-buffer').Buffer function Multipart (request) { this.request = request @@ -15,8 +14,8 @@ function Multipart (request) { Multipart.prototype.isChunked = function (options) { var self = this - , chunked = false - , parts = options.data || options + var chunked = false + var parts = options.data || options if (!parts.forEach) { self.request.emit('error', new Error('Argument error, options.multipart.')) @@ -103,7 +102,7 @@ Multipart.prototype.onRequest = function (options) { var self = this var chunked = self.isChunked(options) - , parts = options.data || options + var parts = options.data || options self.setHeaders(chunked) self.chunked = chunked diff --git a/lib/oauth.js b/lib/oauth.js index 13b693773..0c9c57cfe 100644 --- a/lib/oauth.js +++ b/lib/oauth.js @@ -1,13 +1,12 @@ 'use strict' var url = require('url') - , qs = require('qs') - , caseless = require('caseless') - , uuid = require('uuid') - , oauth = require('oauth-sign') - , crypto = require('crypto') - , Buffer = require('safe-buffer').Buffer - +var qs = require('qs') +var caseless = require('caseless') +var uuid = require('uuid') +var oauth = require('oauth-sign') +var crypto = require('crypto') +var Buffer = require('safe-buffer').Buffer function OAuth (request) { this.request = request @@ -23,7 +22,7 @@ OAuth.prototype.buildParams = function (_oauth, uri, method, query, form, qsLib) oa.oauth_version = '1.0' } if (!oa.oauth_timestamp) { - oa.oauth_timestamp = Math.floor( Date.now() / 1000 ).toString() + oa.oauth_timestamp = Math.floor(Date.now() / 1000).toString() } if (!oa.oauth_nonce) { oa.oauth_nonce = uuid().replace(/-/g, '') @@ -32,11 +31,11 @@ OAuth.prototype.buildParams = function (_oauth, uri, method, query, form, qsLib) oa.oauth_signature_method = 'HMAC-SHA1' } - var consumer_secret_or_private_key = oa.oauth_consumer_secret || oa.oauth_private_key + var consumer_secret_or_private_key = oa.oauth_consumer_secret || oa.oauth_private_key // eslint-disable-line camelcase delete oa.oauth_consumer_secret delete oa.oauth_private_key - var token_secret = oa.oauth_token_secret + var token_secret = oa.oauth_token_secret // eslint-disable-line camelcase delete oa.oauth_token_secret var realm = oa.oauth_realm @@ -51,8 +50,9 @@ OAuth.prototype.buildParams = function (_oauth, uri, method, query, form, qsLib) method, baseurl, params, - consumer_secret_or_private_key, - token_secret) + consumer_secret_or_private_key, // eslint-disable-line camelcase + token_secret // eslint-disable-line camelcase + ) if (realm) { oa.realm = realm @@ -61,7 +61,7 @@ OAuth.prototype.buildParams = function (_oauth, uri, method, query, form, qsLib) return oa } -OAuth.prototype.buildBodyHash = function(_oauth, body) { +OAuth.prototype.buildBodyHash = function (_oauth, body) { if (['HMAC-SHA1', 'RSA-SHA1'].indexOf(_oauth.signature_method || 'HMAC-SHA1') < 0) { this.request.emit('error', new Error('oauth: ' + _oauth.signature_method + ' signature_method not supported with body_hash signing.')) @@ -96,16 +96,16 @@ OAuth.prototype.onRequest = function (_oauth) { self.params = _oauth var uri = self.request.uri || {} - , method = self.request.method || '' - , headers = caseless(self.request.headers) - , body = self.request.body || '' - , qsLib = self.request.qsLib || qs + var method = self.request.method || '' + var headers = caseless(self.request.headers) + var body = self.request.body || '' + var qsLib = self.request.qsLib || qs var form - , query - , contentType = headers.get('content-type') || '' - , formContentType = 'application/x-www-form-urlencoded' - , transport = _oauth.transport_method || 'header' + var query + var contentType = headers.get('content-type') || '' + var formContentType = 'application/x-www-form-urlencoded' + var transport = _oauth.transport_method || 'header' if (contentType.slice(0, formContentType.length) === formContentType) { contentType = formContentType diff --git a/lib/querystring.js b/lib/querystring.js index baf5e8021..4a32cd149 100644 --- a/lib/querystring.js +++ b/lib/querystring.js @@ -1,8 +1,7 @@ 'use strict' var qs = require('qs') - , querystring = require('querystring') - +var querystring = require('querystring') function Querystring (request) { this.request = request @@ -13,7 +12,7 @@ function Querystring (request) { } Querystring.prototype.init = function (options) { - if (this.lib) {return} + if (this.lib) { return } this.useQuerystring = options.useQuerystring this.lib = (this.useQuerystring ? querystring : qs) diff --git a/lib/redirect.js b/lib/redirect.js index f8604491f..b9150e77c 100644 --- a/lib/redirect.js +++ b/lib/redirect.js @@ -9,7 +9,7 @@ function Redirect (request) { this.followRedirects = true this.followAllRedirects = false this.followOriginalHttpMethod = false - this.allowRedirect = function () {return true} + this.allowRedirect = function () { return true } this.maxRedirects = 10 this.redirects = [] this.redirectsFollowed = 0 @@ -44,7 +44,7 @@ Redirect.prototype.onRequest = function (options) { Redirect.prototype.redirectTo = function (response) { var self = this - , request = self.request + var request = self.request var redirectTo = null if (response.statusCode >= 300 && response.statusCode < 400 && response.caseless.has('location')) { @@ -78,7 +78,7 @@ Redirect.prototype.redirectTo = function (response) { Redirect.prototype.onResponse = function (response) { var self = this - , request = self.request + var request = self.request var redirectTo = self.redirectTo(response) if (!redirectTo || !self.allowRedirect.call(request, response)) { @@ -112,13 +112,10 @@ Redirect.prototype.onResponse = function (response) { delete request.agent } - self.redirects.push( - { statusCode : response.statusCode - , redirectUri: redirectTo - } - ) - if (self.followAllRedirects && request.method !== 'HEAD' - && response.statusCode !== 401 && response.statusCode !== 307) { + self.redirects.push({ statusCode: response.statusCode, redirectUri: redirectTo }) + + if (self.followAllRedirects && request.method !== 'HEAD' && + response.statusCode !== 401 && response.statusCode !== 307) { request.method = self.followOriginalHttpMethod ? request.method : 'GET' } // request.method = 'GET' // Force all redirects to use GET || commented out fixes #215 diff --git a/lib/tunnel.js b/lib/tunnel.js index bf96a8fec..4479003f6 100644 --- a/lib/tunnel.js +++ b/lib/tunnel.js @@ -1,7 +1,7 @@ 'use strict' var url = require('url') - , tunnel = require('tunnel-agent') +var tunnel = require('tunnel-agent') var defaultProxyHeaderWhiteList = [ 'accept', @@ -31,10 +31,10 @@ var defaultProxyHeaderExclusiveList = [ 'proxy-authorization' ] -function constructProxyHost(uriObject) { +function constructProxyHost (uriObject) { var port = uriObject.port - , protocol = uriObject.protocol - , proxyHost = uriObject.hostname + ':' + var protocol = uriObject.protocol + var proxyHost = uriObject.hostname + ':' if (port) { proxyHost += port @@ -47,7 +47,7 @@ function constructProxyHost(uriObject) { return proxyHost } -function constructProxyHeaderWhiteList(headers, proxyHeaderWhiteList) { +function constructProxyHeaderWhiteList (headers, proxyHeaderWhiteList) { var whiteList = proxyHeaderWhiteList .reduce(function (set, header) { set[header.toLowerCase()] = true @@ -68,41 +68,40 @@ function constructTunnelOptions (request, proxyHeaders) { var proxy = request.proxy var tunnelOptions = { - proxy : { - host : proxy.hostname, - port : +proxy.port, - proxyAuth : proxy.auth, - headers : proxyHeaders + proxy: { + host: proxy.hostname, + port: +proxy.port, + proxyAuth: proxy.auth, + headers: proxyHeaders }, - headers : request.headers, - ca : request.ca, - cert : request.cert, - key : request.key, - passphrase : request.passphrase, - pfx : request.pfx, - ciphers : request.ciphers, - rejectUnauthorized : request.rejectUnauthorized, - secureOptions : request.secureOptions, - secureProtocol : request.secureProtocol + headers: request.headers, + ca: request.ca, + cert: request.cert, + key: request.key, + passphrase: request.passphrase, + pfx: request.pfx, + ciphers: request.ciphers, + rejectUnauthorized: request.rejectUnauthorized, + secureOptions: request.secureOptions, + secureProtocol: request.secureProtocol } return tunnelOptions } -function constructTunnelFnName(uri, proxy) { +function constructTunnelFnName (uri, proxy) { var uriProtocol = (uri.protocol === 'https:' ? 'https' : 'http') var proxyProtocol = (proxy.protocol === 'https:' ? 'Https' : 'Http') return [uriProtocol, proxyProtocol].join('Over') } -function getTunnelFn(request) { +function getTunnelFn (request) { var uri = request.uri var proxy = request.proxy var tunnelFnName = constructTunnelFnName(uri, proxy) return tunnel[tunnelFnName] } - function Tunnel (request) { this.request = request this.proxyHeaderWhiteList = defaultProxyHeaderWhiteList @@ -114,8 +113,8 @@ function Tunnel (request) { Tunnel.prototype.isEnabled = function () { var self = this - , request = self.request - // Tunnel HTTPS by default. Allow the user to override this setting. + var request = self.request + // Tunnel HTTPS by default. Allow the user to override this setting. // If self.tunnelOverride is set (the user specified a value), use it. if (typeof self.tunnelOverride !== 'undefined') { @@ -133,7 +132,7 @@ Tunnel.prototype.isEnabled = function () { Tunnel.prototype.setup = function (options) { var self = this - , request = self.request + var request = self.request options = options || {} diff --git a/package.json b/package.json index a8f659073..61ef77ca6 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,7 @@ "test-ci": "taper tests/test-*.js", "test-cov": "istanbul cover tape tests/test-*.js", "test-browser": "node tests/browser/start.js", - "lint": "eslint lib/ *.js tests/ && echo Lint passed." + "lint": "standard" }, "devDependencies": { "bluebird": "^3.2.1", @@ -64,7 +64,6 @@ "buffer-equal": "^1.0.0", "codecov": "^2.0.2", "coveralls": "^2.11.4", - "eslint": "^2.5.3", "function-bind": "^1.0.2", "istanbul": "^0.4.0", "karma": "^1.1.1", @@ -76,12 +75,12 @@ "phantomjs-prebuilt": "^2.1.3", "rimraf": "^2.2.8", "server-destroy": "^1.0.1", + "standard": "^9.0.0", "tape": "^4.6.0", "taper": "^0.5.0" }, "greenkeeper": { "ignore": [ - "eslint", "hawk", "har-validator" ] diff --git a/request.js b/request.js index 467524ba4..ff19ca39c 100644 --- a/request.js +++ b/request.js @@ -1,48 +1,47 @@ 'use strict' var http = require('http') - , https = require('https') - , url = require('url') - , util = require('util') - , stream = require('stream') - , zlib = require('zlib') - , hawk = require('hawk') - , aws2 = require('aws-sign2') - , aws4 = require('aws4') - , httpSignature = require('http-signature') - , mime = require('mime-types') - , stringstream = require('stringstream') - , caseless = require('caseless') - , ForeverAgent = require('forever-agent') - , FormData = require('form-data') - , extend = require('extend') - , isstream = require('isstream') - , isTypedArray = require('is-typedarray').strict - , helpers = require('./lib/helpers') - , cookies = require('./lib/cookies') - , getProxyFromURI = require('./lib/getProxyFromURI') - , Querystring = require('./lib/querystring').Querystring - , Har = require('./lib/har').Har - , Auth = require('./lib/auth').Auth - , OAuth = require('./lib/oauth').OAuth - , Multipart = require('./lib/multipart').Multipart - , Redirect = require('./lib/redirect').Redirect - , Tunnel = require('./lib/tunnel').Tunnel - , now = require('performance-now') - , Buffer = require('safe-buffer').Buffer +var https = require('https') +var url = require('url') +var util = require('util') +var stream = require('stream') +var zlib = require('zlib') +var hawk = require('hawk') +var aws2 = require('aws-sign2') +var aws4 = require('aws4') +var httpSignature = require('http-signature') +var mime = require('mime-types') +var stringstream = require('stringstream') +var caseless = require('caseless') +var ForeverAgent = require('forever-agent') +var FormData = require('form-data') +var extend = require('extend') +var isstream = require('isstream') +var isTypedArray = require('is-typedarray').strict +var helpers = require('./lib/helpers') +var cookies = require('./lib/cookies') +var getProxyFromURI = require('./lib/getProxyFromURI') +var Querystring = require('./lib/querystring').Querystring +var Har = require('./lib/har').Har +var Auth = require('./lib/auth').Auth +var OAuth = require('./lib/oauth').OAuth +var Multipart = require('./lib/multipart').Multipart +var Redirect = require('./lib/redirect').Redirect +var Tunnel = require('./lib/tunnel').Tunnel +var now = require('performance-now') +var Buffer = require('safe-buffer').Buffer var safeStringify = helpers.safeStringify - , isReadStream = helpers.isReadStream - , toBase64 = helpers.toBase64 - , defer = helpers.defer - , copy = helpers.copy - , version = helpers.version - , globalCookieJar = cookies.jar() - +var isReadStream = helpers.isReadStream +var toBase64 = helpers.toBase64 +var defer = helpers.defer +var copy = helpers.copy +var version = helpers.version +var globalCookieJar = cookies.jar() var globalPool = {} -function filterForNonReserved(reserved, options) { +function filterForNonReserved (reserved, options) { // Filter out properties that are not reserved. // Reserved values are passed in at call site. @@ -56,7 +55,7 @@ function filterForNonReserved(reserved, options) { return object } -function filterOutReservedFunctions(reserved, options) { +function filterOutReservedFunctions (reserved, options) { // Filter out properties that are functions and are reserved. // Reserved values are passed in at call site. @@ -69,11 +68,10 @@ function filterOutReservedFunctions(reserved, options) { } } return object - } // Return a simpler request object to allow serialization -function requestToJSON() { +function requestToJSON () { var self = this return { uri: self.uri, @@ -83,7 +81,7 @@ function requestToJSON() { } // Return a simpler response object to allow serialization -function responseToJSON() { +function responseToJSON () { var self = this return { statusCode: self.statusCode, @@ -134,7 +132,7 @@ util.inherits(Request, stream.Stream) // Debugging Request.debug = process.env.NODE_DEBUG && /\brequest\b/.test(process.env.NODE_DEBUG) -function debug() { +function debug () { if (Request.debug) { console.error('REQUEST %s', util.format.apply(util, arguments)) } @@ -258,7 +256,7 @@ Request.prototype.init = function (options) { self.rejectUnauthorized = false } - if (!self.uri.pathname) {self.uri.pathname = '/'} + if (!self.uri.pathname) { self.uri.pathname = '/' } if (!(self.uri.host || (self.uri.hostname && self.uri.port)) && !self.uri.isUnix) { // Invalid URI: it may generate lot of bad errors, like 'TypeError: Cannot call method `indexOf` of undefined' in CookieJar @@ -300,8 +298,7 @@ Request.prototype.init = function (options) { self.jar(self._jar || options.jar) if (!self.uri.port) { - if (self.uri.protocol === 'http:') {self.uri.port = 80} - else if (self.uri.protocol === 'https:') {self.uri.port = 443} + if (self.uri.protocol === 'http:') { self.uri.port = 80 } else if (self.uri.protocol === 'https:') { self.uri.port = 443 } } if (self.proxy && !self.tunnel) { @@ -388,12 +385,12 @@ Request.prototype.init = function (options) { } if (self.uri.auth && !self.hasHeader('authorization')) { - var uriAuthPieces = self.uri.auth.split(':').map(function(item) {return self._qs.unescape(item)}) + var uriAuthPieces = self.uri.auth.split(':').map(function (item) { return self._qs.unescape(item) }) self.auth(uriAuthPieces[0], uriAuthPieces.slice(1).join(':'), true) } if (!self.tunnel && self.proxy && self.proxy.auth && !self.hasHeader('proxy-authorization')) { - var proxyAuthPieces = self.proxy.auth.split(':').map(function(item) {return self._qs.unescape(item)}) + var proxyAuthPieces = self.proxy.auth.split(':').map(function (item) { return self._qs.unescape(item) }) var authHeader = 'Basic ' + toBase64(proxyAuthPieces.join(':')) self.setHeader('proxy-authorization', authHeader) } @@ -425,11 +422,9 @@ Request.prototype.init = function (options) { 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 { + } else if (Array.isArray(self.body)) { + length = self.body.reduce(function (a, b) { return a + b.length }, 0) + } else { length = self.body.length } @@ -451,8 +446,8 @@ Request.prototype.init = function (options) { } var protocol = self.proxy && !self.tunnel ? self.proxy.protocol : self.uri.protocol - , defaultModules = {'http:':http, 'https:':https} - , httpModules = self.httpModules || {} + var defaultModules = {'http:': http, 'https:': https} + var httpModules = self.httpModules || {} self.httpModule = httpModules[protocol] || defaultModules[protocol] @@ -517,9 +512,9 @@ Request.prototype.init = function (options) { } } - // self.on('pipe', function () { - // console.error('You have already piped to this stream. Pipeing twice is likely to break the request.') - // }) + // self.on('pipe', function () { + // console.error('You have already piped to this stream. Pipeing twice is likely to break the request.') + // }) }) defer(function () { @@ -531,8 +526,7 @@ Request.prototype.init = function (options) { if (self._form) { if (!self._auth.hasAuth) { self._form.pipe(self) - } - else if (self._auth.hasAuth && self._auth.sentAuth) { + } else if (self._auth.hasAuth && self._auth.sentAuth) { self._form.pipe(self) } } @@ -583,7 +577,6 @@ Request.prototype.init = function (options) { self.ntick = true }) - } Request.prototype.getNewAgent = function () { @@ -778,21 +771,22 @@ Request.prototype.start = function () { self.req.on('response', self.onRequestResponse.bind(self)) self.req.on('error', self.onRequestError.bind(self)) - self.req.on('drain', function() { + self.req.on('drain', function () { self.emit('drain') }) - self.req.on('socket', function(socket) { + + self.req.on('socket', function (socket) { // `._connecting` was the old property which was made public in node v6.1.0 var isConnecting = socket._connecting || socket.connecting if (self.timing) { self.timings.socket = now() - self.startTimeNow if (isConnecting) { - var onLookupTiming = function() { + var onLookupTiming = function () { self.timings.lookup = now() - self.startTimeNow } - var onConnectTiming = function() { + var onConnectTiming = function () { self.timings.connect = now() - self.startTimeNow } @@ -800,14 +794,14 @@ Request.prototype.start = function () { socket.once('connect', onConnectTiming) // clean up timing event listeners if needed on error - self.req.once('error', function() { + self.req.once('error', function () { socket.removeListener('lookup', onLookupTiming) socket.removeListener('connect', onConnectTiming) }) } } - var setReqTimeout = function() { + var setReqTimeout = function () { // This timeout sets the amount of time to wait *between* bytes sent // from the server once connected. // @@ -829,7 +823,7 @@ Request.prototype.start = function () { // keep-alive connection) do not bother. This is important since we won't // get a 'connect' event for an already connected socket. if (isConnecting) { - var onReqSockConnect = function() { + var onReqSockConnect = function () { socket.removeListener('connect', onReqSockConnect) clearTimeout(self.timeoutTimer) self.timeoutTimer = null @@ -838,7 +832,7 @@ Request.prototype.start = function () { socket.on('connect', onReqSockConnect) - self.req.on('error', function(err) { + self.req.on('error', function (err) { // eslint-disable-line handle-callback-err socket.removeListener('connect', onReqSockConnect) }) @@ -870,8 +864,8 @@ Request.prototype.onRequestError = function (error) { if (self._aborted) { return } - if (self.req && self.req._reusedSocket && error.code === 'ECONNRESET' - && self.agent.addRequestNoreuse) { + if (self.req && self.req._reusedSocket && error.code === 'ECONNRESET' && + self.agent.addRequestNoreuse) { self.agent = { addRequest: self.agent.addRequestNoreuse.bind(self.agent) } self.start() self.req.end() @@ -892,7 +886,7 @@ Request.prototype.onRequestResponse = function (response) { } debug('onRequestResponse', self.uri.href, response.statusCode, response.headers) - response.on('end', function() { + response.on('end', function () { if (self.timing) { self.timings.end = now() - self.startTimeNow response.timingStart = self.startTime @@ -948,8 +942,8 @@ Request.prototype.onRequestResponse = function (response) { // XXX This is different on 0.10, because SSL is strict by default if (self.httpModule === https && - self.strictSSL && (!response.hasOwnProperty('socket') || - !response.socket.authorized)) { + self.strictSSL && (!response.hasOwnProperty('socket') || + !response.socket.authorized)) { debug('strict ssl error', self.uri.href) var sslErr = response.hasOwnProperty('socket') ? response.socket.authorizationError : self.uri.href + ' does not support SSL' self.emit('error', new Error('SSL Error: ' + sslErr)) @@ -974,7 +968,7 @@ Request.prototype.onRequestResponse = function (response) { var targetCookieJar = (self._jar && self._jar.setCookie) ? self._jar : globalCookieJar var addCookie = function (cookie) { - //set the cookie if it's domain in the href's domain. + // set the cookie if it's domain in the href's domain. try { targetCookieJar.setCookie(cookie, self.uri.href, {ignoreError: true}) } catch (e) { @@ -1010,13 +1004,13 @@ Request.prototype.onRequestResponse = function (response) { var noBody = function (code) { return ( - self.method === 'HEAD' + self.method === 'HEAD' || // Informational - || (code >= 100 && code < 200) + (code >= 100 && code < 200) || // No Content - || code === 204 + code === 204 || // Not Modified - || code === 304 + code === 304 ) } @@ -1030,8 +1024,8 @@ Request.prototype.onRequestResponse = function (response) { // by common browsers. // Always using Z_SYNC_FLUSH is what cURL does. var zlibOptions = { - flush: zlib.Z_SYNC_FLUSH - , finishFlush: zlib.Z_SYNC_FLUSH + flush: zlib.Z_SYNC_FLUSH, + finishFlush: zlib.Z_SYNC_FLUSH } if (contentEncoding === 'gzip') { @@ -1093,13 +1087,11 @@ Request.prototype.onRequestResponse = function (response) { responseContent.on('error', function (error) { self.emit('error', error) }) - responseContent.on('close', function () {self.emit('close')}) + responseContent.on('close', function () { self.emit('close') }) if (self.callback) { self.readResponseBody(response) - } - //if no callback - else { + } else { // if no callback self.on('end', function () { if (self._aborted) { debug('aborted', self.uri.href) @@ -1114,10 +1106,10 @@ Request.prototype.onRequestResponse = function (response) { Request.prototype.readResponseBody = function (response) { var self = this - debug('reading response\'s body') + debug("reading response's body") var buffers = [] - , bufferLength = 0 - , strings = [] + var bufferLength = 0 + var strings = [] self.on('data', function (chunk) { if (!Buffer.isBuffer(chunk)) { @@ -1178,8 +1170,7 @@ Request.prototype.abort = function () { if (self.req) { self.req.abort() - } - else if (self.response) { + } else if (self.response) { self.response.destroy() } @@ -1195,8 +1186,7 @@ Request.prototype.pipeDest = function (dest) { var ctname = response.caseless.has('content-type') if (dest.setHeader) { dest.setHeader(ctname, response.headers[ctname]) - } - else { + } else { dest.headers[ctname] = response.headers[ctname] } } @@ -1267,7 +1257,7 @@ Request.prototype.form = function (form) { } // create form-data object self._form = new FormData() - self._form.on('error', function(err) { + self._form.on('error', function (err) { err.message = 'form-data: ' + err.message self.emit('error', err) self.abort() @@ -1342,8 +1332,8 @@ Request.prototype.getHeader = function (name, headers) { Request.prototype.enableUnixSocket = function () { // Get the socket & request paths from the URL var unixParts = this.uri.path.split(':') - , host = unixParts[0] - , path = unixParts[1] + var host = unixParts[0] + var path = unixParts[1] // Apply unix properties to request this.socketPath = host this.uri.pathname = path @@ -1353,7 +1343,6 @@ Request.prototype.enableUnixSocket = function () { this.uri.isUnix = true } - Request.prototype.auth = function (user, pass, sendImmediately, bearer) { var self = this @@ -1369,7 +1358,7 @@ Request.prototype.aws = function (opts, now) { return self } - if (opts.sign_version == 4 || opts.sign_version == '4') { + if (opts.sign_version === 4 || opts.sign_version === '4') { // use aws4 var options = { host: self.uri.host, @@ -1390,20 +1379,19 @@ Request.prototype.aws = function (opts, now) { if (signRes.headers['X-Amz-Security-Token']) { self.setHeader('x-amz-security-token', signRes.headers['X-Amz-Security-Token']) } - } - else { + } else { // default: use aws-sign2 var date = new Date() self.setHeader('date', date.toUTCString()) - var auth = - { key: opts.key - , secret: opts.secret - , verb: self.method.toUpperCase() - , date: date - , contentType: self.getHeader('content-type') || '' - , md5: self.getHeader('content-md5') || '' - , amazonHeaders: aws2.canonicalizeHeaders(self.headers) - } + var auth = { + key: opts.key, + secret: opts.secret, + verb: self.method.toUpperCase(), + date: date, + contentType: self.getHeader('content-type') || '', + md5: self.getHeader('content-md5') || '', + amazonHeaders: aws2.canonicalizeHeaders(self.headers) + } var path = self.uri.path if (opts.bucket && path) { auth.resource = '/' + opts.bucket + path @@ -1423,10 +1411,10 @@ Request.prototype.aws = function (opts, now) { Request.prototype.httpSignature = function (opts) { var self = this httpSignature.signRequest({ - getHeader: function(header) { + getHeader: function (header) { return self.getHeader(header, self.headers) }, - setHeader: function(header, value) { + setHeader: function (header, value) { self.setHeader(header, value) }, method: self.method, @@ -1463,13 +1451,13 @@ Request.prototype.jar = function (jar) { } else { var targetCookieJar = (jar && jar.getCookieString) ? jar : globalCookieJar var urihref = self.uri.href - //fetch cookie in the Specified host + // fetch cookie in the Specified host if (targetCookieJar) { cookies = targetCookieJar.getCookieString(urihref) } } - //if need cookie and cookie is not empty + // if need cookie and cookie is not empty if (cookies && cookies.length) { if (self.originalCookieHeader) { // Don't overwrite existing Cookie header @@ -1482,7 +1470,6 @@ Request.prototype.jar = function (jar) { return self } - // Stream API Request.prototype.pipe = function (dest, opts) { var self = this @@ -1505,7 +1492,7 @@ Request.prototype.pipe = function (dest, opts) { } Request.prototype.write = function () { var self = this - if (self._aborted) {return} + if (self._aborted) { return } if (!self._started) { self.start() @@ -1516,7 +1503,7 @@ Request.prototype.write = function () { } Request.prototype.end = function (chunk) { var self = this - if (self._aborted) {return} + if (self._aborted) { return } if (chunk) { self.write(chunk) diff --git a/tests/browser/karma.conf.js b/tests/browser/karma.conf.js index 4c9172471..5fbf31a45 100644 --- a/tests/browser/karma.conf.js +++ b/tests/browser/karma.conf.js @@ -1,7 +1,7 @@ 'use strict' var istanbul = require('browserify-istanbul') -module.exports = function(config) { +module.exports = function (config) { config.set({ client: { requestTestUrl: process.argv[4] }, basePath: '../..', diff --git a/tests/browser/start.js b/tests/browser/start.js index 8ada016f8..3ce0c6a81 100644 --- a/tests/browser/start.js +++ b/tests/browser/start.js @@ -16,7 +16,7 @@ var server = https.createServer({ res.writeHead(200) res.end('Can you hear the sound of an enormous door slamming in the depths of hell?\n') }) -server.listen(0, function() { +server.listen(0, function () { var port = this.address().port console.log('Started https server for karma tests on port ' + port) // Spawn process for karma. @@ -27,7 +27,7 @@ server.listen(0, function() { ]) c.stdout.pipe(process.stdout) c.stderr.pipe(process.stderr) - c.on('exit', function(c) { + c.on('exit', function (c) { // Exit process with karma exit code. if (c !== 0) { throw new Error('Karma exited with status code ' + c) diff --git a/tests/browser/test.js b/tests/browser/test.js index 6ee8f7815..34135a398 100644 --- a/tests/browser/test.js +++ b/tests/browser/test.js @@ -4,15 +4,14 @@ if (!Function.prototype.bind) { // This is because of the fact that phantom.js does not have Function.bind. // This is a bug in phantom.js. // More info: https://github.com/ariya/phantomjs/issues/10522 - /*eslint no-extend-native:0*/ + /* eslint no-extend-native:0 */ Function.prototype.bind = require('function-bind') } - var tape = require('tape') - , request = require('../../index') +var request = require('../../index') -tape('returns on error', function(t) { +tape('returns on error', function (t) { t.plan(1) request({ uri: 'https://stupid.nonexistent.path:port123/\\<-great-idea', @@ -23,12 +22,12 @@ tape('returns on error', function(t) { }) }) -tape('succeeds on valid URLs (with https and CORS)', function(t) { +tape('succeeds on valid URLs (with https and CORS)', function (t) { t.plan(1) request({ - uri: __karma__.config.requestTestUrl, + uri: __karma__.config.requestTestUrl, // eslint-disable-line no-undef withCredentials: false - }, function (error, response) { + }, function (_, response) { t.equal(response.statusCode, 200) t.end() }) diff --git a/tests/server.js b/tests/server.js index 10a667bc1..614f03c44 100644 --- a/tests/server.js +++ b/tests/server.js @@ -1,11 +1,11 @@ 'use strict' var fs = require('fs') - , http = require('http') - , path = require('path') - , https = require('https') - , stream = require('stream') - , assert = require('assert') +var http = require('http') +var path = require('path') +var https = require('https') +var stream = require('stream') +var assert = require('assert') exports.createServer = function () { var s = http.createServer(function (req, resp) { @@ -23,9 +23,9 @@ exports.createServer = function () { exports.createEchoServer = function () { var s = http.createServer(function (req, resp) { var b = '' - req.on('data', function (chunk) {b += chunk}) + req.on('data', function (chunk) { b += chunk }) req.on('end', function () { - resp.writeHead(200, {'content-type':'application/json'}) + resp.writeHead(200, {'content-type': 'application/json'}) resp.write(JSON.stringify({ url: req.url, method: req.method, @@ -44,11 +44,9 @@ exports.createEchoServer = function () { return s } -exports.createSSLServer = function(opts) { +exports.createSSLServer = function (opts) { var i - , options = { 'key' : path.join(__dirname, 'ssl', 'test.key') - , 'cert': path.join(__dirname, 'ssl', 'test.crt') - } + var options = { 'key': path.join(__dirname, 'ssl', 'test.key'), 'cert': path.join(__dirname, 'ssl', 'test.crt') } if (opts) { for (i in opts) { options[i] = opts[i] @@ -77,7 +75,7 @@ exports.createPostStream = function (text) { var postStream = new stream.Stream() postStream.writeable = true postStream.readable = true - setTimeout(function() { + setTimeout(function () { postStream.emit('data', new Buffer(text)) postStream.emit('end') }, 0) @@ -86,7 +84,7 @@ exports.createPostStream = function (text) { exports.createPostValidator = function (text, reqContentType) { var l = function (req, resp) { var r = '' - req.on('data', function (chunk) {r += chunk}) + req.on('data', function (chunk) { r += chunk }) req.on('end', function () { if (req.headers['content-type'] && req.headers['content-type'].indexOf('boundary=') >= 0) { var boundary = req.headers['content-type'].split('boundary=')[1] @@ -97,7 +95,7 @@ exports.createPostValidator = function (text, reqContentType) { assert.ok(req.headers['content-type']) assert.ok(~req.headers['content-type'].indexOf(reqContentType)) } - resp.writeHead(200, {'content-type':'text/plain'}) + resp.writeHead(200, {'content-type': 'text/plain'}) resp.write(r) resp.end() }) @@ -107,7 +105,7 @@ exports.createPostValidator = function (text, reqContentType) { exports.createPostJSONValidator = function (value, reqContentType) { var l = function (req, resp) { var r = '' - req.on('data', function (chunk) {r += chunk}) + req.on('data', function (chunk) { r += chunk }) req.on('end', function () { var parsedValue = JSON.parse(r) assert.deepEqual(parsedValue, value) @@ -115,7 +113,7 @@ exports.createPostJSONValidator = function (value, reqContentType) { assert.ok(req.headers['content-type']) assert.ok(~req.headers['content-type'].indexOf(reqContentType)) } - resp.writeHead(200, {'content-type':'application/json'}) + resp.writeHead(200, {'content-type': 'application/json'}) resp.write(r) resp.end() }) @@ -125,7 +123,7 @@ exports.createPostJSONValidator = function (value, reqContentType) { exports.createGetResponse = function (text, contentType) { var l = function (req, resp) { contentType = contentType || 'text/plain' - resp.writeHead(200, {'content-type':contentType}) + resp.writeHead(200, {'content-type': contentType}) resp.write(text) resp.end() } @@ -134,7 +132,7 @@ exports.createGetResponse = function (text, contentType) { exports.createChunkResponse = function (chunks, contentType) { var l = function (req, resp) { contentType = contentType || 'text/plain' - resp.writeHead(200, {'content-type':contentType}) + resp.writeHead(200, {'content-type': contentType}) chunks.forEach(function (chunk) { resp.write(chunk) }) diff --git a/tests/ssl/ca/localhost.js b/tests/ssl/ca/localhost.js index 8ba3358c6..567bdb8e6 100644 --- a/tests/ssl/ca/localhost.js +++ b/tests/ssl/ca/localhost.js @@ -2,15 +2,15 @@ var fs = require('fs') var https = require('https') -var options = { key: fs.readFileSync('./localhost.key') - , cert: fs.readFileSync('./localhost.crt') } +var options = { key: fs.readFileSync('./localhost.key'), + cert: fs.readFileSync('./localhost.crt') } var server = https.createServer(options, function (req, res) { res.writeHead(200) res.end() server.close() }) -server.listen(0, function() { +server.listen(0, function () { var ca = fs.readFileSync('./ca.crt') var agent = new https.Agent({ host: 'localhost', @@ -18,12 +18,12 @@ server.listen(0, function() { ca: ca }) - https.request({ host: 'localhost' - , method: 'HEAD' - , port: this.address().port - , agent: agent - , ca: [ ca ] - , path: '/' }, function (res) { + https.request({ host: 'localhost', + method: 'HEAD', + port: this.address().port, + agent: agent, + ca: [ ca ], + path: '/' }, function (res) { if (res.socket.authorized) { console.log('node test: OK') } else { diff --git a/tests/ssl/ca/server.js b/tests/ssl/ca/server.js index 934554540..ca2a00e77 100644 --- a/tests/ssl/ca/server.js +++ b/tests/ssl/ca/server.js @@ -2,15 +2,15 @@ var fs = require('fs') var https = require('https') -var options = { key: fs.readFileSync('./server.key') - , cert: fs.readFileSync('./server.crt') } +var options = { key: fs.readFileSync('./server.key'), + cert: fs.readFileSync('./server.crt') } var server = https.createServer(options, function (req, res) { res.writeHead(200) res.end() server.close() }) -server.listen(0, function() { +server.listen(0, function () { var ca = fs.readFileSync('./ca.crt') var agent = new https.Agent({ host: 'localhost', @@ -18,13 +18,13 @@ server.listen(0, function() { ca: ca }) - https.request({ host: 'localhost' - , method: 'HEAD' - , port: this.address().port - , headers: { host: 'testing.request.mikealrogers.com' } - , agent: agent - , ca: [ ca ] - , path: '/' }, function (res) { + https.request({ host: 'localhost', + method: 'HEAD', + port: this.address().port, + headers: { host: 'testing.request.mikealrogers.com' }, + agent: agent, + ca: [ ca ], + path: '/' }, function (res) { if (res.socket.authorized) { console.log('node test: OK') } else { diff --git a/tests/test-agent.js b/tests/test-agent.js index 3bebf446d..40cdac05f 100644 --- a/tests/test-agent.js +++ b/tests/test-agent.js @@ -1,10 +1,10 @@ 'use strict' var request = require('../index') - , version = require('../lib/helpers').version - , http = require('http') - , ForeverAgent = require('forever-agent') - , tape = require('tape') +var version = require('../lib/helpers').version +var http = require('http') +var ForeverAgent = require('forever-agent') +var tape = require('tape') var s = http.createServer(function (req, res) { res.statusCode = 200 @@ -12,7 +12,7 @@ var s = http.createServer(function (req, res) { }) tape('setup', function (t) { - s.listen(0, function() { + s.listen(0, function () { s.port = this.address().port s.url = 'http://localhost:' + s.port t.end() @@ -21,13 +21,12 @@ tape('setup', function (t) { function httpAgent (t, options, req) { var r = (req || request)(options, function (_err, res, body) { - t.ok(r.agent instanceof http.Agent, 'is http.Agent') t.equal(r.agent.options.keepAlive, true, 'is keepAlive') t.equal(Object.keys(r.agent.sockets).length, 1, '1 socket name') var name = (typeof r.agent.getName === 'function') - ? r.agent.getName({port:s.port}) + ? r.agent.getName({port: s.port}) : 'localhost:' + s.port // node 0.10- t.equal(r.agent.sockets[name].length, 1, '1 open socket') @@ -42,7 +41,6 @@ function httpAgent (t, options, req) { function foreverAgent (t, options, req) { var r = (req || request)(options, function (_err, res, body) { - t.ok(r.agent instanceof ForeverAgent, 'is ForeverAgent') t.equal(Object.keys(r.agent.sockets).length, 1, '1 socket name') @@ -84,8 +82,7 @@ tape('options.forever = true', function (t) { forever: true } - if (v.major === 0 && v.minor <= 10) {foreverAgent(t, options)} - else {httpAgent(t, options)} + if (v.major === 0 && v.minor <= 10) { foreverAgent(t, options) } else { httpAgent(t, options) } }) tape('forever() method', function (t) { @@ -95,12 +92,11 @@ tape('forever() method', function (t) { } var r = request.forever({maxSockets: 1}) - if (v.major === 0 && v.minor <= 10) {foreverAgent(t, options, r)} - else {httpAgent(t, options, r)} + if (v.major === 0 && v.minor <= 10) { foreverAgent(t, options, r) } else { httpAgent(t, options, r) } }) tape('cleanup', function (t) { - s.close(function() { + s.close(function () { t.end() }) }) diff --git a/tests/test-agentOptions.js b/tests/test-agentOptions.js index 28a997c10..4682cbbba 100644 --- a/tests/test-agentOptions.js +++ b/tests/test-agentOptions.js @@ -1,53 +1,51 @@ 'use strict' -if (process.env.running_under_istanbul) { - // test-agent.js modifies the process state - // causing these tests to fail when running under single process via tape - return -} - -var request = require('../index') - , http = require('http') - , server = require('./server') - , tape = require('tape') - -var s = server.createServer() - -s.on('/', function (req, resp) { - resp.statusCode = 200 - resp.end('') -}) +// test-agent.js modifies the process state +// causing these tests to fail when running under single process via tape +if (!process.env.running_under_istanbul) { + var request = require('../index') + var http = require('http') + var server = require('./server') + var tape = require('tape') + + var s = server.createServer() + + s.on('/', function (req, resp) { + resp.statusCode = 200 + resp.end('') + }) -tape('setup', function(t) { - s.listen(0, function() { - t.end() + tape('setup', function (t) { + s.listen(0, function () { + t.end() + }) }) -}) -tape('without agentOptions should use global agent', function(t) { - var r = request(s.url, function(err, res, body) { - t.equal(err, null) - t.equal(res.statusCode, 200) - t.deepEqual(r.agent, http.globalAgent) - t.equal(Object.keys(r.pool).length, 0) - t.end() + tape('without agentOptions should use global agent', function (t) { + var r = request(s.url, function (err, res, body) { + t.equal(err, null) + t.equal(res.statusCode, 200) + t.deepEqual(r.agent, http.globalAgent) + t.equal(Object.keys(r.pool).length, 0) + t.end() + }) }) -}) -tape('with agentOptions should apply to new agent in pool', function(t) { - var r = request(s.url, { - agentOptions: { foo: 'bar' } - }, function(err, res, body) { - t.equal(err, null) - t.equal(res.statusCode, 200) - t.equal(r.agent.options.foo, 'bar') - t.equal(Object.keys(r.pool).length, 1) - t.end() + tape('with agentOptions should apply to new agent in pool', function (t) { + var r = request(s.url, { + agentOptions: { foo: 'bar' } + }, function (err, res, body) { + t.equal(err, null) + t.equal(res.statusCode, 200) + t.equal(r.agent.options.foo, 'bar') + t.equal(Object.keys(r.pool).length, 1) + t.end() + }) }) -}) -tape('cleanup', function(t) { - s.close(function() { - t.end() + tape('cleanup', function (t) { + s.close(function () { + t.end() + }) }) -}) +} diff --git a/tests/test-api.js b/tests/test-api.js index 9471c5fc5..3aa12fdc3 100644 --- a/tests/test-api.js +++ b/tests/test-api.js @@ -1,10 +1,9 @@ 'use strict' var http = require('http') - , request = require('../index') - , tape = require('tape') - , server - +var request = require('../index') +var tape = require('tape') +var server tape('setup', function (t) { server = http.createServer() @@ -12,7 +11,7 @@ tape('setup', function (t) { res.writeHead(202) req.pipe(res) }) - server.listen(0, function() { + server.listen(0, function () { server.url = 'http://localhost:' + this.address().port t.end() }) @@ -22,12 +21,13 @@ tape('callback option', function (t) { request({ url: server.url, callback: function (err, res, body) { + t.error(err) t.equal(res.statusCode, 202) t.end() } }) }) -tape('cleanup', function(t) { +tape('cleanup', function (t) { server.close(t.end) }) diff --git a/tests/test-aws.js b/tests/test-aws.js index af854c8cb..214003974 100644 --- a/tests/test-aws.js +++ b/tests/test-aws.js @@ -1,27 +1,27 @@ 'use strict' -var request = require('../index') - , server = require('./server') - , tape = require('tape') +var request = require('../index') +var server = require('./server') +var tape = require('tape') var s = server.createServer() var path = '/aws.json' -s.on(path, function(req, res) { +s.on(path, function (req, res) { res.writeHead(200, { 'Content-Type': 'application/json' }) res.end(JSON.stringify(req.headers)) }) -tape('setup', function(t) { - s.listen(0, function() { +tape('setup', function (t) { + s.listen(0, function () { t.end() }) }) -tape('default behaviour: aws-sign2 without sign_version key', function(t) { +tape('default behaviour: aws-sign2 without sign_version key', function (t) { var options = { url: s.url + path, aws: { @@ -30,14 +30,15 @@ tape('default behaviour: aws-sign2 without sign_version key', function(t) { }, json: true } - request(options, function(err, res, body) { + request(options, function (err, res, body) { + t.error(err) t.ok(body.authorization) t.notOk(body['x-amz-date']) t.end() }) }) -tape('aws-sign4 options', function(t) { +tape('aws-sign4 options', function (t) { var options = { url: s.url + path, aws: { @@ -47,7 +48,8 @@ tape('aws-sign4 options', function(t) { }, json: true } - request(options, function(err, res, body) { + request(options, function (err, res, body) { + t.error(err) t.ok(body.authorization) t.ok(body['x-amz-date']) t.notok(body['x-amz-security-token']) @@ -55,7 +57,7 @@ tape('aws-sign4 options', function(t) { }) }) -tape('aws-sign4 options with session token', function(t) { +tape('aws-sign4 options with session token', function (t) { var options = { url: s.url + path, aws: { @@ -66,7 +68,8 @@ tape('aws-sign4 options with session token', function(t) { }, json: true } - request(options, function(err, res, body) { + request(options, function (err, res, body) { + t.error(err) t.ok(body.authorization) t.ok(body['x-amz-date']) t.ok(body['x-amz-security-token']) @@ -74,8 +77,8 @@ tape('aws-sign4 options with session token', function(t) { }) }) -tape('cleanup', function(t) { - s.close(function() { +tape('cleanup', function (t) { + s.close(function () { t.end() }) }) diff --git a/tests/test-baseUrl.js b/tests/test-baseUrl.js index 7b5d034ea..a9a5e1378 100644 --- a/tests/test-baseUrl.js +++ b/tests/test-baseUrl.js @@ -1,14 +1,14 @@ 'use strict' var http = require('http') - , request = require('../index') - , tape = require('tape') - , url = require('url') +var request = require('../index') +var tape = require('tape') +var url = require('url') -var s = http.createServer(function(req, res) { +var s = http.createServer(function (req, res) { if (req.url === '/redirect/') { res.writeHead(302, { - location : '/' + location: '/' }) } else { res.statusCode = 200 @@ -17,9 +17,9 @@ var s = http.createServer(function(req, res) { res.end('ok') }) -function addTest(baseUrl, uri, expected) { - tape('test baseurl="' + baseUrl + '" uri="' + uri + '"', function(t) { - request(uri, { baseUrl: baseUrl }, function(err, resp, body) { +function addTest (baseUrl, uri, expected) { + tape('test baseurl="' + baseUrl + '" uri="' + uri + '"', function (t) { + request(uri, { baseUrl: baseUrl }, function (err, resp, body) { t.equal(err, null) t.equal(body, 'ok') t.equal(resp.headers['x-path'], expected) @@ -28,7 +28,7 @@ function addTest(baseUrl, uri, expected) { }) } -function addTests() { +function addTests () { addTest(s.url, '', '/') addTest(s.url + '/', '', '/') addTest(s.url, '/', '/') @@ -47,12 +47,12 @@ function addTests() { addTest(s.url + '/api/', '/resource/', '/api/resource/') } -tape('setup', function(t) { - s.listen(0, function() { +tape('setup', function (t) { + s.listen(0, function () { s.url = 'http://localhost:' + this.address().port addTests() - tape('cleanup', function(t) { - s.close(function() { + tape('cleanup', function (t) { + s.close(function () { t.end() }) }) @@ -60,31 +60,31 @@ tape('setup', function(t) { }) }) -tape('baseUrl', function(t) { +tape('baseUrl', function (t) { request('resource', { baseUrl: s.url - }, function(err, resp, body) { + }, function (err, resp, body) { t.equal(err, null) t.equal(body, 'ok') t.end() }) }) -tape('baseUrl defaults', function(t) { +tape('baseUrl defaults', function (t) { var withDefaults = request.defaults({ baseUrl: s.url }) - withDefaults('resource', function(err, resp, body) { + withDefaults('resource', function (err, resp, body) { t.equal(err, null) t.equal(body, 'ok') t.end() }) }) -tape('baseUrl and redirects', function(t) { +tape('baseUrl and redirects', function (t) { request('/', { baseUrl: s.url + '/redirect' - }, function(err, resp, body) { + }, function (err, resp, body) { t.equal(err, null) t.equal(body, 'ok') t.equal(resp.headers['x-path'], '/') @@ -92,40 +92,40 @@ tape('baseUrl and redirects', function(t) { }) }) -tape('error when baseUrl is not a String', function(t) { +tape('error when baseUrl is not a String', function (t) { request('resource', { baseUrl: url.parse(s.url + '/path') - }, function(err, resp, body) { + }, function (err, resp, body) { t.notEqual(err, null) t.equal(err.message, 'options.baseUrl must be a string') t.end() }) }) -tape('error when uri is not a String', function(t) { +tape('error when uri is not a String', function (t) { request(url.parse('resource'), { baseUrl: s.url + '/path' - }, function(err, resp, body) { + }, function (err, resp, body) { t.notEqual(err, null) t.equal(err.message, 'options.uri must be a string when using options.baseUrl') t.end() }) }) -tape('error on baseUrl and uri with scheme', function(t) { +tape('error on baseUrl and uri with scheme', function (t) { request(s.url + '/path/ignoring/baseUrl', { baseUrl: s.url + '/path/' - }, function(err, resp, body) { + }, function (err, resp, body) { t.notEqual(err, null) t.equal(err.message, 'options.uri must be a path when using options.baseUrl') t.end() }) }) -tape('error on baseUrl and uri with scheme-relative url', function(t) { +tape('error on baseUrl and uri with scheme-relative url', function (t) { request(s.url.slice('http:'.length) + '/path/ignoring/baseUrl', { baseUrl: s.url + '/path/' - }, function(err, resp, body) { + }, function (err, resp, body) { t.notEqual(err, null) t.equal(err.message, 'options.uri must be a path when using options.baseUrl') t.end() diff --git a/tests/test-basic-auth.js b/tests/test-basic-auth.js index 983e3fc54..8c1a69a1c 100644 --- a/tests/test-basic-auth.js +++ b/tests/test-basic-auth.js @@ -1,14 +1,14 @@ 'use strict' var assert = require('assert') - , http = require('http') - , request = require('../index') - , tape = require('tape') +var http = require('http') +var request = require('../index') +var tape = require('tape') var numBasicRequests = 0 - , basicServer +var basicServer -tape('setup', function(t) { +tape('setup', function (t) { basicServer = http.createServer(function (req, res) { numBasicRequests++ @@ -17,11 +17,11 @@ tape('setup', function(t) { if (req.headers.authorization) { if (req.headers.authorization === 'Basic ' + new Buffer('user:pass').toString('base64')) { ok = true - } else if ( req.headers.authorization === 'Basic ' + new Buffer('user:').toString('base64')) { + } else if (req.headers.authorization === 'Basic ' + new Buffer('user:').toString('base64')) { ok = true - } else if ( req.headers.authorization === 'Basic ' + new Buffer(':pass').toString('base64')) { + } else if (req.headers.authorization === 'Basic ' + new Buffer(':pass').toString('base64')) { ok = true - } else if ( req.headers.authorization === 'Basic ' + new Buffer('user:pâss').toString('base64')) { + } else if (req.headers.authorization === 'Basic ' + new Buffer('user:pâss').toString('base64')) { ok = true } else { // Bad auth header, don't send back WWW-Authenticate header @@ -35,7 +35,7 @@ tape('setup', function(t) { if (req.url === '/post/') { var expectedContent = 'key=value' - req.on('data', function(data) { + req.on('data', function (data) { assert.equal(data, expectedContent) }) assert.equal(req.method, 'POST') @@ -49,14 +49,14 @@ tape('setup', function(t) { res.statusCode = 401 res.end('401') } - }).listen(0, function() { + }).listen(0, function () { basicServer.port = this.address().port basicServer.url = 'http://localhost:' + basicServer.port t.end() }) }) -tape('sendImmediately - false', function(t) { +tape('sendImmediately - false', function (t) { var r = request({ 'method': 'GET', 'uri': basicServer.url + '/test/', @@ -65,7 +65,8 @@ tape('sendImmediately - false', function(t) { 'pass': 'pass', 'sendImmediately': false } - }, function(error, res, body) { + }, function (error, res, body) { + t.error(error) t.equal(r._auth.user, 'user') t.equal(res.statusCode, 200) t.equal(numBasicRequests, 2) @@ -73,7 +74,7 @@ tape('sendImmediately - false', function(t) { }) }) -tape('sendImmediately - true', function(t) { +tape('sendImmediately - true', function (t) { // If we don't set sendImmediately = false, request will send basic auth var r = request({ 'method': 'GET', @@ -82,7 +83,8 @@ tape('sendImmediately - true', function(t) { 'user': 'user', 'pass': 'pass' } - }, function(error, res, body) { + }, function (error, res, body) { + t.error(error) t.equal(r._auth.user, 'user') t.equal(res.statusCode, 200) t.equal(numBasicRequests, 3) @@ -90,11 +92,12 @@ tape('sendImmediately - true', function(t) { }) }) -tape('credentials in url', function(t) { +tape('credentials in url', function (t) { var r = request({ 'method': 'GET', 'uri': basicServer.url.replace(/:\/\//, '$&user:pass@') + '/test2/' - }, function(error, res, body) { + }, function (error, res, body) { + t.error(error) t.equal(r._auth.user, 'user') t.equal(res.statusCode, 200) t.equal(numBasicRequests, 4) @@ -102,7 +105,7 @@ tape('credentials in url', function(t) { }) }) -tape('POST request', function(t) { +tape('POST request', function (t) { var r = request({ 'method': 'POST', 'form': { 'key': 'value' }, @@ -112,7 +115,8 @@ tape('POST request', function(t) { 'pass': 'pass', 'sendImmediately': false } - }, function(error, res, body) { + }, function (error, res, body) { + t.error(error) t.equal(r._auth.user, 'user') t.equal(res.statusCode, 200) t.equal(numBasicRequests, 6) @@ -120,8 +124,8 @@ tape('POST request', function(t) { }) }) -tape('user - empty string', function(t) { - t.doesNotThrow( function() { +tape('user - empty string', function (t) { + t.doesNotThrow(function () { var r = request({ 'method': 'GET', 'uri': basicServer.url + '/allow_empty_user/', @@ -130,7 +134,8 @@ tape('user - empty string', function(t) { 'pass': 'pass', 'sendImmediately': false } - }, function(error, res, body ) { + }, function (error, res, body) { + t.error(error) t.equal(r._auth.user, '') t.equal(res.statusCode, 200) t.equal(numBasicRequests, 8) @@ -139,8 +144,8 @@ tape('user - empty string', function(t) { }) }) -tape('pass - undefined', function(t) { - t.doesNotThrow( function() { +tape('pass - undefined', function (t) { + t.doesNotThrow(function () { var r = request({ 'method': 'GET', 'uri': basicServer.url + '/allow_undefined_password/', @@ -149,7 +154,8 @@ tape('pass - undefined', function(t) { 'pass': undefined, 'sendImmediately': false } - }, function(error, res, body ) { + }, function (error, res, body) { + t.error(error) t.equal(r._auth.user, 'user') t.equal(res.statusCode, 200) t.equal(numBasicRequests, 10) @@ -158,9 +164,8 @@ tape('pass - undefined', function(t) { }) }) - -tape('pass - utf8', function(t) { - t.doesNotThrow( function() { +tape('pass - utf8', function (t) { + t.doesNotThrow(function () { var r = request({ 'method': 'GET', 'uri': basicServer.url + '/allow_undefined_password/', @@ -169,7 +174,8 @@ tape('pass - utf8', function(t) { 'pass': 'pâss', 'sendImmediately': false } - }, function(error, res, body ) { + }, function (error, res, body) { + t.error(error) t.equal(r._auth.user, 'user') t.equal(r._auth.pass, 'pâss') t.equal(res.statusCode, 200) @@ -179,7 +185,7 @@ tape('pass - utf8', function(t) { }) }) -tape('auth method', function(t) { +tape('auth method', function (t) { var r = request .get(basicServer.url + '/test/') .auth('user', '', false) @@ -191,7 +197,7 @@ tape('auth method', function(t) { }) }) -tape('get method', function(t) { +tape('get method', function (t) { var r = request.get(basicServer.url + '/test/', { auth: { @@ -208,8 +214,8 @@ tape('get method', function(t) { }) }) -tape('cleanup', function(t) { - basicServer.close(function() { +tape('cleanup', function (t) { + basicServer.close(function () { t.end() }) }) diff --git a/tests/test-bearer-auth.js b/tests/test-bearer-auth.js index 8519c6131..032ccc7ee 100644 --- a/tests/test-bearer-auth.js +++ b/tests/test-bearer-auth.js @@ -1,14 +1,14 @@ 'use strict' var assert = require('assert') - , http = require('http') - , request = require('../index') - , tape = require('tape') +var http = require('http') +var request = require('../index') +var tape = require('tape') var numBearerRequests = 0 - , bearerServer +var bearerServer -tape('setup', function(t) { +tape('setup', function (t) { bearerServer = http.createServer(function (req, res) { numBearerRequests++ @@ -29,7 +29,7 @@ tape('setup', function(t) { if (req.url === '/post/') { var expectedContent = 'data_key=data_value' - req.on('data', function(data) { + req.on('data', function (data) { assert.equal(data, expectedContent) }) assert.equal(req.method, 'POST') @@ -43,13 +43,13 @@ tape('setup', function(t) { res.statusCode = 401 res.end('401') } - }).listen(0, function() { + }).listen(0, function () { bearerServer.url = 'http://localhost:' + this.address().port t.end() }) }) -tape('bearer auth', function(t) { +tape('bearer auth', function (t) { request({ 'method': 'GET', 'uri': bearerServer.url + '/test/', @@ -57,14 +57,15 @@ tape('bearer auth', function(t) { 'bearer': 'theToken', 'sendImmediately': false } - }, function(error, res, body) { + }, function (error, res, body) { + t.error(error) t.equal(res.statusCode, 200) t.equal(numBearerRequests, 2) t.end() }) }) -tape('bearer auth with default sendImmediately', function(t) { +tape('bearer auth with default sendImmediately', function (t) { // If we don't set sendImmediately = false, request will send bearer auth request({ 'method': 'GET', @@ -72,14 +73,15 @@ tape('bearer auth with default sendImmediately', function(t) { 'auth': { 'bearer': 'theToken' } - }, function(error, res, body) { + }, function (error, res, body) { + t.error(error) t.equal(res.statusCode, 200) t.equal(numBearerRequests, 3) t.end() }) }) -tape('', function(t) { +tape('', function (t) { request({ 'method': 'POST', 'form': { 'data_key': 'data_value' }, @@ -88,14 +90,15 @@ tape('', function(t) { 'bearer': 'theToken', 'sendImmediately': false } - }, function(error, res, body) { + }, function (error, res, body) { + t.error(error) t.equal(res.statusCode, 200) t.equal(numBearerRequests, 5) t.end() }) }) -tape('using .auth, sendImmediately = false', function(t) { +tape('using .auth, sendImmediately = false', function (t) { request .get(bearerServer.url + '/test/') .auth(null, null, false, 'theToken') @@ -106,7 +109,7 @@ tape('using .auth, sendImmediately = false', function(t) { }) }) -tape('using .auth, sendImmediately = true', function(t) { +tape('using .auth, sendImmediately = true', function (t) { request .get(bearerServer.url + '/test/') .auth(null, null, true, 'theToken') @@ -117,65 +120,68 @@ tape('using .auth, sendImmediately = true', function(t) { }) }) -tape('bearer is a function', function(t) { +tape('bearer is a function', function (t) { request({ 'method': 'GET', 'uri': bearerServer.url + '/test/', 'auth': { - 'bearer': function() { return 'theToken' }, + 'bearer': function () { return 'theToken' }, 'sendImmediately': false } - }, function(error, res, body) { + }, function (error, res, body) { + t.error(error) t.equal(res.statusCode, 200) t.equal(numBearerRequests, 10) t.end() }) }) -tape('bearer is a function, path = test2', function(t) { +tape('bearer is a function, path = test2', function (t) { // If we don't set sendImmediately = false, request will send bearer auth request({ 'method': 'GET', 'uri': bearerServer.url + '/test2/', 'auth': { - 'bearer': function() { return 'theToken' } + 'bearer': function () { return 'theToken' } } - }, function(error, res, body) { + }, function (error, res, body) { + t.error(error) t.equal(res.statusCode, 200) t.equal(numBearerRequests, 11) t.end() }) }) -tape('no auth method', function(t) { +tape('no auth method', function (t) { request({ 'method': 'GET', 'uri': bearerServer.url + '/test2/', 'auth': { 'bearer': undefined } - }, function(error, res, body) { + }, function (error, res, body) { t.equal(error.message, 'no auth mechanism defined') t.end() }) }) -tape('null bearer', function(t) { +tape('null bearer', function (t) { request({ 'method': 'GET', 'uri': bearerServer.url + '/test2/', 'auth': { 'bearer': null } - }, function(error, res, body) { + }, function (error, res, body) { + t.error(error) t.equal(res.statusCode, 401) t.equal(numBearerRequests, 13) t.end() }) }) -tape('cleanup', function(t) { - bearerServer.close(function() { +tape('cleanup', function (t) { + bearerServer.close(function () { t.end() }) }) diff --git a/tests/test-body.js b/tests/test-body.js index be2a67b59..2cbb494cf 100644 --- a/tests/test-body.js +++ b/tests/test-body.js @@ -1,20 +1,20 @@ 'use strict' var server = require('./server') - , request = require('../index') - , tape = require('tape') - , http = require('http') +var request = require('../index') +var tape = require('tape') +var http = require('http') var s = server.createServer() -tape('setup', function(t) { - s.listen(0, function() { +tape('setup', function (t) { + s.listen(0, function () { t.end() }) }) -function addTest(name, data) { - tape('test ' + name, function(t) { +function addTest (name, data) { + tape('test ' + name, function (t) { s.on('/' + name, data.resp) data.uri = s.url + '/' + name request(data, function (err, resp, body) { @@ -30,64 +30,49 @@ function addTest(name, data) { } addTest('testGet', { - resp : server.createGetResponse('TESTING!') - , expectBody: 'TESTING!' + resp: server.createGetResponse('TESTING!'), expectBody: 'TESTING!' }) addTest('testGetChunkBreak', { - resp : server.createChunkResponse( - [ new Buffer([239]) - , new Buffer([163]) - , new Buffer([191]) - , new Buffer([206]) - , new Buffer([169]) - , new Buffer([226]) - , new Buffer([152]) - , new Buffer([131]) - ]) - , expectBody: '\uF8FF\u03A9\u2603' + resp: server.createChunkResponse( + [ new Buffer([239]), + new Buffer([163]), + new Buffer([191]), + new Buffer([206]), + new Buffer([169]), + new Buffer([226]), + new Buffer([152]), + new Buffer([131]) + ]), + expectBody: '\uF8FF\u03A9\u2603' }) addTest('testGetBuffer', { - resp : server.createGetResponse(new Buffer('TESTING!')) - , encoding: null - , expectBody: new Buffer('TESTING!') + resp: server.createGetResponse(new Buffer('TESTING!')), encoding: null, expectBody: new Buffer('TESTING!') }) addTest('testGetEncoding', { - resp : server.createGetResponse(new Buffer('efa3bfcea9e29883', 'hex')) - , encoding: 'hex' - , expectBody: 'efa3bfcea9e29883' + resp: server.createGetResponse(new Buffer('efa3bfcea9e29883', 'hex')), encoding: 'hex', expectBody: 'efa3bfcea9e29883' }) addTest('testGetUTF', { - resp: server.createGetResponse(new Buffer([0xEF, 0xBB, 0xBF, 226, 152, 131])) - , encoding: 'utf8' - , expectBody: '\u2603' + resp: server.createGetResponse(new Buffer([0xEF, 0xBB, 0xBF, 226, 152, 131])), encoding: 'utf8', expectBody: '\u2603' }) addTest('testGetJSON', { - resp : server.createGetResponse('{"test":true}', 'application/json') - , json : true - , expectBody: {'test':true} + resp: server.createGetResponse('{"test":true}', 'application/json'), json: true, expectBody: {'test': true} }) addTest('testPutString', { - resp : server.createPostValidator('PUTTINGDATA') - , method : 'PUT' - , body : 'PUTTINGDATA' + resp: server.createPostValidator('PUTTINGDATA'), method: 'PUT', body: 'PUTTINGDATA' }) addTest('testPutBuffer', { - resp : server.createPostValidator('PUTTINGDATA') - , method : 'PUT' - , body : new Buffer('PUTTINGDATA') + resp: server.createPostValidator('PUTTINGDATA'), method: 'PUT', body: new Buffer('PUTTINGDATA') }) addTest('testPutJSON', { - resp : server.createPostValidator(JSON.stringify({foo: 'bar'})) - , method: 'PUT' - , json: {foo: 'bar'} + resp: server.createPostValidator(JSON.stringify({foo: 'bar'})), method: 'PUT', json: {foo: 'bar'} }) addTest('testPutMultipart', { @@ -99,12 +84,11 @@ addTest('testPutMultipart', { '\r\n--__BOUNDARY__\r\n\r\n' + 'Oh hi.' + '\r\n--__BOUNDARY__--' - ) - , method: 'PUT' - , multipart: - [ {'content-type': 'text/html', 'body': 'Oh hi.'} - , {'body': 'Oh hi.'} - ] + ), + method: 'PUT', + multipart: [ {'content-type': 'text/html', 'body': 'Oh hi.'}, + {'body': 'Oh hi.'} + ] }) addTest('testPutMultipartPreambleCRLF', { @@ -116,13 +100,12 @@ addTest('testPutMultipartPreambleCRLF', { '\r\n--__BOUNDARY__\r\n\r\n' + 'Oh hi.' + '\r\n--__BOUNDARY__--' - ) - , method: 'PUT' - , preambleCRLF: true - , multipart: - [ {'content-type': 'text/html', 'body': 'Oh hi.'} - , {'body': 'Oh hi.'} - ] + ), + method: 'PUT', + preambleCRLF: true, + multipart: [ {'content-type': 'text/html', 'body': 'Oh hi.'}, + {'body': 'Oh hi.'} + ] }) addTest('testPutMultipartPostambleCRLF', { @@ -135,14 +118,13 @@ addTest('testPutMultipartPostambleCRLF', { 'Oh hi.' + '\r\n--__BOUNDARY__--' + '\r\n' - ) - , method: 'PUT' - , preambleCRLF: true - , postambleCRLF: true - , multipart: - [ {'content-type': 'text/html', 'body': 'Oh hi.'} - , {'body': 'Oh hi.'} - ] + ), + method: 'PUT', + preambleCRLF: true, + postambleCRLF: true, + multipart: [ {'content-type': 'text/html', 'body': 'Oh hi.'}, + {'body': 'Oh hi.'} + ] }) tape('typed array', function (t) { @@ -158,14 +140,15 @@ tape('typed array', function (t) { body: data, encoding: null }, function (err, res, body) { + t.error(err) t.deepEqual(new Buffer(data), body) server.close(t.end) }) }) }) -tape('cleanup', function(t) { - s.close(function() { +tape('cleanup', function (t) { + s.close(function () { t.end() }) }) diff --git a/tests/test-cookies.js b/tests/test-cookies.js index 8a6065927..6bebcaf12 100644 --- a/tests/test-cookies.js +++ b/tests/test-cookies.js @@ -1,13 +1,12 @@ 'use strict' var http = require('http') - , request = require('../index') - , tape = require('tape') - +var request = require('../index') +var tape = require('tape') var validUrl - , malformedUrl - , invalidUrl +var malformedUrl +var invalidUrl var server = http.createServer(function (req, res) { if (req.url === '/valid') { @@ -20,8 +19,8 @@ var server = http.createServer(function (req, res) { res.end('okay') }) -tape('setup', function(t) { - server.listen(0, function() { +tape('setup', function (t) { + server.listen(0, function () { server.url = 'http://localhost:' + this.address().port validUrl = server.url + '/valid' malformedUrl = server.url + '/malformed' @@ -30,79 +29,79 @@ tape('setup', function(t) { }) }) -tape('simple cookie creation', function(t) { +tape('simple cookie creation', function (t) { var cookie = request.cookie('foo=bar') t.equals(cookie.key, 'foo') t.equals(cookie.value, 'bar') t.end() }) -tape('simple malformed cookie creation', function(t) { +tape('simple malformed cookie creation', function (t) { var cookie = request.cookie('foo') t.equals(cookie.key, '') t.equals(cookie.value, 'foo') t.end() }) -tape('after server sends a cookie', function(t) { +tape('after server sends a cookie', function (t) { var jar1 = request.jar() request({ method: 'GET', url: validUrl, jar: jar1 }, - function (error, response, body) { - t.equal(error, null) - t.equal(jar1.getCookieString(validUrl), 'foo=bar') - t.equal(body, 'okay') + function (error, response, body) { + t.equal(error, null) + t.equal(jar1.getCookieString(validUrl), 'foo=bar') + t.equal(body, 'okay') - var cookies = jar1.getCookies(validUrl) - t.equal(cookies.length, 1) - t.equal(cookies[0].key, 'foo') - t.equal(cookies[0].value, 'bar') - t.end() - }) + var cookies = jar1.getCookies(validUrl) + t.equal(cookies.length, 1) + t.equal(cookies[0].key, 'foo') + t.equal(cookies[0].value, 'bar') + t.end() + }) }) -tape('after server sends a malformed cookie', function(t) { +tape('after server sends a malformed cookie', function (t) { var jar = request.jar() request({ method: 'GET', url: malformedUrl, jar: jar }, - function (error, response, body) { - t.equal(error, null) - t.equal(jar.getCookieString(malformedUrl), 'foo') - t.equal(body, 'okay') + function (error, response, body) { + t.equal(error, null) + t.equal(jar.getCookieString(malformedUrl), 'foo') + t.equal(body, 'okay') - var cookies = jar.getCookies(malformedUrl) - t.equal(cookies.length, 1) - t.equal(cookies[0].key, '') - t.equal(cookies[0].value, 'foo') - t.end() - }) + var cookies = jar.getCookies(malformedUrl) + t.equal(cookies.length, 1) + t.equal(cookies[0].key, '') + t.equal(cookies[0].value, 'foo') + t.end() + }) }) -tape('after server sends a cookie for a different domain', function(t) { +tape('after server sends a cookie for a different domain', function (t) { var jar2 = request.jar() request({ method: 'GET', url: invalidUrl, jar: jar2 }, - function (error, response, body) { - t.equal(error, null) - t.equal(jar2.getCookieString(validUrl), '') - t.deepEqual(jar2.getCookies(validUrl), []) - t.equal(body, 'okay') - t.end() - }) + function (error, response, body) { + t.equal(error, null) + t.equal(jar2.getCookieString(validUrl), '') + t.deepEqual(jar2.getCookies(validUrl), []) + t.equal(body, 'okay') + t.end() + }) }) -tape('make sure setCookie works', function(t) { +tape('make sure setCookie works', function (t) { var jar3 = request.jar() - , err = null + var err = null try { jar3.setCookie(request.cookie('foo=bar'), validUrl) } catch (e) { @@ -116,16 +115,16 @@ tape('make sure setCookie works', function(t) { t.end() }) -tape('custom store', function(t) { - var Store = function() {} +tape('custom store', function (t) { + var Store = function () {} var store = new Store() var jar = request.jar(store) t.equals(store, jar._jar.store) t.end() }) -tape('cleanup', function(t) { - server.close(function() { +tape('cleanup', function (t) { + server.close(function () { t.end() }) }) diff --git a/tests/test-defaults.js b/tests/test-defaults.js index 0fc578e7b..f75f5d7bc 100644 --- a/tests/test-defaults.js +++ b/tests/test-defaults.js @@ -1,37 +1,38 @@ 'use strict' var server = require('./server') - , request = require('../index') - , qs = require('qs') - , tape = require('tape') +var request = require('../index') +var qs = require('qs') +var tape = require('tape') var s = server.createServer() -tape('setup', function(t) { - s.listen(0, function() { +tape('setup', function (t) { + s.listen(0, function () { s.on('/', function (req, res) { res.writeHead(200, {'content-type': 'application/json'}) res.end(JSON.stringify({ - method: req.method, headers: req.headers, + method: req.method, + headers: req.headers, qs: qs.parse(req.url.replace(/.*\?(.*)/, '$1')) })) }) s.on('/head', function (req, res) { - res.writeHead(200, {'x-data': - JSON.stringify({method: req.method, headers: req.headers})}) + res.writeHead(200, {'x-data': JSON.stringify({method: req.method, headers: req.headers})}) res.end() }) s.on('/set-undefined', function (req, res) { var data = '' - req.on('data', function(d) { + req.on('data', function (d) { data += d }) - req.on('end', function() { + req.on('end', function () { res.writeHead(200, {'Content-Type': 'application/json'}) res.end(JSON.stringify({ - method: req.method, headers: req.headers, data: JSON.parse(data)})) + method: req.method, headers: req.headers, data: JSON.parse(data) + })) }) }) @@ -39,7 +40,7 @@ tape('setup', function(t) { }) }) -tape('get(string, function)', function(t) { +tape('get(string, function)', function (t) { request.defaults({ headers: { foo: 'bar' } })(s.url + '/', function (e, r, b) { @@ -50,7 +51,7 @@ tape('get(string, function)', function(t) { }) }) -tape('merge headers', function(t) { +tape('merge headers', function (t) { request.defaults({ headers: { foo: 'bar', merged: 'no' } })(s.url + '/', { @@ -62,9 +63,9 @@ tape('merge headers', function(t) { }) }) -tape('deep extend', function(t) { +tape('deep extend', function (t) { request.defaults({ - headers: {a: 1, b: 2 }, + headers: { a: 1, b: 2 }, qs: { a: 1, b: 2 } })(s.url + '/', { headers: { b: 3, c: 4 }, @@ -80,10 +81,10 @@ tape('deep extend', function(t) { }) }) -tape('default undefined header', function(t) { +tape('default undefined header', function (t) { request.defaults({ headers: { foo: 'bar', test: undefined }, json: true - })(s.url + '/', function(e, r, b) { + })(s.url + '/', function (e, r, b) { t.equal(b.method, 'GET') t.equal(b.headers.foo, 'bar') t.equal(b.headers.test, undefined) @@ -91,7 +92,7 @@ tape('default undefined header', function(t) { }) }) -tape('post(string, object, function)', function(t) { +tape('post(string, object, function)', function (t) { request.defaults({ headers: { foo: 'bar' } }).post(s.url + '/', { json: true }, function (e, r, b) { @@ -102,7 +103,7 @@ tape('post(string, object, function)', function(t) { }) }) -tape('patch(string, object, function)', function(t) { +tape('patch(string, object, function)', function (t) { request.defaults({ headers: { foo: 'bar' } }).patch(s.url + '/', { json: true }, function (e, r, b) { @@ -113,7 +114,7 @@ tape('patch(string, object, function)', function(t) { }) }) -tape('post(string, object, function) with body', function(t) { +tape('post(string, object, function) with body', function (t) { request.defaults({ headers: { foo: 'bar' } }).post(s.url + '/', { @@ -127,7 +128,7 @@ tape('post(string, object, function) with body', function(t) { }) }) -tape('del(string, function)', function(t) { +tape('del(string, function)', function (t) { request.defaults({ headers: {foo: 'bar'}, json: true @@ -138,7 +139,7 @@ tape('del(string, function)', function(t) { }) }) -tape('delete(string, function)', function(t) { +tape('delete(string, function)', function (t) { request.defaults({ headers: {foo: 'bar'}, json: true @@ -149,7 +150,7 @@ tape('delete(string, function)', function(t) { }) }) -tape('head(object, function)', function(t) { +tape('head(object, function)', function (t) { request.defaults({ headers: { foo: 'bar' } }).head({ uri: s.url + '/head' }, function (e, r, b) { @@ -160,17 +161,17 @@ tape('head(object, function)', function(t) { }) }) -tape('recursive defaults', function(t) { +tape('recursive defaults', function (t) { t.plan(11) var defaultsOne = request.defaults({ headers: { foo: 'bar1' } }) - , defaultsTwo = defaultsOne.defaults({ headers: { baz: 'bar2' } }) - , defaultsThree = defaultsTwo.defaults({}, function(options, callback) { - options.headers = { - foo: 'bar3' - } - defaultsTwo(options, callback) - }) + var defaultsTwo = defaultsOne.defaults({ headers: { baz: 'bar2' } }) + var defaultsThree = defaultsTwo.defaults({}, function (options, callback) { + options.headers = { + foo: 'bar3' + } + defaultsTwo(options, callback) + }) defaultsOne(s.url + '/', {json: true}, function (e, r, b) { t.equal(b.method, 'GET') @@ -197,23 +198,24 @@ tape('recursive defaults', function(t) { }) }) -tape('recursive defaults requester', function(t) { +tape('recursive defaults requester', function (t) { t.plan(5) - var defaultsOne = request.defaults({}, function(options, callback) { - var headers = options.headers || {} - headers.foo = 'bar1' - options.headers = headers + var defaultsOne = request.defaults({}, function (options, callback) { + var headers = options.headers || {} + headers.foo = 'bar1' + options.headers = headers - request(options, callback) - }) - , defaultsTwo = defaultsOne.defaults({}, function(options, callback) { - var headers = options.headers || {} - headers.baz = 'bar2' - options.headers = headers + request(options, callback) + }) - defaultsOne(options, callback) - }) + var defaultsTwo = defaultsOne.defaults({}, function (options, callback) { + var headers = options.headers || {} + headers.baz = 'bar2' + options.headers = headers + + defaultsOne(options, callback) + }) defaultsOne.get(s.url + '/', {json: true}, function (e, r, b) { t.equal(b.method, 'GET') @@ -227,35 +229,35 @@ tape('recursive defaults requester', function(t) { }) }) -tape('test custom request handler function', function(t) { +tape('test custom request handler function', function (t) { t.plan(3) var requestWithCustomHandler = request.defaults({ headers: { foo: 'bar' }, body: 'TESTING!' - }, function(uri, options, callback) { + }, function (uri, options, callback) { var params = request.initParams(uri, options, callback) params.headers.x = 'y' return request(params.uri, params, params.callback) }) - t.throws(function() { - requestWithCustomHandler.head(s.url + '/', function(e, r, b) { + t.throws(function () { + requestWithCustomHandler.head(s.url + '/', function (e, r, b) { throw new Error('We should never get here') }) }, /HTTP HEAD requests MUST NOT include a request body/) - requestWithCustomHandler.get(s.url + '/', function(e, r, b) { + requestWithCustomHandler.get(s.url + '/', function (e, r, b) { b = JSON.parse(b) t.equal(b.headers.foo, 'bar') t.equal(b.headers.x, 'y') }) }) -tape('test custom request handler function without options', function(t) { +tape('test custom request handler function without options', function (t) { t.plan(2) - var customHandlerWithoutOptions = request.defaults(function(uri, options, callback) { + var customHandlerWithoutOptions = request.defaults(function (uri, options, callback) { var params = request.initParams(uri, options, callback) var headers = params.headers || {} headers.x = 'y' @@ -264,14 +266,14 @@ tape('test custom request handler function without options', function(t) { return request(params.uri, params, params.callback) }) - customHandlerWithoutOptions.get(s.url + '/', function(e, r, b) { + customHandlerWithoutOptions.get(s.url + '/', function (e, r, b) { b = JSON.parse(b) t.equal(b.headers.foo, 'bar') t.equal(b.headers.x, 'y') }) }) -tape('test only setting undefined properties', function(t) { +tape('test only setting undefined properties', function (t) { request.defaults({ method: 'post', json: true, @@ -289,7 +291,7 @@ tape('test only setting undefined properties', function(t) { }) }) -tape('test only function', function(t) { +tape('test only function', function (t) { var post = request.post t.doesNotThrow(function () { post(s.url + '/', function (e, r, b) { @@ -299,7 +301,7 @@ tape('test only function', function(t) { }) }) -tape('invoke defaults', function(t) { +tape('invoke defaults', function (t) { var d = request.defaults({ uri: s.url + '/', headers: { foo: 'bar' } @@ -311,7 +313,7 @@ tape('invoke defaults', function(t) { }) }) -tape('invoke convenience method from defaults', function(t) { +tape('invoke convenience method from defaults', function (t) { var d = request.defaults({ uri: s.url + '/', headers: { foo: 'bar' } @@ -323,7 +325,7 @@ tape('invoke convenience method from defaults', function(t) { }) }) -tape('defaults without options', function(t) { +tape('defaults without options', function (t) { var d = request.defaults() d.get(s.url + '/', {json: true}, function (e, r, b) { t.equal(r.statusCode, 200) @@ -331,8 +333,8 @@ tape('defaults without options', function(t) { }) }) -tape('cleanup', function(t) { - s.close(function() { +tape('cleanup', function (t) { + s.close(function () { t.end() }) }) diff --git a/tests/test-digest-auth.js b/tests/test-digest-auth.js index b5801ca61..d5c3c0ee5 100644 --- a/tests/test-digest-auth.js +++ b/tests/test-digest-auth.js @@ -1,15 +1,15 @@ 'use strict' var http = require('http') - , request = require('../index') - , tape = require('tape') - , crypto = require('crypto') +var request = require('../index') +var tape = require('tape') +var crypto = require('crypto') -function makeHeader() { +function makeHeader () { return [].join.call(arguments, ', ') } -function makeHeaderRegex() { +function makeHeaderRegex () { return new RegExp('^' + makeHeader.apply(null, arguments) + '$') } @@ -17,23 +17,23 @@ function md5 (str) { return crypto.createHash('md5').update(str).digest('hex') } -var digestServer = http.createServer(function(req, res) { - var ok - , testHeader +var digestServer = http.createServer(function (req, res) { + var ok, + testHeader if (req.url === '/test/') { if (req.headers.authorization) { testHeader = makeHeaderRegex( - 'Digest username="test"', - 'realm="Private"', - 'nonce="WpcHS2/TBAA=dffcc0dbd5f96d49a5477166649b7c0ae3866a93"', - 'uri="/test/"', - 'qop=auth', - 'response="[a-f0-9]{32}"', - 'nc=00000001', - 'cnonce="[a-f0-9]{32}"', - 'algorithm=MD5', - 'opaque="5ccc069c403ebaf9f0171e9517f40e41"' + 'Digest username="test"', + 'realm="Private"', + 'nonce="WpcHS2/TBAA=dffcc0dbd5f96d49a5477166649b7c0ae3866a93"', + 'uri="/test/"', + 'qop=auth', + 'response="[a-f0-9]{32}"', + 'nc=00000001', + 'cnonce="[a-f0-9]{32}"', + 'algorithm=MD5', + 'opaque="5ccc069c403ebaf9f0171e9517f40e41"' ) if (testHeader.test(req.headers.authorization)) { ok = true @@ -45,11 +45,11 @@ var digestServer = http.createServer(function(req, res) { // No auth header, send back WWW-Authenticate header ok = false res.setHeader('www-authenticate', makeHeader( - 'Digest realm="Private"', - 'nonce="WpcHS2/TBAA=dffcc0dbd5f96d49a5477166649b7c0ae3866a93"', - 'algorithm=MD5', - 'qop="auth"', - 'opaque="5ccc069c403ebaf9f0171e9517f40e41"' + 'Digest realm="Private"', + 'nonce="WpcHS2/TBAA=dffcc0dbd5f96d49a5477166649b7c0ae3866a93"', + 'algorithm=MD5', + 'qop="auth"', + 'opaque="5ccc069c403ebaf9f0171e9517f40e41"' )) } } else if (req.url === '/test/md5-sess') { // RFC 2716 MD5-sess w/ qop=auth @@ -61,10 +61,9 @@ var digestServer = http.createServer(function(req, res) { var qop = 'auth' var algorithm = 'MD5-sess' if (req.headers.authorization) { - - //HA1=MD5(MD5(username:realm:password):nonce:cnonce) - //HA2=MD5(method:digestURI) - //response=MD5(HA1:nonce:nonceCount:clientNonce:qop:HA2) + // HA1=MD5(MD5(username:realm:password):nonce:cnonce) + // HA2=MD5(method:digestURI) + // response=MD5(HA1:nonce:nonceCount:clientNonce:qop:HA2) var cnonce = /cnonce="(.*)"/.exec(req.headers.authorization)[1] var ha1 = md5(md5(user + ':' + realm + ':' + pass) + ':' + nonce + ':' + cnonce) @@ -72,15 +71,15 @@ var digestServer = http.createServer(function(req, res) { var response = md5(ha1 + ':' + nonce + ':' + nonceCount + ':' + cnonce + ':' + qop + ':' + ha2) testHeader = makeHeaderRegex( - 'Digest username="' + user + '"', - 'realm="' + realm + '"', - 'nonce="' + nonce + '"', - 'uri="/test/md5-sess"', - 'qop=' + qop, - 'response="' + response + '"', - 'nc=' + nonceCount, - 'cnonce="' + cnonce + '"', - 'algorithm=' + algorithm + 'Digest username="' + user + '"', + 'realm="' + realm + '"', + 'nonce="' + nonce + '"', + 'uri="/test/md5-sess"', + 'qop=' + qop, + 'response="' + response + '"', + 'nc=' + nonceCount, + 'cnonce="' + cnonce + '"', + 'algorithm=' + algorithm ) ok = testHeader.test(req.headers.authorization) @@ -88,10 +87,10 @@ var digestServer = http.createServer(function(req, res) { // No auth header, send back WWW-Authenticate header ok = false res.setHeader('www-authenticate', makeHeader( - 'Digest realm="' + realm + '"', - 'nonce="' + nonce + '"', - 'algorithm=' + algorithm, - 'qop="' + qop + '"' + 'Digest realm="' + realm + '"', + 'nonce="' + nonce + '"', + 'algorithm=' + algorithm, + 'qop="' + qop + '"' )) } } else if (req.url === '/dir/index.html') { @@ -131,14 +130,14 @@ var digestServer = http.createServer(function(req, res) { } }) -tape('setup', function(t) { - digestServer.listen(0, function() { +tape('setup', function (t) { + digestServer.listen(0, function () { digestServer.url = 'http://localhost:' + this.address().port t.end() }) }) -tape('with sendImmediately = false', function(t) { +tape('with sendImmediately = false', function (t) { var numRedirects = 0 request({ @@ -149,18 +148,18 @@ tape('with sendImmediately = false', function(t) { pass: 'testing', sendImmediately: false } - }, function(error, response, body) { + }, function (error, response, body) { t.equal(error, null) t.equal(response.statusCode, 200) t.equal(numRedirects, 1) t.end() - }).on('redirect', function() { + }).on('redirect', function () { t.equal(this.response.statusCode, 401) numRedirects++ }) }) -tape('with MD5-sess algorithm', function(t) { +tape('with MD5-sess algorithm', function (t) { var numRedirects = 0 request({ @@ -171,18 +170,18 @@ tape('with MD5-sess algorithm', function(t) { pass: 'testing', sendImmediately: false } - }, function(error, response, body) { + }, function (error, response, body) { t.equal(error, null) t.equal(response.statusCode, 200) t.equal(numRedirects, 1) t.end() - }).on('redirect', function() { + }).on('redirect', function () { t.equal(this.response.statusCode, 401) numRedirects++ }) }) -tape('without sendImmediately = false', function(t) { +tape('without sendImmediately = false', function (t) { var numRedirects = 0 // If we don't set sendImmediately = false, request will send basic auth @@ -193,18 +192,18 @@ tape('without sendImmediately = false', function(t) { user: 'test', pass: 'testing' } - }, function(error, response, body) { + }, function (error, response, body) { t.equal(error, null) t.equal(response.statusCode, 401) t.equal(numRedirects, 0) t.end() - }).on('redirect', function() { + }).on('redirect', function () { t.equal(this.response.statusCode, 401) numRedirects++ }) }) -tape('with different credentials', function(t) { +tape('with different credentials', function (t) { var numRedirects = 0 request({ @@ -215,19 +214,19 @@ tape('with different credentials', function(t) { pass: 'CircleOfLife', sendImmediately: false } - }, function(error, response, body) { + }, function (error, response, body) { t.equal(error, null) t.equal(response.statusCode, 200) t.equal(numRedirects, 1) t.end() - }).on('redirect', function() { + }).on('redirect', function () { t.equal(this.response.statusCode, 401) numRedirects++ }) }) -tape('cleanup', function(t) { - digestServer.close(function() { +tape('cleanup', function (t) { + digestServer.close(function () { t.end() }) }) diff --git a/tests/test-emptyBody.js b/tests/test-emptyBody.js index 412e93229..250bfe179 100644 --- a/tests/test-emptyBody.js +++ b/tests/test-emptyBody.js @@ -1,23 +1,23 @@ 'use strict' var request = require('../index') - , http = require('http') - , tape = require('tape') +var http = require('http') +var tape = require('tape') var s = http.createServer(function (req, resp) { resp.statusCode = 200 resp.end('') }) -tape('setup', function(t) { - s.listen(0, function() { +tape('setup', function (t) { + s.listen(0, function () { s.url = 'http://localhost:' + this.address().port t.end() }) }) -tape('empty body with encoding', function(t) { - request(s.url, function(err, res, body) { +tape('empty body with encoding', function (t) { + request(s.url, function (err, res, body) { t.equal(err, null) t.equal(res.statusCode, 200) t.equal(body, '') @@ -25,11 +25,11 @@ tape('empty body with encoding', function(t) { }) }) -tape('empty body without encoding', function(t) { +tape('empty body without encoding', function (t) { request({ url: s.url, encoding: null - }, function(err, res, body) { + }, function (err, res, body) { t.equal(err, null) t.equal(res.statusCode, 200) t.same(body, new Buffer(0)) @@ -37,11 +37,11 @@ tape('empty body without encoding', function(t) { }) }) -tape('empty JSON body', function(t) { +tape('empty JSON body', function (t) { request({ url: s.url, json: {} - }, function(err, res, body) { + }, function (err, res, body) { t.equal(err, null) t.equal(res.statusCode, 200) t.equal(body, undefined) @@ -49,8 +49,8 @@ tape('empty JSON body', function(t) { }) }) -tape('cleanup', function(t) { - s.close(function() { +tape('cleanup', function (t) { + s.close(function () { t.end() }) }) diff --git a/tests/test-errors.js b/tests/test-errors.js index 9adc0a0ee..7060e9fca 100644 --- a/tests/test-errors.js +++ b/tests/test-errors.js @@ -1,19 +1,19 @@ 'use strict' var request = require('../index') - , tape = require('tape') +var tape = require('tape') var local = 'http://localhost:0/asdf' -tape('without uri', function(t) { - t.throws(function() { +tape('without uri', function (t) { + t.throws(function () { request({}) }, /^Error: options\.uri is a required argument$/) t.end() }) -tape('invalid uri 1', function(t) { - t.throws(function() { +tape('invalid uri 1', function (t) { + t.throws(function () { request({ uri: 'this-is-not-a-valid-uri' }) @@ -21,8 +21,8 @@ tape('invalid uri 1', function(t) { t.end() }) -tape('invalid uri 2', function(t) { - t.throws(function() { +tape('invalid uri 2', function (t) { + t.throws(function () { request({ uri: 'github.com/uri-is-not-valid-without-protocol' }) @@ -30,9 +30,9 @@ tape('invalid uri 2', function(t) { t.end() }) -tape('invalid uri + NO_PROXY', function(t) { +tape('invalid uri + NO_PROXY', function (t) { process.env.NO_PROXY = 'google.com' - t.throws(function() { + t.throws(function () { request({ uri: 'invalid' }) @@ -41,8 +41,8 @@ tape('invalid uri + NO_PROXY', function(t) { t.end() }) -tape('deprecated unix URL', function(t) { - t.throws(function() { +tape('deprecated unix URL', function (t) { + t.throws(function () { request({ uri: 'unix://path/to/socket/and/then/request/path' }) @@ -50,8 +50,8 @@ tape('deprecated unix URL', function(t) { t.end() }) -tape('invalid body', function(t) { - t.throws(function() { +tape('invalid body', function (t) { + t.throws(function () { request({ uri: local, body: {} }) @@ -59,8 +59,8 @@ tape('invalid body', function(t) { t.end() }) -tape('invalid multipart', function(t) { - t.throws(function() { +tape('invalid multipart', function (t) { + t.throws(function () { request({ uri: local, multipart: 'foo' @@ -69,8 +69,8 @@ tape('invalid multipart', function(t) { t.end() }) -tape('multipart without body 1', function(t) { - t.throws(function() { +tape('multipart without body 1', function (t) { + t.throws(function () { request({ uri: local, multipart: [ {} ] @@ -79,8 +79,8 @@ tape('multipart without body 1', function(t) { t.end() }) -tape('multipart without body 2', function(t) { - t.throws(function() { +tape('multipart without body 2', function (t) { + t.throws(function () { request(local, { multipart: [ {} ] }) @@ -88,8 +88,8 @@ tape('multipart without body 2', function(t) { t.end() }) -tape('head method with a body', function(t) { - t.throws(function() { +tape('head method with a body', function (t) { + t.throws(function () { request(local, { method: 'HEAD', body: 'foo' @@ -98,8 +98,8 @@ tape('head method with a body', function(t) { t.end() }) -tape('head method with a body 2', function(t) { - t.throws(function() { +tape('head method with a body 2', function (t) { + t.throws(function () { request.head(local, { body: 'foo' }) diff --git a/tests/test-event-forwarding.js b/tests/test-event-forwarding.js index 3c2086eb3..c057a0bb9 100644 --- a/tests/test-event-forwarding.js +++ b/tests/test-event-forwarding.js @@ -1,14 +1,14 @@ 'use strict' var server = require('./server') - , request = require('../index') - , tape = require('tape') +var request = require('../index') +var tape = require('tape') var s = server.createServer() -tape('setup', function(t) { - s.listen(0, function() { - s.on('/', function(req, res) { +tape('setup', function (t) { + s.listen(0, function () { + s.on('/', function (req, res) { res.writeHead(200, { 'content-type': 'text/plain' }) res.write('waited') res.end() @@ -17,23 +17,23 @@ tape('setup', function(t) { }) }) -tape('should emit socket event', function(t) { +tape('should emit socket event', function (t) { t.plan(4) - var req = request(s.url, function(err, res, body) { + var req = request(s.url, function (err, res, body) { t.equal(err, null) t.equal(res.statusCode, 200) t.equal(body, 'waited') }) - req.on('socket', function(socket) { + req.on('socket', function (socket) { var requestSocket = req.req.socket t.equal(requestSocket, socket) }) }) -tape('cleanup', function(t) { - s.close(function() { +tape('cleanup', function (t) { + s.close(function () { t.end() }) }) diff --git a/tests/test-follow-all-303.js b/tests/test-follow-all-303.js index 2110146fc..b40adf84b 100644 --- a/tests/test-follow-all-303.js +++ b/tests/test-follow-all-303.js @@ -1,8 +1,8 @@ 'use strict' var http = require('http') - , request = require('../index') - , tape = require('tape') +var request = require('../index') +var tape = require('tape') var server = http.createServer(function (req, res) { if (req.method === 'POST') { @@ -14,14 +14,14 @@ var server = http.createServer(function (req, res) { } }) -tape('setup', function(t) { - server.listen(0, function() { +tape('setup', function (t) { + server.listen(0, function () { server.url = 'http://localhost:' + this.address().port t.end() }) }) -tape('followAllRedirects with 303', function(t) { +tape('followAllRedirects with 303', function (t) { var redirects = 0 request.post({ @@ -33,13 +33,13 @@ tape('followAllRedirects with 303', function(t) { t.equal(body, 'ok') t.equal(redirects, 1) t.end() - }).on('redirect', function() { + }).on('redirect', function () { redirects++ }) }) -tape('cleanup', function(t) { - server.close(function() { +tape('cleanup', function (t) { + server.close(function () { t.end() }) }) diff --git a/tests/test-follow-all.js b/tests/test-follow-all.js index e8054cafb..c35d74b3e 100644 --- a/tests/test-follow-all.js +++ b/tests/test-follow-all.js @@ -1,8 +1,8 @@ 'use strict' var http = require('http') - , request = require('../index') - , tape = require('tape') +var request = require('../index') +var tape = require('tape') var server = http.createServer(function (req, res) { // redirect everything 3 times, no matter what. @@ -25,14 +25,14 @@ var server = http.createServer(function (req, res) { res.end('try again') }) -tape('setup', function(t) { - server.listen(0, function() { +tape('setup', function (t) { + server.listen(0, function () { server.url = 'http://localhost:' + this.address().port t.end() }) }) -tape('followAllRedirects', function(t) { +tape('followAllRedirects', function (t) { var redirects = 0 request.post({ @@ -45,13 +45,13 @@ tape('followAllRedirects', function(t) { t.equal(body, 'ok') t.equal(redirects, 4) t.end() - }).on('redirect', function() { + }).on('redirect', function () { redirects++ }) }) -tape('cleanup', function(t) { - server.close(function() { +tape('cleanup', function (t) { + server.close(function () { t.end() }) }) diff --git a/tests/test-form-data-error.js b/tests/test-form-data-error.js index d5d6f2a5d..d6ee25d1b 100644 --- a/tests/test-form-data-error.js +++ b/tests/test-form-data-error.js @@ -1,19 +1,19 @@ 'use strict' var request = require('../index') - , server = require('./server') - , tape = require('tape') +var server = require('./server') +var tape = require('tape') var s = server.createServer() -tape('setup', function(t) { - s.listen(0, function() { +tape('setup', function (t) { + s.listen(0, function () { t.end() }) }) -tape('re-emit formData errors', function(t) { - s.on('/', function(req, res) { +tape('re-emit formData errors', function (t) { + s.on('/', function (req, res) { res.writeHead(400) res.end() t.fail('The form-data error did not abort the request.') @@ -21,14 +21,13 @@ tape('re-emit formData errors', function(t) { request.post(s.url, function (err, res, body) { t.equal(err.message, 'form-data: Arrays are not supported.') - setTimeout(function() { + setTimeout(function () { t.end() }, 10) }).form().append('field', ['value1', 'value2']) }) -tape('omit content-length header if the value is set to NaN', function(t) { - +tape('omit content-length header if the value is set to NaN', function (t) { // returns chunked HTTP response which is streamed to the 2nd HTTP request in the form data s.on('/chunky', server.createChunkResponse( ['some string', @@ -36,31 +35,31 @@ tape('omit content-length header if the value is set to NaN', function(t) { ])) // accepts form data request - s.on('/stream', function(req, resp) { - req.on('data', function(chunk) { + s.on('/stream', function (req, resp) { + req.on('data', function (chunk) { // consume the request body }) - req.on('end', function() { + req.on('end', function () { resp.writeHead(200) resp.end() }) }) - var sendStreamRequest = function(stream) { + var sendStreamRequest = function (stream) { request.post({ uri: s.url + '/stream', formData: { param: stream } - }, function(err, res) { + }, function (err, res) { t.error(err, 'request failed') t.end() }) } request.get({ - uri: s.url + '/chunky', - }).on('response', function(res) { + uri: s.url + '/chunky' + }).on('response', function (res) { sendStreamRequest(res) }) }) @@ -79,8 +78,8 @@ tape('form-data should throw on null value', function (t) { t.end() }) -tape('cleanup', function(t) { - s.close(function() { +tape('cleanup', function (t) { + s.close(function () { t.end() }) }) diff --git a/tests/test-form-data.js b/tests/test-form-data.js index fbfc8c5e2..d43a88d7c 100644 --- a/tests/test-form-data.js +++ b/tests/test-form-data.js @@ -1,20 +1,20 @@ 'use strict' var http = require('http') - , path = require('path') - , mime = require('mime-types') - , request = require('../index') - , fs = require('fs') - , tape = require('tape') +var path = require('path') +var mime = require('mime-types') +var request = require('../index') +var fs = require('fs') +var tape = require('tape') -function runTest(t, options) { +function runTest (t, options) { var remoteFile = path.join(__dirname, 'googledoodle.jpg') - , localFile = path.join(__dirname, 'unicycle.jpg') - , multipartFormData = {} + var localFile = path.join(__dirname, 'unicycle.jpg') + var multipartFormData = {} - var server = http.createServer(function(req, res) { + var server = http.createServer(function (req, res) { if (req.url === '/file') { - res.writeHead(200, {'content-type': 'image/jpg', 'content-length':7187}) + res.writeHead(200, {'content-type': 'image/jpg', 'content-length': 7187}) res.end(fs.readFileSync(remoteFile), 'binary') return } @@ -36,51 +36,51 @@ function runTest(t, options) { var data = '' req.setEncoding('utf8') - req.on('data', function(d) { + req.on('data', function (d) { data += d }) - req.on('end', function() { + req.on('end', function () { // check for the fields' traces // 1st field : my_field - t.ok( data.indexOf('form-data; name="my_field"') !== -1 ) - t.ok( data.indexOf(multipartFormData.my_field) !== -1 ) + t.ok(data.indexOf('form-data; name="my_field"') !== -1) + t.ok(data.indexOf(multipartFormData.my_field) !== -1) // 2nd field : my_buffer - t.ok( data.indexOf('form-data; name="my_buffer"') !== -1 ) - t.ok( data.indexOf(multipartFormData.my_buffer) !== -1 ) + t.ok(data.indexOf('form-data; name="my_buffer"') !== -1) + t.ok(data.indexOf(multipartFormData.my_buffer) !== -1) // 3rd field : my_file - t.ok( data.indexOf('form-data; name="my_file"') !== -1 ) - t.ok( data.indexOf('; filename="' + path.basename(multipartFormData.my_file.path) + '"') !== -1 ) + t.ok(data.indexOf('form-data; name="my_file"') !== -1) + t.ok(data.indexOf('; filename="' + path.basename(multipartFormData.my_file.path) + '"') !== -1) // check for unicycle.jpg traces - t.ok( data.indexOf('2005:06:21 01:44:12') !== -1 ) - t.ok( data.indexOf('Content-Type: ' + mime.lookup(multipartFormData.my_file.path) ) !== -1 ) + t.ok(data.indexOf('2005:06:21 01:44:12') !== -1) + t.ok(data.indexOf('Content-Type: ' + mime.lookup(multipartFormData.my_file.path)) !== -1) // 4th field : remote_file - t.ok( data.indexOf('form-data; name="remote_file"') !== -1 ) - t.ok( data.indexOf('; filename="' + path.basename(multipartFormData.remote_file.path) + '"') !== -1 ) + t.ok(data.indexOf('form-data; name="remote_file"') !== -1) + t.ok(data.indexOf('; filename="' + path.basename(multipartFormData.remote_file.path) + '"') !== -1) // 5th field : file with metadata - t.ok( data.indexOf('form-data; name="secret_file"') !== -1 ) - t.ok( data.indexOf('Content-Disposition: form-data; name="secret_file"; filename="topsecret.jpg"') !== -1 ) - t.ok( data.indexOf('Content-Type: image/custom') !== -1 ) + t.ok(data.indexOf('form-data; name="secret_file"') !== -1) + t.ok(data.indexOf('Content-Disposition: form-data; name="secret_file"; filename="topsecret.jpg"') !== -1) + t.ok(data.indexOf('Content-Type: image/custom') !== -1) // 6th field : batch of files - t.ok( data.indexOf('form-data; name="batch"') !== -1 ) - t.ok( data.match(/form-data; name="batch"/g).length === 2 ) + t.ok(data.indexOf('form-data; name="batch"') !== -1) + t.ok(data.match(/form-data; name="batch"/g).length === 2) // check for http://localhost:nnnn/file traces - t.ok( data.indexOf('Photoshop ICC') !== -1 ) - t.ok( data.indexOf('Content-Type: ' + mime.lookup(remoteFile) ) !== -1 ) + t.ok(data.indexOf('Photoshop ICC') !== -1) + t.ok(data.indexOf('Content-Type: ' + mime.lookup(remoteFile)) !== -1) res.writeHead(200) res.end(options.json ? JSON.stringify({status: 'done'}) : 'done') }) }) - server.listen(0, function() { + server.listen(0, function () { var url = 'http://localhost:' + this.address().port // @NOTE: multipartFormData properties must be set here so that my_file read stream does not leak in node v0.8 multipartFormData.my_field = 'my_value' @@ -113,22 +113,21 @@ function runTest(t, options) { t.equal(err, null) t.equal(res.statusCode, 200) t.deepEqual(body, options.json ? {status: 'done'} : 'done') - server.close(function() { + server.close(function () { t.end() }) }) - }) } -tape('multipart formData', function(t) { +tape('multipart formData', function (t) { runTest(t, {json: false}) }) -tape('multipart formData + JSON', function(t) { +tape('multipart formData + JSON', function (t) { runTest(t, {json: true}) }) -tape('multipart formData + basic auth', function(t) { +tape('multipart formData + basic auth', function (t) { runTest(t, {json: false, auth: true}) }) diff --git a/tests/test-form-urlencoded.js b/tests/test-form-urlencoded.js index f080a27aa..5e46917bb 100644 --- a/tests/test-form-urlencoded.js +++ b/tests/test-form-urlencoded.js @@ -1,14 +1,11 @@ 'use strict' var http = require('http') - , request = require('../index') - , tape = require('tape') - +var request = require('../index') +var tape = require('tape') function runTest (t, options, index) { - - var server = http.createServer(function(req, res) { - + var server = http.createServer(function (req, res) { if (index === 0 || index === 3) { t.equal(req.headers['content-type'], 'application/x-www-form-urlencoded') } else { @@ -20,11 +17,11 @@ function runTest (t, options, index) { var data = '' req.setEncoding('utf8') - req.on('data', function(d) { + req.on('data', function (d) { data += d }) - req.on('end', function() { + req.on('end', function () { t.equal(data, 'some=url&encoded=data') res.writeHead(200) @@ -32,13 +29,13 @@ function runTest (t, options, index) { }) }) - server.listen(0, function() { + server.listen(0, function () { var url = 'http://localhost:' + this.address().port - var r = request.post(url, options, function(err, res, body) { + var r = request.post(url, options, function (err, res, body) { t.equal(err, null) t.equal(res.statusCode, 200) t.equal(body, 'done') - server.close(function() { + server.close(function () { t.end() }) }) @@ -70,7 +67,7 @@ var cases = [ ] cases.forEach(function (options, index) { - tape('application/x-www-form-urlencoded ' + index, function(t) { + tape('application/x-www-form-urlencoded ' + index, function (t) { runTest(t, options, index) }) }) diff --git a/tests/test-form.js b/tests/test-form.js index 836ec1dfe..1c0a4d25d 100644 --- a/tests/test-form.js +++ b/tests/test-form.js @@ -1,22 +1,21 @@ 'use strict' var http = require('http') - , path = require('path') - , mime = require('mime-types') - , request = require('../index') - , fs = require('fs') - , tape = require('tape') - -tape('multipart form append', function(t) { +var path = require('path') +var mime = require('mime-types') +var request = require('../index') +var fs = require('fs') +var tape = require('tape') +tape('multipart form append', function (t) { var remoteFile = path.join(__dirname, 'googledoodle.jpg') - , localFile = path.join(__dirname, 'unicycle.jpg') - , totalLength = null - , FIELDS = [] + var localFile = path.join(__dirname, 'unicycle.jpg') + var totalLength = null + var FIELDS = [] - var server = http.createServer(function(req, res) { + var server = http.createServer(function (req, res) { if (req.url === '/file') { - res.writeHead(200, {'content-type': 'image/jpg', 'content-length':7187}) + res.writeHead(200, {'content-type': 'image/jpg', 'content-length': 7187}) res.end(fs.readFileSync(remoteFile), 'binary') return } @@ -28,41 +27,41 @@ tape('multipart form append', function(t) { var data = '' req.setEncoding('utf8') - req.on('data', function(d) { + req.on('data', function (d) { data += d }) - req.on('end', function() { + req.on('end', function () { var field // check for the fields' traces // 1st field : my_field field = FIELDS.shift() - t.ok( data.indexOf('form-data; name="' + field.name + '"') !== -1 ) - t.ok( data.indexOf(field.value) !== -1 ) + t.ok(data.indexOf('form-data; name="' + field.name + '"') !== -1) + t.ok(data.indexOf(field.value) !== -1) // 2nd field : my_buffer field = FIELDS.shift() - t.ok( data.indexOf('form-data; name="' + field.name + '"') !== -1 ) - t.ok( data.indexOf(field.value) !== -1 ) + t.ok(data.indexOf('form-data; name="' + field.name + '"') !== -1) + t.ok(data.indexOf(field.value) !== -1) // 3rd field : my_file field = FIELDS.shift() - t.ok( data.indexOf('form-data; name="' + field.name + '"') !== -1 ) - t.ok( data.indexOf('; filename="' + path.basename(field.value.path) + '"') !== -1 ) + t.ok(data.indexOf('form-data; name="' + field.name + '"') !== -1) + t.ok(data.indexOf('; filename="' + path.basename(field.value.path) + '"') !== -1) // check for unicycle.jpg traces - t.ok( data.indexOf('2005:06:21 01:44:12') !== -1 ) - t.ok( data.indexOf('Content-Type: ' + mime.lookup(field.value.path) ) !== -1 ) + t.ok(data.indexOf('2005:06:21 01:44:12') !== -1) + t.ok(data.indexOf('Content-Type: ' + mime.lookup(field.value.path)) !== -1) // 4th field : remote_file field = FIELDS.shift() - t.ok( data.indexOf('form-data; name="' + field.name + '"') !== -1 ) - t.ok( data.indexOf('; filename="' + path.basename(field.value.path) + '"') !== -1 ) + t.ok(data.indexOf('form-data; name="' + field.name + '"') !== -1) + t.ok(data.indexOf('; filename="' + path.basename(field.value.path) + '"') !== -1) // check for http://localhost:nnnn/file traces - t.ok( data.indexOf('Photoshop ICC') !== -1 ) - t.ok( data.indexOf('Content-Type: ' + mime.lookup(remoteFile) ) !== -1 ) + t.ok(data.indexOf('Photoshop ICC') !== -1) + t.ok(data.indexOf('Content-Type: ' + mime.lookup(remoteFile)) !== -1) - t.ok( +req.headers['content-length'] === totalLength ) + t.ok(+req.headers['content-length'] === totalLength) res.writeHead(200) res.end('done') @@ -71,7 +70,7 @@ tape('multipart form append', function(t) { }) }) - server.listen(0, function() { + server.listen(0, function () { var url = 'http://localhost:' + this.address().port FIELDS = [ { name: 'my_field', value: 'my_value' }, @@ -80,21 +79,21 @@ tape('multipart form append', function(t) { { name: 'remote_file', value: request(url + '/file') } ] - var req = request.post(url + '/upload', function(err, res, body) { + var req = request.post(url + '/upload', function (err, res, body) { t.equal(err, null) t.equal(res.statusCode, 200) t.equal(body, 'done') - server.close(function() { + server.close(function () { t.end() }) }) var form = req.form() - FIELDS.forEach(function(field) { + FIELDS.forEach(function (field) { form.append(field.name, field.value) }) - form.getLength(function(err, length) { + form.getLength(function (err, length) { t.equal(err, null) totalLength = length }) diff --git a/tests/test-gzip.js b/tests/test-gzip.js index ac523a8d7..b69f3cdc4 100644 --- a/tests/test-gzip.js +++ b/tests/test-gzip.js @@ -1,18 +1,18 @@ 'use strict' var request = require('../index') - , http = require('http') - , zlib = require('zlib') - , assert = require('assert') - , bufferEqual = require('buffer-equal') - , tape = require('tape') +var http = require('http') +var zlib = require('zlib') +var assert = require('assert') +var bufferEqual = require('buffer-equal') +var tape = require('tape') var testContent = 'Compressible response content.\n' - , testContentBig - , testContentBigGzip - , testContentGzip +var testContentBig +var testContentBigGzip +var testContentGzip -var server = http.createServer(function(req, res) { +var server = http.createServer(function (req, res) { res.statusCode = 200 res.setHeader('Content-Type', 'text/plain') @@ -38,15 +38,15 @@ var server = http.createServer(function(req, res) { } else if (req.url === '/chunks') { res.writeHead(200) res.write(testContentBigGzip.slice(0, 4096)) - setTimeout(function() { res.end(testContentBigGzip.slice(4096)) }, 10) + setTimeout(function () { res.end(testContentBigGzip.slice(4096)) }, 10) } else if (req.url === '/just-slightly-truncated') { - zlib.gzip(testContent, function(err, data) { + zlib.gzip(testContent, function (err, data) { assert.equal(err, null) // truncate the CRC checksum and size check at the end of the stream - res.end(data.slice(0, data.length-8)) + res.end(data.slice(0, data.length - 8)) }) } else { - zlib.gzip(testContent, function(err, data) { + zlib.gzip(testContent, function (err, data) { assert.equal(err, null) res.end(data) }) @@ -62,13 +62,13 @@ var server = http.createServer(function(req, res) { } }) -tape('setup', function(t) { +tape('setup', function (t) { // Need big compressed content to be large enough to chunk into gzip blocks. // Want it to be deterministic to ensure test is reliable. // Generate pseudo-random printable ASCII characters using MINSTD var a = 48271 - , m = 0x7FFFFFFF - , x = 1 + var m = 0x7FFFFFFF + var x = 1 testContentBig = new Buffer(10240) for (var i = 0; i < testContentBig.length; ++i) { x = (a * x) & m @@ -76,15 +76,15 @@ tape('setup', function(t) { testContentBig[i] = (x % 95) + 32 } - zlib.gzip(testContent, function(err, data) { + zlib.gzip(testContent, function (err, data) { t.equal(err, null) testContentGzip = data - zlib.gzip(testContentBig, function(err, data2) { + zlib.gzip(testContentBig, function (err, data2) { t.equal(err, null) testContentBigGzip = data2 - server.listen(0, function() { + server.listen(0, function () { server.url = 'http://localhost:' + this.address().port t.end() }) @@ -92,9 +92,9 @@ tape('setup', function(t) { }) }) -tape('transparently supports gzip decoding to callbacks', function(t) { +tape('transparently supports gzip decoding to callbacks', function (t) { var options = { url: server.url + '/foo', gzip: true } - request.get(options, function(err, res, body) { + request.get(options, function (err, res, body) { t.equal(err, null) t.equal(res.headers['content-encoding'], 'gzip') t.equal(body, testContent) @@ -102,9 +102,9 @@ tape('transparently supports gzip decoding to callbacks', function(t) { }) }) -tape('supports slightly invalid gzip content', function(t) { +tape('supports slightly invalid gzip content', function (t) { var options = { url: server.url + '/just-slightly-truncated', gzip: true } - request.get(options, function(err, res, body) { + request.get(options, function (err, res, body) { t.equal(err, null) t.equal(res.headers['content-encoding'], 'gzip') t.equal(body, testContent) @@ -112,30 +112,30 @@ tape('supports slightly invalid gzip content', function(t) { }) }) -tape('transparently supports gzip decoding to pipes', function(t) { +tape('transparently supports gzip decoding to pipes', function (t) { var options = { url: server.url + '/foo', gzip: true } var chunks = [] request.get(options) - .on('data', function(chunk) { + .on('data', function (chunk) { chunks.push(chunk) }) - .on('end', function() { + .on('end', function () { t.equal(Buffer.concat(chunks).toString(), testContent) t.end() }) - .on('error', function(err) { + .on('error', function (err) { t.fail(err) }) }) -tape('does not request gzip if user specifies Accepted-Encodings', function(t) { +tape('does not request gzip if user specifies Accepted-Encodings', function (t) { var headers = { 'Accept-Encoding': null } var options = { url: server.url + '/foo', headers: headers, gzip: true } - request.get(options, function(err, res, body) { + request.get(options, function (err, res, body) { t.equal(err, null) t.equal(res.headers['content-encoding'], undefined) t.equal(body, testContent) @@ -143,10 +143,10 @@ tape('does not request gzip if user specifies Accepted-Encodings', function(t) { }) }) -tape('does not decode user-requested encoding by default', function(t) { +tape('does not decode user-requested encoding by default', function (t) { var headers = { 'Accept-Encoding': 'gzip' } var options = { url: server.url + '/foo', headers: headers } - request.get(options, function(err, res, body) { + request.get(options, function (err, res, body) { t.equal(err, null) t.equal(res.headers['content-encoding'], 'gzip') t.equal(body, testContentGzip.toString()) @@ -154,7 +154,7 @@ tape('does not decode user-requested encoding by default', function(t) { }) }) -tape('supports character encoding with gzip encoding', function(t) { +tape('supports character encoding with gzip encoding', function (t) { var headers = { 'Accept-Encoding': 'gzip' } var options = { url: server.url + '/foo', @@ -164,22 +164,22 @@ tape('supports character encoding with gzip encoding', function(t) { } var strings = [] request.get(options) - .on('data', function(string) { + .on('data', function (string) { t.equal(typeof string, 'string') strings.push(string) }) - .on('end', function() { + .on('end', function () { t.equal(strings.join(''), testContent) t.end() }) - .on('error', function(err) { + .on('error', function (err) { t.fail(err) }) }) -tape('transparently supports gzip error to callbacks', function(t) { +tape('transparently supports gzip error to callbacks', function (t) { var options = { url: server.url + '/error', gzip: true } - request.get(options, function(err, res, body) { + request.get(options, function (err, res, body) { t.equal(err.code, 'Z_DATA_ERROR') t.equal(res, undefined) t.equal(body, undefined) @@ -187,10 +187,10 @@ tape('transparently supports gzip error to callbacks', function(t) { }) }) -tape('transparently supports gzip error to pipes', function(t) { +tape('transparently supports gzip error to pipes', function (t) { var options = { url: server.url + '/error', gzip: true } request.get(options) - .on('data', function (/*chunk*/) { + .on('data', function (chunk) { t.fail('Should not receive data event') }) .on('end', function () { @@ -202,12 +202,12 @@ tape('transparently supports gzip error to pipes', function(t) { }) }) -tape('pause when streaming from a gzip request object', function(t) { +tape('pause when streaming from a gzip request object', function (t) { var chunks = [] var paused = false var options = { url: server.url + '/chunks', gzip: true } request.get(options) - .on('data', function(chunk) { + .on('data', function (chunk) { var self = this t.notOk(paused, 'Only receive data when not paused') @@ -216,40 +216,40 @@ tape('pause when streaming from a gzip request object', function(t) { if (chunks.length === 1) { self.pause() paused = true - setTimeout(function() { + setTimeout(function () { paused = false self.resume() }, 100) } }) - .on('end', function() { + .on('end', function () { t.ok(chunks.length > 1, 'Received multiple chunks') t.ok(bufferEqual(Buffer.concat(chunks), testContentBig), 'Expected content') t.end() }) }) -tape('pause before streaming from a gzip request object', function(t) { +tape('pause before streaming from a gzip request object', function (t) { var paused = true var options = { url: server.url + '/foo', gzip: true } var r = request.get(options) r.pause() - r.on('data', function(data) { + r.on('data', function (data) { t.notOk(paused, 'Only receive data when not paused') t.equal(data.toString(), testContent) }) r.on('end', t.end.bind(t)) - setTimeout(function() { + setTimeout(function () { paused = false r.resume() }, 100) }) -tape('transparently supports deflate decoding to callbacks', function(t) { +tape('transparently supports deflate decoding to callbacks', function (t) { var options = { url: server.url + '/foo', gzip: true, headers: { 'Accept-Encoding': 'deflate' } } - request.get(options, function(err, res, body) { + request.get(options, function (err, res, body) { t.equal(err, null) t.equal(res.headers['content-encoding'], 'deflate') t.equal(body, testContent) @@ -257,33 +257,33 @@ tape('transparently supports deflate decoding to callbacks', function(t) { }) }) -tape('do not try to pipe HEAD request responses', function(t) { +tape('do not try to pipe HEAD request responses', function (t) { var options = { method: 'HEAD', url: server.url + '/foo', gzip: true } - request(options, function(err, res, body) { + request(options, function (err, res, body) { t.equal(err, null) t.equal(body, '') t.end() }) }) -tape('do not try to pipe responses with no body', function(t) { +tape('do not try to pipe responses with no body', function (t) { var options = { url: server.url + '/foo', gzip: true } options.headers = {code: 105} - request.post(options, function(err, res, body) { + request.post(options, function (err, res, body) { t.equal(err, null) t.equal(res.headers.code, '105') t.equal(body, '') - + options.headers = {code: 204} - request.post(options, function(err, res, body) { + request.post(options, function (err, res, body) { t.equal(err, null) t.equal(res.headers.code, '204') t.equal(body, '') - + options.headers = {code: 304} - request.post(options, function(err, res, body) { + request.post(options, function (err, res, body) { t.equal(err, null) t.equal(res.headers.code, '304') t.equal(body, '') @@ -294,9 +294,8 @@ tape('do not try to pipe responses with no body', function(t) { }) }) - -tape('cleanup', function(t) { - server.close(function() { +tape('cleanup', function (t) { + server.close(function () { t.end() }) }) diff --git a/tests/test-hawk.js b/tests/test-hawk.js index f0aa1d56b..34db8da25 100644 --- a/tests/test-hawk.js +++ b/tests/test-hawk.js @@ -1,13 +1,13 @@ 'use strict' var http = require('http') - , request = require('../index') - , hawk = require('hawk') - , tape = require('tape') - , assert = require('assert') +var request = require('../index') +var hawk = require('hawk') +var tape = require('tape') +var assert = require('assert') -var server = http.createServer(function(req, res) { - var getCred = function(id, callback) { +var server = http.createServer(function (req, res) { + var getCred = function (id, callback) { assert.equal(id, 'dh37fgj492je') var credentials = { key: 'werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn', @@ -17,7 +17,7 @@ var server = http.createServer(function(req, res) { return callback(null, credentials) } - hawk.server.authenticate(req, getCred, {}, function(err, credentials, attributes) { + hawk.server.authenticate(req, getCred, {}, function (err, credentials, attributes) { res.writeHead(err ? 401 : 200, { 'Content-Type': 'text/plain' }) @@ -25,14 +25,14 @@ var server = http.createServer(function(req, res) { }) }) -tape('setup', function(t) { - server.listen(0, function() { +tape('setup', function (t) { + server.listen(0, function () { server.url = 'http://localhost:' + this.address().port t.end() }) }) -tape('hawk', function(t) { +tape('hawk', function (t) { var creds = { key: 'werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn', algorithm: 'sha256', @@ -40,7 +40,7 @@ tape('hawk', function(t) { } request(server.url, { hawk: { credentials: creds } - }, function(err, res, body) { + }, function (err, res, body) { t.equal(err, null) t.equal(res.statusCode, 200) t.equal(body, 'Hello Steve') @@ -48,8 +48,8 @@ tape('hawk', function(t) { }) }) -tape('cleanup', function(t) { - server.close(function() { +tape('cleanup', function (t) { + server.close(function () { t.end() }) }) diff --git a/tests/test-headers.js b/tests/test-headers.js index 91abd25ef..c1c29622a 100644 --- a/tests/test-headers.js +++ b/tests/test-headers.js @@ -1,25 +1,25 @@ 'use strict' var server = require('./server') - , request = require('../index') - , util = require('util') - , tape = require('tape') - , url = require('url') +var request = require('../index') +var util = require('util') +var tape = require('tape') +var url = require('url') var s = server.createServer() -s.on('/redirect/from', function(req, res) { +s.on('/redirect/from', function (req, res) { res.writeHead(301, { - location : '/redirect/to' + location: '/redirect/to' }) res.end() }) -s.on('/redirect/to', function(req, res) { +s.on('/redirect/to', function (req, res) { res.end('ok') }) -s.on('/headers.json', function(req, res) { +s.on('/headers.json', function (req, res) { res.writeHead(200, { 'Content-Type': 'application/json' }) @@ -27,15 +27,15 @@ s.on('/headers.json', function(req, res) { res.end(JSON.stringify(req.headers)) }) -function runTest(name, path, requestObj, serverAssertFn) { - tape(name, function(t) { - s.on('/' + path, function(req, res) { +function runTest (name, path, requestObj, serverAssertFn) { + tape(name, function (t) { + s.on('/' + path, function (req, res) { serverAssertFn(t, req, res) res.writeHead(200) res.end() }) requestObj.url = s.url + '/' + path - request(requestObj, function(err, res, body) { + request(requestObj, function (err, res, body) { t.equal(err, null) t.equal(res.statusCode, 200) t.end() @@ -43,12 +43,12 @@ function runTest(name, path, requestObj, serverAssertFn) { }) } -function addTests() { +function addTests () { runTest( '#125: headers.cookie with no cookie jar', 'no-jar', {headers: {cookie: 'foo=bar'}}, - function(t, req, res) { + function (t, req, res) { t.equal(req.headers.cookie, 'foo=bar') }) @@ -58,7 +58,7 @@ function addTests() { '#125: headers.cookie + cookie jar', 'header-and-jar', {jar: jar, headers: {cookie: 'foo=bar'}}, - function(t, req, res) { + function (t, req, res) { t.equal(req.headers.cookie, 'foo=bar; quux=baz') }) @@ -68,7 +68,7 @@ function addTests() { '#794: ignore cookie parsing and domain errors', 'ignore-errors', {jar: jar2, headers: {cookie: 'foo=bar'}}, - function(t, req, res) { + function (t, req, res) { t.equal(req.headers.cookie, 'foo=bar') }) @@ -80,7 +80,7 @@ function addTests() { method: 'POST', headers: { 'content-type': 'application/json; charset=UTF-8' }, body: { hello: 'my friend' }}, - function(t, req, res) { + function (t, req, res) { t.equal(req.headers['content-type'], 'application/json; charset=UTF-8') } ) @@ -89,16 +89,16 @@ function addTests() { 'neither headers.cookie nor a cookie jar is specified', 'no-cookie', {}, - function(t, req, res) { + function (t, req, res) { t.equal(req.headers.cookie, undefined) }) } -tape('setup', function(t) { - s.listen(0, function() { +tape('setup', function (t) { + s.listen(0, function () { addTests() - tape('cleanup', function(t) { - s.close(function() { + tape('cleanup', function (t) { + s.close(function () { t.end() }) }) @@ -106,12 +106,12 @@ tape('setup', function(t) { }) }) -tape('upper-case Host header and redirect', function(t) { +tape('upper-case Host header and redirect', function (t) { // Horrible hack to observe the raw data coming to the server (before Node // core lower-cases the headers) var rawData = '' - s.on('connection', function(socket) { + s.on('connection', function (socket) { if (socket.ondata) { var ondata = socket.ondata } @@ -127,7 +127,7 @@ tape('upper-case Host header and redirect', function(t) { socket.ondata = handledata }) - function checkHostHeader(host) { + function checkHostHeader (host) { t.ok( new RegExp('^Host: ' + host + '$', 'm').test(rawData), util.format( @@ -138,9 +138,9 @@ tape('upper-case Host header and redirect', function(t) { var redirects = 0 request({ - url : s.url + '/redirect/from', - headers : { Host : '127.0.0.1' } - }, function(err, res, body) { + url: s.url + '/redirect/from', + headers: { Host: '127.0.0.1' } + }, function (err, res, body) { t.equal(err, null) t.equal(res.statusCode, 200) t.equal(body, 'ok') @@ -148,14 +148,14 @@ tape('upper-case Host header and redirect', function(t) { // XXX should the host header change like this after a redirect? checkHostHeader('localhost:' + s.port) t.end() - }).on('redirect', function() { + }).on('redirect', function () { redirects++ t.equal(this.uri.href, s.url + '/redirect/to') checkHostHeader('127.0.0.1') }) }) -tape('undefined headers', function(t) { +tape('undefined headers', function (t) { request({ url: s.url + '/headers.json', headers: { @@ -163,7 +163,7 @@ tape('undefined headers', function(t) { 'X-TEST-2': undefined }, json: true - }, function(err, res, body) { + }, function (err, res, body) { t.equal(err, null) t.equal(body['x-test-1'], 'test1') t.equal(typeof body['x-test-2'], 'undefined') @@ -171,13 +171,13 @@ tape('undefined headers', function(t) { }) }) -tape('catch invalid characters error - GET', function(t) { +tape('catch invalid characters error - GET', function (t) { request({ url: s.url + '/headers.json', headers: { 'test': 'אבגד' } - }, function(err, res, body) { + }, function (err, res, body) { t.equal(err.message, 'The header content contains invalid characters') }) .on('error', function (err) { @@ -186,7 +186,7 @@ tape('catch invalid characters error - GET', function(t) { }) }) -tape('catch invalid characters error - POST', function(t) { +tape('catch invalid characters error - POST', function (t) { request({ method: 'POST', url: s.url + '/headers.json', @@ -194,7 +194,7 @@ tape('catch invalid characters error - POST', function(t) { 'test': 'אבגד' }, body: 'beep' - }, function(err, res, body) { + }, function (err, res, body) { t.equal(err.message, 'The header content contains invalid characters') }) .on('error', function (err) { @@ -203,11 +203,11 @@ tape('catch invalid characters error - POST', function(t) { }) }) -tape('IPv6 Host header', function(t) { +tape('IPv6 Host header', function (t) { // Horrible hack to observe the raw data coming to the server var rawData = '' - s.on('connection', function(socket) { + s.on('connection', function (socket) { if (socket.ondata) { var ondata = socket.ondata } @@ -223,7 +223,7 @@ tape('IPv6 Host header', function(t) { socket.ondata = handledata }) - function checkHostHeader(host) { + function checkHostHeader (host) { t.ok( new RegExp('^Host: ' + host + '$', 'im').test(rawData), util.format( @@ -233,8 +233,8 @@ tape('IPv6 Host header', function(t) { } request({ - url : s.url.replace(url.parse(s.url).hostname, '[::1]') + '/headers.json' - }, function(err, res, body) { + url: s.url.replace(url.parse(s.url).hostname, '[::1]') + '/headers.json' + }, function (err, res, body) { t.equal(err, null) t.equal(res.statusCode, 200) checkHostHeader('\\[::1\\]:' + s.port) diff --git a/tests/test-http-signature.js b/tests/test-http-signature.js index b5679beba..5ce015cba 100644 --- a/tests/test-http-signature.js +++ b/tests/test-http-signature.js @@ -1,9 +1,9 @@ 'use strict' var http = require('http') - , request = require('../index') - , httpSignature = require('http-signature') - , tape = require('tape') +var request = require('../index') +var httpSignature = require('http-signature') +var tape = require('tape') var privateKeyPEMs = {} @@ -68,43 +68,43 @@ var server = http.createServer(function (req, res) { res.end() }) -tape('setup', function(t) { - server.listen(0, function() { +tape('setup', function (t) { + server.listen(0, function () { server.url = 'http://localhost:' + this.address().port t.end() }) }) -tape('correct key', function(t) { +tape('correct key', function (t) { var options = { httpSignature: { keyId: 'key-1', key: privateKeyPEMs['key-1'] } } - request(server.url, options, function(err, res, body) { + request(server.url, options, function (err, res, body) { t.equal(err, null) t.equal(200, res.statusCode) t.end() }) }) -tape('incorrect key', function(t) { +tape('incorrect key', function (t) { var options = { httpSignature: { keyId: 'key-2', key: privateKeyPEMs['key-1'] } } - request(server.url, options, function(err, res, body) { + request(server.url, options, function (err, res, body) { t.equal(err, null) t.equal(400, res.statusCode) t.end() }) }) -tape('cleanup', function(t) { - server.close(function() { +tape('cleanup', function (t) { + server.close(function () { t.end() }) }) diff --git a/tests/test-httpModule.js b/tests/test-httpModule.js index 9acf80c0e..4d4e236bf 100644 --- a/tests/test-httpModule.js +++ b/tests/test-httpModule.js @@ -1,27 +1,27 @@ 'use strict' var http = require('http') - , https = require('https') - , destroyable = require('server-destroy') - , server = require('./server') - , request = require('../index') - , tape = require('tape') +var https = require('https') +var destroyable = require('server-destroy') +var server = require('./server') +var request = require('../index') +var tape = require('tape') -var faux_requests_made +var fauxRequestsMade -function clear_faux_requests() { - faux_requests_made = { http: 0, https: 0 } +function clearFauxRequests () { + fauxRequestsMade = { http: 0, https: 0 } } -function wrap_request(name, module) { +function wrapRequest (name, module) { // Just like the http or https module, but note when a request is made. var wrapped = {} - Object.keys(module).forEach(function(key) { + Object.keys(module).forEach(function (key) { var value = module[key] if (key === 'request') { - wrapped[key] = function(/*options, callback*/) { - faux_requests_made[name] += 1 + wrapped[key] = function (/* options, callback */) { + fauxRequestsMade[name] += 1 return value.apply(this, arguments) } } else { @@ -32,32 +32,32 @@ function wrap_request(name, module) { return wrapped } -var faux_http = wrap_request('http', http) - , faux_https = wrap_request('https', https) - , plain_server = server.createServer() - , https_server = server.createSSLServer() +var fauxHTTP = wrapRequest('http', http) +var fauxHTTPS = wrapRequest('https', https) +var plainServer = server.createServer() +var httpsServer = server.createSSLServer() -destroyable(plain_server) -destroyable(https_server) +destroyable(plainServer) +destroyable(httpsServer) -tape('setup', function(t) { - plain_server.listen(0, function() { - plain_server.on('/plain', function (req, res) { +tape('setup', function (t) { + plainServer.listen(0, function () { + plainServer.on('/plain', function (req, res) { res.writeHead(200) res.end('plain') }) - plain_server.on('/to_https', function (req, res) { - res.writeHead(301, { 'location': 'https://localhost:' + https_server.port + '/https' }) + plainServer.on('/to_https', function (req, res) { + res.writeHead(301, { 'location': 'https://localhost:' + httpsServer.port + '/https' }) res.end() }) - https_server.listen(0, function() { - https_server.on('/https', function (req, res) { + httpsServer.listen(0, function () { + httpsServer.on('/https', function (req, res) { res.writeHead(200) res.end('https') }) - https_server.on('/to_plain', function (req, res) { - res.writeHead(302, { 'location': 'http://localhost:' + plain_server.port + '/plain' }) + httpsServer.on('/to_plain', function (req, res) { + res.writeHead(302, { 'location': 'http://localhost:' + plainServer.port + '/plain' }) res.end() }) @@ -66,30 +66,30 @@ tape('setup', function(t) { }) }) -function run_tests(name, httpModules) { - tape(name, function(t) { - var to_https = 'http://localhost:' + plain_server.port + '/to_https' - , to_plain = 'https://localhost:' + https_server.port + '/to_plain' - , options = { httpModules: httpModules, strictSSL: false } - , modulesTest = httpModules || {} +function runTests (name, httpModules) { + tape(name, function (t) { + var toHttps = 'http://localhost:' + plainServer.port + '/to_https' + var toPlain = 'https://localhost:' + httpsServer.port + '/to_plain' + var options = { httpModules: httpModules, strictSSL: false } + var modulesTest = httpModules || {} - clear_faux_requests() + clearFauxRequests() - request(to_https, options, function (err, res, body) { + request(toHttps, options, function (err, res, body) { t.equal(err, null) t.equal(res.statusCode, 200) t.equal(body, 'https', 'Received HTTPS server body') - t.equal(faux_requests_made.http, modulesTest['http:' ] ? 1 : 0) - t.equal(faux_requests_made.https, modulesTest['https:'] ? 1 : 0) + t.equal(fauxRequestsMade.http, modulesTest['http:'] ? 1 : 0) + t.equal(fauxRequestsMade.https, modulesTest['https:'] ? 1 : 0) - request(to_plain, options, function (err, res, body) { + request(toPlain, options, function (err, res, body) { t.equal(err, null) t.equal(res.statusCode, 200) t.equal(body, 'plain', 'Received HTTPS server body') - t.equal(faux_requests_made.http, modulesTest['http:' ] ? 2 : 0) - t.equal(faux_requests_made.https, modulesTest['https:'] ? 2 : 0) + t.equal(fauxRequestsMade.http, modulesTest['http:'] ? 2 : 0) + t.equal(fauxRequestsMade.https, modulesTest['https:'] ? 2 : 0) t.end() }) @@ -97,15 +97,15 @@ function run_tests(name, httpModules) { }) } -run_tests('undefined') -run_tests('empty', {}) -run_tests('http only', { 'http:': faux_http }) -run_tests('https only', { 'https:': faux_https }) -run_tests('http and https', { 'http:': faux_http, 'https:': faux_https }) +runTests('undefined') +runTests('empty', {}) +runTests('http only', { 'http:': fauxHTTP }) +runTests('https only', { 'https:': fauxHTTPS }) +runTests('http and https', { 'http:': fauxHTTP, 'https:': fauxHTTPS }) -tape('cleanup', function(t) { - plain_server.destroy(function() { - https_server.destroy(function() { +tape('cleanup', function (t) { + plainServer.destroy(function () { + httpsServer.destroy(function () { t.end() }) }) diff --git a/tests/test-https.js b/tests/test-https.js index c298f7d54..3138f3d1e 100644 --- a/tests/test-https.js +++ b/tests/test-https.js @@ -4,32 +4,32 @@ // otherwise exactly the same as the ssl test var server = require('./server') - , request = require('../index') - , fs = require('fs') - , path = require('path') - , tape = require('tape') +var request = require('../index') +var fs = require('fs') +var path = require('path') +var tape = require('tape') var s = server.createSSLServer() - , caFile = path.resolve(__dirname, 'ssl/ca/ca.crt') - , ca = fs.readFileSync(caFile) - , opts = { - ciphers: 'AES256-SHA', - key: path.resolve(__dirname, 'ssl/ca/server.key'), - cert: path.resolve(__dirname, 'ssl/ca/server.crt') - } - , sStrict = server.createSSLServer(opts) +var caFile = path.resolve(__dirname, 'ssl/ca/ca.crt') +var ca = fs.readFileSync(caFile) +var opts = { + ciphers: 'AES256-SHA', + key: path.resolve(__dirname, 'ssl/ca/server.key'), + cert: path.resolve(__dirname, 'ssl/ca/server.crt') +} +var sStrict = server.createSSLServer(opts) -function runAllTests(strict, s) { +function runAllTests (strict, s) { var strictMsg = (strict ? 'strict ' : 'relaxed ') - tape(strictMsg + 'setup', function(t) { - s.listen(0, function() { + tape(strictMsg + 'setup', function (t) { + s.listen(0, function () { t.end() }) }) - function runTest(name, test) { - tape(strictMsg + name, function(t) { + function runTest (name, test) { + tape(strictMsg + name, function (t) { s.on('/' + name, test.resp) test.uri = s.url + '/' + name if (strict) { @@ -39,7 +39,7 @@ function runAllTests(strict, s) { } else { test.rejectUnauthorized = false } - request(test, function(err, resp, body) { + request(test, function (err, resp, body) { t.equal(err, null) if (test.expectBody) { t.deepEqual(test.expectBody, body) @@ -50,46 +50,37 @@ function runAllTests(strict, s) { } runTest('testGet', { - resp : server.createGetResponse('TESTING!') - , expectBody: 'TESTING!' + resp: server.createGetResponse('TESTING!'), expectBody: 'TESTING!' }) runTest('testGetChunkBreak', { - resp : server.createChunkResponse( - [ new Buffer([239]) - , new Buffer([163]) - , new Buffer([191]) - , new Buffer([206]) - , new Buffer([169]) - , new Buffer([226]) - , new Buffer([152]) - , new Buffer([131]) - ]) - , expectBody: '\uf8ff\u03a9\u2603' + resp: server.createChunkResponse( + [ new Buffer([239]), + new Buffer([163]), + new Buffer([191]), + new Buffer([206]), + new Buffer([169]), + new Buffer([226]), + new Buffer([152]), + new Buffer([131]) + ]), + expectBody: '\uf8ff\u03a9\u2603' }) runTest('testGetJSON', { - resp : server.createGetResponse('{"test":true}', 'application/json') - , json : true - , expectBody: {'test':true} + resp: server.createGetResponse('{"test":true}', 'application/json'), json: true, expectBody: {'test': true} }) runTest('testPutString', { - resp : server.createPostValidator('PUTTINGDATA') - , method : 'PUT' - , body : 'PUTTINGDATA' + resp: server.createPostValidator('PUTTINGDATA'), method: 'PUT', body: 'PUTTINGDATA' }) runTest('testPutBuffer', { - resp : server.createPostValidator('PUTTINGDATA') - , method : 'PUT' - , body : new Buffer('PUTTINGDATA') + resp: server.createPostValidator('PUTTINGDATA'), method: 'PUT', body: new Buffer('PUTTINGDATA') }) runTest('testPutJSON', { - resp : server.createPostValidator(JSON.stringify({foo: 'bar'})) - , method: 'PUT' - , json: {foo: 'bar'} + resp: server.createPostValidator(JSON.stringify({foo: 'bar'})), method: 'PUT', json: {foo: 'bar'} }) runTest('testPutMultipart', { @@ -101,16 +92,15 @@ function runAllTests(strict, s) { '\r\n--__BOUNDARY__\r\n\r\n' + 'Oh hi.' + '\r\n--__BOUNDARY__--' - ) - , method: 'PUT' - , multipart: - [ {'content-type': 'text/html', 'body': 'Oh hi.'} - , {'body': 'Oh hi.'} - ] + ), + method: 'PUT', + multipart: [ {'content-type': 'text/html', 'body': 'Oh hi.'}, + {'body': 'Oh hi.'} + ] }) - tape(strictMsg + 'cleanup', function(t) { - s.close(function() { + tape(strictMsg + 'cleanup', function (t) { + s.close(function () { t.end() }) }) diff --git a/tests/test-isUrl.js b/tests/test-isUrl.js index cbdd246df..ae7f3ba11 100644 --- a/tests/test-isUrl.js +++ b/tests/test-isUrl.js @@ -1,94 +1,94 @@ 'use strict' var http = require('http') - , request = require('../index') - , tape = require('tape') +var request = require('../index') +var tape = require('tape') -var s = http.createServer(function(req, res) { +var s = http.createServer(function (req, res) { res.statusCode = 200 res.end('ok') }) -tape('setup', function(t) { - s.listen(0, function() { +tape('setup', function (t) { + s.listen(0, function () { s.port = this.address().port s.url = 'http://localhost:' + s.port t.end() }) }) -tape('lowercase', function(t) { - request(s.url, function(err, resp, body) { +tape('lowercase', function (t) { + request(s.url, function (err, resp, body) { t.equal(err, null) t.equal(body, 'ok') t.end() }) }) -tape('uppercase', function(t) { - request(s.url.replace('http', 'HTTP'), function(err, resp, body) { +tape('uppercase', function (t) { + request(s.url.replace('http', 'HTTP'), function (err, resp, body) { t.equal(err, null) t.equal(body, 'ok') t.end() }) }) -tape('mixedcase', function(t) { - request(s.url.replace('http', 'HtTp'), function(err, resp, body) { +tape('mixedcase', function (t) { + request(s.url.replace('http', 'HtTp'), function (err, resp, body) { t.equal(err, null) t.equal(body, 'ok') t.end() }) }) -tape('hostname and port', function(t) { +tape('hostname and port', function (t) { request({ uri: { protocol: 'http:', hostname: 'localhost', port: s.port } - }, function(err, res, body) { + }, function (err, res, body) { t.equal(err, null) t.equal(body, 'ok') t.end() }) }) -tape('hostname and port 1', function(t) { +tape('hostname and port 1', function (t) { request({ uri: { protocol: 'http:', hostname: 'localhost', port: s.port } - }, function(err, res, body) { + }, function (err, res, body) { t.equal(err, null) t.equal(body, 'ok') t.end() }) }) -tape('hostname and port 2', function(t) { +tape('hostname and port 2', function (t) { request({ protocol: 'http:', hostname: 'localhost', port: s.port }, { // need this empty options object, otherwise request thinks no uri was set - }, function(err, res, body) { + }, function (err, res, body) { t.equal(err, null) t.equal(body, 'ok') t.end() }) }) -tape('hostname and port 3', function(t) { +tape('hostname and port 3', function (t) { request({ protocol: 'http:', hostname: 'localhost', port: s.port - }, function(err, res, body) { + }, function (err, res, body) { t.notEqual(err, null) t.equal(err.message, 'options.uri is a required argument') t.equal(body, undefined) @@ -96,7 +96,7 @@ tape('hostname and port 3', function(t) { }) }) -tape('hostname and query string', function(t) { +tape('hostname and query string', function (t) { request({ uri: { protocol: 'http:', @@ -106,15 +106,15 @@ tape('hostname and query string', function(t) { qs: { test: 'test' } - }, function(err, res, body) { + }, function (err, res, body) { t.equal(err, null) t.equal(body, 'ok') t.end() }) }) -tape('cleanup', function(t) { - s.close(function() { +tape('cleanup', function (t) { + s.close(function () { t.end() }) }) diff --git a/tests/test-json-request.js b/tests/test-json-request.js index b89e254e2..af82f15b5 100644 --- a/tests/test-json-request.js +++ b/tests/test-json-request.js @@ -1,19 +1,19 @@ 'use strict' var server = require('./server') - , request = require('../index') - , tape = require('tape') +var request = require('../index') +var tape = require('tape') var s = server.createServer() -tape('setup', function(t) { - s.listen(0, function() { +tape('setup', function (t) { + s.listen(0, function () { t.end() }) }) -function testJSONValue(testId, value) { - tape('test ' + testId, function(t) { +function testJSONValue (testId, value) { + tape('test ' + testId, function (t) { var testUrl = '/' + testId s.on(testUrl, server.createPostJSONValidator(value, 'application/json')) var opts = { @@ -31,8 +31,8 @@ function testJSONValue(testId, value) { }) } -function testJSONValueReviver(testId, value, reviver, revivedValue) { - tape('test ' + testId, function(t) { +function testJSONValueReviver (testId, value, reviver, revivedValue) { + tape('test ' + testId, function (t) { var testUrl = '/' + testId s.on(testUrl, server.createPostJSONValidator(value, 'application/json')) var opts = { @@ -51,8 +51,8 @@ function testJSONValueReviver(testId, value, reviver, revivedValue) { }) } -function testJSONValueReplacer(testId, value, replacer, replacedValue) { - tape('test ' + testId, function(t) { +function testJSONValueReplacer (testId, value, replacer, replacedValue) { + tape('test ' + testId, function (t) { var testUrl = '/' + testId s.on(testUrl, server.createPostJSONValidator(replacedValue, 'application/json')) var opts = { @@ -95,24 +95,23 @@ testJSONValueReviver('jsonReviverInvalid', -48269.592, 'invalid reviver', -48269 testJSONValueReplacer('jsonReplacer', -48269.592, function (k, v) { return v * -1 }, 48269.592) -testJSONValueReplacer('jsonReplacerInvalid', -48269.592,'invalid replacer', -48269.592) +testJSONValueReplacer('jsonReplacerInvalid', -48269.592, 'invalid replacer', -48269.592) testJSONValueReplacer('jsonReplacerObject', {foo: 'bar'}, function (k, v) { return v.toUpperCase ? v.toUpperCase() : v }, {foo: 'BAR'}) - tape('missing body', function (t) { s.on('/missing-body', function (req, res) { t.equal(req.headers['content-type'], undefined) res.end() }) - request({url:s.url + '/missing-body', json:true}, function () { + request({url: s.url + '/missing-body', json: true}, function () { t.end() }) }) -tape('cleanup', function(t) { - s.close(function() { +tape('cleanup', function (t) { + s.close(function () { t.end() }) }) diff --git a/tests/test-localAddress.js b/tests/test-localAddress.js index ea3a4ce7c..88a335326 100644 --- a/tests/test-localAddress.js +++ b/tests/test-localAddress.js @@ -1,6 +1,6 @@ 'use strict' var request = require('../index') - , tape = require('tape') +var tape = require('tape') tape('bind to invalid address', function (t) { request.get({ @@ -39,7 +39,7 @@ tape('bind to local address on redirect', function (t) { }) }) request.get({ - uri: 'http://google.com', //redirects to 'http://google.com' + uri: 'http://google.com', // redirects to 'http://google.com' localAddress: localIPS[0] }, function (err, res) { t.equal(err, null) diff --git a/tests/test-multipart-encoding.js b/tests/test-multipart-encoding.js index 8691f1f76..c88a6f143 100644 --- a/tests/test-multipart-encoding.js +++ b/tests/test-multipart-encoding.js @@ -1,11 +1,10 @@ 'use strict' var http = require('http') - , path = require('path') - , request = require('../index') - , fs = require('fs') - , tape = require('tape') - +var path = require('path') +var request = require('../index') +var fs = require('fs') +var tape = require('tape') var localFile = path.join(__dirname, 'unicycle.jpg') var cases = { @@ -83,10 +82,8 @@ var cases = { } } -function runTest(t, test) { - - var server = http.createServer(function(req, res) { - +function runTest (t, test) { + var server = http.createServer(function (req, res) { t.ok(req.headers['content-type'].match(/^multipart\/related; boundary=[^\s;]+$/)) if (test.expected.chunked) { @@ -101,11 +98,11 @@ function runTest(t, test) { var data = '' req.setEncoding('utf8') - req.on('data', function(d) { + req.on('data', function (d) { data += d }) - req.on('end', function() { + req.on('end', function () { // check for the fields traces if (test.expected.chunked && data.indexOf('name: file') !== -1) { // file @@ -124,7 +121,7 @@ function runTest(t, test) { }) }) - server.listen(0, function() { + server.listen(0, function () { var url = 'http://localhost:' + this.address().port // @NOTE: multipartData properties must be set here // so that file read stream does not leak in node v0.8 @@ -144,7 +141,7 @@ function runTest(t, test) { } Object.keys(cases).forEach(function (name) { - tape('multipart-encoding ' + name, function(t) { + tape('multipart-encoding ' + name, function (t) { runTest(t, cases[name]) }) }) diff --git a/tests/test-multipart.js b/tests/test-multipart.js index c1bf26d23..e52cd0490 100644 --- a/tests/test-multipart.js +++ b/tests/test-multipart.js @@ -1,18 +1,17 @@ 'use strict' var http = require('http') - , path = require('path') - , request = require('../index') - , fs = require('fs') - , tape = require('tape') +var path = require('path') +var request = require('../index') +var fs = require('fs') +var tape = require('tape') - -function runTest(t, a) { +function runTest (t, a) { var remoteFile = path.join(__dirname, 'googledoodle.jpg') - , localFile = path.join(__dirname, 'unicycle.jpg') - , multipartData = [] + var localFile = path.join(__dirname, 'unicycle.jpg') + var multipartData = [] - var server = http.createServer(function(req, res) { + var server = http.createServer(function (req, res) { if (req.url === '/file') { res.writeHead(200, {'content-type': 'image/jpg'}) res.end(fs.readFileSync(remoteFile), 'binary') @@ -34,17 +33,17 @@ function runTest(t, a) { var data = '' req.setEncoding('utf8') - req.on('data', function(d) { + req.on('data', function (d) { data += d }) - req.on('end', function() { + req.on('end', function () { // check for the fields traces // my_field t.ok(data.indexOf('name: my_field') !== -1) t.ok(data.indexOf(multipartData[0].body) !== -1) - + // my_number t.ok(data.indexOf('name: my_number') !== -1) t.ok(data.indexOf(multipartData[1].body) !== -1) @@ -72,7 +71,7 @@ function runTest(t, a) { }) }) - server.listen(0, function() { + server.listen(0, function () { var url = 'http://localhost:' + this.address().port // @NOTE: multipartData properties must be set here so that my_file read stream does not leak in node v0.8 multipartData = [ @@ -99,7 +98,7 @@ function runTest(t, a) { t.equal(err, null) t.equal(res.statusCode, 200) t.deepEqual(body, a.json ? {status: 'done'} : 'done') - server.close(function() { + server.close(function () { t.end() }) }) @@ -113,16 +112,16 @@ var testHeaders = [ ] var methods = ['post', 'get'] -methods.forEach(function(method) { - testHeaders.forEach(function(header) { - [true, false].forEach(function(json) { +methods.forEach(function (method) { + testHeaders.forEach(function (header) { + [true, false].forEach(function (json) { var name = [ 'multipart-related', method.toUpperCase(), (header || 'default'), (json ? '+' : '-') + 'json' ].join(' ') - tape(name, function(t) { + tape(name, function (t) { runTest(t, {method: method, header: header, json: json}) }) }) diff --git a/tests/test-node-debug.js b/tests/test-node-debug.js index 2291bf9c1..bcc6a401d 100644 --- a/tests/test-node-debug.js +++ b/tests/test-node-debug.js @@ -1,36 +1,36 @@ 'use strict' var request = require('../index') - , http = require('http') - , tape = require('tape') +var http = require('http') +var tape = require('tape') -var s = http.createServer(function(req, res) { +var s = http.createServer(function (req, res) { res.statusCode = 200 res.end('') }) var stderr = [] - , prevStderrLen = 0 +var prevStderrLen = 0 -tape('setup', function(t) { +tape('setup', function (t) { process.stderr._oldWrite = process.stderr.write - process.stderr.write = function(string, encoding, fd) { + process.stderr.write = function (string, encoding, fd) { stderr.push(string) } - s.listen(0, function() { + s.listen(0, function () { s.url = 'http://localhost:' + this.address().port t.end() }) }) -tape('a simple request should not fail with debugging enabled', function(t) { +tape('a simple request should not fail with debugging enabled', function (t) { request.debug = true t.equal(request.Request.debug, true, 'request.debug sets request.Request.debug') t.equal(request.debug, true, 'request.debug gets request.Request.debug') stderr = [] - request(s.url, function(err, res, body) { + request(s.url, function (err, res, body) { t.ifError(err, 'the request did not fail') t.ok(res, 'the request did not fail') @@ -38,16 +38,16 @@ tape('a simple request should not fail with debugging enabled', function(t) { var url = s.url.replace(/\//g, '\\/') var patterns = [ /^REQUEST { uri: /, - new RegExp('^REQUEST make request ' + url + '\/\n$'), + new RegExp('^REQUEST make request ' + url + '/\n$'), /^REQUEST onRequestResponse /, /^REQUEST finish init /, /^REQUEST response end /, /^REQUEST end event /, /^REQUEST emitting complete / ] - patterns.forEach(function(pattern) { + patterns.forEach(function (pattern) { var found = false - stderr.forEach(function(msg) { + stderr.forEach(function (msg) { if (pattern.test(msg)) { found = true } @@ -59,11 +59,11 @@ tape('a simple request should not fail with debugging enabled', function(t) { }) }) -tape('there should be no further lookups on process.env', function(t) { +tape('there should be no further lookups on process.env', function (t) { process.env.NODE_DEBUG = '' stderr = [] - request(s.url, function(err, res, body) { + request(s.url, function (err, res, body) { t.ifError(err, 'the request did not fail') t.ok(res, 'the request did not fail') t.equal(stderr.length, prevStderrLen, 'env.NODE_DEBUG is not retested') @@ -71,13 +71,13 @@ tape('there should be no further lookups on process.env', function(t) { }) }) -tape('it should be possible to disable debugging at runtime', function(t) { +tape('it should be possible to disable debugging at runtime', function (t) { request.debug = false t.equal(request.Request.debug, false, 'request.debug sets request.Request.debug') t.equal(request.debug, false, 'request.debug gets request.Request.debug') stderr = [] - request(s.url, function(err, res, body) { + request(s.url, function (err, res, body) { t.ifError(err, 'the request did not fail') t.ok(res, 'the request did not fail') t.equal(stderr.length, 0, 'debugging can be disabled') @@ -85,11 +85,11 @@ tape('it should be possible to disable debugging at runtime', function(t) { }) }) -tape('cleanup', function(t) { +tape('cleanup', function (t) { process.stderr.write = process.stderr._oldWrite delete process.stderr._oldWrite - s.close(function() { + s.close(function () { t.end() }) }) diff --git a/tests/test-oauth.js b/tests/test-oauth.js index dd994f07d..bfb03b971 100644 --- a/tests/test-oauth.js +++ b/tests/test-oauth.js @@ -1,17 +1,17 @@ 'use strict' var oauth = require('oauth-sign') - , qs = require('querystring') - , fs = require('fs') - , path = require('path') - , request = require('../index') - , tape = require('tape') - , crypto = require('crypto') - , http = require('http') - -function getSignature(r) { +var qs = require('querystring') +var fs = require('fs') +var path = require('path') +var request = require('../index') +var tape = require('tape') +var crypto = require('crypto') +var http = require('http') + +function getSignature (r) { var sign - r.headers.Authorization.slice('OAuth '.length).replace(/,\ /g, ',').split(',').forEach(function(v) { + r.headers.Authorization.slice('OAuth '.length).replace(/, /g, ',').split(',').forEach(function (v) { if (v.slice(0, 'oauth_signature="'.length) === 'oauth_signature="') { sign = v.slice('oauth_signature="'.length, -1) } @@ -22,254 +22,247 @@ function getSignature(r) { // Tests from Twitter documentation https://dev.twitter.com/docs/auth/oauth var hmacsign = oauth.hmacsign - , rsasign = oauth.rsasign - , rsa_private_pem = fs.readFileSync(path.join(__dirname, 'ssl', 'test.key')) - , reqsign - , reqsign_rsa - , accsign - , accsign_rsa - , upsign - , upsign_rsa - -tape('reqsign', function(t) { +var rsasign = oauth.rsasign +var rsaPrivatePEM = fs.readFileSync(path.join(__dirname, 'ssl', 'test.key')) +var reqsign +var reqsignRSA +var accsign +var accsignRSA +var upsign +var upsignRSA + +tape('reqsign', function (t) { reqsign = hmacsign('POST', 'https://api.twitter.com/oauth/request_token', - { oauth_callback: 'http://localhost:3005/the_dance/process_callback?service_provider_id=11' - , oauth_consumer_key: 'GDdmIQH6jhtmLUypg82g' - , oauth_nonce: 'QP70eNmVz8jvdPevU3oJD2AfF7R7odC2XJcn4XlZJqk' - , oauth_signature_method: 'HMAC-SHA1' - , oauth_timestamp: '1272323042' - , oauth_version: '1.0' + { oauth_callback: 'http://localhost:3005/the_dance/process_callback?service_provider_id=11', + oauth_consumer_key: 'GDdmIQH6jhtmLUypg82g', + oauth_nonce: 'QP70eNmVz8jvdPevU3oJD2AfF7R7odC2XJcn4XlZJqk', + oauth_signature_method: 'HMAC-SHA1', + oauth_timestamp: '1272323042', + oauth_version: '1.0' }, 'MCD8BKwGdgPHvAuvgvz4EQpqDAtx89grbuNMRd7Eh98') t.equal(reqsign, '8wUi7m5HFQy76nowoCThusfgB+Q=') t.end() }) -tape('reqsign_rsa', function(t) { - reqsign_rsa = rsasign('POST', 'https://api.twitter.com/oauth/request_token', - { oauth_callback: 'http://localhost:3005/the_dance/process_callback?service_provider_id=11' - , oauth_consumer_key: 'GDdmIQH6jhtmLUypg82g' - , oauth_nonce: 'QP70eNmVz8jvdPevU3oJD2AfF7R7odC2XJcn4XlZJqk' - , oauth_signature_method: 'RSA-SHA1' - , oauth_timestamp: '1272323042' - , oauth_version: '1.0' - }, rsa_private_pem, 'this parameter is not used for RSA signing') - - t.equal(reqsign_rsa, 'MXdzEnIrQco3ACPoVWxCwv5pxYrm5MFRXbsP3LfRV+zfcRr+WMp/dOPS/3r+Wcb+17Z2IK3uJ8dMHfzb5LiDNCTUIj7SWBrbxOpy3Y6SA6z3vcrtjSekkTHLek1j+mzxOi3r3fkbYaNwjHx3PyoFSazbEstnkQQotbITeFt5FBE=') +tape('reqsignRSA', function (t) { + reqsignRSA = rsasign('POST', 'https://api.twitter.com/oauth/request_token', + { oauth_callback: 'http://localhost:3005/the_dance/process_callback?service_provider_id=11', + oauth_consumer_key: 'GDdmIQH6jhtmLUypg82g', + oauth_nonce: 'QP70eNmVz8jvdPevU3oJD2AfF7R7odC2XJcn4XlZJqk', + oauth_signature_method: 'RSA-SHA1', + oauth_timestamp: '1272323042', + oauth_version: '1.0' + }, rsaPrivatePEM, 'this parameter is not used for RSA signing') + + t.equal(reqsignRSA, 'MXdzEnIrQco3ACPoVWxCwv5pxYrm5MFRXbsP3LfRV+zfcRr+WMp/dOPS/3r+Wcb+17Z2IK3uJ8dMHfzb5LiDNCTUIj7SWBrbxOpy3Y6SA6z3vcrtjSekkTHLek1j+mzxOi3r3fkbYaNwjHx3PyoFSazbEstnkQQotbITeFt5FBE=') t.end() }) -tape('accsign', function(t) { +tape('accsign', function (t) { accsign = hmacsign('POST', 'https://api.twitter.com/oauth/access_token', - { oauth_consumer_key: 'GDdmIQH6jhtmLUypg82g' - , oauth_nonce: '9zWH6qe0qG7Lc1telCn7FhUbLyVdjEaL3MO5uHxn8' - , oauth_signature_method: 'HMAC-SHA1' - , oauth_token: '8ldIZyxQeVrFZXFOZH5tAwj6vzJYuLQpl0WUEYtWc' - , oauth_timestamp: '1272323047' - , oauth_verifier: 'pDNg57prOHapMbhv25RNf75lVRd6JDsni1AJJIDYoTY' - , oauth_version: '1.0' + { oauth_consumer_key: 'GDdmIQH6jhtmLUypg82g', + oauth_nonce: '9zWH6qe0qG7Lc1telCn7FhUbLyVdjEaL3MO5uHxn8', + oauth_signature_method: 'HMAC-SHA1', + oauth_token: '8ldIZyxQeVrFZXFOZH5tAwj6vzJYuLQpl0WUEYtWc', + oauth_timestamp: '1272323047', + oauth_verifier: 'pDNg57prOHapMbhv25RNf75lVRd6JDsni1AJJIDYoTY', + oauth_version: '1.0' }, 'MCD8BKwGdgPHvAuvgvz4EQpqDAtx89grbuNMRd7Eh98', 'x6qpRnlEmW9JbQn4PQVVeVG8ZLPEx6A0TOebgwcuA') t.equal(accsign, 'PUw/dHA4fnlJYM6RhXk5IU/0fCc=') t.end() }) -tape('accsign_rsa', function(t) { - accsign_rsa = rsasign('POST', 'https://api.twitter.com/oauth/access_token', - { oauth_consumer_key: 'GDdmIQH6jhtmLUypg82g' - , oauth_nonce: '9zWH6qe0qG7Lc1telCn7FhUbLyVdjEaL3MO5uHxn8' - , oauth_signature_method: 'RSA-SHA1' - , oauth_token: '8ldIZyxQeVrFZXFOZH5tAwj6vzJYuLQpl0WUEYtWc' - , oauth_timestamp: '1272323047' - , oauth_verifier: 'pDNg57prOHapMbhv25RNf75lVRd6JDsni1AJJIDYoTY' - , oauth_version: '1.0' - }, rsa_private_pem) - - t.equal(accsign_rsa, 'gZrMPexdgGMVUl9H6RxK0MbR6Db8tzf2kIIj52kOrDFcMgh4BunMBgUZAO1msUwz6oqZIvkVqyfyDAOP2wIrpYem0mBg3vqwPIroSE1AlUWo+TtQxOTuqrU+3kDcXpdvJe7CAX5hUx9Np/iGRqaCcgByqb9DaCcQ9ViQ+0wJiXI=') +tape('accsignRSA', function (t) { + accsignRSA = rsasign('POST', 'https://api.twitter.com/oauth/access_token', + { oauth_consumer_key: 'GDdmIQH6jhtmLUypg82g', + oauth_nonce: '9zWH6qe0qG7Lc1telCn7FhUbLyVdjEaL3MO5uHxn8', + oauth_signature_method: 'RSA-SHA1', + oauth_token: '8ldIZyxQeVrFZXFOZH5tAwj6vzJYuLQpl0WUEYtWc', + oauth_timestamp: '1272323047', + oauth_verifier: 'pDNg57prOHapMbhv25RNf75lVRd6JDsni1AJJIDYoTY', + oauth_version: '1.0' + }, rsaPrivatePEM) + + t.equal(accsignRSA, 'gZrMPexdgGMVUl9H6RxK0MbR6Db8tzf2kIIj52kOrDFcMgh4BunMBgUZAO1msUwz6oqZIvkVqyfyDAOP2wIrpYem0mBg3vqwPIroSE1AlUWo+TtQxOTuqrU+3kDcXpdvJe7CAX5hUx9Np/iGRqaCcgByqb9DaCcQ9ViQ+0wJiXI=') t.end() }) -tape('upsign', function(t) { +tape('upsign', function (t) { upsign = hmacsign('POST', 'http://api.twitter.com/1/statuses/update.json', - { oauth_consumer_key: 'GDdmIQH6jhtmLUypg82g' - , oauth_nonce: 'oElnnMTQIZvqvlfXM56aBLAf5noGD0AQR3Fmi7Q6Y' - , oauth_signature_method: 'HMAC-SHA1' - , oauth_token: '819797-Jxq8aYUDRmykzVKrgoLhXSq67TEa5ruc4GJC2rWimw' - , oauth_timestamp: '1272325550' - , oauth_version: '1.0' - , status: 'setting up my twitter 私のさえずりを設定する' + { oauth_consumer_key: 'GDdmIQH6jhtmLUypg82g', + oauth_nonce: 'oElnnMTQIZvqvlfXM56aBLAf5noGD0AQR3Fmi7Q6Y', + oauth_signature_method: 'HMAC-SHA1', + oauth_token: '819797-Jxq8aYUDRmykzVKrgoLhXSq67TEa5ruc4GJC2rWimw', + oauth_timestamp: '1272325550', + oauth_version: '1.0', + status: 'setting up my twitter 私のさえずりを設定する' }, 'MCD8BKwGdgPHvAuvgvz4EQpqDAtx89grbuNMRd7Eh98', 'J6zix3FfA9LofH0awS24M3HcBYXO5nI1iYe8EfBA') t.equal(upsign, 'yOahq5m0YjDDjfjxHaXEsW9D+X0=') t.end() }) -tape('upsign_rsa', function(t) { - upsign_rsa = rsasign('POST', 'http://api.twitter.com/1/statuses/update.json', - { oauth_consumer_key: 'GDdmIQH6jhtmLUypg82g' - , oauth_nonce: 'oElnnMTQIZvqvlfXM56aBLAf5noGD0AQR3Fmi7Q6Y' - , oauth_signature_method: 'RSA-SHA1' - , oauth_token: '819797-Jxq8aYUDRmykzVKrgoLhXSq67TEa5ruc4GJC2rWimw' - , oauth_timestamp: '1272325550' - , oauth_version: '1.0' - , status: 'setting up my twitter 私のさえずりを設定する' - }, rsa_private_pem) - - t.equal(upsign_rsa, 'fF4G9BNzDxPu/htctzh9CWzGhtXo9DYYl+ZyRO1/QNOhOZPqnWVUOT+CGUKxmAeJSzLKMAH8y/MFSHI0lzihqwgfZr7nUhTx6kH7lUChcVasr+TZ4qPqvGGEhfJ8Av8D5dF5fytfCSzct62uONU0iHYVqainP+zefk1K7Ptb6hI=') +tape('upsignRSA', function (t) { + upsignRSA = rsasign('POST', 'http://api.twitter.com/1/statuses/update.json', + { oauth_consumer_key: 'GDdmIQH6jhtmLUypg82g', + oauth_nonce: 'oElnnMTQIZvqvlfXM56aBLAf5noGD0AQR3Fmi7Q6Y', + oauth_signature_method: 'RSA-SHA1', + oauth_token: '819797-Jxq8aYUDRmykzVKrgoLhXSq67TEa5ruc4GJC2rWimw', + oauth_timestamp: '1272325550', + oauth_version: '1.0', + status: 'setting up my twitter 私のさえずりを設定する' + }, rsaPrivatePEM) + + t.equal(upsignRSA, 'fF4G9BNzDxPu/htctzh9CWzGhtXo9DYYl+ZyRO1/QNOhOZPqnWVUOT+CGUKxmAeJSzLKMAH8y/MFSHI0lzihqwgfZr7nUhTx6kH7lUChcVasr+TZ4qPqvGGEhfJ8Av8D5dF5fytfCSzct62uONU0iHYVqainP+zefk1K7Ptb6hI=') t.end() }) -tape('rsign', function(t) { +tape('rsign', function (t) { var rsign = request.post( - { url: 'https://api.twitter.com/oauth/request_token' - , oauth: - { callback: 'http://localhost:3005/the_dance/process_callback?service_provider_id=11' - , consumer_key: 'GDdmIQH6jhtmLUypg82g' - , nonce: 'QP70eNmVz8jvdPevU3oJD2AfF7R7odC2XJcn4XlZJqk' - , timestamp: '1272323042' - , version: '1.0' - , consumer_secret: 'MCD8BKwGdgPHvAuvgvz4EQpqDAtx89grbuNMRd7Eh98' + { url: 'https://api.twitter.com/oauth/request_token', + oauth: { callback: 'http://localhost:3005/the_dance/process_callback?service_provider_id=11', + consumer_key: 'GDdmIQH6jhtmLUypg82g', + nonce: 'QP70eNmVz8jvdPevU3oJD2AfF7R7odC2XJcn4XlZJqk', + timestamp: '1272323042', + version: '1.0', + consumer_secret: 'MCD8BKwGdgPHvAuvgvz4EQpqDAtx89grbuNMRd7Eh98' } }) - process.nextTick(function() { + process.nextTick(function () { t.equal(reqsign, getSignature(rsign)) rsign.abort() t.end() }) }) -tape('rsign_rsa', function(t) { - var rsign_rsa = request.post( - { url: 'https://api.twitter.com/oauth/request_token' - , oauth: - { callback: 'http://localhost:3005/the_dance/process_callback?service_provider_id=11' - , consumer_key: 'GDdmIQH6jhtmLUypg82g' - , nonce: 'QP70eNmVz8jvdPevU3oJD2AfF7R7odC2XJcn4XlZJqk' - , timestamp: '1272323042' - , version: '1.0' - , private_key: rsa_private_pem - , signature_method: 'RSA-SHA1' +tape('rsign_rsa', function (t) { + var rsignRSA = request.post( + { url: 'https://api.twitter.com/oauth/request_token', + oauth: { callback: 'http://localhost:3005/the_dance/process_callback?service_provider_id=11', + consumer_key: 'GDdmIQH6jhtmLUypg82g', + nonce: 'QP70eNmVz8jvdPevU3oJD2AfF7R7odC2XJcn4XlZJqk', + timestamp: '1272323042', + version: '1.0', + private_key: rsaPrivatePEM, + signature_method: 'RSA-SHA1' } }) - process.nextTick(function() { - t.equal(reqsign_rsa, getSignature(rsign_rsa)) - rsign_rsa.abort() + process.nextTick(function () { + t.equal(reqsignRSA, getSignature(rsignRSA)) + rsignRSA.abort() t.end() }) }) -tape('raccsign', function(t) { +tape('raccsign', function (t) { var raccsign = request.post( - { url: 'https://api.twitter.com/oauth/access_token' - , oauth: - { consumer_key: 'GDdmIQH6jhtmLUypg82g' - , nonce: '9zWH6qe0qG7Lc1telCn7FhUbLyVdjEaL3MO5uHxn8' - , signature_method: 'HMAC-SHA1' - , token: '8ldIZyxQeVrFZXFOZH5tAwj6vzJYuLQpl0WUEYtWc' - , timestamp: '1272323047' - , verifier: 'pDNg57prOHapMbhv25RNf75lVRd6JDsni1AJJIDYoTY' - , version: '1.0' - , consumer_secret: 'MCD8BKwGdgPHvAuvgvz4EQpqDAtx89grbuNMRd7Eh98' - , token_secret: 'x6qpRnlEmW9JbQn4PQVVeVG8ZLPEx6A0TOebgwcuA' + { url: 'https://api.twitter.com/oauth/access_token', + oauth: { consumer_key: 'GDdmIQH6jhtmLUypg82g', + nonce: '9zWH6qe0qG7Lc1telCn7FhUbLyVdjEaL3MO5uHxn8', + signature_method: 'HMAC-SHA1', + token: '8ldIZyxQeVrFZXFOZH5tAwj6vzJYuLQpl0WUEYtWc', + timestamp: '1272323047', + verifier: 'pDNg57prOHapMbhv25RNf75lVRd6JDsni1AJJIDYoTY', + version: '1.0', + consumer_secret: 'MCD8BKwGdgPHvAuvgvz4EQpqDAtx89grbuNMRd7Eh98', + token_secret: 'x6qpRnlEmW9JbQn4PQVVeVG8ZLPEx6A0TOebgwcuA' } }) - process.nextTick(function() { + process.nextTick(function () { t.equal(accsign, getSignature(raccsign)) raccsign.abort() t.end() }) }) -tape('raccsign_rsa', function(t) { - var raccsign_rsa = request.post( - { url: 'https://api.twitter.com/oauth/access_token' - , oauth: - { consumer_key: 'GDdmIQH6jhtmLUypg82g' - , nonce: '9zWH6qe0qG7Lc1telCn7FhUbLyVdjEaL3MO5uHxn8' - , signature_method: 'RSA-SHA1' - , token: '8ldIZyxQeVrFZXFOZH5tAwj6vzJYuLQpl0WUEYtWc' - , timestamp: '1272323047' - , verifier: 'pDNg57prOHapMbhv25RNf75lVRd6JDsni1AJJIDYoTY' - , version: '1.0' - , private_key: rsa_private_pem - , token_secret: 'x6qpRnlEmW9JbQn4PQVVeVG8ZLPEx6A0TOebgwcuA' +tape('raccsignRSA', function (t) { + var raccsignRSA = request.post( + { url: 'https://api.twitter.com/oauth/access_token', + oauth: { consumer_key: 'GDdmIQH6jhtmLUypg82g', + nonce: '9zWH6qe0qG7Lc1telCn7FhUbLyVdjEaL3MO5uHxn8', + signature_method: 'RSA-SHA1', + token: '8ldIZyxQeVrFZXFOZH5tAwj6vzJYuLQpl0WUEYtWc', + timestamp: '1272323047', + verifier: 'pDNg57prOHapMbhv25RNf75lVRd6JDsni1AJJIDYoTY', + version: '1.0', + private_key: rsaPrivatePEM, + token_secret: 'x6qpRnlEmW9JbQn4PQVVeVG8ZLPEx6A0TOebgwcuA' } }) - process.nextTick(function() { - t.equal(accsign_rsa, getSignature(raccsign_rsa)) - raccsign_rsa.abort() + process.nextTick(function () { + t.equal(accsignRSA, getSignature(raccsignRSA)) + raccsignRSA.abort() t.end() }) }) -tape('rupsign', function(t) { +tape('rupsign', function (t) { var rupsign = request.post( - { url: 'http://api.twitter.com/1/statuses/update.json' - , oauth: - { consumer_key: 'GDdmIQH6jhtmLUypg82g' - , nonce: 'oElnnMTQIZvqvlfXM56aBLAf5noGD0AQR3Fmi7Q6Y' - , signature_method: 'HMAC-SHA1' - , token: '819797-Jxq8aYUDRmykzVKrgoLhXSq67TEa5ruc4GJC2rWimw' - , timestamp: '1272325550' - , version: '1.0' - , consumer_secret: 'MCD8BKwGdgPHvAuvgvz4EQpqDAtx89grbuNMRd7Eh98' - , token_secret: 'J6zix3FfA9LofH0awS24M3HcBYXO5nI1iYe8EfBA' - } - , form: {status: 'setting up my twitter 私のさえずりを設定する'} + { url: 'http://api.twitter.com/1/statuses/update.json', + oauth: { consumer_key: 'GDdmIQH6jhtmLUypg82g', + nonce: 'oElnnMTQIZvqvlfXM56aBLAf5noGD0AQR3Fmi7Q6Y', + signature_method: 'HMAC-SHA1', + token: '819797-Jxq8aYUDRmykzVKrgoLhXSq67TEa5ruc4GJC2rWimw', + timestamp: '1272325550', + version: '1.0', + consumer_secret: 'MCD8BKwGdgPHvAuvgvz4EQpqDAtx89grbuNMRd7Eh98', + token_secret: 'J6zix3FfA9LofH0awS24M3HcBYXO5nI1iYe8EfBA' + }, + form: {status: 'setting up my twitter 私のさえずりを設定する'} }) - process.nextTick(function() { + process.nextTick(function () { t.equal(upsign, getSignature(rupsign)) rupsign.abort() t.end() }) }) -tape('rupsign_rsa', function(t) { - var rupsign_rsa = request.post( - { url: 'http://api.twitter.com/1/statuses/update.json' - , oauth: - { consumer_key: 'GDdmIQH6jhtmLUypg82g' - , nonce: 'oElnnMTQIZvqvlfXM56aBLAf5noGD0AQR3Fmi7Q6Y' - , signature_method: 'RSA-SHA1' - , token: '819797-Jxq8aYUDRmykzVKrgoLhXSq67TEa5ruc4GJC2rWimw' - , timestamp: '1272325550' - , version: '1.0' - , private_key: rsa_private_pem - , token_secret: 'J6zix3FfA9LofH0awS24M3HcBYXO5nI1iYe8EfBA' - } - , form: {status: 'setting up my twitter 私のさえずりを設定する'} +tape('rupsignRSA', function (t) { + var rupsignRSA = request.post( + { url: 'http://api.twitter.com/1/statuses/update.json', + oauth: { consumer_key: 'GDdmIQH6jhtmLUypg82g', + nonce: 'oElnnMTQIZvqvlfXM56aBLAf5noGD0AQR3Fmi7Q6Y', + signature_method: 'RSA-SHA1', + token: '819797-Jxq8aYUDRmykzVKrgoLhXSq67TEa5ruc4GJC2rWimw', + timestamp: '1272325550', + version: '1.0', + private_key: rsaPrivatePEM, + token_secret: 'J6zix3FfA9LofH0awS24M3HcBYXO5nI1iYe8EfBA' + }, + form: {status: 'setting up my twitter 私のさえずりを設定する'} }) - process.nextTick(function() { - t.equal(upsign_rsa, getSignature(rupsign_rsa)) - rupsign_rsa.abort() + process.nextTick(function () { + t.equal(upsignRSA, getSignature(rupsignRSA)) + rupsignRSA.abort() t.end() }) }) -tape('rfc5849 example', function(t) { +tape('rfc5849 example', function (t) { var rfc5849 = request.post( - { url: 'http://example.com/request?b5=%3D%253D&a3=a&c%40=&a2=r%20b' - , oauth: - { consumer_key: '9djdj82h48djs9d2' - , nonce: '7d8f3e4a' - , signature_method: 'HMAC-SHA1' - , token: 'kkk9d7dh3k39sjv7' - , timestamp: '137131201' - , consumer_secret: 'j49sk3j29djd' - , token_secret: 'dh893hdasih9' - , realm: 'Example' - } - , form: { - c2: '', - a3: '2 q' - } + { url: 'http://example.com/request?b5=%3D%253D&a3=a&c%40=&a2=r%20b', + oauth: { consumer_key: '9djdj82h48djs9d2', + nonce: '7d8f3e4a', + signature_method: 'HMAC-SHA1', + token: 'kkk9d7dh3k39sjv7', + timestamp: '137131201', + consumer_secret: 'j49sk3j29djd', + token_secret: 'dh893hdasih9', + realm: 'Example' + }, + form: { + c2: '', + a3: '2 q' + } }) - process.nextTick(function() { + process.nextTick(function () { // different signature in rfc5849 because request sets oauth_version by default t.equal('OB33pYjWAnf+xtOHN4Gmbdil168=', getSignature(rfc5849)) rfc5849.abort() @@ -277,110 +270,104 @@ tape('rfc5849 example', function(t) { }) }) -tape('rfc5849 RSA example', function(t) { - var rfc5849_rsa = request.post( - { url: 'http://example.com/request?b5=%3D%253D&a3=a&c%40=&a2=r%20b' - , oauth: - { consumer_key: '9djdj82h48djs9d2' - , nonce: '7d8f3e4a' - , signature_method: 'RSA-SHA1' - , token: 'kkk9d7dh3k39sjv7' - , timestamp: '137131201' - , private_key: rsa_private_pem - , token_secret: 'dh893hdasih9' - , realm: 'Example' +tape('rfc5849 RSA example', function (t) { + var rfc5849RSA = request.post( + { url: 'http://example.com/request?b5=%3D%253D&a3=a&c%40=&a2=r%20b', + oauth: { consumer_key: '9djdj82h48djs9d2', + nonce: '7d8f3e4a', + signature_method: 'RSA-SHA1', + token: 'kkk9d7dh3k39sjv7', + timestamp: '137131201', + private_key: rsaPrivatePEM, + token_secret: 'dh893hdasih9', + realm: 'Example' + }, + form: { + c2: '', + a3: '2 q' } - , form: { - c2: '', - a3: '2 q' - } }) - process.nextTick(function() { + process.nextTick(function () { // different signature in rfc5849 because request sets oauth_version by default - t.equal('ThNYfZhYogcAU6rWgI3ZFlPEhoIXHMZcuMzl+jykJZW/ab+AxyefS03dyd64CclIZ0u8JEW64TQ5SHthoQS8aM8qir4t+t88lRF3LDkD2KtS1krgCZTUQxkDL5BO5pxsqAQ2Zfdcrzaxb6VMGD1Hf+Pno+fsHQo/UUKjq4V3RMo=', getSignature(rfc5849_rsa)) - rfc5849_rsa.abort() + t.equal('ThNYfZhYogcAU6rWgI3ZFlPEhoIXHMZcuMzl+jykJZW/ab+AxyefS03dyd64CclIZ0u8JEW64TQ5SHthoQS8aM8qir4t+t88lRF3LDkD2KtS1krgCZTUQxkDL5BO5pxsqAQ2Zfdcrzaxb6VMGD1Hf+Pno+fsHQo/UUKjq4V3RMo=', getSignature(rfc5849RSA)) + rfc5849RSA.abort() t.end() }) }) -tape('plaintext signature method', function(t) { +tape('plaintext signature method', function (t) { var plaintext = request.post( - { url: 'https://dummy.com' - , oauth: - { consumer_secret: 'consumer_secret' - , token_secret: 'token_secret' - , signature_method: 'PLAINTEXT' + { url: 'https://dummy.com', + oauth: { consumer_secret: 'consumer_secret', + token_secret: 'token_secret', + signature_method: 'PLAINTEXT' } }) - process.nextTick(function() { + process.nextTick(function () { t.equal('consumer_secret&token_secret', getSignature(plaintext)) plaintext.abort() t.end() }) }) -tape('invalid transport_method', function(t) { +tape('invalid transport_method', function (t) { t.throws( function () { request.post( - { url: 'http://example.com/' - , oauth: - { transport_method: 'headerquery' - } - }) + { url: 'http://example.com/', + oauth: { transport_method: 'headerquery' + } + }) }, /transport_method invalid/) t.end() }) -tape('invalid method while using transport_method \'body\'', function(t) { +tape("invalid method while using transport_method 'body'", function (t) { t.throws( function () { request.get( - { url: 'http://example.com/' - , headers: { 'content-type': 'application/x-www-form-urlencoded; charset=UTF-8' } - , oauth: - { transport_method: 'body' - } - }) + { url: 'http://example.com/', + headers: { 'content-type': 'application/x-www-form-urlencoded; charset=UTF-8' }, + oauth: { transport_method: 'body' + } + }) }, /requires POST/) t.end() }) -tape('invalid content-type while using transport_method \'body\'', function(t) { +tape("invalid content-type while using transport_method 'body'", function (t) { t.throws( function () { request.post( - { url: 'http://example.com/' - , headers: { 'content-type': 'application/json; charset=UTF-8' } - , oauth: - { transport_method: 'body' - } - }) + { url: 'http://example.com/', + headers: { 'content-type': 'application/json; charset=UTF-8' }, + oauth: { transport_method: 'body' + } + }) }, /requires POST/) t.end() }) -tape('query transport_method', function(t) { +tape('query transport_method', function (t) { var r = request.post( - { url: 'https://api.twitter.com/oauth/access_token' - , oauth: - { consumer_key: 'GDdmIQH6jhtmLUypg82g' - , nonce: '9zWH6qe0qG7Lc1telCn7FhUbLyVdjEaL3MO5uHxn8' - , signature_method: 'HMAC-SHA1' - , token: '8ldIZyxQeVrFZXFOZH5tAwj6vzJYuLQpl0WUEYtWc' - , timestamp: '1272323047' - , verifier: 'pDNg57prOHapMbhv25RNf75lVRd6JDsni1AJJIDYoTY' - , version: '1.0' - , consumer_secret: 'MCD8BKwGdgPHvAuvgvz4EQpqDAtx89grbuNMRd7Eh98' - , token_secret: 'x6qpRnlEmW9JbQn4PQVVeVG8ZLPEx6A0TOebgwcuA' - , transport_method: 'query' + { url: 'https://api.twitter.com/oauth/access_token', + oauth: { consumer_key: 'GDdmIQH6jhtmLUypg82g', + nonce: '9zWH6qe0qG7Lc1telCn7FhUbLyVdjEaL3MO5uHxn8', + signature_method: 'HMAC-SHA1', + token: '8ldIZyxQeVrFZXFOZH5tAwj6vzJYuLQpl0WUEYtWc', + timestamp: '1272323047', + verifier: 'pDNg57prOHapMbhv25RNf75lVRd6JDsni1AJJIDYoTY', + version: '1.0', + consumer_secret: 'MCD8BKwGdgPHvAuvgvz4EQpqDAtx89grbuNMRd7Eh98', + token_secret: 'x6qpRnlEmW9JbQn4PQVVeVG8ZLPEx6A0TOebgwcuA', + transport_method: 'query' } }) - process.nextTick(function() { - t.notOk(r.headers.Authorization, 'oauth Authorization header should not be present with transport_method \'query\'') + process.nextTick(function () { + t.notOk(r.headers.Authorization, "oauth Authorization header should not be present with transport_method 'query'") t.equal(r.uri.path, r.path, 'r.uri.path should equal r.path') t.ok(r.path.match(/^\/oauth\/access_token\?/), 'path should contain path + query') t.deepEqual(qs.parse(r.uri.query), @@ -397,28 +384,27 @@ tape('query transport_method', function(t) { }) }) -tape('query transport_method + form option + url params', function(t) { +tape('query transport_method + form option + url params', function (t) { var r = request.post( - { url: 'http://example.com/request?b5=%3D%253D&a3=a&c%40=&a2=r%20b' - , oauth: - { consumer_key: '9djdj82h48djs9d2' - , nonce: '7d8f3e4a' - , signature_method: 'HMAC-SHA1' - , token: 'kkk9d7dh3k39sjv7' - , timestamp: '137131201' - , consumer_secret: 'j49sk3j29djd' - , token_secret: 'dh893hdasih9' - , realm: 'Example' - , transport_method: 'query' + { url: 'http://example.com/request?b5=%3D%253D&a3=a&c%40=&a2=r%20b', + oauth: { consumer_key: '9djdj82h48djs9d2', + nonce: '7d8f3e4a', + signature_method: 'HMAC-SHA1', + token: 'kkk9d7dh3k39sjv7', + timestamp: '137131201', + consumer_secret: 'j49sk3j29djd', + token_secret: 'dh893hdasih9', + realm: 'Example', + transport_method: 'query' + }, + form: { + c2: '', + a3: '2 q' } - , form: { - c2: '', - a3: '2 q' - } }) - process.nextTick(function() { - t.notOk(r.headers.Authorization, 'oauth Authorization header should not be present with transport_method \'query\'') + process.nextTick(function () { + t.notOk(r.headers.Authorization, "oauth Authorization header should not be present with transport_method 'query'") t.equal(r.uri.path, r.path, 'r.uri.path should equal r.path') t.ok(r.path.match(/^\/request\?/), 'path should contain path + query') t.deepEqual(qs.parse(r.uri.query), @@ -439,30 +425,29 @@ tape('query transport_method + form option + url params', function(t) { }) }) -tape('query transport_method + qs option + url params', function(t) { +tape('query transport_method + qs option + url params', function (t) { var r = request.post( - { url: 'http://example.com/request?a2=r%20b' - , oauth: - { consumer_key: '9djdj82h48djs9d2' - , nonce: '7d8f3e4a' - , signature_method: 'HMAC-SHA1' - , token: 'kkk9d7dh3k39sjv7' - , timestamp: '137131201' - , consumer_secret: 'j49sk3j29djd' - , token_secret: 'dh893hdasih9' - , realm: 'Example' - , transport_method: 'query' + { url: 'http://example.com/request?a2=r%20b', + oauth: { consumer_key: '9djdj82h48djs9d2', + nonce: '7d8f3e4a', + signature_method: 'HMAC-SHA1', + token: 'kkk9d7dh3k39sjv7', + timestamp: '137131201', + consumer_secret: 'j49sk3j29djd', + token_secret: 'dh893hdasih9', + realm: 'Example', + transport_method: 'query' + }, + qs: { + b5: '=%3D', + a3: ['a', '2 q'], + 'c@': '', + c2: '' } - , qs: { - b5: '=%3D', - a3: ['a', '2 q'], - 'c@': '', - c2: '' - } - }) + }) - process.nextTick(function() { - t.notOk(r.headers.Authorization, 'oauth Authorization header should not be present with transport_method \'query\'') + process.nextTick(function () { + t.notOk(r.headers.Authorization, "oauth Authorization header should not be present with transport_method 'query'") t.equal(r.uri.path, r.path, 'r.uri.path should equal r.path') t.ok(r.path.match(/^\/request\?/), 'path should contain path + query') t.deepEqual(qs.parse(r.uri.query), @@ -485,26 +470,25 @@ tape('query transport_method + qs option + url params', function(t) { }) }) -tape('body transport_method', function(t) { +tape('body transport_method', function (t) { var r = request.post( - { url: 'https://api.twitter.com/oauth/access_token' - , headers: { 'content-type': 'application/x-www-form-urlencoded; charset=UTF-8' } - , oauth: - { consumer_key: 'GDdmIQH6jhtmLUypg82g' - , nonce: '9zWH6qe0qG7Lc1telCn7FhUbLyVdjEaL3MO5uHxn8' - , signature_method: 'HMAC-SHA1' - , token: '8ldIZyxQeVrFZXFOZH5tAwj6vzJYuLQpl0WUEYtWc' - , timestamp: '1272323047' - , verifier: 'pDNg57prOHapMbhv25RNf75lVRd6JDsni1AJJIDYoTY' - , version: '1.0' - , consumer_secret: 'MCD8BKwGdgPHvAuvgvz4EQpqDAtx89grbuNMRd7Eh98' - , token_secret: 'x6qpRnlEmW9JbQn4PQVVeVG8ZLPEx6A0TOebgwcuA' - , transport_method: 'body' + { url: 'https://api.twitter.com/oauth/access_token', + headers: { 'content-type': 'application/x-www-form-urlencoded; charset=UTF-8' }, + oauth: { consumer_key: 'GDdmIQH6jhtmLUypg82g', + nonce: '9zWH6qe0qG7Lc1telCn7FhUbLyVdjEaL3MO5uHxn8', + signature_method: 'HMAC-SHA1', + token: '8ldIZyxQeVrFZXFOZH5tAwj6vzJYuLQpl0WUEYtWc', + timestamp: '1272323047', + verifier: 'pDNg57prOHapMbhv25RNf75lVRd6JDsni1AJJIDYoTY', + version: '1.0', + consumer_secret: 'MCD8BKwGdgPHvAuvgvz4EQpqDAtx89grbuNMRd7Eh98', + token_secret: 'x6qpRnlEmW9JbQn4PQVVeVG8ZLPEx6A0TOebgwcuA', + transport_method: 'body' } }) - process.nextTick(function() { - t.notOk(r.headers.Authorization, 'oauth Authorization header should not be present with transport_method \'body\'') + process.nextTick(function () { + t.notOk(r.headers.Authorization, "oauth Authorization header should not be present with transport_method 'body'") t.deepEqual(qs.parse(r.body), { oauth_consumer_key: 'GDdmIQH6jhtmLUypg82g', oauth_nonce: '9zWH6qe0qG7Lc1telCn7FhUbLyVdjEaL3MO5uHxn8', @@ -519,28 +503,27 @@ tape('body transport_method', function(t) { }) }) -tape('body transport_method + form option + url params', function(t) { +tape('body transport_method + form option + url params', function (t) { var r = request.post( - { url: 'http://example.com/request?b5=%3D%253D&a3=a&c%40=&a2=r%20b' - , oauth: - { consumer_key: '9djdj82h48djs9d2' - , nonce: '7d8f3e4a' - , signature_method: 'HMAC-SHA1' - , token: 'kkk9d7dh3k39sjv7' - , timestamp: '137131201' - , consumer_secret: 'j49sk3j29djd' - , token_secret: 'dh893hdasih9' - , realm: 'Example' - , transport_method: 'body' + { url: 'http://example.com/request?b5=%3D%253D&a3=a&c%40=&a2=r%20b', + oauth: { consumer_key: '9djdj82h48djs9d2', + nonce: '7d8f3e4a', + signature_method: 'HMAC-SHA1', + token: 'kkk9d7dh3k39sjv7', + timestamp: '137131201', + consumer_secret: 'j49sk3j29djd', + token_secret: 'dh893hdasih9', + realm: 'Example', + transport_method: 'body' + }, + form: { + c2: '', + a3: '2 q' } - , form: { - c2: '', - a3: '2 q' - } }) - process.nextTick(function() { - t.notOk(r.headers.Authorization, 'oauth Authorization header should not be present with transport_method \'body\'') + process.nextTick(function () { + t.notOk(r.headers.Authorization, "oauth Authorization header should not be present with transport_method 'body'") t.deepEqual(qs.parse(r.body), { c2: '', a3: '2 q', @@ -557,7 +540,7 @@ tape('body transport_method + form option + url params', function(t) { }) }) -tape('body_hash manual built', function(t) { +tape('body_hash manual built', function (t) { function buildBodyHash (body) { var shasum = crypto.createHash('sha1') shasum.update(body || '') @@ -567,81 +550,79 @@ tape('body_hash manual built', function(t) { var json = {foo: 'bar'} var r = request.post( - { url: 'http://example.com' - , oauth: - { consumer_secret: 'consumer_secret' - , body_hash: buildBodyHash(JSON.stringify(json)) - } - , json: json + { url: 'http://example.com', + oauth: { consumer_secret: 'consumer_secret', + body_hash: buildBodyHash(JSON.stringify(json)) + }, + json: json }) - process.nextTick(function() { - var body_hash = r.headers.Authorization.replace(/.*oauth_body_hash="([^"]+)".*/, '$1') - t.equal('YTVlNzQ0ZDAxNjQ1NDBkMzNiMWQ3ZWE2MTZjMjhmMmZhOTdlNzU0YQ%3D%3D', body_hash) + process.nextTick(function () { + var hash = r.headers.Authorization.replace(/.*oauth_body_hash="([^"]+)".*/, '$1') + t.equal('YTVlNzQ0ZDAxNjQ1NDBkMzNiMWQ3ZWE2MTZjMjhmMmZhOTdlNzU0YQ%3D%3D', hash) r.abort() t.end() }) }) -tape('body_hash automatic built', function(t) { +tape('body_hash automatic built', function (t) { var r = request.post( - { url: 'http://example.com' - , oauth: - { consumer_secret: 'consumer_secret' - , body_hash: true - } - , json: {foo: 'bar'} + { url: 'http://example.com', + oauth: { consumer_secret: 'consumer_secret', + body_hash: true + }, + json: {foo: 'bar'} }) - process.nextTick(function() { - var body_hash = r.headers.Authorization.replace(/.*oauth_body_hash="([^"]+)".*/, '$1') - t.equal('YTVlNzQ0ZDAxNjQ1NDBkMzNiMWQ3ZWE2MTZjMjhmMmZhOTdlNzU0YQ%3D%3D', body_hash) + process.nextTick(function () { + var hash = r.headers.Authorization.replace(/.*oauth_body_hash="([^"]+)".*/, '$1') + t.equal('YTVlNzQ0ZDAxNjQ1NDBkMzNiMWQ3ZWE2MTZjMjhmMmZhOTdlNzU0YQ%3D%3D', hash) r.abort() t.end() }) }) -tape('body_hash PLAINTEXT signature_method', function(t) { - t.throws(function() { +tape('body_hash PLAINTEXT signature_method', function (t) { + t.throws(function () { request.post( - { url: 'http://example.com' - , oauth: - { consumer_secret: 'consumer_secret' - , body_hash: true - , signature_method: 'PLAINTEXT' - } - , json: {foo: 'bar'} - }) + { url: 'http://example.com', + oauth: { consumer_secret: 'consumer_secret', + body_hash: true, + signature_method: 'PLAINTEXT' + }, + json: {foo: 'bar'} + }) }, /oauth: PLAINTEXT signature_method not supported with body_hash signing/) t.end() }) -tape('refresh oauth_nonce on redirect', function(t) { - var oauth_nonce1, oauth_nonce2, url +tape('refresh oauth_nonce on redirect', function (t) { + var oauthNonce1 + var oauthNonce2 + var url var s = http.createServer(function (req, res) { if (req.url === '/redirect') { - oauth_nonce1 = req.headers.authorization.replace(/.*oauth_nonce="([^"]+)".*/, '$1') - res.writeHead(302, {location:url + '/response'}) + oauthNonce1 = req.headers.authorization.replace(/.*oauth_nonce="([^"]+)".*/, '$1') + res.writeHead(302, {location: url + '/response'}) res.end() } else if (req.url === '/response') { - oauth_nonce2 = req.headers.authorization.replace(/.*oauth_nonce="([^"]+)".*/, '$1') - res.writeHead(200, {'content-type':'text/plain'}) + oauthNonce2 = req.headers.authorization.replace(/.*oauth_nonce="([^"]+)".*/, '$1') + res.writeHead(200, {'content-type': 'text/plain'}) res.end() } }) s.listen(0, function () { url = 'http://localhost:' + this.address().port request.get( - { url: url + '/redirect' - , oauth: - { consumer_key: 'consumer_key' - , consumer_secret: 'consumer_secret' - , token: 'token' - , token_secret: 'token_secret' + { url: url + '/redirect', + oauth: { consumer_key: 'consumer_key', + consumer_secret: 'consumer_secret', + token: 'token', + token_secret: 'token_secret' } }, function (err, res, body) { t.equal(err, null) - t.notEqual(oauth_nonce1, oauth_nonce2) + t.notEqual(oauthNonce1, oauthNonce2) s.close(function () { t.end() }) @@ -649,13 +630,13 @@ tape('refresh oauth_nonce on redirect', function(t) { }) }) -tape('no credentials on external redirect', function(t) { +tape('no credentials on external redirect', function (t) { var s2 = http.createServer(function (req, res) { - res.writeHead(200, {'content-type':'text/plain'}) + res.writeHead(200, {'content-type': 'text/plain'}) res.end() }) var s1 = http.createServer(function (req, res) { - res.writeHead(302, {location:s2.url}) + res.writeHead(302, {location: s2.url}) res.end() }) s1.listen(0, function () { @@ -663,12 +644,11 @@ tape('no credentials on external redirect', function(t) { s2.listen(0, function () { s2.url = 'http://127.0.0.1:' + this.address().port request.get( - { url: s1.url - , oauth: - { consumer_key: 'consumer_key' - , consumer_secret: 'consumer_secret' - , token: 'token' - , token_secret: 'token_secret' + { url: s1.url, + oauth: { consumer_key: 'consumer_key', + consumer_secret: 'consumer_secret', + token: 'token', + token_secret: 'token_secret' } }, function (err, res, body) { t.equal(err, null) diff --git a/tests/test-onelineproxy.js b/tests/test-onelineproxy.js index 5732f0512..b2219f246 100644 --- a/tests/test-onelineproxy.js +++ b/tests/test-onelineproxy.js @@ -1,11 +1,11 @@ 'use strict' var http = require('http') - , assert = require('assert') - , request = require('../index') - , tape = require('tape') +var assert = require('assert') +var request = require('../index') +var tape = require('tape') -var server = http.createServer(function(req, resp) { +var server = http.createServer(function (req, resp) { resp.statusCode = 200 if (req.url === '/get') { assert.equal(req.method, 'GET') @@ -16,10 +16,10 @@ var server = http.createServer(function(req, resp) { if (req.url === '/put') { var x = '' assert.equal(req.method, 'PUT') - req.on('data', function(chunk) { + req.on('data', function (chunk) { x += chunk }) - req.on('end', function() { + req.on('end', function () { assert.equal(x, 'content') resp.write('success') resp.end() @@ -38,15 +38,15 @@ var server = http.createServer(function(req, resp) { throw new Error('Unknown url', req.url) }) -tape('setup', function(t) { - server.listen(0, function() { +tape('setup', function (t) { + server.listen(0, function () { server.url = 'http://localhost:' + this.address().port t.end() }) }) -tape('chained one-line proxying', function(t) { - request(server.url + '/test', function(err, res, body) { +tape('chained one-line proxying', function (t) { + request(server.url + '/test', function (err, res, body) { t.equal(err, null) t.equal(res.statusCode, 200) t.equal(body, 'success') @@ -54,8 +54,8 @@ tape('chained one-line proxying', function(t) { }) }) -tape('cleanup', function(t) { - server.close(function() { +tape('cleanup', function (t) { + server.close(function () { t.end() }) }) diff --git a/tests/test-option-reuse.js b/tests/test-option-reuse.js index 706b121a9..1c9b09d64 100644 --- a/tests/test-option-reuse.js +++ b/tests/test-option-reuse.js @@ -1,39 +1,39 @@ 'use strict' var request = require('../index') - , http = require('http') - , tape = require('tape') +var http = require('http') +var tape = require('tape') var methodsSeen = { head: 0, get: 0 } -var s = http.createServer(function(req, res) { +var s = http.createServer(function (req, res) { res.statusCode = 200 res.end('ok') methodsSeen[req.method.toLowerCase()]++ }) -tape('setup', function(t) { - s.listen(0, function() { +tape('setup', function (t) { + s.listen(0, function () { s.url = 'http://localhost:' + this.address().port t.end() }) }) -tape('options object is not mutated', function(t) { +tape('options object is not mutated', function (t) { var url = s.url var options = { url: url } - request.head(options, function(err, resp, body) { + request.head(options, function (err, resp, body) { t.equal(err, null) t.equal(body, '') t.equal(Object.keys(options).length, 1) t.equal(options.url, url) - request.get(options, function(err, resp, body) { + request.get(options, function (err, resp, body) { t.equal(err, null) t.equal(body, 'ok') t.equal(Object.keys(options).length, 1) @@ -47,8 +47,8 @@ tape('options object is not mutated', function(t) { }) }) -tape('cleanup', function(t) { - s.close(function() { +tape('cleanup', function (t) { + s.close(function () { t.end() }) }) diff --git a/tests/test-params.js b/tests/test-params.js index 6cd0a99f2..5b7880dd4 100644 --- a/tests/test-params.js +++ b/tests/test-params.js @@ -1,15 +1,15 @@ 'use strict' var server = require('./server') - , request = require('../index') - , tape = require('tape') +var request = require('../index') +var tape = require('tape') var s = server.createServer() -function runTest(name, test) { - tape(name, function(t) { +function runTest (name, test) { + tape(name, function (t) { s.on('/' + name, test.resp) - request(s.url + '/' + name, test, function(err, resp, body) { + request(s.url + '/' + name, test, function (err, resp, body) { t.equal(err, null) if (test.expectBody) { if (Buffer.isBuffer(test.expectBody)) { @@ -23,59 +23,59 @@ function runTest(name, test) { }) } -tape('setup', function(t) { - s.listen(0, function() { +tape('setup', function (t) { + s.listen(0, function () { t.end() }) }) runTest('testGet', { - resp : server.createGetResponse('TESTING!') - , expectBody: 'TESTING!' + resp: server.createGetResponse('TESTING!'), + expectBody: 'TESTING!' }) runTest('testGetChunkBreak', { - resp : server.createChunkResponse( - [ new Buffer([239]) - , new Buffer([163]) - , new Buffer([191]) - , new Buffer([206]) - , new Buffer([169]) - , new Buffer([226]) - , new Buffer([152]) - , new Buffer([131]) - ]) - , expectBody: '\uf8ff\u03a9\u2603' + resp: server.createChunkResponse( + [ new Buffer([239]), + new Buffer([163]), + new Buffer([191]), + new Buffer([206]), + new Buffer([169]), + new Buffer([226]), + new Buffer([152]), + new Buffer([131]) + ]), + expectBody: '\uf8ff\u03a9\u2603' }) runTest('testGetBuffer', { - resp : server.createGetResponse(new Buffer('TESTING!')) - , encoding: null - , expectBody: new Buffer('TESTING!') + resp: server.createGetResponse(new Buffer('TESTING!')), + encoding: null, + expectBody: new Buffer('TESTING!') }) runTest('testGetJSON', { - resp : server.createGetResponse('{"test":true}', 'application/json') - , json : true - , expectBody: {'test':true} + resp: server.createGetResponse('{"test":true}', 'application/json'), + json: true, + expectBody: {'test': true} }) runTest('testPutString', { - resp : server.createPostValidator('PUTTINGDATA') - , method : 'PUT' - , body : 'PUTTINGDATA' + resp: server.createPostValidator('PUTTINGDATA'), + method: 'PUT', + body: 'PUTTINGDATA' }) runTest('testPutBuffer', { - resp : server.createPostValidator('PUTTINGDATA') - , method : 'PUT' - , body : new Buffer('PUTTINGDATA') + resp: server.createPostValidator('PUTTINGDATA'), + method: 'PUT', + body: new Buffer('PUTTINGDATA') }) runTest('testPutJSON', { - resp : server.createPostValidator(JSON.stringify({foo: 'bar'})) - , method: 'PUT' - , json: {foo: 'bar'} + resp: server.createPostValidator(JSON.stringify({foo: 'bar'})), + method: 'PUT', + json: {foo: 'bar'} }) runTest('testPutMultipart', { @@ -87,16 +87,15 @@ runTest('testPutMultipart', { '\r\n--__BOUNDARY__\r\n\r\n' + 'Oh hi.' + '\r\n--__BOUNDARY__--' - ) - , method: 'PUT' - , multipart: - [ {'content-type': 'text/html', 'body': 'Oh hi.'} - , {'body': 'Oh hi.'} - ] + ), + method: 'PUT', + multipart: [ {'content-type': 'text/html', 'body': 'Oh hi.'}, + {'body': 'Oh hi.'} + ] }) -tape('cleanup', function(t) { - s.close(function() { +tape('cleanup', function (t) { + s.close(function () { t.end() }) }) diff --git a/tests/test-piped-redirect.js b/tests/test-piped-redirect.js index d669c0923..77135d4d1 100644 --- a/tests/test-piped-redirect.js +++ b/tests/test-piped-redirect.js @@ -1,13 +1,13 @@ 'use strict' var http = require('http') - , request = require('../index') - , tape = require('tape') +var request = require('../index') +var tape = require('tape') var port1 - , port2 +var port2 -var s1 = http.createServer(function(req, resp) { +var s1 = http.createServer(function (req, resp) { if (req.url === '/original') { resp.writeHeader(302, { 'location': '/redirected' @@ -22,33 +22,33 @@ var s1 = http.createServer(function(req, resp) { } }) -var s2 = http.createServer(function(req, resp) { +var s2 = http.createServer(function (req, resp) { var x = request('http://localhost:' + port1 + '/original') req.pipe(x) x.pipe(resp) }) -tape('setup', function(t) { - s1.listen(0, function() { +tape('setup', function (t) { + s1.listen(0, function () { port1 = this.address().port - s2.listen(0, function() { + s2.listen(0, function () { port2 = this.address().port t.end() }) }) }) -tape('piped redirect', function(t) { - request('http://localhost:' + port2 + '/original', function(err, res, body) { +tape('piped redirect', function (t) { + request('http://localhost:' + port2 + '/original', function (err, res, body) { t.equal(err, null) t.equal(body, 'OK') t.end() }) }) -tape('cleanup', function(t) { - s1.close(function() { - s2.close(function() { +tape('cleanup', function (t) { + s1.close(function () { + s2.close(function () { t.end() }) }) diff --git a/tests/test-pipes.js b/tests/test-pipes.js index f1498e17d..0ee3dd6c8 100644 --- a/tests/test-pipes.js +++ b/tests/test-pipes.js @@ -1,16 +1,16 @@ 'use strict' var server = require('./server') - , stream = require('stream') - , fs = require('fs') - , request = require('../index') - , path = require('path') - , util = require('util') - , tape = require('tape') +var stream = require('stream') +var fs = require('fs') +var request = require('../index') +var path = require('path') +var util = require('util') +var tape = require('tape') var s = server.createServer() -s.on('/cat', function(req, res) { +s.on('/cat', function (req, res) { if (req.method === 'GET') { res.writeHead(200, { 'content-type': 'text/plain-test', @@ -19,9 +19,9 @@ s.on('/cat', function(req, res) { res.end('asdf') } else if (req.method === 'PUT') { var body = '' - req.on('data', function(chunk) { + req.on('data', function (chunk) { body += chunk - }).on('end', function() { + }).on('end', function () { res.writeHead(201) res.end() s.emit('catDone', req, res, body) @@ -29,7 +29,7 @@ s.on('/cat', function(req, res) { } }) -s.on('/doodle', function(req, res) { +s.on('/doodle', function (req, res) { if (req.headers['x-oneline-proxy']) { res.setHeader('x-oneline-proxy', 'yup') } @@ -37,13 +37,13 @@ s.on('/doodle', function(req, res) { fs.createReadStream(path.join(__dirname, 'googledoodle.jpg')).pipe(res) }) -function ValidationStream(t, str) { +function ValidationStream (t, str) { this.str = str this.buf = '' - this.on('data', function(data) { + this.on('data', function (data) { this.buf += data }) - this.on('end', function() { + this.on('end', function () { t.equal(this.str, this.buf) }) this.writable = true @@ -51,25 +51,24 @@ function ValidationStream(t, str) { util.inherits(ValidationStream, stream.Stream) -ValidationStream.prototype.write = function(chunk) { +ValidationStream.prototype.write = function (chunk) { this.emit('data', chunk) } -ValidationStream.prototype.end = function(chunk) { +ValidationStream.prototype.end = function (chunk) { if (chunk) { this.emit('data', chunk) } this.emit('end') } - -tape('setup', function(t) { - s.listen(0, function() { +tape('setup', function (t) { + s.listen(0, function () { t.end() }) }) -tape('piping to a request object', function(t) { +tape('piping to a request object', function (t) { s.once('/push', server.createPostValidator('mydata')) var mydata = new stream.Stream() @@ -77,7 +76,7 @@ tape('piping to a request object', function(t) { var r1 = request.put({ url: s.url + '/push' - }, function(err, res, body) { + }, function (err, res, body) { t.equal(err, null) t.equal(res.statusCode, 200) t.equal(body, 'mydata') @@ -89,14 +88,14 @@ tape('piping to a request object', function(t) { mydata.emit('end') }) -tape('piping to a request object with invalid uri', function(t) { +tape('piping to a request object with invalid uri', function (t) { var mybodydata = new stream.Stream() mybodydata.readable = true var r2 = request.put({ url: '/bad-uri', json: true - }, function(err, res, body) { + }, function (err, res, body) { t.ok(err instanceof Error) t.equal(err.message, 'Invalid URI "/bad-uri"') t.end() @@ -107,7 +106,7 @@ tape('piping to a request object with invalid uri', function(t) { mybodydata.emit('end') }) -tape('piping to a request object with a json body', function(t) { +tape('piping to a request object with a json body', function (t) { var obj = {foo: 'bar'} var json = JSON.stringify(obj) s.once('/push-json', server.createPostValidator(json, 'application/json')) @@ -117,7 +116,7 @@ tape('piping to a request object with a json body', function(t) { var r2 = request.put({ url: s.url + '/push-json', json: true - }, function(err, res, body) { + }, function (err, res, body) { t.equal(err, null) t.equal(res.statusCode, 200) t.deepEqual(body, obj) @@ -129,7 +128,7 @@ tape('piping to a request object with a json body', function(t) { mybodydata.emit('end') }) -tape('piping from a request object', function(t) { +tape('piping from a request object', function (t) { s.once('/pull', server.createGetResponse('mypulldata')) var mypulldata = new stream.Stream() @@ -141,22 +140,22 @@ tape('piping from a request object', function(t) { var d = '' - mypulldata.write = function(chunk) { + mypulldata.write = function (chunk) { d += chunk } - mypulldata.end = function() { + mypulldata.end = function () { t.equal(d, 'mypulldata') t.end() } }) -tape('pause when piping from a request object', function(t) { - s.once('/chunks', function(req, res) { +tape('pause when piping from a request object', function (t) { + s.once('/chunks', function (req, res) { res.writeHead(200, { 'content-type': 'text/plain' }) res.write('Chunk 1') - setTimeout(function() { res.end('Chunk 2') }, 10) + setTimeout(function () { res.end('Chunk 2') }, 10) }) var chunkNum = 0 @@ -164,7 +163,7 @@ tape('pause when piping from a request object', function(t) { request({ url: s.url + '/chunks' }) - .on('data', function(chunk) { + .on('data', function (chunk) { var self = this t.notOk(paused, 'Only receive data when not paused') @@ -174,7 +173,7 @@ tape('pause when piping from a request object', function(t) { t.equal(chunk.toString(), 'Chunk 1') self.pause() paused = true - setTimeout(function() { + setTimeout(function () { paused = false self.resume() }, 100) @@ -185,8 +184,8 @@ tape('pause when piping from a request object', function(t) { .on('end', t.end.bind(t)) }) -tape('pause before piping from a request object', function(t) { - s.once('/pause-before', function(req, res) { +tape('pause before piping from a request object', function (t) { + s.once('/pause-before', function (req, res) { res.writeHead(200, { 'content-type': 'text/plain' }) @@ -198,22 +197,22 @@ tape('pause before piping from a request object', function(t) { url: s.url + '/pause-before' }) r.pause() - r.on('data', function(data) { + r.on('data', function (data) { t.notOk(paused, 'Only receive data when not paused') t.equal(data.toString(), 'Data') }) r.on('end', t.end.bind(t)) - setTimeout(function() { + setTimeout(function () { paused = false r.resume() }, 100) }) var fileContents = fs.readFileSync(__filename) -function testPipeFromFile(testName, hasContentLength) { - tape(testName, function(t) { - s.once('/pushjs', function(req, res) { +function testPipeFromFile (testName, hasContentLength) { + tape(testName, function (t) { + s.once('/pushjs', function (req, res) { if (req.method === 'PUT') { t.equal(req.headers['content-type'], 'application/javascript') t.equal( @@ -221,10 +220,10 @@ function testPipeFromFile(testName, hasContentLength) { (hasContentLength ? '' + fileContents.length : undefined)) var body = '' req.setEncoding('utf8') - req.on('data', function(data) { + req.on('data', function (data) { body += data }) - req.on('end', function() { + req.on('end', function () { res.end() t.equal(body, fileContents.toString()) t.end() @@ -245,8 +244,8 @@ function testPipeFromFile(testName, hasContentLength) { testPipeFromFile('piping from a file', false) testPipeFromFile('piping from a file with content-length', true) -tape('piping to and from same URL', function(t) { - s.once('catDone', function(req, res, body) { +tape('piping to and from same URL', function (t) { + s.once('catDone', function (req, res, body) { t.equal(req.headers['content-type'], 'text/plain-test') t.equal(req.headers['content-length'], '4') t.equal(body, 'asdf') @@ -256,12 +255,12 @@ tape('piping to and from same URL', function(t) { .pipe(request.put(s.url + '/cat')) }) -tape('piping between urls', function(t) { - s.once('/catresp', function(req, res) { +tape('piping between urls', function (t) { + s.once('/catresp', function (req, res) { request.get(s.url + '/cat').pipe(res) }) - request.get(s.url + '/catresp', function(err, res, body) { + request.get(s.url + '/catresp', function (err, res, body) { t.equal(err, null) t.equal(res.headers['content-type'], 'text/plain-test') t.equal(res.headers['content-length'], '4') @@ -269,12 +268,12 @@ tape('piping between urls', function(t) { }) }) -tape('writing to file', function(t) { +tape('writing to file', function (t) { var doodleWrite = fs.createWriteStream(path.join(__dirname, 'test.jpg')) request.get(s.url + '/doodle').pipe(doodleWrite) - doodleWrite.on('close', function() { + doodleWrite.on('close', function () { t.deepEqual( fs.readFileSync(path.join(__dirname, 'googledoodle.jpg')), fs.readFileSync(path.join(__dirname, 'test.jpg'))) @@ -283,8 +282,8 @@ tape('writing to file', function(t) { }) }) -tape('one-line proxy', function(t) { - s.once('/onelineproxy', function(req, res) { +tape('one-line proxy', function (t) { + s.once('/onelineproxy', function (req, res) { var x = request(s.url + '/doodle') req.pipe(x) x.pipe(res) @@ -293,36 +292,36 @@ tape('one-line proxy', function(t) { request.get({ uri: s.url + '/onelineproxy', headers: { 'x-oneline-proxy': 'nope' } - }, function(err, res, body) { + }, function (err, res, body) { t.equal(err, null) t.equal(res.headers['x-oneline-proxy'], 'yup') t.end() }) }) -tape('piping after response', function(t) { - s.once('/afterresponse', function(req, res) { +tape('piping after response', function (t) { + s.once('/afterresponse', function (req, res) { res.write('d') res.end() }) var rAfterRes = request.post(s.url + '/afterresponse') - rAfterRes.on('response', function() { + rAfterRes.on('response', function () { var v = new ValidationStream(t, 'd') rAfterRes.pipe(v) - v.on('end', function() { + v.on('end', function () { t.end() }) }) }) -tape('piping through a redirect', function(t) { - s.once('/forward1', function(req, res) { +tape('piping through a redirect', function (t) { + s.once('/forward1', function (req, res) { res.writeHead(302, { location: '/forward2' }) res.end() }) - s.once('/forward2', function(req, res) { + s.once('/forward2', function (req, res) { res.writeHead('200', { 'content-type': 'image/png' }) res.write('d') res.end() @@ -332,27 +331,27 @@ tape('piping through a redirect', function(t) { request.get(s.url + '/forward1').pipe(validateForward) - validateForward.on('end', function() { + validateForward.on('end', function () { t.end() }) }) -tape('pipe options', function(t) { +tape('pipe options', function (t) { s.once('/opts', server.createGetResponse('opts response')) var optsStream = new stream.Stream() - , optsData = '' + var optsData = '' optsStream.writable = true - optsStream.write = function(buf) { + optsStream.write = function (buf) { optsData += buf if (optsData === 'opts response') { - setTimeout(function() { + setTimeout(function () { t.end() }, 10) } } - optsStream.end = function() { + optsStream.end = function () { t.fail('end called') } @@ -361,23 +360,23 @@ tape('pipe options', function(t) { }).pipe(optsStream, { end: false }) }) -tape('request.pipefilter is called correctly', function(t) { - s.once('/pipefilter', function(req, res) { +tape('request.pipefilter is called correctly', function (t) { + s.once('/pipefilter', function (req, res) { res.end('d') }) var validatePipeFilter = new ValidationStream(t, 'd') var r3 = request.get(s.url + '/pipefilter') r3.pipe(validatePipeFilter) - r3.pipefilter = function(res, dest) { + r3.pipefilter = function (res, dest) { t.equal(res, r3.response) t.equal(dest, validatePipeFilter) t.end() } }) -tape('cleanup', function(t) { - s.close(function() { +tape('cleanup', function (t) { + s.close(function () { t.end() }) }) diff --git a/tests/test-pool.js b/tests/test-pool.js index 6c5446936..f2d96bd1f 100644 --- a/tests/test-pool.js +++ b/tests/test-pool.js @@ -1,26 +1,26 @@ 'use strict' var request = require('../index') - , http = require('http') - , tape = require('tape') +var http = require('http') +var tape = require('tape') var s = http.createServer(function (req, res) { res.statusCode = 200 res.end('asdf') }) -tape('setup', function(t) { - s.listen(0, function() { +tape('setup', function (t) { + s.listen(0, function () { s.url = 'http://localhost:' + this.address().port t.end() }) }) -tape('pool', function(t) { +tape('pool', function (t) { request({ url: s.url, pool: false - }, function(err, res, body) { + }, function (err, res, body) { t.equal(err, null) t.equal(res.statusCode, 200) t.equal(body, 'asdf') @@ -31,12 +31,12 @@ tape('pool', function(t) { }) }) -tape('forever', function(t) { +tape('forever', function (t) { var r = request({ url: s.url, forever: true, pool: {maxSockets: 1024} - }, function(err, res, body) { + }, function (err, res, body) { // explicitly shut down the agent if (typeof r.agent.destroy === 'function') { r.agent.destroy() @@ -59,7 +59,7 @@ tape('forever', function(t) { }) }) -tape('forever, should use same agent in sequential requests', function(t) { +tape('forever, should use same agent in sequential requests', function (t) { var r = request.defaults({ forever: true }) @@ -77,7 +77,7 @@ tape('forever, should use same agent in sequential requests', function(t) { t.end() }) -tape('forever, should use same agent in sequential requests(with pool.maxSockets)', function(t) { +tape('forever, should use same agent in sequential requests(with pool.maxSockets)', function (t) { var r = request.defaults({ forever: true, pool: {maxSockets: 1024} @@ -97,7 +97,7 @@ tape('forever, should use same agent in sequential requests(with pool.maxSockets t.end() }) -tape('forever, should use same agent in request() and request.verb', function(t) { +tape('forever, should use same agent in request() and request.verb', function (t) { var r = request.defaults({ forever: true, pool: {maxSockets: 1024} @@ -117,7 +117,7 @@ tape('forever, should use same agent in request() and request.verb', function(t) t.end() }) -tape('should use different agent if pool option specified', function(t) { +tape('should use different agent if pool option specified', function (t) { var r = request.defaults({ forever: true, pool: {maxSockets: 1024} @@ -141,8 +141,8 @@ tape('should use different agent if pool option specified', function(t) { t.end() }) -tape('cleanup', function(t) { - s.close(function() { +tape('cleanup', function (t) { + s.close(function () { t.end() }) }) diff --git a/tests/test-promise.js b/tests/test-promise.js index f5343cf46..028d15fbb 100644 --- a/tests/test-promise.js +++ b/tests/test-promise.js @@ -1,23 +1,23 @@ 'use strict' var http = require('http') - , request = require('../index') - , tape = require('tape') - , Promise = require('bluebird') +var request = require('../index') +var tape = require('tape') +var Promise = require('bluebird') -var s = http.createServer(function(req, res) { +var s = http.createServer(function (req, res) { res.writeHead(200, {}) res.end('ok') }) -tape('setup', function(t) { - s.listen(0, function() { +tape('setup', function (t) { + s.listen(0, function () { s.url = 'http://localhost:' + this.address().port t.end() }) }) -tape('promisify convenience method', function(t) { +tape('promisify convenience method', function (t) { var get = request.get var p = Promise.promisify(get, {multiArgs: true}) p(s.url) @@ -28,7 +28,7 @@ tape('promisify convenience method', function(t) { }) }) -tape('promisify request function', function(t) { +tape('promisify request function', function (t) { var p = Promise.promisify(request, {multiArgs: true}) p(s.url) .spread(function (res, body) { @@ -37,7 +37,7 @@ tape('promisify request function', function(t) { }) }) -tape('promisify all methods', function(t) { +tape('promisify all methods', function (t) { Promise.promisifyAll(request, {multiArgs: true}) request.getAsync(s.url) .spread(function (res, body) { @@ -46,8 +46,8 @@ tape('promisify all methods', function(t) { }) }) -tape('cleanup', function(t) { - s.close(function() { +tape('cleanup', function (t) { + s.close(function () { t.end() }) }) diff --git a/tests/test-proxy-connect.js b/tests/test-proxy-connect.js index 084e19fee..06800d00e 100644 --- a/tests/test-proxy-connect.js +++ b/tests/test-proxy-connect.js @@ -1,13 +1,13 @@ 'use strict' var request = require('../index') - , tape = require('tape') +var tape = require('tape') var called = false - , proxiedHost = 'google.com' - , data = '' +var proxiedHost = 'google.com' +var data = '' -var s = require('net').createServer(function(sock) { +var s = require('net').createServer(function (sock) { called = true sock.once('data', function (c) { data += c @@ -26,28 +26,28 @@ var s = require('net').createServer(function(sock) { }) }) -tape('setup', function(t) { - s.listen(0, function() { +tape('setup', function (t) { + s.listen(0, function () { s.url = 'http://localhost:' + this.address().port t.end() }) }) -tape('proxy', function(t) { +tape('proxy', function (t) { request({ tunnel: true, url: 'http://' + proxiedHost, proxy: s.url, headers: { - 'Proxy-Authorization' : 'Basic dXNlcjpwYXNz', - 'authorization' : 'Token deadbeef', - 'dont-send-to-proxy' : 'ok', - 'dont-send-to-dest' : 'ok', - 'accept' : 'yo', - 'user-agent' : 'just another foobar' + 'Proxy-Authorization': 'Basic dXNlcjpwYXNz', + 'authorization': 'Token deadbeef', + 'dont-send-to-proxy': 'ok', + 'dont-send-to-dest': 'ok', + 'accept': 'yo', + 'user-agent': 'just another foobar' }, proxyHeaderExclusiveList: ['Dont-send-to-dest'] - }, function(err, res, body) { + }, function (err, res, body) { t.equal(err, null) t.equal(res.statusCode, 200) t.equal(body, 'derp\n') @@ -73,8 +73,8 @@ tape('proxy', function(t) { }) }) -tape('cleanup', function(t) { - s.close(function() { +tape('cleanup', function (t) { + s.close(function () { t.end() }) }) diff --git a/tests/test-proxy.js b/tests/test-proxy.js index dd5cefbcb..77cb7a831 100644 --- a/tests/test-proxy.js +++ b/tests/test-proxy.js @@ -1,14 +1,14 @@ 'use strict' var server = require('./server') - , request = require('../index') - , tape = require('tape') +var request = require('../index') +var tape = require('tape') var s = server.createServer() - , currResponseHandler +var currResponseHandler -['http://google.com/', 'https://google.com/'].forEach(function(url) { - s.on(url, function(req, res) { +['http://google.com/', 'https://google.com/'].forEach(function (url) { + s.on(url, function (req, res) { currResponseHandler(req, res) res.writeHeader(200) res.end('ok') @@ -34,9 +34,9 @@ var proxyEnvVars = [ // `responseHandler` should be truthy to indicate that the proxy should be used // for this request, or falsy to indicate that the proxy should not be used for // this request. -function runTest(name, options, responseHandler) { - tape(name, function(t) { - proxyEnvVars.forEach(function(v) { +function runTest (name, options, responseHandler) { + tape(name, function (t) { + proxyEnvVars.forEach(function (v) { delete process.env[v] }) if (options.env) { @@ -47,7 +47,7 @@ function runTest(name, options, responseHandler) { } var called = false - currResponseHandler = function(req, res) { + currResponseHandler = function (req, res) { if (responseHandler) { called = true t.equal(req.headers.host, 'google.com') @@ -60,7 +60,7 @@ function runTest(name, options, responseHandler) { } options.url = options.url || 'http://google.com' - request(options, function(err, res, body) { + request(options, function (err, res, body) { if (responseHandler && !called) { t.fail('proxy response should be called') } @@ -79,190 +79,188 @@ function runTest(name, options, responseHandler) { }) } -function addTests() { +function addTests () { // If the `runTest` function is changed, run the following command and make // sure both of these tests fail: // // TEST_PROXY_HARNESS=y node tests/test-proxy.js if (process.env.TEST_PROXY_HARNESS) { - runTest('should fail with "proxy response should not be called"', { - proxy : s.url + proxy: s.url }, false) runTest('should fail with "proxy response should be called"', { - proxy : null + proxy: null }, true) - } else { // Run the real tests runTest('basic proxy', { - proxy : s.url, - headers : { + proxy: s.url, + headers: { 'proxy-authorization': 'Token Fooblez' } - }, function(t, req, res) { + }, function (t, req, res) { t.equal(req.headers['proxy-authorization'], 'Token Fooblez') }) runTest('proxy auth without uri auth', { - proxy : 'http://user:pass@localhost:' + s.port - }, function(t, req, res) { + proxy: 'http://user:pass@localhost:' + s.port + }, function (t, req, res) { t.equal(req.headers['proxy-authorization'], 'Basic dXNlcjpwYXNz') }) // http: urls and basic proxy settings runTest('HTTP_PROXY environment variable and http: url', { - env : { HTTP_PROXY : s.url } + env: { HTTP_PROXY: s.url } }, true) runTest('http_proxy environment variable and http: url', { - env : { http_proxy : s.url } + env: { http_proxy: s.url } }, true) runTest('HTTPS_PROXY environment variable and http: url', { - env : { HTTPS_PROXY : s.url } + env: { HTTPS_PROXY: s.url } }, false) runTest('https_proxy environment variable and http: url', { - env : { https_proxy : s.url } + env: { https_proxy: s.url } }, false) // https: urls and basic proxy settings runTest('HTTP_PROXY environment variable and https: url', { - env : { HTTP_PROXY : s.url }, - url : 'https://google.com', - tunnel : false, - pool : false + env: { HTTP_PROXY: s.url }, + url: 'https://google.com', + tunnel: false, + pool: false }, true) runTest('http_proxy environment variable and https: url', { - env : { http_proxy : s.url }, - url : 'https://google.com', - tunnel : false + env: { http_proxy: s.url }, + url: 'https://google.com', + tunnel: false }, true) runTest('HTTPS_PROXY environment variable and https: url', { - env : { HTTPS_PROXY : s.url }, - url : 'https://google.com', - tunnel : false + env: { HTTPS_PROXY: s.url }, + url: 'https://google.com', + tunnel: false }, true) runTest('https_proxy environment variable and https: url', { - env : { https_proxy : s.url }, - url : 'https://google.com', - tunnel : false + env: { https_proxy: s.url }, + url: 'https://google.com', + tunnel: false }, true) runTest('multiple environment variables and https: url', { - env : { - HTTPS_PROXY : s.url, - HTTP_PROXY : 'http://localhost:0/' + env: { + HTTPS_PROXY: s.url, + HTTP_PROXY: 'http://localhost:0/' }, - url : 'https://google.com', - tunnel : false + url: 'https://google.com', + tunnel: false }, true) // no_proxy logic runTest('NO_PROXY hostnames are case insensitive', { - env : { - HTTP_PROXY : s.url, - NO_PROXY : 'GOOGLE.COM' + env: { + HTTP_PROXY: s.url, + NO_PROXY: 'GOOGLE.COM' } }, false) runTest('NO_PROXY hostnames are case insensitive 2', { - env : { - http_proxy : s.url, - NO_PROXY : 'GOOGLE.COM' + env: { + http_proxy: s.url, + NO_PROXY: 'GOOGLE.COM' } }, false) runTest('NO_PROXY hostnames are case insensitive 3', { - env : { - HTTP_PROXY : s.url, - no_proxy : 'GOOGLE.COM' + env: { + HTTP_PROXY: s.url, + no_proxy: 'GOOGLE.COM' } }, false) runTest('NO_PROXY ignored with explicit proxy passed', { - env : { NO_PROXY : '*' }, - proxy : s.url + env: { NO_PROXY: '*' }, + proxy: s.url }, true) runTest('NO_PROXY overrides HTTP_PROXY for specific hostname', { - env : { - HTTP_PROXY : s.url, - NO_PROXY : 'google.com' + env: { + HTTP_PROXY: s.url, + NO_PROXY: 'google.com' } }, false) runTest('no_proxy overrides HTTP_PROXY for specific hostname', { - env : { - HTTP_PROXY : s.url, - no_proxy : 'google.com' + env: { + HTTP_PROXY: s.url, + no_proxy: 'google.com' } }, false) runTest('NO_PROXY does not override HTTP_PROXY if no hostnames match', { - env : { - HTTP_PROXY : s.url, - NO_PROXY : 'foo.bar,bar.foo' + env: { + HTTP_PROXY: s.url, + NO_PROXY: 'foo.bar,bar.foo' } }, true) runTest('NO_PROXY overrides HTTP_PROXY if a hostname matches', { - env : { - HTTP_PROXY : s.url, - NO_PROXY : 'foo.bar,google.com' + env: { + HTTP_PROXY: s.url, + NO_PROXY: 'foo.bar,google.com' } }, false) runTest('NO_PROXY allows an explicit port', { - env : { - HTTP_PROXY : s.url, - NO_PROXY : 'google.com:80' + env: { + HTTP_PROXY: s.url, + NO_PROXY: 'google.com:80' } }, false) runTest('NO_PROXY only overrides HTTP_PROXY if the port matches', { - env : { - HTTP_PROXY : s.url, - NO_PROXY : 'google.com:1234' + env: { + HTTP_PROXY: s.url, + NO_PROXY: 'google.com:1234' } }, true) runTest('NO_PROXY=* should override HTTP_PROXY for all hosts', { - env : { - HTTP_PROXY : s.url, - NO_PROXY : '*' + env: { + HTTP_PROXY: s.url, + NO_PROXY: '*' } }, false) runTest('NO_PROXY should override HTTP_PROXY for all subdomains', { - env : { - HTTP_PROXY : s.url, - NO_PROXY : 'google.com' + env: { + HTTP_PROXY: s.url, + NO_PROXY: 'google.com' }, - headers : { host : 'www.google.com' } + headers: { host: 'www.google.com' } }, false) runTest('NO_PROXY should not override HTTP_PROXY for partial domain matches', { - env : { - HTTP_PROXY : s.url, - NO_PROXY : 'oogle.com' + env: { + HTTP_PROXY: s.url, + NO_PROXY: 'oogle.com' } }, true) runTest('NO_PROXY with port should not override HTTP_PROXY for partial domain matches', { - env : { - HTTP_PROXY : s.url, - NO_PROXY : 'oogle.com:80' + env: { + HTTP_PROXY: s.url, + NO_PROXY: 'oogle.com:80' } }, true) @@ -271,33 +269,33 @@ function addTests() { // this fails if the check 'isMatchedAt > -1' in lib/getProxyFromURI.js is // missing or broken runTest('http_proxy with length of one more than the URL', { - env : { - HTTP_PROXY : s.url, - NO_PROXY : 'elgoog1.com' // one more char than google.com + env: { + HTTP_PROXY: s.url, + NO_PROXY: 'elgoog1.com' // one more char than google.com } }, true) runTest('proxy: null should override HTTP_PROXY', { - env : { HTTP_PROXY : s.url }, - proxy : null, - timeout : 500 + env: { HTTP_PROXY: s.url }, + proxy: null, + timeout: 500 }, false) runTest('uri auth without proxy auth', { - url : 'http://user:pass@google.com', - proxy : s.url - }, function(t, req, res) { + url: 'http://user:pass@google.com', + proxy: s.url + }, function (t, req, res) { t.equal(req.headers['proxy-authorization'], undefined) t.equal(req.headers.authorization, 'Basic dXNlcjpwYXNz') }) } } -tape('setup', function(t) { - s.listen(0, function() { +tape('setup', function (t) { + s.listen(0, function () { addTests() - tape('cleanup', function(t) { - s.close(function() { + tape('cleanup', function (t) { + s.close(function () { t.end() }) }) diff --git a/tests/test-qs.js b/tests/test-qs.js index 85d741403..f70c685db 100644 --- a/tests/test-qs.js +++ b/tests/test-qs.js @@ -1,7 +1,7 @@ 'use strict' var request = require('../index') - , tape = require('tape') +var tape = require('tape') // Run a querystring test. `options` can have the following keys: // - suffix : a string to be added to the URL @@ -11,10 +11,10 @@ var request = require('../index') // - afterRequest : a function to execute after creating the request // - expected : the expected path of the request // - expectedQuerystring : expected path when using the querystring library -function runTest(name, options) { +function runTest (name, options) { var uri = 'http://www.google.com' + (options.suffix || '') var opts = { - uri : uri, + uri: uri, qsParseOptions: options.qsParseOptions, qsStringifyOptions: options.qsStringifyOptions } @@ -23,25 +23,25 @@ function runTest(name, options) { opts.qs = options.qs } - tape(name + ' - using qs', function(t) { + tape(name + ' - using qs', function (t) { var r = request.get(opts) if (typeof options.afterRequest === 'function') { options.afterRequest(r) } - process.nextTick(function() { + process.nextTick(function () { t.equal(r.path, options.expected) r.abort() t.end() }) }) - tape(name + ' - using querystring', function(t) { + tape(name + ' - using querystring', function (t) { opts.useQuerystring = true var r = request.get(opts) if (typeof options.afterRequest === 'function') { options.afterRequest(r) } - process.nextTick(function() { + process.nextTick(function () { t.equal(r.path, options.expectedQuerystring || options.expected) r.abort() t.end() @@ -49,87 +49,87 @@ function runTest(name, options) { }) } -function esc(str) { +function esc (str) { return str .replace(/\[/g, '%5B') .replace(/\]/g, '%5D') } runTest('adding a querystring', { - qs : { q : 'search' }, - expected : '/?q=search' + qs: { q: 'search' }, + expected: '/?q=search' }) runTest('replacing a querystring value', { - suffix : '?q=abc', - qs : { q : 'search' }, - expected : '/?q=search' + suffix: '?q=abc', + qs: { q: 'search' }, + expected: '/?q=search' }) runTest('appending a querystring value to the ones present in the uri', { - suffix : '?x=y', - qs : { q : 'search' }, - expected : '/?x=y&q=search' + suffix: '?x=y', + qs: { q: 'search' }, + expected: '/?x=y&q=search' }) runTest('leaving a querystring alone', { - suffix : '?x=y', - expected : '/?x=y' + suffix: '?x=y', + expected: '/?x=y' }) runTest('giving empty qs property', { - qs : {}, - expected : '/' + qs: {}, + expected: '/' }) runTest('modifying the qs after creating the request', { - qs : {}, - afterRequest : function(r) { - r.qs({ q : 'test' }) + qs: {}, + afterRequest: function (r) { + r.qs({ q: 'test' }) }, - expected : '/?q=test' + expected: '/?q=test' }) runTest('a query with an object for a value', { - qs : { where : { foo: 'bar' } }, - expected : esc('/?where[foo]=bar'), - expectedQuerystring : '/?where=' + qs: { where: { foo: 'bar' } }, + expected: esc('/?where[foo]=bar'), + expectedQuerystring: '/?where=' }) runTest('a query with an array for a value', { - qs : { order : ['bar', 'desc'] }, - expected : esc('/?order[0]=bar&order[1]=desc'), - expectedQuerystring : '/?order=bar&order=desc' + qs: { order: ['bar', 'desc'] }, + expected: esc('/?order[0]=bar&order[1]=desc'), + expectedQuerystring: '/?order=bar&order=desc' }) runTest('pass options to the qs module via the qsParseOptions key', { - suffix : '?a=1;b=2', + suffix: '?a=1;b=2', qs: {}, - qsParseOptions: { delimiter : ';' }, - qsStringifyOptions: { delimiter : ';' }, - expected : esc('/?a=1;b=2'), - expectedQuerystring : '/?a=1%3Bb%3D2' + qsParseOptions: { delimiter: ';' }, + qsStringifyOptions: { delimiter: ';' }, + expected: esc('/?a=1;b=2'), + expectedQuerystring: '/?a=1%3Bb%3D2' }) runTest('pass options to the qs module via the qsStringifyOptions key', { - qs : { order : ['bar', 'desc'] }, - qsStringifyOptions: { arrayFormat : 'brackets' }, - expected : esc('/?order[]=bar&order[]=desc'), - expectedQuerystring : '/?order=bar&order=desc' + qs: { order: ['bar', 'desc'] }, + qsStringifyOptions: { arrayFormat: 'brackets' }, + expected: esc('/?order[]=bar&order[]=desc'), + expectedQuerystring: '/?order=bar&order=desc' }) runTest('pass options to the querystring module via the qsParseOptions key', { - suffix : '?a=1;b=2', + suffix: '?a=1;b=2', qs: {}, - qsParseOptions: { sep : ';' }, - qsStringifyOptions: { sep : ';' }, - expected : esc('/?a=1%3Bb%3D2'), - expectedQuerystring : '/?a=1;b=2' + qsParseOptions: { sep: ';' }, + qsStringifyOptions: { sep: ';' }, + expected: esc('/?a=1%3Bb%3D2'), + expectedQuerystring: '/?a=1;b=2' }) runTest('pass options to the querystring module via the qsStringifyOptions key', { - qs : { order : ['bar', 'desc'] }, - qsStringifyOptions: { sep : ';' }, - expected : esc('/?order[0]=bar&order[1]=desc'), - expectedQuerystring : '/?order=bar;order=desc' + qs: { order: ['bar', 'desc'] }, + qsStringifyOptions: { sep: ';' }, + expected: esc('/?order[0]=bar&order[1]=desc'), + expectedQuerystring: '/?order=bar;order=desc' }) diff --git a/tests/test-redirect-auth.js b/tests/test-redirect-auth.js index 400ad5429..7aef6edcc 100644 --- a/tests/test-redirect-auth.js +++ b/tests/test-redirect-auth.js @@ -1,40 +1,40 @@ 'use strict' var server = require('./server') - , request = require('../index') - , util = require('util') - , tape = require('tape') - , destroyable = require('server-destroy') +var request = require('../index') +var util = require('util') +var tape = require('tape') +var destroyable = require('server-destroy') var s = server.createServer() - , ss = server.createSSLServer() +var ss = server.createSSLServer() destroyable(s) destroyable(ss) // always send basic auth and allow non-strict SSL request = request.defaults({ - auth : { - user : 'test', - pass : 'testing' + auth: { + user: 'test', + pass: 'testing' }, - rejectUnauthorized : false + rejectUnauthorized: false }) // redirect.from(proto, host).to(proto, host) returns an object with keys: // src : source URL // dst : destination URL var redirect = { - from : function(fromProto, fromHost) { + from: function (fromProto, fromHost) { return { - to : function(toProto, toHost) { + to: function (toProto, toHost) { var fromPort = (fromProto === 'http' ? s.port : ss.port) - , toPort = (toProto === 'http' ? s.port : ss.port) + var toPort = (toProto === 'http' ? s.port : ss.port) return { - src : util.format( + src: util.format( '%s://%s:%d/to/%s/%s', fromProto, fromHost, fromPort, toProto, toHost), - dst : util.format( + dst: util.format( '%s://%s:%d/from/%s/%s', toProto, toHost, toPort, fromProto, fromHost) } @@ -43,20 +43,20 @@ var redirect = { } } -function handleRequests(srv) { - ['http', 'https'].forEach(function(proto) { - ['localhost', '127.0.0.1'].forEach(function(host) { - srv.on(util.format('/to/%s/%s', proto, host), function(req, res) { +function handleRequests (srv) { + ['http', 'https'].forEach(function (proto) { + ['localhost', '127.0.0.1'].forEach(function (host) { + srv.on(util.format('/to/%s/%s', proto, host), function (req, res) { var r = redirect .from(srv.protocol, req.headers.host.split(':')[0]) .to(proto, host) res.writeHead(301, { - location : r.dst + location: r.dst }) res.end() }) - srv.on(util.format('/from/%s/%s', proto, host), function(req, res) { + srv.on(util.format('/from/%s/%s', proto, host), function (req, res) { res.end('auth: ' + (req.headers.authorization || '(nothing)')) }) }) @@ -66,9 +66,9 @@ function handleRequests(srv) { handleRequests(s) handleRequests(ss) -function runTest(name, redir, expectAuth) { - tape('redirect to ' + name, function(t) { - request(redir.src, function(err, res, body) { +function runTest (name, redir, expectAuth) { + tape('redirect to ' + name, function (t) { + request(redir.src, function (err, res, body) { t.equal(err, null) t.equal(res.request.uri.href, redir.dst) t.equal(res.statusCode, 200) @@ -80,7 +80,7 @@ function runTest(name, redir, expectAuth) { }) } -function addTests() { +function addTests () { runTest('same host and protocol', redirect.from('http', 'localhost').to('http', 'localhost'), true) @@ -98,13 +98,13 @@ function addTests() { false) } -tape('setup', function(t) { - s.listen(0, function() { - ss.listen(0, function() { +tape('setup', function (t) { + s.listen(0, function () { + ss.listen(0, function () { addTests() - tape('cleanup', function(t) { - s.destroy(function() { - ss.destroy(function() { + tape('cleanup', function (t) { + s.destroy(function () { + ss.destroy(function () { t.end() }) }) @@ -114,18 +114,18 @@ tape('setup', function(t) { }) }) -tape('redirect URL helper', function(t) { +tape('redirect URL helper', function (t) { t.deepEqual( redirect.from('http', 'localhost').to('https', '127.0.0.1'), { - src : util.format('http://localhost:%d/to/https/127.0.0.1', s.port), - dst : util.format('https://127.0.0.1:%d/from/http/localhost', ss.port) + src: util.format('http://localhost:%d/to/https/127.0.0.1', s.port), + dst: util.format('https://127.0.0.1:%d/from/http/localhost', ss.port) }) t.deepEqual( redirect.from('https', 'localhost').to('http', 'localhost'), { - src : util.format('https://localhost:%d/to/http/localhost', ss.port), - dst : util.format('http://localhost:%d/from/https/localhost', s.port) + src: util.format('https://localhost:%d/to/http/localhost', ss.port), + dst: util.format('http://localhost:%d/from/https/localhost', s.port) }) t.end() }) diff --git a/tests/test-redirect-complex.js b/tests/test-redirect-complex.js index 4f11ab56b..072b5986c 100644 --- a/tests/test-redirect-complex.js +++ b/tests/test-redirect-complex.js @@ -1,27 +1,29 @@ 'use strict' var server = require('./server') - , request = require('../index') - , events = require('events') - , tape = require('tape') - , destroyable = require('server-destroy') +var request = require('../index') +var events = require('events') +var tape = require('tape') +var destroyable = require('server-destroy') var s = server.createServer() - , ss = server.createSSLServer() - , e = new events.EventEmitter() +var ss = server.createSSLServer() +var e = new events.EventEmitter() destroyable(s) destroyable(ss) -function bouncy(s, serverUrl) { - var redirs = { a: 'b' - , b: 'c' - , c: 'd' - , d: 'e' - , e: 'f' - , f: 'g' - , g: 'h' - , h: 'end' } +function bouncy (s, serverUrl) { + var redirs = { + a: 'b', + b: 'c', + c: 'd', + d: 'e', + e: 'f', + f: 'g', + g: 'h', + h: 'end' + } var perm = true Object.keys(redirs).forEach(function (p) { @@ -31,7 +33,7 @@ function bouncy(s, serverUrl) { var type = perm ? 301 : 302 perm = !perm s.on('/' + p, function (req, res) { - setTimeout(function() { + setTimeout(function () { res.writeHead(type, { location: serverUrl + '/' + t }) res.end() }, Math.round(Math.random() * 25)) @@ -46,9 +48,9 @@ function bouncy(s, serverUrl) { }) } -tape('setup', function(t) { - s.listen(0, function() { - ss.listen(0, function() { +tape('setup', function (t) { + s.listen(0, function () { + ss.listen(0, function () { bouncy(s, ss.url) bouncy(ss, s.url) t.end() @@ -56,23 +58,23 @@ tape('setup', function(t) { }) }) -tape('lots of redirects', function(t) { +tape('lots of redirects', function (t) { var n = 10 t.plan(n * 4) - function doRedirect(i) { + function doRedirect (i) { var key = 'test_' + i request({ url: (i % 2 ? s.url : ss.url) + '/a', headers: { 'x-test-key': key }, rejectUnauthorized: false - }, function(err, res, body) { + }, function (err, res, body) { t.equal(err, null) t.equal(res.statusCode, 200) t.equal(body, key) }) - e.once('hit-' + key, function(v) { + e.once('hit-' + key, function (v) { t.equal(v, key) }) } @@ -82,9 +84,9 @@ tape('lots of redirects', function(t) { } }) -tape('cleanup', function(t) { - s.destroy(function() { - ss.destroy(function() { +tape('cleanup', function (t) { + s.destroy(function () { + ss.destroy(function () { t.end() }) }) diff --git a/tests/test-redirect.js b/tests/test-redirect.js index decfd2602..b7b5ca676 100644 --- a/tests/test-redirect.js +++ b/tests/test-redirect.js @@ -1,34 +1,34 @@ 'use strict' var server = require('./server') - , assert = require('assert') - , request = require('../index') - , tape = require('tape') - , http = require('http') - , destroyable = require('server-destroy') +var assert = require('assert') +var request = require('../index') +var tape = require('tape') +var http = require('http') +var destroyable = require('server-destroy') var s = server.createServer() - , ss = server.createSSLServer() - , hits = {} - , jar = request.jar() +var ss = server.createSSLServer() +var hits = {} +var jar = request.jar() destroyable(s) destroyable(ss) -s.on('/ssl', function(req, res) { +s.on('/ssl', function (req, res) { res.writeHead(302, { - location : ss.url + '/' + location: ss.url + '/' }) res.end() }) -ss.on('/', function(req, res) { +ss.on('/', function (req, res) { res.writeHead(200) res.end('SSL') }) -function createRedirectEndpoint(code, label, landing) { - s.on('/' + label, function(req, res) { +function createRedirectEndpoint (code, label, landing) { + s.on('/' + label, function (req, res) { hits[label] = true res.writeHead(code, { 'location': s.url + '/' + landing, @@ -38,8 +38,8 @@ function createRedirectEndpoint(code, label, landing) { }) } -function createLandingEndpoint(landing) { - s.on('/' + landing, function(req, res) { +function createLandingEndpoint (landing) { + s.on('/' + landing, function (req, res) { // Make sure the cookie doesn't get included twice, see #139: // Make sure cookies are set properly after redirect assert.equal(req.headers.cookie, 'foo=bar; quux=baz; ham=eggs') @@ -49,11 +49,11 @@ function createLandingEndpoint(landing) { }) } -function bouncer(code, label, hops) { - var hop, - landing = label + '_landing', - currentLabel, - currentLanding +function bouncer (code, label, hops) { + var hop + var landing = label + '_landing' + var currentLabel + var currentLanding hops = hops || 1 @@ -71,9 +71,9 @@ function bouncer(code, label, hops) { createLandingEndpoint(landing) } -tape('setup', function(t) { - s.listen(0, function() { - ss.listen(0, function() { +tape('setup', function (t) { + s.listen(0, function () { + ss.listen(0, function () { bouncer(301, 'temp') bouncer(301, 'double', 2) bouncer(301, 'treble', 3) @@ -85,14 +85,14 @@ tape('setup', function(t) { }) }) -tape('permanent bounce', function(t) { +tape('permanent bounce', function (t) { jar.setCookie('quux=baz', s.url) hits = {} request({ uri: s.url + '/perm', jar: jar, headers: { cookie: 'foo=bar' } - }, function(err, res, body) { + }, function (err, res, body) { t.equal(err, null) t.equal(res.statusCode, 200) t.ok(hits.perm, 'Original request is to /perm') @@ -102,7 +102,7 @@ tape('permanent bounce', function(t) { }) }) -tape('preserve HEAD method when using followAllRedirects', function(t) { +tape('preserve HEAD method when using followAllRedirects', function (t) { jar.setCookie('quux=baz', s.url) hits = {} request({ @@ -111,7 +111,7 @@ tape('preserve HEAD method when using followAllRedirects', function(t) { followAllRedirects: true, jar: jar, headers: { cookie: 'foo=bar' } - }, function(err, res, body) { + }, function (err, res, body) { t.equal(err, null) t.equal(res.statusCode, 200) t.ok(hits.perm, 'Original request is to /perm') @@ -121,13 +121,13 @@ tape('preserve HEAD method when using followAllRedirects', function(t) { }) }) -tape('temporary bounce', function(t) { +tape('temporary bounce', function (t) { hits = {} request({ uri: s.url + '/temp', jar: jar, headers: { cookie: 'foo=bar' } - }, function(err, res, body) { + }, function (err, res, body) { t.equal(err, null) t.equal(res.statusCode, 200) t.ok(hits.temp, 'Original request is to /temp') @@ -137,14 +137,14 @@ tape('temporary bounce', function(t) { }) }) -tape('prevent bouncing', function(t) { +tape('prevent bouncing', function (t) { hits = {} request({ uri: s.url + '/nope', jar: jar, headers: { cookie: 'foo=bar' }, followRedirect: false - }, function(err, res, body) { + }, function (err, res, body) { t.equal(err, null) t.equal(res.statusCode, 302) t.ok(hits.nope, 'Original request to /nope') @@ -154,12 +154,12 @@ tape('prevent bouncing', function(t) { }) }) -tape('should not follow post redirects by default', function(t) { +tape('should not follow post redirects by default', function (t) { hits = {} request.post(s.url + '/temp', { jar: jar, headers: { cookie: 'foo=bar' } - }, function(err, res, body) { + }, function (err, res, body) { t.equal(err, null) t.equal(res.statusCode, 301) t.ok(hits.temp, 'Original request is to /temp') @@ -169,14 +169,14 @@ tape('should not follow post redirects by default', function(t) { }) }) -tape('should follow post redirects when followallredirects true', function(t) { +tape('should follow post redirects when followallredirects true', function (t) { hits = {} request.post({ uri: s.url + '/temp', followAllRedirects: true, jar: jar, headers: { cookie: 'foo=bar' } - }, function(err, res, body) { + }, function (err, res, body) { t.equal(err, null) t.equal(res.statusCode, 200) t.ok(hits.temp, 'Original request is to /temp') @@ -186,7 +186,7 @@ tape('should follow post redirects when followallredirects true', function(t) { }) }) -tape('should follow post redirects when followallredirects true and followOriginalHttpMethod is enabled', function(t) { +tape('should follow post redirects when followallredirects true and followOriginalHttpMethod is enabled', function (t) { hits = {} request.post({ uri: s.url + '/temp', @@ -194,7 +194,7 @@ tape('should follow post redirects when followallredirects true and followOrigin followOriginalHttpMethod: true, jar: jar, headers: { cookie: 'foo=bar' } - }, function(err, res, body) { + }, function (err, res, body) { t.equal(err, null) t.equal(res.statusCode, 200) t.ok(hits.temp, 'Original request is to /temp') @@ -204,14 +204,14 @@ tape('should follow post redirects when followallredirects true and followOrigin }) }) -tape('should not follow post redirects when followallredirects false', function(t) { +tape('should not follow post redirects when followallredirects false', function (t) { hits = {} request.post({ uri: s.url + '/temp', followAllRedirects: false, jar: jar, headers: { cookie: 'foo=bar' } - }, function(err, res, body) { + }, function (err, res, body) { t.equal(err, null) t.equal(res.statusCode, 301) t.ok(hits.temp, 'Original request is to /temp') @@ -221,12 +221,12 @@ tape('should not follow post redirects when followallredirects false', function( }) }) -tape('should not follow delete redirects by default', function(t) { +tape('should not follow delete redirects by default', function (t) { hits = {} request.del(s.url + '/temp', { jar: jar, headers: { cookie: 'foo=bar' } - }, function(err, res, body) { + }, function (err, res, body) { t.equal(err, null) t.ok(res.statusCode >= 301 && res.statusCode < 400, 'Status is a redirect') t.ok(hits.temp, 'Original request is to /temp') @@ -236,13 +236,13 @@ tape('should not follow delete redirects by default', function(t) { }) }) -tape('should not follow delete redirects even if followredirect is set to true', function(t) { +tape('should not follow delete redirects even if followredirect is set to true', function (t) { hits = {} request.del(s.url + '/temp', { followRedirect: true, jar: jar, headers: { cookie: 'foo=bar' } - }, function(err, res, body) { + }, function (err, res, body) { t.equal(err, null) t.equal(res.statusCode, 301) t.ok(hits.temp, 'Original request is to /temp') @@ -252,13 +252,13 @@ tape('should not follow delete redirects even if followredirect is set to true', }) }) -tape('should follow delete redirects when followallredirects true', function(t) { +tape('should follow delete redirects when followallredirects true', function (t) { hits = {} request.del(s.url + '/temp', { followAllRedirects: true, jar: jar, headers: { cookie: 'foo=bar' } - }, function(err, res, body) { + }, function (err, res, body) { t.equal(err, null) t.equal(res.statusCode, 200) t.ok(hits.temp, 'Original request is to /temp') @@ -268,13 +268,13 @@ tape('should follow delete redirects when followallredirects true', function(t) }) }) -tape('should follow 307 delete redirects when followallredirects true', function(t) { +tape('should follow 307 delete redirects when followallredirects true', function (t) { hits = {} request.del(s.url + '/fwd', { followAllRedirects: true, jar: jar, headers: { cookie: 'foo=bar' } - }, function(err, res, body) { + }, function (err, res, body) { t.equal(err, null) t.equal(res.statusCode, 200) t.ok(hits.fwd, 'Original request is to /fwd') @@ -284,13 +284,13 @@ tape('should follow 307 delete redirects when followallredirects true', function }) }) -tape('double bounce', function(t) { +tape('double bounce', function (t) { hits = {} request({ uri: s.url + '/double', jar: jar, headers: { cookie: 'foo=bar' } - }, function(err, res, body) { + }, function (err, res, body) { t.equal(err, null) t.equal(res.statusCode, 200) t.ok(hits.double, 'Original request is to /double') @@ -301,8 +301,8 @@ tape('double bounce', function(t) { }) }) -tape('double bounce terminated after first redirect', function(t) { - function filterDouble(response) { +tape('double bounce terminated after first redirect', function (t) { + function filterDouble (response) { return (response.headers.location || '').indexOf('double_2') === -1 } @@ -312,7 +312,7 @@ tape('double bounce terminated after first redirect', function(t) { jar: jar, headers: { cookie: 'foo=bar' }, followRedirect: filterDouble - }, function(err, res, body) { + }, function (err, res, body) { t.equal(err, null) t.equal(res.statusCode, 301) t.ok(hits.double, 'Original request is to /double') @@ -321,8 +321,8 @@ tape('double bounce terminated after first redirect', function(t) { }) }) -tape('triple bounce terminated after second redirect', function(t) { - function filterTreble(response) { +tape('triple bounce terminated after second redirect', function (t) { + function filterTreble (response) { return (response.headers.location || '').indexOf('treble_3') === -1 } @@ -332,7 +332,7 @@ tape('triple bounce terminated after second redirect', function(t) { jar: jar, headers: { cookie: 'foo=bar' }, followRedirect: filterTreble - }, function(err, res, body) { + }, function (err, res, body) { t.equal(err, null) t.equal(res.statusCode, 301) t.ok(hits.treble, 'Original request is to /treble') @@ -341,12 +341,12 @@ tape('triple bounce terminated after second redirect', function(t) { }) }) -tape('http to https redirect', function(t) { +tape('http to https redirect', function (t) { hits = {} request.get({ uri: require('url').parse(s.url + '/ssl'), rejectUnauthorized: false - }, function(err, res, body) { + }, function (err, res, body) { t.equal(err, null) t.equal(res.statusCode, 200) t.equal(body, 'SSL', 'Got SSL redirect') @@ -354,67 +354,67 @@ tape('http to https redirect', function(t) { }) }) -tape('should have referer header by default when following redirect', function(t) { +tape('should have referer header by default when following redirect', function (t) { request.post({ uri: s.url + '/temp', jar: jar, followAllRedirects: true, headers: { cookie: 'foo=bar' } - }, function(err, res, body) { + }, function (err, res, body) { t.equal(err, null) t.equal(res.statusCode, 200) t.end() }) - .on('redirect', function() { + .on('redirect', function () { t.equal(this.headers.referer, s.url + '/temp') }) }) -tape('should not have referer header when removeRefererHeader is true', function(t) { +tape('should not have referer header when removeRefererHeader is true', function (t) { request.post({ uri: s.url + '/temp', jar: jar, followAllRedirects: true, removeRefererHeader: true, headers: { cookie: 'foo=bar' } - }, function(err, res, body) { + }, function (err, res, body) { t.equal(err, null) t.equal(res.statusCode, 200) t.end() }) - .on('redirect', function() { + .on('redirect', function () { t.equal(this.headers.referer, undefined) }) }) -tape('should preserve referer header set in the initial request when removeRefererHeader is true', function(t) { +tape('should preserve referer header set in the initial request when removeRefererHeader is true', function (t) { request.post({ uri: s.url + '/temp', jar: jar, followAllRedirects: true, removeRefererHeader: true, headers: { cookie: 'foo=bar', referer: 'http://awesome.com' } - }, function(err, res, body) { + }, function (err, res, body) { t.equal(err, null) t.equal(res.statusCode, 200) t.end() }) - .on('redirect', function() { + .on('redirect', function () { t.equal(this.headers.referer, 'http://awesome.com') }) }) -tape('should use same agent class on redirect', function(t) { +tape('should use same agent class on redirect', function (t) { var agent var calls = 0 var agentOptions = {} - function FakeAgent(agentOptions) { + function FakeAgent (agentOptions) { var createConnection agent = new http.Agent(agentOptions) createConnection = agent.createConnection - agent.createConnection = function() { + agent.createConnection = function () { calls++ return createConnection.apply(agent, arguments) } @@ -429,7 +429,7 @@ tape('should use same agent class on redirect', function(t) { headers: { cookie: 'foo=bar' }, agentOptions: agentOptions, agentClass: FakeAgent - }, function(err, res, body) { + }, function (err, res, body) { t.equal(err, null) t.equal(res.statusCode, 200) t.equal(body, 'GET temp_landing', 'Got temporary landing content') @@ -440,9 +440,9 @@ tape('should use same agent class on redirect', function(t) { }) }) -tape('cleanup', function(t) { - s.destroy(function() { - ss.destroy(function() { +tape('cleanup', function (t) { + s.destroy(function () { + ss.destroy(function () { t.end() }) }) diff --git a/tests/test-rfc3986.js b/tests/test-rfc3986.js index a48bd31db..a3918628d 100644 --- a/tests/test-rfc3986.js +++ b/tests/test-rfc3986.js @@ -1,22 +1,19 @@ 'use strict' var http = require('http') - , request = require('../index') - , tape = require('tape') - +var request = require('../index') +var tape = require('tape') function runTest (t, options) { - - var server = http.createServer(function(req, res) { - + var server = http.createServer(function (req, res) { var data = '' req.setEncoding('utf8') - req.on('data', function(d) { + req.on('data', function (d) { data += d }) - req.on('end', function() { + req.on('end', function () { if (options.qs) { t.equal(req.url, '/?rfc3986=%21%2A%28%29%27') } @@ -27,11 +24,11 @@ function runTest (t, options) { }) }) - server.listen(0, function() { + server.listen(0, function () { var port = this.address().port - request.post('http://localhost:' + port, options, function(err, res, body) { + request.post('http://localhost:' + port, options, function (err, res, body) { t.equal(err, null) - server.close(function() { + server.close(function () { t.end() }) }) @@ -39,60 +36,60 @@ function runTest (t, options) { } var bodyEscaped = 'rfc3986=%21%2A%28%29%27' - , bodyJson = '{"rfc3986":"!*()\'"}' +var bodyJson = '{"rfc3986":"!*()\'"}' var cases = [ { _name: 'qs', - qs: {rfc3986: '!*()\''}, + qs: {rfc3986: "!*()'"}, _expectBody: '' }, { _name: 'qs + json', - qs: {rfc3986: '!*()\''}, + qs: {rfc3986: "!*()'"}, json: true, _expectBody: '' }, { _name: 'form', - form: {rfc3986: '!*()\''}, + form: {rfc3986: "!*()'"}, _expectBody: bodyEscaped }, { _name: 'form + json', - form: {rfc3986: '!*()\''}, + form: {rfc3986: "!*()'"}, json: true, _expectBody: bodyEscaped }, { _name: 'qs + form', - qs: {rfc3986: '!*()\''}, - form: {rfc3986: '!*()\''}, + qs: {rfc3986: "!*()'"}, + form: {rfc3986: "!*()'"}, _expectBody: bodyEscaped }, { _name: 'qs + form + json', - qs: {rfc3986: '!*()\''}, - form: {rfc3986: '!*()\''}, + qs: {rfc3986: "!*()'"}, + form: {rfc3986: "!*()'"}, json: true, _expectBody: bodyEscaped }, { _name: 'body + header + json', headers: {'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'}, - body: 'rfc3986=!*()\'', + body: "rfc3986=!*()'", json: true, _expectBody: bodyEscaped }, { _name: 'body + json', - body: {rfc3986: '!*()\''}, + body: {rfc3986: "!*()'"}, json: true, _expectBody: bodyJson }, { _name: 'json object', - json: {rfc3986: '!*()\''}, + json: {rfc3986: "!*()'"}, _expectBody: bodyJson } ] @@ -102,7 +99,7 @@ var libs = ['qs', 'querystring'] libs.forEach(function (lib) { cases.forEach(function (options) { options.useQuerystring = (lib === 'querystring') - tape(lib + ' rfc3986 ' + options._name, function(t) { + tape(lib + ' rfc3986 ' + options._name, function (t) { runTest(t, options) }) }) diff --git a/tests/test-stream.js b/tests/test-stream.js index 88142f030..1d7bf3de0 100644 --- a/tests/test-stream.js +++ b/tests/test-stream.js @@ -1,4 +1,3 @@ - var fs = require('fs') var path = require('path') var http = require('http') @@ -6,13 +5,12 @@ var tape = require('tape') var request = require('../') var server - tape('before', function (t) { server = http.createServer() server.on('request', function (req, res) { req.pipe(res) }) - server.listen(0, function() { + server.listen(0, function () { server.url = 'http://localhost:' + this.address().port t.end() }) @@ -27,6 +25,7 @@ tape('request body stream', function (t) { body: input, encoding: null }, function (err, res, body) { + t.error(err) t.equal(body.length, fs.statSync(fpath).size) t.end() }) diff --git a/tests/test-timeout.js b/tests/test-timeout.js index 7fb733c52..2ab0639c4 100644 --- a/tests/test-timeout.js +++ b/tests/test-timeout.js @@ -1,12 +1,12 @@ 'use strict' -function checkErrCode(t, err) { +function checkErrCode (t, err) { t.notEqual(err, null) t.ok(err.code === 'ETIMEDOUT' || err.code === 'ESOCKETTIMEDOUT', 'Error ETIMEDOUT or ESOCKETTIMEDOUT') } -function checkEventHandlers(t, socket) { +function checkEventHandlers (t, socket) { var connectListeners = socket.listeners('connect') var found = false for (var i = 0; i < connectListeners.length; ++i) { @@ -20,52 +20,52 @@ function checkEventHandlers(t, socket) { } var server = require('./server') - , request = require('../index') - , tape = require('tape') +var request = require('../index') +var tape = require('tape') var s = server.createServer() // Request that waits for 200ms -s.on('/timeout', function(req, res) { - setTimeout(function() { - res.writeHead(200, {'content-type':'text/plain'}) +s.on('/timeout', function (req, res) { + setTimeout(function () { + res.writeHead(200, {'content-type': 'text/plain'}) res.write('waited') res.end() }, 200) }) -tape('setup', function(t) { - s.listen(0, function() { +tape('setup', function (t) { + s.listen(0, function () { t.end() }) }) -tape('should timeout', function(t) { +tape('should timeout', function (t) { var shouldTimeout = { url: s.url + '/timeout', timeout: 100 } - request(shouldTimeout, function(err, res, body) { + request(shouldTimeout, function (err, res, body) { checkErrCode(t, err) t.end() }) }) -tape('should set connect to false', function(t) { +tape('should set connect to false', function (t) { var shouldTimeout = { url: s.url + '/timeout', timeout: 100 } - request(shouldTimeout, function(err, res, body) { + request(shouldTimeout, function (err, res, body) { checkErrCode(t, err) t.ok(err.connect === false, 'Read Timeout Error should set \'connect\' property to false') t.end() }) }) -tape('should timeout with events', function(t) { +tape('should timeout with events', function (t) { t.plan(3) var shouldTimeoutWithEvents = { @@ -75,49 +75,49 @@ tape('should timeout with events', function(t) { var eventsEmitted = 0 request(shouldTimeoutWithEvents) - .on('error', function(err) { + .on('error', function (err) { eventsEmitted++ t.equal(1, eventsEmitted) checkErrCode(t, err) }) }) -tape('should not timeout', function(t) { +tape('should not timeout', function (t) { var shouldntTimeout = { url: s.url + '/timeout', timeout: 1200 } var socket - request(shouldntTimeout, function(err, res, body) { + request(shouldntTimeout, function (err, res, body) { t.equal(err, null) t.equal(body, 'waited') checkEventHandlers(t, socket) t.end() - }).on('socket', function(socket_) { + }).on('socket', function (socket_) { socket = socket_ }) }) -tape('no timeout', function(t) { +tape('no timeout', function (t) { var noTimeout = { url: s.url + '/timeout' } - request(noTimeout, function(err, res, body) { + request(noTimeout, function (err, res, body) { t.equal(err, null) t.equal(body, 'waited') t.end() }) }) -tape('negative timeout', function(t) { // should be treated a zero or the minimum delay +tape('negative timeout', function (t) { // should be treated a zero or the minimum delay var negativeTimeout = { url: s.url + '/timeout', timeout: -1000 } - request(negativeTimeout, function(err, res, body) { + request(negativeTimeout, function (err, res, body) { // Only verify error if it is set, since using a timeout value of 0 can lead // to inconsistent results, depending on a variety of factors if (err) { @@ -127,13 +127,13 @@ tape('negative timeout', function(t) { // should be treated a zero or the minimu }) }) -tape('float timeout', function(t) { // should be rounded by setTimeout anyway +tape('float timeout', function (t) { // should be rounded by setTimeout anyway var floatTimeout = { url: s.url + '/timeout', timeout: 100.76 } - request(floatTimeout, function(err, res, body) { + request(floatTimeout, function (err, res, body) { checkErrCode(t, err) t.end() }) @@ -151,7 +151,7 @@ var nonRoutable = [ '172.31.255.255' ] var nrIndex = 0 -function getNonRoutable() { +function getNonRoutable () { var ip = nonRoutable[nrIndex] if (!ip) { throw new Error('No more non-routable addresses') @@ -159,14 +159,14 @@ function getNonRoutable() { ++nrIndex return ip } -tape('connect timeout', function tryConnect(t) { +tape('connect timeout', function tryConnect (t) { var tarpitHost = 'http://' + getNonRoutable() var shouldConnectTimeout = { url: tarpitHost + '/timeout', timeout: 100 } var socket - request(shouldConnectTimeout, function(err) { + request(shouldConnectTimeout, function (err) { t.notEqual(err, null) if (err.code === 'ENETUNREACH' && nrIndex < nonRoutable.length) { // With some network configurations, some addresses will be reported as @@ -179,19 +179,19 @@ tape('connect timeout', function tryConnect(t) { checkEventHandlers(t, socket) nrIndex = 0 t.end() - }).on('socket', function(socket_) { + }).on('socket', function (socket_) { socket = socket_ }) }) -tape('connect timeout with non-timeout error', function tryConnect(t) { +tape('connect timeout with non-timeout error', function tryConnect (t) { var tarpitHost = 'http://' + getNonRoutable() var shouldConnectTimeout = { url: tarpitHost + '/timeout', timeout: 1000 } var socket - request(shouldConnectTimeout, function(err) { + request(shouldConnectTimeout, function (err) { t.notEqual(err, null) if (err.code === 'ENETUNREACH' && nrIndex < nonRoutable.length) { // With some network configurations, some addresses will be reported as @@ -201,26 +201,27 @@ tape('connect timeout with non-timeout error', function tryConnect(t) { } // Delay the check since the 'connect' handler is removed in a separate // 'error' handler which gets triggered after this callback - setImmediate(function() { + setImmediate(function () { checkEventHandlers(t, socket) nrIndex = 0 t.end() }) - }).on('socket', function(socket_) { + }).on('socket', function (socket_) { socket = socket_ - setImmediate(function() { + setImmediate(function () { socket.emit('error', new Error('Fake Error')) }) }) }) -tape('request timeout with keep-alive connection', function(t) { - var agent = new require('http').Agent({ keepAlive: true }) +tape('request timeout with keep-alive connection', function (t) { + var Agent = require('http').Agent + var agent = new Agent({ keepAlive: true }) var firstReq = { url: s.url + '/timeout', agent: agent } - request(firstReq, function(err) { + request(firstReq, function (err) { // We should now still have a socket open. For the second request we should // see a request timeout on the active socket ... t.equal(err, null) @@ -229,22 +230,22 @@ tape('request timeout with keep-alive connection', function(t) { timeout: 100, agent: agent } - request(shouldReqTimeout, function(err) { + request(shouldReqTimeout, function (err) { checkErrCode(t, err) t.ok(err.connect === false, 'Error should have been a request timeout error') t.end() - }).on('socket', function(socket) { + }).on('socket', function (socket) { var isConnecting = socket._connecting || socket.connecting t.ok(isConnecting !== true, 'Socket should already be connected') }) - }).on('socket', function(socket) { + }).on('socket', function (socket) { var isConnecting = socket._connecting || socket.connecting t.ok(isConnecting === true, 'Socket should be new') }) }) -tape('cleanup', function(t) { - s.close(function() { +tape('cleanup', function (t) { + s.close(function () { t.end() }) }) diff --git a/tests/test-timing.js b/tests/test-timing.js index 4e87afcee..f3e77f929 100644 --- a/tests/test-timing.js +++ b/tests/test-timing.js @@ -1,35 +1,38 @@ 'use strict' var server = require('./server') - , request = require('../index') - , tape = require('tape') +var request = require('../index') +var tape = require('tape') +var http = require('http') -var plain_server = server.createServer() - , redirect_mock_time = 10 +var plainServer = server.createServer() +var redirectMockTime = 10 -tape('setup', function(t) { - plain_server.listen(0, function() { - plain_server.on('/', function (req, res) { +tape('setup', function (t) { + plainServer.listen(0, function () { + plainServer.on('/', function (req, res) { res.writeHead(200) res.end('plain') }) - plain_server.on('/redir', function (req, res) { + plainServer.on('/redir', function (req, res) { // fake redirect delay to ensure strong signal for rollup check - setTimeout(function() { - res.writeHead(301, { 'location': 'http://localhost:' + plain_server.port + '/' }) + setTimeout(function () { + res.writeHead(301, { 'location': 'http://localhost:' + plainServer.port + '/' }) res.end() - }, redirect_mock_time) + }, redirectMockTime) }) t.end() }) }) -tape('non-redirected request is timed', function(t) { +tape('non-redirected request is timed', function (t) { var options = {time: true} + var start = new Date().getTime() - var r = request('http://localhost:' + plain_server.port + '/', options, function(err, res, body) { + var r = request('http://localhost:' + plainServer.port + '/', options, function (err, res, body) { var end = new Date().getTime() + t.equal(err, null) t.equal(typeof res.elapsedTime, 'number') t.equal(typeof res.responseStartTime, 'number') @@ -63,7 +66,7 @@ tape('non-redirected request is timed', function(t) { t.deepEqual(propNames, ['socket', 'lookup', 'connect', 'response', 'end']) propNames = [] - for (var propName in res.timingPhases) { + for (propName in res.timingPhases) { if (res.timingPhases.hasOwnProperty(propName)) { propNames.push(propName) } @@ -74,25 +77,26 @@ tape('non-redirected request is timed', function(t) { }) }) -tape('redirected request is timed with rollup', function(t) { +tape('redirected request is timed with rollup', function (t) { var options = {time: true} - var r = request('http://localhost:' + plain_server.port + '/redir', options, function(err, res, body) { + var r = request('http://localhost:' + plainServer.port + '/redir', options, function (err, res, body) { t.equal(err, null) t.equal(typeof res.elapsedTime, 'number') t.equal(typeof res.responseStartTime, 'number') t.equal((res.elapsedTime > 0), true) t.equal((res.responseStartTime > 0), true) - t.equal((res.elapsedTime > redirect_mock_time), true) + t.equal((res.elapsedTime > redirectMockTime), true) t.equal((res.responseStartTime > r.startTime), true) t.end() }) }) -tape('keepAlive is timed', function(t) { - var agent = new require('http').Agent({ keepAlive: true }) +tape('keepAlive is timed', function (t) { + var agent = new http.Agent({ keepAlive: true }) var options = { time: true, agent: agent } var start1 = new Date().getTime() - request('http://localhost:' + plain_server.port + '/', options, function(err1, res1, body1) { + + request('http://localhost:' + plainServer.port + '/', options, function (err1, res1, body1) { var end1 = new Date().getTime() // ensure the first request's timestamps look ok @@ -106,7 +110,7 @@ tape('keepAlive is timed', function(t) { // open a second request with the same agent so we re-use the same connection var start2 = new Date().getTime() - request('http://localhost:' + plain_server.port + '/', options, function(err2, res2, body2) { + request('http://localhost:' + plainServer.port + '/', options, function (err2, res2, body2) { var end2 = new Date().getTime() // ensure the second request's timestamps look ok @@ -115,8 +119,8 @@ tape('keepAlive is timed', function(t) { // ensure socket==lookup==connect for the second request t.equal((res2.timings.socket >= 0), true) - t.equal((res2.timings.lookup == res2.timings.socket), true) - t.equal((res2.timings.connect == res2.timings.lookup), true) + t.equal((res2.timings.lookup === res2.timings.socket), true) + t.equal((res2.timings.connect === res2.timings.lookup), true) t.equal((res2.timings.response >= res2.timings.connect), true) // explicitly shut down the agent @@ -136,8 +140,8 @@ tape('keepAlive is timed', function(t) { }) }) -tape('cleanup', function(t) { - plain_server.close(function() { +tape('cleanup', function (t) { + plainServer.close(function () { t.end() }) }) diff --git a/tests/test-toJSON.js b/tests/test-toJSON.js index 4549844d4..43fa79169 100644 --- a/tests/test-toJSON.js +++ b/tests/test-toJSON.js @@ -1,45 +1,45 @@ 'use strict' var request = require('../index') - , http = require('http') - , tape = require('tape') +var http = require('http') +var tape = require('tape') var s = http.createServer(function (req, resp) { resp.statusCode = 200 resp.end('asdf') }) -tape('setup', function(t) { - s.listen(0, function() { +tape('setup', function (t) { + s.listen(0, function () { s.url = 'http://localhost:' + this.address().port t.end() }) }) -tape('request().toJSON()', function(t) { +tape('request().toJSON()', function (t) { var r = request({ url: s.url, headers: { foo: 'bar' } - }, function(err, res) { - var json_r = JSON.parse(JSON.stringify(r)) - , json_res = JSON.parse(JSON.stringify(res)) + }, function (err, res) { + var jsonR = JSON.parse(JSON.stringify(r)) + var jsonRes = JSON.parse(JSON.stringify(res)) t.equal(err, null) - t.equal(json_r.uri.href, r.uri.href) - t.equal(json_r.method, r.method) - t.equal(json_r.headers.foo, r.headers.foo) + t.equal(jsonR.uri.href, r.uri.href) + t.equal(jsonR.method, r.method) + t.equal(jsonR.headers.foo, r.headers.foo) - t.equal(json_res.statusCode, res.statusCode) - t.equal(json_res.body, res.body) - t.equal(json_res.headers.date, res.headers.date) + t.equal(jsonRes.statusCode, res.statusCode) + t.equal(jsonRes.body, res.body) + t.equal(jsonRes.headers.date, res.headers.date) t.end() }) }) -tape('cleanup', function(t) { - s.close(function() { +tape('cleanup', function (t) { + s.close(function () { t.end() }) }) diff --git a/tests/test-tunnel.js b/tests/test-tunnel.js index 75847345a..fa2ebce33 100644 --- a/tests/test-tunnel.js +++ b/tests/test-tunnel.js @@ -1,33 +1,34 @@ 'use strict' var server = require('./server') - , tape = require('tape') - , request = require('../index') - , https = require('https') - , net = require('net') - , fs = require('fs') - , path = require('path') - , util = require('util') - , url = require('url') - , destroyable = require('server-destroy') +var tape = require('tape') +var request = require('../index') +var https = require('https') +var net = require('net') +var fs = require('fs') +var path = require('path') +var util = require('util') +var url = require('url') +var destroyable = require('server-destroy') var events = [] - , caFile = path.resolve(__dirname, 'ssl/ca/ca.crt') - , ca = fs.readFileSync(caFile) - , clientCert = fs.readFileSync(path.resolve(__dirname, 'ssl/ca/client.crt')) - , clientKey = fs.readFileSync(path.resolve(__dirname, 'ssl/ca/client-enc.key')) - , clientPassword = 'password' - , sslOpts = { - key : path.resolve(__dirname, 'ssl/ca/localhost.key'), - cert : path.resolve(__dirname, 'ssl/ca/localhost.crt') - } - , mutualSSLOpts = { - key : path.resolve(__dirname, 'ssl/ca/localhost.key'), - cert : path.resolve(__dirname, 'ssl/ca/localhost.crt'), - ca : caFile, - requestCert : true, - rejectUnauthorized : true - } +var caFile = path.resolve(__dirname, 'ssl/ca/ca.crt') +var ca = fs.readFileSync(caFile) +var clientCert = fs.readFileSync(path.resolve(__dirname, 'ssl/ca/client.crt')) +var clientKey = fs.readFileSync(path.resolve(__dirname, 'ssl/ca/client-enc.key')) +var clientPassword = 'password' +var sslOpts = { + key: path.resolve(__dirname, 'ssl/ca/localhost.key'), + cert: path.resolve(__dirname, 'ssl/ca/localhost.crt') +} + +var mutualSSLOpts = { + key: path.resolve(__dirname, 'ssl/ca/localhost.key'), + cert: path.resolve(__dirname, 'ssl/ca/localhost.crt'), + ca: caFile, + requestCert: true, + rejectUnauthorized: true +} // this is needed for 'https over http, tunnel=false' test // from https://github.com/coolaj86/node-ssl-root-cas/blob/v1.1.9-beta/ssl-root-cas.js#L4267-L4281 @@ -36,8 +37,8 @@ httpsOpts.ca = httpsOpts.ca || [] httpsOpts.ca.push(ca) var s = server.createServer() - , ss = server.createSSLServer(sslOpts) - , ss2 = server.createSSLServer(mutualSSLOpts) +var ss = server.createSSLServer(sslOpts) +var ss2 = server.createSSLServer(mutualSSLOpts) // XXX when tunneling https over https, connections get left open so the server // doesn't want to close normally (and same issue with http server on v0.8.x) @@ -45,17 +46,17 @@ destroyable(s) destroyable(ss) destroyable(ss2) -function event() { +function event () { events.push(util.format.apply(null, arguments)) } -function setListeners(server, type) { - server.on('/', function(req, res) { +function setListeners (server, type) { + server.on('/', function (req, res) { event('%s response', type) res.end(type + ' ok') }) - server.on('request', function(req, res) { + server.on('request', function (req, res) { if (/^https?:/.test(req.url)) { // This is a proxy request var dest = req.url.split(':')[0] @@ -65,29 +66,29 @@ function setListeners(server, type) { dest += '->' + match[1] } event('%s proxy to %s', type, dest) - request(req.url, { followRedirect : false }).pipe(res) + request(req.url, { followRedirect: false }).pipe(res) } }) - server.on('/redirect/http', function(req, res) { + server.on('/redirect/http', function (req, res) { event('%s redirect to http', type) res.writeHead(301, { - location : s.url + location: s.url }) res.end() }) - server.on('/redirect/https', function(req, res) { + server.on('/redirect/https', function (req, res) { event('%s redirect to https', type) res.writeHead(301, { - location : ss.url + location: ss.url }) res.end() }) - server.on('connect', function(req, client, head) { + server.on('connect', function (req, client, head) { var u = url.parse(req.url) - var server = net.connect(u.host, u.port, function() { + var server = net.connect(u.host, u.port, function () { event('%s connect to %s', type, req.url) client.write('HTTP/1.1 200 Connection established\r\n\r\n') client.pipe(server) @@ -105,7 +106,7 @@ setListeners(ss2, 'https') // proxy in tunnel-agent (this is necessary for "* over https" tests) var customCaCount = 0 var httpsRequestOld = https.request -https.request = function(options) { +https.request = function (options) { if (customCaCount) { options.ca = ca customCaCount-- @@ -113,13 +114,13 @@ https.request = function(options) { return httpsRequestOld.apply(this, arguments) } -function runTest(name, opts, expected) { - tape(name, function(t) { +function runTest (name, opts, expected) { + tape(name, function (t) { opts.ca = ca if (opts.proxy === ss.url) { customCaCount = (opts.url === ss.url ? 2 : 1) } - request(opts, function(err, res, body) { + request(opts, function (err, res, body) { event(err ? 'err ' + err.message : res.statusCode + ' ' + body) t.deepEqual(events, expected) events = [] @@ -128,13 +129,13 @@ function runTest(name, opts, expected) { }) } -function addTests() { +function addTests () { // HTTP OVER HTTP runTest('http over http, tunnel=true', { - url : s.url, - proxy : s.url, - tunnel : true + url: s.url, + proxy: s.url, + tunnel: true }, [ 'http connect to localhost:' + s.port, 'http response', @@ -142,9 +143,9 @@ function addTests() { ]) runTest('http over http, tunnel=false', { - url : s.url, - proxy : s.url, - tunnel : false + url: s.url, + proxy: s.url, + tunnel: false }, [ 'http proxy to http', 'http response', @@ -152,21 +153,20 @@ function addTests() { ]) runTest('http over http, tunnel=default', { - url : s.url, - proxy : s.url + url: s.url, + proxy: s.url }, [ 'http proxy to http', 'http response', '200 http ok' ]) - // HTTP OVER HTTPS runTest('http over https, tunnel=true', { - url : s.url, - proxy : ss.url, - tunnel : true + url: s.url, + proxy: ss.url, + tunnel: true }, [ 'https connect to localhost:' + s.port, 'http response', @@ -174,9 +174,9 @@ function addTests() { ]) runTest('http over https, tunnel=false', { - url : s.url, - proxy : ss.url, - tunnel : false + url: s.url, + proxy: ss.url, + tunnel: false }, [ 'https proxy to http', 'http response', @@ -184,21 +184,20 @@ function addTests() { ]) runTest('http over https, tunnel=default', { - url : s.url, - proxy : ss.url + url: s.url, + proxy: ss.url }, [ 'https proxy to http', 'http response', '200 http ok' ]) - // HTTPS OVER HTTP runTest('https over http, tunnel=true', { - url : ss.url, - proxy : s.url, - tunnel : true + url: ss.url, + proxy: s.url, + tunnel: true }, [ 'http connect to localhost:' + ss.port, 'https response', @@ -206,9 +205,9 @@ function addTests() { ]) runTest('https over http, tunnel=false', { - url : ss.url, - proxy : s.url, - tunnel : false + url: ss.url, + proxy: s.url, + tunnel: false }, [ 'http proxy to https', 'https response', @@ -216,21 +215,20 @@ function addTests() { ]) runTest('https over http, tunnel=default', { - url : ss.url, - proxy : s.url + url: ss.url, + proxy: s.url }, [ 'http connect to localhost:' + ss.port, 'https response', '200 https ok' ]) - // HTTPS OVER HTTPS runTest('https over https, tunnel=true', { - url : ss.url, - proxy : ss.url, - tunnel : true + url: ss.url, + proxy: ss.url, + tunnel: true }, [ 'https connect to localhost:' + ss.port, 'https response', @@ -238,10 +236,10 @@ function addTests() { ]) runTest('https over https, tunnel=false', { - url : ss.url, - proxy : ss.url, - tunnel : false, - pool : false // must disable pooling here or Node.js hangs + url: ss.url, + proxy: ss.url, + tunnel: false, + pool: false // must disable pooling here or Node.js hangs }, [ 'https proxy to https', 'https response', @@ -249,21 +247,20 @@ function addTests() { ]) runTest('https over https, tunnel=default', { - url : ss.url, - proxy : ss.url + url: ss.url, + proxy: ss.url }, [ 'https connect to localhost:' + ss.port, 'https response', '200 https ok' ]) - // HTTP->HTTP OVER HTTP runTest('http->http over http, tunnel=true', { - url : s.url + '/redirect/http', - proxy : s.url, - tunnel : true + url: s.url + '/redirect/http', + proxy: s.url, + tunnel: true }, [ 'http connect to localhost:' + s.port, 'http redirect to http', @@ -273,9 +270,9 @@ function addTests() { ]) runTest('http->http over http, tunnel=false', { - url : s.url + '/redirect/http', - proxy : s.url, - tunnel : false + url: s.url + '/redirect/http', + proxy: s.url, + tunnel: false }, [ 'http proxy to http->http', 'http redirect to http', @@ -285,8 +282,8 @@ function addTests() { ]) runTest('http->http over http, tunnel=default', { - url : s.url + '/redirect/http', - proxy : s.url + url: s.url + '/redirect/http', + proxy: s.url }, [ 'http proxy to http->http', 'http redirect to http', @@ -295,13 +292,12 @@ function addTests() { '200 http ok' ]) - // HTTP->HTTPS OVER HTTP runTest('http->https over http, tunnel=true', { - url : s.url + '/redirect/https', - proxy : s.url, - tunnel : true + url: s.url + '/redirect/https', + proxy: s.url, + tunnel: true }, [ 'http connect to localhost:' + s.port, 'http redirect to https', @@ -311,9 +307,9 @@ function addTests() { ]) runTest('http->https over http, tunnel=false', { - url : s.url + '/redirect/https', - proxy : s.url, - tunnel : false + url: s.url + '/redirect/https', + proxy: s.url, + tunnel: false }, [ 'http proxy to http->https', 'http redirect to https', @@ -323,8 +319,8 @@ function addTests() { ]) runTest('http->https over http, tunnel=default', { - url : s.url + '/redirect/https', - proxy : s.url + url: s.url + '/redirect/https', + proxy: s.url }, [ 'http proxy to http->https', 'http redirect to https', @@ -333,13 +329,12 @@ function addTests() { '200 https ok' ]) - // HTTPS->HTTP OVER HTTP runTest('https->http over http, tunnel=true', { - url : ss.url + '/redirect/http', - proxy : s.url, - tunnel : true + url: ss.url + '/redirect/http', + proxy: s.url, + tunnel: true }, [ 'http connect to localhost:' + ss.port, 'https redirect to http', @@ -349,9 +344,9 @@ function addTests() { ]) runTest('https->http over http, tunnel=false', { - url : ss.url + '/redirect/http', - proxy : s.url, - tunnel : false + url: ss.url + '/redirect/http', + proxy: s.url, + tunnel: false }, [ 'http proxy to https->http', 'https redirect to http', @@ -361,8 +356,8 @@ function addTests() { ]) runTest('https->http over http, tunnel=default', { - url : ss.url + '/redirect/http', - proxy : s.url + url: ss.url + '/redirect/http', + proxy: s.url }, [ 'http connect to localhost:' + ss.port, 'https redirect to http', @@ -371,13 +366,12 @@ function addTests() { '200 http ok' ]) - // HTTPS->HTTPS OVER HTTP runTest('https->https over http, tunnel=true', { - url : ss.url + '/redirect/https', - proxy : s.url, - tunnel : true + url: ss.url + '/redirect/https', + proxy: s.url, + tunnel: true }, [ 'http connect to localhost:' + ss.port, 'https redirect to https', @@ -387,9 +381,9 @@ function addTests() { ]) runTest('https->https over http, tunnel=false', { - url : ss.url + '/redirect/https', - proxy : s.url, - tunnel : false + url: ss.url + '/redirect/https', + proxy: s.url, + tunnel: false }, [ 'http proxy to https->https', 'https redirect to https', @@ -399,8 +393,8 @@ function addTests() { ]) runTest('https->https over http, tunnel=default', { - url : ss.url + '/redirect/https', - proxy : s.url + url: ss.url + '/redirect/https', + proxy: s.url }, [ 'http connect to localhost:' + ss.port, 'https redirect to https', @@ -409,16 +403,15 @@ function addTests() { '200 https ok' ]) - // MUTUAL HTTPS OVER HTTP runTest('mutual https over http, tunnel=true', { - url : ss2.url, - proxy : s.url, - tunnel : true, - cert : clientCert, - key : clientKey, - passphrase : clientPassword + url: ss2.url, + proxy: s.url, + tunnel: true, + cert: clientCert, + key: clientKey, + passphrase: clientPassword }, [ 'http connect to localhost:' + ss2.port, 'https response', @@ -440,11 +433,11 @@ function addTests() { // ]) runTest('mutual https over http, tunnel=default', { - url : ss2.url, - proxy : s.url, - cert : clientCert, - key : clientKey, - passphrase : clientPassword + url: ss2.url, + proxy: s.url, + cert: clientCert, + key: clientKey, + passphrase: clientPassword }, [ 'http connect to localhost:' + ss2.port, 'https response', @@ -452,15 +445,15 @@ function addTests() { ]) } -tape('setup', function(t) { - s.listen(0, function() { - ss.listen(0, function() { - ss2.listen(0, 'localhost', function() { +tape('setup', function (t) { + s.listen(0, function () { + ss.listen(0, function () { + ss2.listen(0, 'localhost', function () { addTests() - tape('cleanup', function(t) { - s.destroy(function() { - ss.destroy(function() { - ss2.destroy(function() { + tape('cleanup', function (t) { + s.destroy(function () { + ss.destroy(function () { + ss2.destroy(function () { t.end() }) }) diff --git a/tests/test-unix.js b/tests/test-unix.js index 7a75023b3..acf883273 100644 --- a/tests/test-unix.js +++ b/tests/test-unix.js @@ -1,23 +1,23 @@ 'use strict' var request = require('../index') - , http = require('http') - , fs = require('fs') - , rimraf = require('rimraf') - , assert = require('assert') - , tape = require('tape') - , url = require('url') +var http = require('http') +var fs = require('fs') +var rimraf = require('rimraf') +var assert = require('assert') +var tape = require('tape') +var url = require('url') var rawPath = [null, 'raw', 'path'].join('/') - , queryPath = [null, 'query', 'path'].join('/') - , searchString = '?foo=bar' - , socket = [__dirname, 'tmp-socket'].join('/') - , expectedBody = 'connected' - , statusCode = 200 +var queryPath = [null, 'query', 'path'].join('/') +var searchString = '?foo=bar' +var socket = [__dirname, 'tmp-socket'].join('/') +var expectedBody = 'connected' +var statusCode = 200 rimraf.sync(socket) -var s = http.createServer(function(req, res) { +var s = http.createServer(function (req, res) { var incomingUrl = url.parse(req.url) switch (incomingUrl.pathname) { case rawPath: @@ -36,14 +36,14 @@ var s = http.createServer(function(req, res) { res.end(expectedBody) }) -tape('setup', function(t) { - s.listen(socket, function() { +tape('setup', function (t) { + s.listen(socket, function () { t.end() }) }) -tape('unix socket connection', function(t) { - request( 'http://unix:' + socket + ':' + rawPath, function(err, res, body) { +tape('unix socket connection', function (t) { + request('http://unix:' + socket + ':' + rawPath, function (err, res, body) { t.equal(err, null, 'no error in connection') t.equal(res.statusCode, statusCode, 'got HTTP 200 OK response') t.equal(body, expectedBody, 'expected response body is received') @@ -51,13 +51,13 @@ tape('unix socket connection', function(t) { }) }) -tape('unix socket connection with qs', function(t) { +tape('unix socket connection with qs', function (t) { request({ uri: 'http://unix:' + socket + ':' + queryPath, qs: { foo: 'bar' } - }, function(err, res, body) { + }, function (err, res, body) { t.equal(err, null, 'no error in connection') t.equal(res.statusCode, statusCode, 'got HTTP 200 OK response') t.equal(body, expectedBody, 'expected response body is received') @@ -65,9 +65,9 @@ tape('unix socket connection with qs', function(t) { }) }) -tape('cleanup', function(t) { - s.close(function() { - fs.unlink(socket, function() { +tape('cleanup', function (t) { + s.close(function () { + fs.unlink(socket, function () { t.end() }) }) From 52d6945858a2d4d1a44f9dd5a8b14f0bb502fb49 Mon Sep 17 00:00:00 2001 From: "Fred K. Schott" Date: Mon, 27 Mar 2017 12:49:53 -0700 Subject: [PATCH 417/490] Add promise support section to README (#2605) --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index 3eaec064f..257d3fc52 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ request('http://www.google.com', function (error, response, body) { ## Table of contents - [Streaming](#streaming) +- [Promises & Async/Await](#promises--asyncawait) - [Forms](#forms) - [HTTP Authentication](#http-authentication) - [Custom HTTP Headers](#custom-http-headers) @@ -142,6 +143,22 @@ You can still use intermediate proxies, the requests will still follow HTTP forw --- +## Promises & Async/Await + +`request` supports both streaming and callback interfaces natively. If you'd like `request` to return a Promise instead, you can use an alternative interface wrapper for `request`. These wrappers can be useful if you prefer to work with Promises, or if you'd like to use `async`/`await` in ES2017. + +Several alternative interfaces are provided by the request team, including: +- [`request-promise`](https://github.com/request/request-promise) (uses [Bluebird](https://github.com/petkaantonov/bluebird) Promises) +- [`request-promise-native`](https://github.com/request/request-promise-native) (uses native Promises) +- [`request-promise-any`](https://github.com/request/request-promise-any) (uses [any-promise](https://www.npmjs.com/package/any-promise) Promises) + + +[back to top](#table-of-contents) + + +--- + + ## Forms `request` supports `application/x-www-form-urlencoded` and `multipart/form-data` form uploads. For `multipart/related` refer to the `multipart` API. From a76559325fb43adfad26c7c63d8a7c5900b618ef Mon Sep 17 00:00:00 2001 From: James Wright Date: Tue, 18 Apr 2017 00:40:39 +0100 Subject: [PATCH 418/490] Add convenience method for HTTP OPTIONS (#2541) * Add convenience method for HTTP OPTIONS. Tests * Suggested version no * Applying code review suggestions --- index.js | 1 + tests/test-options-convenience-method.js | 52 ++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 tests/test-options-convenience-method.js diff --git a/index.js b/index.js index 979260db8..f9b480a1d 100755 --- a/index.js +++ b/index.js @@ -65,6 +65,7 @@ function verbFunc (verb) { // define like this to please codeintel/intellisense IDEs request.get = verbFunc('get') request.head = verbFunc('head') +request.options = verbFunc('options') request.post = verbFunc('post') request.put = verbFunc('put') request.patch = verbFunc('patch') diff --git a/tests/test-options-convenience-method.js b/tests/test-options-convenience-method.js new file mode 100644 index 000000000..a9063b6ef --- /dev/null +++ b/tests/test-options-convenience-method.js @@ -0,0 +1,52 @@ +'use strict' + +var server = require('./server') + , request = require('../index') + , tape = require('tape') + , destroyable = require('server-destroy') + +var s = server.createServer() + +destroyable(s) + +tape('setup', function (t) { + s.listen(0, function () { + s.on('/options', function (req, res) { + res.writeHead(200, { + 'x-original-method': req.method, + 'allow': 'OPTIONS, GET, HEAD' + }) + + res.end() + }) + + t.end() + }) +}) + +tape('options(string, function)', function (t) { + request.options(s.url + '/options', function (err, res) { + t.equal(err, null) + t.equal(res.statusCode, 200) + t.equal(res.headers['x-original-method'], 'OPTIONS') + t.end() + }) +}) + +tape('options(object, function)', function (t) { + request.options({ + url: s.url + '/options', + headers: { foo: 'bar' } + }, function (err, res) { + t.equal(err, null) + t.equal(res.statusCode, 200) + t.equal(res.headers['x-original-method'], 'OPTIONS') + t.end() + }) +}) + +tape('cleanup', function(t) { + s.destroy(function () { + t.end() + }) +}) \ No newline at end of file From 6f286c81586a90e6a9d97055f131fdc68e523120 Mon Sep 17 00:00:00 2001 From: "Fred K. Schott" Date: Mon, 17 Apr 2017 16:53:43 -0700 Subject: [PATCH 419/490] lint fix, PR from pre-standard was merged with passing tests --- tests/test-options-convenience-method.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test-options-convenience-method.js b/tests/test-options-convenience-method.js index a9063b6ef..43231f27d 100644 --- a/tests/test-options-convenience-method.js +++ b/tests/test-options-convenience-method.js @@ -1,9 +1,9 @@ 'use strict' var server = require('./server') - , request = require('../index') - , tape = require('tape') - , destroyable = require('server-destroy') +var request = require('../index') +var tape = require('tape') +var destroyable = require('server-destroy') var s = server.createServer() @@ -45,8 +45,8 @@ tape('options(object, function)', function (t) { }) }) -tape('cleanup', function(t) { +tape('cleanup', function (t) { s.destroy(function () { t.end() }) -}) \ No newline at end of file +}) From e9992031105190e7a132ab0b5d0876073598db46 Mon Sep 17 00:00:00 2001 From: "Fred K. Schott" Date: Tue, 18 Apr 2017 18:25:56 -0500 Subject: [PATCH 420/490] Update README to simplify & update convenience methods (#2641) --- README.md | 56 ++++++++++--------------------------------------------- 1 file changed, 10 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index 257d3fc52..0eeb692c1 100644 --- a/README.md +++ b/README.md @@ -891,55 +891,19 @@ var specialRequest = baseRequest.defaults({ }) ``` -### request.put +### request.METHOD() -Same as `request()`, but defaults to `method: "PUT"`. +These HTTP method convenience functions act just like `request()` but with a default method already set for you: -```js -request.put(url) -``` - -### request.patch - -Same as `request()`, but defaults to `method: "PATCH"`. - -```js -request.patch(url) -``` - -### request.post - -Same as `request()`, but defaults to `method: "POST"`. - -```js -request.post(url) -``` - -### request.head +- *request.get()*: Defaults to `method: "GET"`. +- *request.post()*: Defaults to `method: "POST"`. +- *request.put()*: Defaults to `method: "PUT"`. +- *request.patch()*: Defaults to `method: "PATCH"`. +- *request.del() / request.delete()*: Defaults to `method: "DELETE"`. +- *request.head()*: Defaults to `method: "HEAD"`. +- *request.options()*: Defaults to `method: "OPTIONS"`. -Same as `request()`, but defaults to `method: "HEAD"`. - -```js -request.head(url) -``` - -### request.del / request.delete - -Same as `request()`, but defaults to `method: "DELETE"`. - -```js -request.del(url) -request.delete(url) -``` - -### request.get - -Same as `request()` (for uniformity). - -```js -request.get(url) -``` -### request.cookie +### request.cookie() Function that creates a new cookie. From e8fca511ba2800a809c7759a1c09ea33a440e4fb Mon Sep 17 00:00:00 2001 From: Greenkeeper Date: Wed, 19 Apr 2017 01:28:14 +0200 Subject: [PATCH 421/490] chore(package): update aws-sign2 to version 0.7.0 (#2635) https://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 61ef77ca6..e9fd88ce1 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "request.js" ], "dependencies": { - "aws-sign2": "~0.6.0", + "aws-sign2": "~0.7.0", "aws4": "^1.2.1", "caseless": "~0.12.0", "combined-stream": "~1.0.5", From 643c43ab7be269a1efaa080ff05a18fff3f64cd7 Mon Sep 17 00:00:00 2001 From: Dmytro Shpakovskyi Date: Tue, 27 Jun 2017 00:52:32 +0300 Subject: [PATCH 422/490] Fixed some text in README.md (#2658) --- README.md | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 0eeb692c1..cedc19d51 100644 --- a/README.md +++ b/README.md @@ -625,7 +625,7 @@ request.get(options); ### Using `options.agentOptions` -In the example below, we call an API requires client side SSL certificate +In the example below, we call an API that requires client side SSL certificate (in PEM format) with passphrase protected private key (in PEM format) and disable the SSLv3 protocol: ```js @@ -684,7 +684,7 @@ request.get({ The `options.har` property will override the values: `url`, `method`, `qs`, `headers`, `form`, `formData`, `body`, `json`, as well as construct multipart data and read files from disk when `request.postData.params[].fileName` is present without a matching `value`. -a validation step will check if the HAR Request format matches the latest spec (v1.2) and will skip parsing if not matching. +A validation step will check if the HAR Request format matches the latest spec (v1.2) and will skip parsing if not matching. ```js var request = require('request') @@ -743,7 +743,7 @@ The first argument can be either a `url` or an `options` object. The only requir - `qs` - object containing querystring values to be appended to the `uri` - `qsParseOptions` - object containing options to pass to the [qs.parse](https://github.com/hapijs/qs#parsing-objects) method. Alternatively pass options to the [querystring.parse](https://nodejs.org/docs/v0.12.0/api/querystring.html#querystring_querystring_parse_str_sep_eq_options) method using this format `{sep:';', eq:':', options:{}}` - `qsStringifyOptions` - object containing options to pass to the [qs.stringify](https://github.com/hapijs/qs#stringifying) method. Alternatively pass options to the [querystring.stringify](https://nodejs.org/docs/v0.12.0/api/querystring.html#querystring_querystring_stringify_obj_sep_eq_options) method using this format `{sep:';', eq:':', options:{}}`. For example, to change the way arrays are converted to query strings using the `qs` module pass the `arrayFormat` option with one of `indices|brackets|repeat` -- `useQuerystring` - If true, use `querystring` to stringify and parse +- `useQuerystring` - if true, use `querystring` to stringify and parse querystrings, otherwise use `qs` (default: `false`). Set this option to `true` if you need arrays to be serialized as `foo=bar&foo=baz` instead of the default `foo[0]=bar&foo[1]=baz`. @@ -752,7 +752,7 @@ The first argument can be either a `url` or an `options` object. The only requir - `body` - entity body for PATCH, POST and PUT requests. Must be a `Buffer`, `String` or `ReadStream`. If `json` is `true`, then `body` must be a JSON-serializable object. - `form` - when passed an object or a querystring, this sets `body` to a querystring representation of value, and adds `Content-type: application/x-www-form-urlencoded` header. When passed no options, a `FormData` instance is returned (and is piped to request). See "Forms" section above. -- `formData` - Data to pass for a `multipart/form-data` request. See +- `formData` - data to pass for a `multipart/form-data` request. See [Forms](#forms) section above. - `multipart` - array of objects which contain their own headers and `body` attributes. Sends a `multipart/related` request. See [Forms](#forms) section @@ -769,11 +769,11 @@ The first argument can be either a `url` or an `options` object. The only requir --- -- `auth` - A hash containing values `user` || `username`, `pass` || `password`, and `sendImmediately` (optional). See documentation above. -- `oauth` - Options for OAuth HMAC-SHA1 signing. See documentation above. -- `hawk` - Options for [Hawk signing](https://github.com/hueniverse/hawk). The `credentials` key must contain the necessary signing info, [see hawk docs for details](https://github.com/hueniverse/hawk#usage-example). +- `auth` - a hash containing values `user` || `username`, `pass` || `password`, and `sendImmediately` (optional). See documentation above. +- `oauth` - options for OAuth HMAC-SHA1 signing. See documentation above. +- `hawk` - options for [Hawk signing](https://github.com/hueniverse/hawk). The `credentials` key must contain the necessary signing info, [see hawk docs for details](https://github.com/hueniverse/hawk#usage-example). - `aws` - `object` containing AWS signing information. Should have the properties `key`, `secret`, and optionally `session` (note that this only works for services that require session as part of the canonical string). Also requires the property `bucket`, unless you’re specifying your `bucket` as part of the path, or the request doesn’t use a bucket (i.e. GET Services). If you want to use AWS sign version 4 use the parameter `sign_version` with value `4` otherwise the default is version 2. **Note:** you need to `npm install aws4` first. -- `httpSignature` - Options for the [HTTP Signature Scheme](https://github.com/joyent/node-http-signature/blob/master/http_signing.md) using [Joyent's library](https://github.com/joyent/node-http-signature). The `keyId` and `key` properties must be specified. See the docs for other options. +- `httpSignature` - options for the [HTTP Signature Scheme](https://github.com/joyent/node-http-signature/blob/master/http_signing.md) using [Joyent's library](https://github.com/joyent/node-http-signature). The `keyId` and `key` properties must be specified. See the docs for other options. --- @@ -785,9 +785,9 @@ The first argument can be either a `url` or an `options` object. The only requir --- -- `encoding` - Encoding to be used on `setEncoding` of response data. If `null`, the `body` is returned as a `Buffer`. Anything else **(including the default value of `undefined`)** will be passed as the [encoding](http://nodejs.org/api/buffer.html#buffer_buffer) parameter to `toString()` (meaning this is effectively `utf8` by default). (**Note:** if you expect binary data, you should set `encoding: null`.) -- `gzip` - If `true`, add an `Accept-Encoding` header to request compressed content encodings from the server (if not already present) and decode supported content encodings in the response. **Note:** Automatic decoding of the response content is performed on the body data returned through `request` (both through the `request` stream and passed to the callback function) but is not performed on the `response` stream (available from the `response` event) which is the unmodified `http.IncomingMessage` object which may contain compressed data. See example below. -- `jar` - If `true`, remember cookies for future use (or define your custom cookie jar; see examples section) +- `encoding` - encoding to be used on `setEncoding` of response data. If `null`, the `body` is returned as a `Buffer`. Anything else **(including the default value of `undefined`)** will be passed as the [encoding](http://nodejs.org/api/buffer.html#buffer_buffer) parameter to `toString()` (meaning this is effectively `utf8` by default). (**Note:** if you expect binary data, you should set `encoding: null`.) +- `gzip` - if `true`, add an `Accept-Encoding` header to request compressed content encodings from the server (if not already present) and decode supported content encodings in the response. **Note:** Automatic decoding of the response content is performed on the body data returned through `request` (both through the `request` stream and passed to the callback function) but is not performed on the `response` stream (available from the `response` event) which is the unmodified `http.IncomingMessage` object which may contain compressed data. See example below. +- `jar` - if `true`, remember cookies for future use (or define your custom cookie jar; see examples section) --- @@ -795,14 +795,14 @@ The first argument can be either a `url` or an `options` object. The only requir - `agentClass` - alternatively specify your agent's class name - `agentOptions` - and pass its options. **Note:** for HTTPS see [tls API doc for TLS/SSL options](http://nodejs.org/api/tls.html#tls_tls_connect_options_callback) and the [documentation above](#using-optionsagentoptions). - `forever` - set to `true` to use the [forever-agent](https://github.com/request/forever-agent) **Note:** Defaults to `http(s).Agent({keepAlive:true})` in node 0.12+ -- `pool` - An object describing which agents to use for the request. If this option is omitted the request will use the global agent (as long as your options allow for it). Otherwise, request will search the pool for your custom agent. If no custom agent is found, a new agent will be created and added to the pool. **Note:** `pool` is used only when the `agent` option is not specified. +- `pool` - an object describing which agents to use for the request. If this option is omitted the request will use the global agent (as long as your options allow for it). Otherwise, request will search the pool for your custom agent. If no custom agent is found, a new agent will be created and added to the pool. **Note:** `pool` is used only when the `agent` option is not specified. - A `maxSockets` property can also be provided on the `pool` object to set the max number of sockets for all agents created (ex: `pool: {maxSockets: Infinity}`). - Note that if you are sending multiple requests in a loop and creating multiple new `pool` objects, `maxSockets` will not work as intended. To work around this, either use [`request.defaults`](#requestdefaultsoptions) 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 +- `timeout` - integer containing the number of milliseconds to wait for a 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 @@ -812,9 +812,9 @@ default in Linux can be anywhere from 20-120 seconds][linux-timeout]). --- -- `localAddress` - Local interface to bind for network connections. -- `proxy` - An HTTP proxy to be used. Supports proxy Auth with Basic Auth, identical to support for the `url` parameter (by embedding the auth info in the `uri`) -- `strictSSL` - If `true`, requires SSL certificates be valid. **Note:** to use your own certificate authority, you need to specify an agent that was created with that CA as an option. +- `localAddress` - local interface to bind for network connections. +- `proxy` - an HTTP proxy to be used. Supports proxy Auth with Basic Auth, identical to support for the `url` parameter (by embedding the auth info in the `uri`) +- `strictSSL` - if `true`, requires SSL certificates be valid. **Note:** to use your own certificate authority, you need to specify an agent that was created with that CA as an option. - `tunnel` - controls the behavior of [HTTP `CONNECT` tunneling](https://en.wikipedia.org/wiki/HTTP_tunnel#HTTP_CONNECT_tunneling) as follows: @@ -822,14 +822,14 @@ default in Linux can be anywhere from 20-120 seconds][linux-timeout]). - `true` - always tunnel to the destination by making a `CONNECT` request to the proxy - `false` - request the destination as a `GET` request. -- `proxyHeaderWhiteList` - A whitelist of headers to send to a +- `proxyHeaderWhiteList` - a whitelist of headers to send to a tunneling proxy. -- `proxyHeaderExclusiveList` - A whitelist of headers to send +- `proxyHeaderExclusiveList` - a whitelist of headers to send exclusively to a tunneling proxy and not to destination. --- -- `time` - If `true`, the request-response cycle (including all redirects) is timed at millisecond resolution. When set, the following properties are added to the response object: +- `time` - if `true`, the request-response cycle (including all redirects) is timed at millisecond resolution. When set, the following properties are added to the response object: - `elapsedTime` Duration of the entire request/response in milliseconds (*deprecated*). - `responseStartTime` Timestamp when the response began (in Unix Epoch milliseconds) (*deprecated*). - `timingStart` Timestamp of the start of the request (in Unix Epoch milliseconds). @@ -847,7 +847,7 @@ default in Linux can be anywhere from 20-120 seconds][linux-timeout]). - `download`: Duration of HTTP download (`timings.end` - `timings.response`) - `total`: Duration entire HTTP round-trip (`timings.end`) -- `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)* +- `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 The callback argument gets 3 arguments: From 169be114952d3a769b13e2f321ab5736d69804bc Mon Sep 17 00:00:00 2001 From: Ryuma Yoshida Date: Sun, 2 Jul 2017 19:32:06 +0900 Subject: [PATCH 423/490] Add Node.js v8 to Travis CI --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 643e6551b..f3fc327d7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ language: node_js node_js: - node + - 8 - 6 - 4 From 479143d546d6dff378da0e5fac5801dd3bf01f15 Mon Sep 17 00:00:00 2001 From: Olivier-Moreau <30801967+Olivier-Moreau@users.noreply.github.com> Date: Thu, 24 Aug 2017 21:26:54 +0200 Subject: [PATCH 424/490] Update of hawk and qs to latest version (#2751) --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e9fd88ce1..c650f28a6 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "forever-agent": "~0.6.1", "form-data": "~2.1.1", "har-validator": "~5.0.2", - "hawk": "~3.1.3", + "hawk": "~6.0.2", "http-signature": "~1.1.0", "is-typedarray": "~1.0.0", "isstream": "~0.1.2", @@ -43,7 +43,7 @@ "mime-types": "~2.1.7", "oauth-sign": "~0.8.1", "performance-now": "^0.2.0", - "qs": "~6.4.0", + "qs": "~6.5.0", "safe-buffer": "^5.0.1", "stringstream": "~0.0.4", "tough-cookie": "~2.3.0", From ffdf0d3270a2c4427c4777cb8be7775dcdecdd95 Mon Sep 17 00:00:00 2001 From: Mikeal Rogers Date: Tue, 19 Sep 2017 12:34:08 -0700 Subject: [PATCH 425/490] Updating deps. --- .gitignore | 1 + package.json | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index e80332692..9a254ab59 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ node_modules coverage .idea npm-debug.log +package-lock.json diff --git a/package.json b/package.json index c650f28a6..deed62497 100644 --- a/package.json +++ b/package.json @@ -28,27 +28,27 @@ ], "dependencies": { "aws-sign2": "~0.7.0", - "aws4": "^1.2.1", + "aws4": "^1.6.0", "caseless": "~0.12.0", "combined-stream": "~1.0.5", - "extend": "~3.0.0", + "extend": "~3.0.1", "forever-agent": "~0.6.1", - "form-data": "~2.1.1", - "har-validator": "~5.0.2", + "form-data": "~2.3.1", + "har-validator": "~5.0.3", "hawk": "~6.0.2", - "http-signature": "~1.1.0", + "http-signature": "~1.2.0", "is-typedarray": "~1.0.0", "isstream": "~0.1.2", "json-stringify-safe": "~5.0.1", - "mime-types": "~2.1.7", - "oauth-sign": "~0.8.1", - "performance-now": "^0.2.0", - "qs": "~6.5.0", - "safe-buffer": "^5.0.1", - "stringstream": "~0.0.4", - "tough-cookie": "~2.3.0", + "mime-types": "~2.1.17", + "oauth-sign": "~0.8.2", + "performance-now": "^2.1.0", + "qs": "~6.5.1", + "safe-buffer": "^5.1.1", + "stringstream": "~0.0.5", + "tough-cookie": "~2.3.2", "tunnel-agent": "^0.6.0", - "uuid": "^3.0.0" + "uuid": "^3.1.0" }, "scripts": { "test": "npm run lint && npm run test-ci && npm run test-browser", From 0ab5c36b6715ae054b8398c80791fdd65be69f72 Mon Sep 17 00:00:00 2001 From: Mikeal Rogers Date: Tue, 19 Sep 2017 12:39:26 -0700 Subject: [PATCH 426/490] 2.82.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index deed62497..41a78d6c6 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.81.1", + "version": "2.82.0", "author": "Mikeal Rogers ", "repository": { "type": "git", From 6f1b51ed43309128487739f20f9df0699a043124 Mon Sep 17 00:00:00 2001 From: Mikeal Rogers Date: Tue, 19 Sep 2017 12:39:30 -0700 Subject: [PATCH 427/490] 2.82.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 41a78d6c6..a4ae2f4db 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.82.0", + "version": "2.82.1", "author": "Mikeal Rogers ", "repository": { "type": "git", From 5b623b55a5a3c9478a96072934a9aca89beea90f Mon Sep 17 00:00:00 2001 From: Karl Norling Date: Mon, 25 Sep 2017 13:38:11 -0400 Subject: [PATCH 428/490] Updating tough-cookie due to security fix. (#2776) - See: https://www.versioneye.com/Node.JS/tough-cookie/2.3.2 - Also tough-cookie: - https://github.com/salesforce/tough-cookie/pull/97 - https://github.com/salesforce/tough-cookie/pull/92 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a4ae2f4db..be52b6b4c 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "qs": "~6.5.1", "safe-buffer": "^5.1.1", "stringstream": "~0.0.5", - "tough-cookie": "~2.3.2", + "tough-cookie": "~2.3.3", "tunnel-agent": "^0.6.0", "uuid": "^3.1.0" }, From dd427d7aa0177a876da69f82801bf0c63a855310 Mon Sep 17 00:00:00 2001 From: Mikeal Rogers Date: Tue, 26 Sep 2017 20:00:33 -0700 Subject: [PATCH 429/490] 2.83.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index be52b6b4c..f2afc828e 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.82.1", + "version": "2.83.0", "author": "Mikeal Rogers ", "repository": { "type": "git", From 253c5e507ddb95dd88622087b6387655bd0ff935 Mon Sep 17 00:00:00 2001 From: Mikeal Rogers Date: Tue, 26 Sep 2017 20:00:37 -0700 Subject: [PATCH 430/490] 2.83.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f2afc828e..58090fa22 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.83.0", + "version": "2.83.1", "author": "Mikeal Rogers ", "repository": { "type": "git", From efeaf004f27c23e1688c0b0ca51c96a31e2f3726 Mon Sep 17 00:00:00 2001 From: Denis Vishniakov Date: Wed, 11 Oct 2017 23:57:10 -0400 Subject: [PATCH 431/490] Fixed calculation of oauth_body_hash, issue #2792 --- lib/oauth.js | 2 +- tests/test-oauth.js | 37 +++++++++++++++++++++++-------------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/lib/oauth.js b/lib/oauth.js index 0c9c57cfe..01c626282 100644 --- a/lib/oauth.js +++ b/lib/oauth.js @@ -71,7 +71,7 @@ OAuth.prototype.buildBodyHash = function (_oauth, body) { shasum.update(body || '') var sha1 = shasum.digest('hex') - return Buffer.from(sha1).toString('base64') + return Buffer.from(sha1, 'hex').toString('base64') } OAuth.prototype.concatParams = function (oa, sep, wrap) { diff --git a/tests/test-oauth.js b/tests/test-oauth.js index bfb03b971..2dd40bb9c 100644 --- a/tests/test-oauth.js +++ b/tests/test-oauth.js @@ -6,7 +6,6 @@ var fs = require('fs') var path = require('path') var request = require('../index') var tape = require('tape') -var crypto = require('crypto') var http = require('http') function getSignature (r) { @@ -540,32 +539,42 @@ tape('body transport_method + form option + url params', function (t) { }) }) -tape('body_hash manual built', function (t) { - function buildBodyHash (body) { - var shasum = crypto.createHash('sha1') - shasum.update(body || '') - var sha1 = shasum.digest('hex') - return new Buffer(sha1).toString('base64') - } +tape('body_hash manually set', function (t) { + var r = request.post( + { url: 'http://example.com', + oauth: { consumer_secret: 'consumer_secret', + body_hash: 'ManuallySetHash' + }, + json: {foo: 'bar'} + }) + + process.nextTick(function () { + var hash = r.headers.Authorization.replace(/.*oauth_body_hash="([^"]+)".*/, '$1') + t.equal('ManuallySetHash', hash) + r.abort() + t.end() + }) +}) - var json = {foo: 'bar'} +tape('body_hash automatically built for string', function (t) { var r = request.post( { url: 'http://example.com', oauth: { consumer_secret: 'consumer_secret', - body_hash: buildBodyHash(JSON.stringify(json)) + body_hash: true }, - json: json + body: 'Hello World!' }) process.nextTick(function () { var hash = r.headers.Authorization.replace(/.*oauth_body_hash="([^"]+)".*/, '$1') - t.equal('YTVlNzQ0ZDAxNjQ1NDBkMzNiMWQ3ZWE2MTZjMjhmMmZhOTdlNzU0YQ%3D%3D', hash) + // from https://tools.ietf.org/id/draft-eaton-oauth-bodyhash-00.html#anchor15 + t.equal('Lve95gjOVATpfV8EL5X4nxwjKHE%3D', hash) r.abort() t.end() }) }) -tape('body_hash automatic built', function (t) { +tape('body_hash automatically built for JSON', function (t) { var r = request.post( { url: 'http://example.com', oauth: { consumer_secret: 'consumer_secret', @@ -576,7 +585,7 @@ tape('body_hash automatic built', function (t) { process.nextTick(function () { var hash = r.headers.Authorization.replace(/.*oauth_body_hash="([^"]+)".*/, '$1') - t.equal('YTVlNzQ0ZDAxNjQ1NDBkMzNiMWQ3ZWE2MTZjMjhmMmZhOTdlNzU0YQ%3D%3D', hash) + t.equal('pedE0BZFQNM7HX6mFsKPL6l%2BdUo%3D', hash) r.abort() t.end() }) From cfd230708c5a0a5c09935d5f1074f43de6e9c010 Mon Sep 17 00:00:00 2001 From: kornel-kedzierski Date: Tue, 6 Mar 2018 09:46:03 +0100 Subject: [PATCH 432/490] Update hawk to 7.0.7 (#2880) --- package.json | 2 +- request.js | 2 +- tests/test-hawk.js | 18 ++++++++++-------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 58090fa22..a1dce8e31 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "forever-agent": "~0.6.1", "form-data": "~2.3.1", "har-validator": "~5.0.3", - "hawk": "~6.0.2", + "hawk": "~7.0.7", "http-signature": "~1.2.0", "is-typedarray": "~1.0.0", "isstream": "~0.1.2", diff --git a/request.js b/request.js index ff19ca39c..404c859d2 100644 --- a/request.js +++ b/request.js @@ -1426,7 +1426,7 @@ Request.prototype.httpSignature = function (opts) { } Request.prototype.hawk = function (opts) { var self = this - self.setHeader('Authorization', hawk.client.header(self.uri, self.method, opts).field) + self.setHeader('Authorization', hawk.client.header(self.uri, self.method, opts).header) } Request.prototype.oauth = function (_oauth) { var self = this diff --git a/tests/test-hawk.js b/tests/test-hawk.js index 34db8da25..19aab5d7d 100644 --- a/tests/test-hawk.js +++ b/tests/test-hawk.js @@ -7,22 +7,24 @@ var tape = require('tape') var assert = require('assert') var server = http.createServer(function (req, res) { - var getCred = function (id, callback) { + var getCred = function (id) { assert.equal(id, 'dh37fgj492je') var credentials = { key: 'werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn', algorithm: 'sha256', user: 'Steve' } - return callback(null, credentials) + return credentials } - - hawk.server.authenticate(req, getCred, {}, function (err, credentials, attributes) { - res.writeHead(err ? 401 : 200, { - 'Content-Type': 'text/plain' + hawk.server.authenticate(req, getCred) + .then((credentials, artifacts) => { + res.writeHead(200, {'Content-Type': 'text/plain'}) + res.end('Hello ' + credentials.credentials.user) + }) + .catch(() => { + res.writeHead(401, {'Content-Type': 'text/plain'}) + res.end('Shoosh!') }) - res.end(err ? 'Shoosh!' : 'Hello ' + credentials.user) - }) }) tape('setup', function (t) { From 4b46a13daaafe83d1c7db3f86f60d7b3733cd726 Mon Sep 17 00:00:00 2001 From: simov Date: Mon, 12 Mar 2018 10:29:19 +0200 Subject: [PATCH 433/490] 2.84.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a1dce8e31..8fc0f2a37 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.83.1", + "version": "2.84.0", "author": "Mikeal Rogers ", "repository": { "type": "git", From d77c8397e387e28745ee8b66723367e0bfc70fc0 Mon Sep 17 00:00:00 2001 From: simov Date: Mon, 12 Mar 2018 10:40:11 +0200 Subject: [PATCH 434/490] Update changelog --- CHANGELOG.md | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index af76719b4..69eb01a70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,30 @@ ## Change Log +### v2.84.0 (2018/03/12) +- [#2793](https://github.com/request/request/pull/2793) Fixed calculation of oauth_body_hash, issue #2792 (@dvishniakov) +- [#2880](https://github.com/request/request/pull/2880) Update hawk to 7.0.7 (#2880) (@kornel-kedzierski) + +### v2.83.0 (2017/09/27) +- [#2776](https://github.com/request/request/pull/2776) Updating tough-cookie due to security fix. (#2776) (@karlnorling) + +### v2.82.0 (2017/09/19) +- [#2703](https://github.com/request/request/pull/2703) Add Node.js v8 to Travis CI (@ryysud) +- [#2751](https://github.com/request/request/pull/2751) Update of hawk and qs to latest version (#2751) (@Olivier-Moreau) +- [#2658](https://github.com/request/request/pull/2658) Fixed some text in README.md (#2658) (@Marketionist) +- [#2635](https://github.com/request/request/pull/2635) chore(package): update aws-sign2 to version 0.7.0 (#2635) (@greenkeeperio-bot) +- [#2641](https://github.com/request/request/pull/2641) Update README to simplify & update convenience methods (#2641) (@FredKSchott) +- [#2541](https://github.com/request/request/pull/2541) Add convenience method for HTTP OPTIONS (#2541) (@jamesseanwright) +- [#2605](https://github.com/request/request/pull/2605) Add promise support section to README (#2605) (@FredKSchott) +- [#2579](https://github.com/request/request/pull/2579) refactor(lint): replace eslint with standard (#2579) (@ahmadnassri) +- [#2598](https://github.com/request/request/pull/2598) Update codecov to version 2.0.2 🚀 (@greenkeeperio-bot) +- [#2590](https://github.com/request/request/pull/2590) Adds test-timing keepAlive test (@nicjansma) +- [#2589](https://github.com/request/request/pull/2589) fix tabulation on request example README.MD (@odykyi) +- [#2594](https://github.com/request/request/pull/2594) chore(dependencies): har-validator to 5.x [removes babel dep] (@ahmadnassri) + ### v2.81.0 (2017/03/09) - [#2584](https://github.com/request/request/pull/2584) Security issue: Upgrade qs to version 6.4.0 (@sergejmueller) +- [#2578](https://github.com/request/request/pull/2578) safe-buffer doesn't zero-fill by default, its just a polyfill. (#2578) (@mikeal) +- [#2566](https://github.com/request/request/pull/2566) Timings: Tracks 'lookup', adds 'wait' time, fixes connection re-use (#2566) (@nicjansma) - [#2574](https://github.com/request/request/pull/2574) Migrating to safe-buffer for improved security. (@mikeal) - [#2573](https://github.com/request/request/pull/2573) fixes #2572 (@ahmadnassri) @@ -186,7 +209,8 @@ - [#1687](https://github.com/request/request/pull/1687) Fix caseless bug - content-type not being set for multipart/form-data (@simov, @garymathews) ### v2.59.0 (2015/07/20) -- [#1671](https://github.com/request/request/pull/1671) Add tests and docs for using the agent, agentClass, agentOptions and forever options. Forever option defaults to using http(s).Agent in node 0.12+ (@simov) +- [#1671](https://github.com/request/request/pull/1671) Add tests and docs for using the agent, agentClass, agentOptions and forever options. + Forever option defaults to using http(s).Agent in node 0.12+ (@simov) - [#1679](https://github.com/request/request/pull/1679) Fix - do not remove OAuth param when using OAuth realm (@simov, @jhalickman) - [#1668](https://github.com/request/request/pull/1668) updated dependencies (@deamme) - [#1656](https://github.com/request/request/pull/1656) Fix form method (@simov) From b191514c1080838a579eac272dbb0d1226ebef00 Mon Sep 17 00:00:00 2001 From: simov Date: Mon, 12 Mar 2018 10:40:43 +0200 Subject: [PATCH 435/490] 2.84.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8fc0f2a37..a292127d2 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.84.0", + "version": "2.84.1", "author": "Mikeal Rogers ", "repository": { "type": "git", From 5ba8eb44da7cd639ca21070ea9be20d611b85f66 Mon Sep 17 00:00:00 2001 From: simov Date: Mon, 12 Mar 2018 12:28:03 +0200 Subject: [PATCH 436/490] Revert "Update hawk to 7.0.7 (#2880)" This reverts commit cfd230708c5a0a5c09935d5f1074f43de6e9c010. --- package.json | 2 +- request.js | 2 +- tests/test-hawk.js | 18 ++++++++---------- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index a292127d2..0cf56d34a 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "forever-agent": "~0.6.1", "form-data": "~2.3.1", "har-validator": "~5.0.3", - "hawk": "~7.0.7", + "hawk": "~6.0.2", "http-signature": "~1.2.0", "is-typedarray": "~1.0.0", "isstream": "~0.1.2", diff --git a/request.js b/request.js index 404c859d2..ff19ca39c 100644 --- a/request.js +++ b/request.js @@ -1426,7 +1426,7 @@ Request.prototype.httpSignature = function (opts) { } Request.prototype.hawk = function (opts) { var self = this - self.setHeader('Authorization', hawk.client.header(self.uri, self.method, opts).header) + self.setHeader('Authorization', hawk.client.header(self.uri, self.method, opts).field) } Request.prototype.oauth = function (_oauth) { var self = this diff --git a/tests/test-hawk.js b/tests/test-hawk.js index 19aab5d7d..34db8da25 100644 --- a/tests/test-hawk.js +++ b/tests/test-hawk.js @@ -7,24 +7,22 @@ var tape = require('tape') var assert = require('assert') var server = http.createServer(function (req, res) { - var getCred = function (id) { + var getCred = function (id, callback) { assert.equal(id, 'dh37fgj492je') var credentials = { key: 'werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn', algorithm: 'sha256', user: 'Steve' } - return credentials + return callback(null, credentials) } - hawk.server.authenticate(req, getCred) - .then((credentials, artifacts) => { - res.writeHead(200, {'Content-Type': 'text/plain'}) - res.end('Hello ' + credentials.credentials.user) - }) - .catch(() => { - res.writeHead(401, {'Content-Type': 'text/plain'}) - res.end('Shoosh!') + + hawk.server.authenticate(req, getCred, {}, function (err, credentials, attributes) { + res.writeHead(err ? 401 : 200, { + 'Content-Type': 'text/plain' }) + res.end(err ? 'Shoosh!' : 'Hello ' + credentials.user) + }) }) tape('setup', function (t) { From 5dad86e14c22c79c6b128e24ddd8dcb78a6464b7 Mon Sep 17 00:00:00 2001 From: simov Date: Mon, 12 Mar 2018 12:36:06 +0200 Subject: [PATCH 437/490] 2.85.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0cf56d34a..d3dfc3c4f 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.84.1", + "version": "2.85.0", "author": "Mikeal Rogers ", "repository": { "type": "git", From 21ef363b91c17763d6c79a639a197bf72135b97a Mon Sep 17 00:00:00 2001 From: simov Date: Mon, 12 Mar 2018 12:37:40 +0200 Subject: [PATCH 438/490] Update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 69eb01a70..1f9e8a2e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## Change Log +### v2.85.0 (2018/03/12) +- [#2880](https://github.com/request/request/pull/2880) Revert "Update hawk to 7.0.7 (#2880)" (@simov) + ### v2.84.0 (2018/03/12) - [#2793](https://github.com/request/request/pull/2793) Fixed calculation of oauth_body_hash, issue #2792 (@dvishniakov) - [#2880](https://github.com/request/request/pull/2880) Update hawk to 7.0.7 (#2880) (@kornel-kedzierski) From bbb3a0bbbe173342de8462a2171765a39681b248 Mon Sep 17 00:00:00 2001 From: simov Date: Mon, 12 Mar 2018 12:38:01 +0200 Subject: [PATCH 439/490] 2.85.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d3dfc3c4f..1c58f20aa 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.85.0", + "version": "2.85.1", "author": "Mikeal Rogers ", "repository": { "type": "git", From 219a2982dde56f5551dcd5a1acae64b01b747adc Mon Sep 17 00:00:00 2001 From: Gareth Robinson Date: Sun, 22 Apr 2018 22:54:44 +0100 Subject: [PATCH 440/490] Alterations for failing CI tests --- tests/test-headers.js | 90 +++++++++++++++++++++++++------------------ 1 file changed, 53 insertions(+), 37 deletions(-) diff --git a/tests/test-headers.js b/tests/test-headers.js index c1c29622a..6f2b79605 100644 --- a/tests/test-headers.js +++ b/tests/test-headers.js @@ -5,6 +5,15 @@ var request = require('../index') var util = require('util') var tape = require('tape') var url = require('url') +var os = require('os') + +var interfaces = os.networkInterfaces() +var loopbackKeyTest = exports.isWindows ? /Loopback Pseudo-Interface/ : /lo/ +var hasIPv6interface = Object.keys(interfaces).some(function (name) { + return loopbackKeyTest.test(name) && interfaces[name].some(function (info) { + return info.family === 'IPv6' + }) +}) var s = server.createServer() @@ -171,6 +180,11 @@ tape('undefined headers', function (t) { }) }) +var isExpectedHeaderCharacterError = function (headerName, err) { + return err.message === 'The header content contains invalid characters' || + err.message === ('Invalid character in header content ["' + headerName + '"]') +} + tape('catch invalid characters error - GET', function (t) { request({ url: s.url + '/headers.json', @@ -178,10 +192,10 @@ tape('catch invalid characters error - GET', function (t) { 'test': 'אבגד' } }, function (err, res, body) { - t.equal(err.message, 'The header content contains invalid characters') + t.true(isExpectedHeaderCharacterError('test', err)) }) .on('error', function (err) { - t.equal(err.message, 'The header content contains invalid characters') + t.true(isExpectedHeaderCharacterError('test', err)) t.end() }) }) @@ -195,49 +209,51 @@ tape('catch invalid characters error - POST', function (t) { }, body: 'beep' }, function (err, res, body) { - t.equal(err.message, 'The header content contains invalid characters') + t.true(isExpectedHeaderCharacterError('test', err)) }) .on('error', function (err) { - t.equal(err.message, 'The header content contains invalid characters') + t.true(isExpectedHeaderCharacterError('test', err)) t.end() }) }) -tape('IPv6 Host header', function (t) { - // Horrible hack to observe the raw data coming to the server - var rawData = '' +if (hasIPv6interface) { + tape('IPv6 Host header', function (t) { + // Horrible hack to observe the raw data coming to the server + var rawData = '' - s.on('connection', function (socket) { - if (socket.ondata) { - var ondata = socket.ondata - } - function handledata (d, start, end) { - if (ondata) { - rawData += d.slice(start, end).toString() - return ondata.apply(this, arguments) - } else { - rawData += d + s.on('connection', function (socket) { + if (socket.ondata) { + var ondata = socket.ondata } - } - socket.on('data', handledata) - socket.ondata = handledata - }) + function handledata (d, start, end) { + if (ondata) { + rawData += d.slice(start, end).toString() + return ondata.apply(this, arguments) + } else { + rawData += d + } + } + socket.on('data', handledata) + socket.ondata = handledata + }) - function checkHostHeader (host) { - t.ok( - new RegExp('^Host: ' + host + '$', 'im').test(rawData), - util.format( - 'Expected "Host: %s" in data "%s"', - host, rawData.trim().replace(/\r?\n/g, '\\n'))) - rawData = '' - } + function checkHostHeader (host) { + t.ok( + new RegExp('^Host: ' + host + '$', 'im').test(rawData), + util.format( + 'Expected "Host: %s" in data "%s"', + host, rawData.trim().replace(/\r?\n/g, '\\n'))) + rawData = '' + } - request({ - url: s.url.replace(url.parse(s.url).hostname, '[::1]') + '/headers.json' - }, function (err, res, body) { - t.equal(err, null) - t.equal(res.statusCode, 200) - checkHostHeader('\\[::1\\]:' + s.port) - t.end() + request({ + url: s.url.replace(url.parse(s.url).hostname, '[::1]') + '/headers.json' + }, function (err, res, body) { + t.equal(err, null) + t.equal(res.statusCode, 200) + checkHostHeader('\\[::1\\]:' + s.port) + t.end() + }) }) -}) +} From 3745cece1d3be3cd6612c1ac9fed9087674b75e2 Mon Sep 17 00:00:00 2001 From: Gareth Robinson Date: Mon, 23 Apr 2018 11:13:58 +0100 Subject: [PATCH 441/490] Correction for Windows OS identification --- tests/test-headers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-headers.js b/tests/test-headers.js index 6f2b79605..b80c9b312 100644 --- a/tests/test-headers.js +++ b/tests/test-headers.js @@ -8,7 +8,7 @@ var url = require('url') var os = require('os') var interfaces = os.networkInterfaces() -var loopbackKeyTest = exports.isWindows ? /Loopback Pseudo-Interface/ : /lo/ +var loopbackKeyTest = os.platform() === 'win32' ? /Loopback Pseudo-Interface/ : /lo/ var hasIPv6interface = Object.keys(interfaces).some(function (name) { return loopbackKeyTest.test(name) && interfaces[name].some(function (info) { return info.family === 'IPv6' From db17497d599d135d4f3c67bf926c8def318f14d5 Mon Sep 17 00:00:00 2001 From: simov Date: Fri, 4 May 2018 16:30:38 +0300 Subject: [PATCH 442/490] Use Buffer.from and Buffer.alloc in tests --- README.md | 4 ++-- tests/server.js | 2 +- tests/test-basic-auth.js | 8 ++++---- tests/test-body.js | 26 +++++++++++++------------- tests/test-emptyBody.js | 2 +- tests/test-form-data.js | 4 ++-- tests/test-form.js | 2 +- tests/test-gzip.js | 2 +- tests/test-https.js | 18 +++++++++--------- tests/test-multipart.js | 2 +- tests/test-params.js | 22 +++++++++++----------- 11 files changed, 46 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index cedc19d51..81ffd95ef 100644 --- a/README.md +++ b/README.md @@ -187,7 +187,7 @@ var formData = { // Pass a simple key-value pair my_field: 'my_value', // Pass data via Buffers - my_buffer: new Buffer([1, 2, 3]), + my_buffer: Buffer.from([1, 2, 3]), // Pass data via Streams my_file: fs.createReadStream(__dirname + '/unicycle.jpg'), // Pass multiple values /w an Array @@ -221,7 +221,7 @@ For advanced cases, you can access the form-data object itself via `r.form()`. T var r = request.post('http://service.com/upload', function optionalCallback(err, httpResponse, body) {...}) var form = r.form(); form.append('my_field', 'my_value'); -form.append('my_buffer', new Buffer([1, 2, 3])); +form.append('my_buffer', Buffer.from([1, 2, 3])); form.append('custom_file', fs.createReadStream(__dirname + '/unicycle.jpg'), {filename: 'unicycle.jpg'}); ``` See the [form-data README](https://github.com/form-data/form-data) for more information & examples. diff --git a/tests/server.js b/tests/server.js index 614f03c44..93a68913d 100644 --- a/tests/server.js +++ b/tests/server.js @@ -76,7 +76,7 @@ exports.createPostStream = function (text) { postStream.writeable = true postStream.readable = true setTimeout(function () { - postStream.emit('data', new Buffer(text)) + postStream.emit('data', Buffer.from(text)) postStream.emit('end') }, 0) return postStream diff --git a/tests/test-basic-auth.js b/tests/test-basic-auth.js index 8c1a69a1c..5368b0584 100644 --- a/tests/test-basic-auth.js +++ b/tests/test-basic-auth.js @@ -15,13 +15,13 @@ tape('setup', function (t) { var ok if (req.headers.authorization) { - if (req.headers.authorization === 'Basic ' + new Buffer('user:pass').toString('base64')) { + if (req.headers.authorization === 'Basic ' + Buffer.from('user:pass').toString('base64')) { ok = true - } else if (req.headers.authorization === 'Basic ' + new Buffer('user:').toString('base64')) { + } else if (req.headers.authorization === 'Basic ' + Buffer.from('user:').toString('base64')) { ok = true - } else if (req.headers.authorization === 'Basic ' + new Buffer(':pass').toString('base64')) { + } else if (req.headers.authorization === 'Basic ' + Buffer.from(':pass').toString('base64')) { ok = true - } else if (req.headers.authorization === 'Basic ' + new Buffer('user:pâss').toString('base64')) { + } else if (req.headers.authorization === 'Basic ' + Buffer.from('user:pâss').toString('base64')) { ok = true } else { // Bad auth header, don't send back WWW-Authenticate header diff --git a/tests/test-body.js b/tests/test-body.js index 2cbb494cf..dc482125a 100644 --- a/tests/test-body.js +++ b/tests/test-body.js @@ -35,28 +35,28 @@ addTest('testGet', { addTest('testGetChunkBreak', { resp: server.createChunkResponse( - [ new Buffer([239]), - new Buffer([163]), - new Buffer([191]), - new Buffer([206]), - new Buffer([169]), - new Buffer([226]), - new Buffer([152]), - new Buffer([131]) + [ Buffer.from([239]), + Buffer.from([163]), + Buffer.from([191]), + Buffer.from([206]), + Buffer.from([169]), + Buffer.from([226]), + Buffer.from([152]), + Buffer.from([131]) ]), expectBody: '\uF8FF\u03A9\u2603' }) addTest('testGetBuffer', { - resp: server.createGetResponse(new Buffer('TESTING!')), encoding: null, expectBody: new Buffer('TESTING!') + resp: server.createGetResponse(Buffer.from('TESTING!')), encoding: null, expectBody: Buffer.from('TESTING!') }) addTest('testGetEncoding', { - resp: server.createGetResponse(new Buffer('efa3bfcea9e29883', 'hex')), encoding: 'hex', expectBody: 'efa3bfcea9e29883' + resp: server.createGetResponse(Buffer.from('efa3bfcea9e29883', 'hex')), encoding: 'hex', expectBody: 'efa3bfcea9e29883' }) addTest('testGetUTF', { - resp: server.createGetResponse(new Buffer([0xEF, 0xBB, 0xBF, 226, 152, 131])), encoding: 'utf8', expectBody: '\u2603' + resp: server.createGetResponse(Buffer.from([0xEF, 0xBB, 0xBF, 226, 152, 131])), encoding: 'utf8', expectBody: '\u2603' }) addTest('testGetJSON', { @@ -68,7 +68,7 @@ addTest('testPutString', { }) addTest('testPutBuffer', { - resp: server.createPostValidator('PUTTINGDATA'), method: 'PUT', body: new Buffer('PUTTINGDATA') + resp: server.createPostValidator('PUTTINGDATA'), method: 'PUT', body: Buffer.from('PUTTINGDATA') }) addTest('testPutJSON', { @@ -141,7 +141,7 @@ tape('typed array', function (t) { encoding: null }, function (err, res, body) { t.error(err) - t.deepEqual(new Buffer(data), body) + t.deepEqual(Buffer.from(data), body) server.close(t.end) }) }) diff --git a/tests/test-emptyBody.js b/tests/test-emptyBody.js index 250bfe179..684d3d5ae 100644 --- a/tests/test-emptyBody.js +++ b/tests/test-emptyBody.js @@ -32,7 +32,7 @@ tape('empty body without encoding', function (t) { }, function (err, res, body) { t.equal(err, null) t.equal(res.statusCode, 200) - t.same(body, new Buffer(0)) + t.same(body, Buffer.alloc(0)) t.end() }) }) diff --git a/tests/test-form-data.js b/tests/test-form-data.js index d43a88d7c..990562be5 100644 --- a/tests/test-form-data.js +++ b/tests/test-form-data.js @@ -25,7 +25,7 @@ function runTest (t, options) { res.end() return } else { - t.ok(req.headers.authorization === 'Basic ' + new Buffer('user:pass').toString('base64')) + t.ok(req.headers.authorization === 'Basic ' + Buffer.from('user:pass').toString('base64')) } } @@ -84,7 +84,7 @@ function runTest (t, options) { var url = 'http://localhost:' + this.address().port // @NOTE: multipartFormData properties must be set here so that my_file read stream does not leak in node v0.8 multipartFormData.my_field = 'my_value' - multipartFormData.my_buffer = new Buffer([1, 2, 3]) + multipartFormData.my_buffer = Buffer.from([1, 2, 3]) multipartFormData.my_file = fs.createReadStream(localFile) multipartFormData.remote_file = request(url + '/file') multipartFormData.secret_file = { diff --git a/tests/test-form.js b/tests/test-form.js index 1c0a4d25d..5f262f204 100644 --- a/tests/test-form.js +++ b/tests/test-form.js @@ -74,7 +74,7 @@ tape('multipart form append', function (t) { var url = 'http://localhost:' + this.address().port FIELDS = [ { name: 'my_field', value: 'my_value' }, - { name: 'my_buffer', value: new Buffer([1, 2, 3]) }, + { name: 'my_buffer', value: Buffer.from([1, 2, 3]) }, { name: 'my_file', value: fs.createReadStream(localFile) }, { name: 'remote_file', value: request(url + '/file') } ] diff --git a/tests/test-gzip.js b/tests/test-gzip.js index b69f3cdc4..df0d2d6a0 100644 --- a/tests/test-gzip.js +++ b/tests/test-gzip.js @@ -69,7 +69,7 @@ tape('setup', function (t) { var a = 48271 var m = 0x7FFFFFFF var x = 1 - testContentBig = new Buffer(10240) + testContentBig = Buffer.alloc(10240) for (var i = 0; i < testContentBig.length; ++i) { x = (a * x) & m // Printable ASCII range from 32-126, inclusive diff --git a/tests/test-https.js b/tests/test-https.js index 3138f3d1e..028bc775b 100644 --- a/tests/test-https.js +++ b/tests/test-https.js @@ -55,14 +55,14 @@ function runAllTests (strict, s) { runTest('testGetChunkBreak', { resp: server.createChunkResponse( - [ new Buffer([239]), - new Buffer([163]), - new Buffer([191]), - new Buffer([206]), - new Buffer([169]), - new Buffer([226]), - new Buffer([152]), - new Buffer([131]) + [ Buffer.from([239]), + Buffer.from([163]), + Buffer.from([191]), + Buffer.from([206]), + Buffer.from([169]), + Buffer.from([226]), + Buffer.from([152]), + Buffer.from([131]) ]), expectBody: '\uf8ff\u03a9\u2603' }) @@ -76,7 +76,7 @@ function runAllTests (strict, s) { }) runTest('testPutBuffer', { - resp: server.createPostValidator('PUTTINGDATA'), method: 'PUT', body: new Buffer('PUTTINGDATA') + resp: server.createPostValidator('PUTTINGDATA'), method: 'PUT', body: Buffer.from('PUTTINGDATA') }) runTest('testPutJSON', { diff --git a/tests/test-multipart.js b/tests/test-multipart.js index e52cd0490..8eff422e2 100644 --- a/tests/test-multipart.js +++ b/tests/test-multipart.js @@ -77,7 +77,7 @@ function runTest (t, a) { multipartData = [ {name: 'my_field', body: 'my_value'}, {name: 'my_number', body: 1000}, - {name: 'my_buffer', body: new Buffer([1, 2, 3])}, + {name: 'my_buffer', body: Buffer.from([1, 2, 3])}, {name: 'my_file', body: fs.createReadStream(localFile)}, {name: 'remote_file', body: request(url + '/file')} ] diff --git a/tests/test-params.js b/tests/test-params.js index 5b7880dd4..4659aa70f 100644 --- a/tests/test-params.js +++ b/tests/test-params.js @@ -36,22 +36,22 @@ runTest('testGet', { runTest('testGetChunkBreak', { resp: server.createChunkResponse( - [ new Buffer([239]), - new Buffer([163]), - new Buffer([191]), - new Buffer([206]), - new Buffer([169]), - new Buffer([226]), - new Buffer([152]), - new Buffer([131]) + [ Buffer.from([239]), + Buffer.from([163]), + Buffer.from([191]), + Buffer.from([206]), + Buffer.from([169]), + Buffer.from([226]), + Buffer.from([152]), + Buffer.from([131]) ]), expectBody: '\uf8ff\u03a9\u2603' }) runTest('testGetBuffer', { - resp: server.createGetResponse(new Buffer('TESTING!')), + resp: server.createGetResponse(Buffer.from('TESTING!')), encoding: null, - expectBody: new Buffer('TESTING!') + expectBody: Buffer.from('TESTING!') }) runTest('testGetJSON', { @@ -69,7 +69,7 @@ runTest('testPutString', { runTest('testPutBuffer', { resp: server.createPostValidator('PUTTINGDATA'), method: 'PUT', - body: new Buffer('PUTTINGDATA') + body: Buffer.from('PUTTINGDATA') }) runTest('testPutJSON', { From 81f8cb57bbc9fed0533c268e6a0c94ec45d9da9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=BA=D0=BE=D0=B2=D0=BE=D1=80=D0=BE=D0=B4=D0=B0=20?= =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=90=D0=BD=D0=B4=D1=80?= =?UTF-8?q?=D0=B5=D0=B5=D0=B2=D0=B8=D1=87?= Date: Sun, 4 Mar 2018 01:04:49 +0300 Subject: [PATCH 443/490] Remove redundant code That one was needed for Node.js 0.9.4 and below, which is not supported anymore. --- package.json | 1 - request.js | 8 +------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/package.json b/package.json index 1c58f20aa..f00a1f86f 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,6 @@ "performance-now": "^2.1.0", "qs": "~6.5.1", "safe-buffer": "^5.1.1", - "stringstream": "~0.0.5", "tough-cookie": "~2.3.3", "tunnel-agent": "^0.6.0", "uuid": "^3.1.0" diff --git a/request.js b/request.js index ff19ca39c..c93258b3b 100644 --- a/request.js +++ b/request.js @@ -11,7 +11,6 @@ var aws2 = require('aws-sign2') var aws4 = require('aws4') var httpSignature = require('http-signature') var mime = require('mime-types') -var stringstream = require('stringstream') var caseless = require('caseless') var ForeverAgent = require('forever-agent') var FormData = require('form-data') @@ -1049,13 +1048,8 @@ Request.prototype.onRequestResponse = function (response) { if (self.encoding) { if (self.dests.length !== 0) { console.error('Ignoring encoding parameter as this stream is being piped to another stream which makes the encoding option invalid.') - } else if (responseContent.setEncoding) { - responseContent.setEncoding(self.encoding) } else { - // Should only occur on node pre-v0.9.4 (joyent/node@9b5abe5) with - // zlib streams. - // If/When support for 0.9.4 is dropped, this should be unnecessary. - responseContent = responseContent.pipe(stringstream(self.encoding)) + responseContent.setEncoding(self.encoding) } } From d555bd74e9e45310269440671765da9858eca471 Mon Sep 17 00:00:00 2001 From: simov Date: Tue, 15 May 2018 14:12:15 +0300 Subject: [PATCH 444/490] Generate server certificates for Node > v10 --- tests/ssl/ca/ca.srl | 2 +- tests/ssl/ca/gen-server.sh | 13 +++++++++ tests/ssl/ca/server.crt | 29 +++++++++++++------- tests/ssl/ca/server.csr | 36 ++++++++++++++++++------ tests/ssl/ca/server.key | 56 +++++++++++++++++++++++++++++++++----- 5 files changed, 109 insertions(+), 27 deletions(-) create mode 100755 tests/ssl/ca/gen-server.sh diff --git a/tests/ssl/ca/ca.srl b/tests/ssl/ca/ca.srl index 17128db3a..641a1184a 100644 --- a/tests/ssl/ca/ca.srl +++ b/tests/ssl/ca/ca.srl @@ -1 +1 @@ -ADF62016AA40C9C3 +ADF62016AA40C9C4 diff --git a/tests/ssl/ca/gen-server.sh b/tests/ssl/ca/gen-server.sh new file mode 100755 index 000000000..d80e586ac --- /dev/null +++ b/tests/ssl/ca/gen-server.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +# fixes: +# Error: error:140AB18F:SSL routines:SSL_CTX_use_certificate:ee key too small +# on Node > v10 + +openssl genrsa 4096 > server.key + +openssl req -new -nodes -sha256 -key server.key -config server.cnf -out server.csr + +openssl x509 -req -sha256 -in server.csr -CA ca.crt -CAkey ca.key -out server.crt + +# password: password diff --git a/tests/ssl/ca/server.crt b/tests/ssl/ca/server.crt index efe96cefc..14d53d494 100644 --- a/tests/ssl/ca/server.crt +++ b/tests/ssl/ca/server.crt @@ -1,16 +1,25 @@ -----BEGIN CERTIFICATE----- -MIICejCCAeMCCQCt9iAWqkDJwzANBgkqhkiG9w0BAQUFADCBojELMAkGA1UEBhMC +MIIEQjCCA6sCCQCt9iAWqkDJxDANBgkqhkiG9w0BAQsFADCBojELMAkGA1UEBhMC VVMxCzAJBgNVBAgTAkNBMRAwDgYDVQQHEwdPYWtsYW5kMRAwDgYDVQQKEwdyZXF1 ZXN0MSYwJAYDVQQLEx1yZXF1ZXN0IENlcnRpZmljYXRlIEF1dGhvcml0eTESMBAG A1UEAxMJcmVxdWVzdENBMSYwJAYJKoZIhvcNAQkBFhdtaWtlYWxAbWlrZWFscm9n -ZXJzLmNvbTAeFw0xMjAzMDEyMjUwNTZaFw0yMjAyMjcyMj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Y5DSVAoV1hwGbS +OCowi+9KKsbiymWoN0SrjzEk0MZlXdpdD+nWbIr2krt1Farf94zho0I1I3ZGmca6 +2cZX5/6pA+lWo2M3IwzHSzhnMvTLeOUrlEC0Xi7g4Iduopmsl2pPV8s0/h8KUZ06 +DRIEW+ebQxH36a7rA+CGTq/wMWh9YlN6hVaAgIGF86jsOwZRKA1tZlmjUZ7h1D85 +ULbtrkpDjGhnOvX/bClQ/gs0ZbpgJA0RNFQjhmiAsWJhCfmdVGTw2Ejz6sntGeUR +aJXTkCIRFj+b8f5GjPhvGJZW7JEoSadnrY90Slb3BLVFbbeKwVN+bt3HdVDays3P +QyHInIjcdPuxP6PfwWdGaZ1MfRd6g5NfUtPgPtr7Qn/r+giDuVmUONtvTFWuZA3N +GOMCZcVk8eE2j4koGH5dbFBcpegHBrbscZudoQJLAgMBAAEwDQYJKoZIhvcNAQEL +BQADgYEAJqzJnlV8AQx3rvW5W1PDW7SqtdDyM4yMTaMvmYgBz9+RKNaND8Nmx46L +pZ7bXP4QJg9vdz3/Cjy4GzNwSkXj8IMJ0cTCbLANwQux0DJR95OUNUJOuRFd1oty +kb8G2rAIIV1wd3JiXHrqyxJhs/Cx/R4IlpTxqoLXBSHrjD94ZYo= -----END CERTIFICATE----- diff --git a/tests/ssl/ca/server.csr b/tests/ssl/ca/server.csr index a8e7595a5..218a5ffa9 100644 --- a/tests/ssl/ca/server.csr +++ b/tests/ssl/ca/server.csr @@ -1,11 +1,29 @@ -----BEGIN CERTIFICATE REQUEST----- -MIIBgjCCASwCAQAwgaMxCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJDQTEQMA4GA1UE -BxMHT2FrbGFuZDEQMA4GA1UEChMHcmVxdWVzdDEQMA4GA1UECxMHdGVzdGluZzEp -MCcGA1UEAxMgdGVzdGluZy5yZXF1ZXN0Lm1pa2VhbHJvZ2Vycy5jb20xJjAkBgkq -hkiG9w0BCQEWF21pa2VhbEBtaWtlYWxyb2dlcnMuY29tMFwwDQYJK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ICxYmEJ+Z1UZPDYSPPqye0Z5RFoldOQIhEWP5vx/kaM+G8YllbskShJp2etj3RK +VvcEtUVtt4rBU35u3cd1UNrKzc9DIciciNx0+7E/o9/BZ0ZpnUx9F3qDk19S0+A+ +2vtCf+v6CIO5WZQ4229MVa5kDc0Y4wJlxWTx4TaPiSgYfl1sUFyl6AcGtuxxm52h +AksCAwEAAaAjMCEGCSqGSIb3DQEJBzEUDBJwYXNzd29yZCBjaGFsbGVuZ2UwDQYJ +KoZIhvcNAQELBQADggIBALdF0DPA1PRdoZhUmyTILL3+jimfQb0AYVs74okurIMK +aPTrnfq1XxwKlFyO3thBcjbXfJ4uDGk/xBty6ifBJeAox5CHpbS4fDriuMI79VLZ +FWsP9cVGlDV4kUfn/r24+ByNHRJvkVEGo0BmO3LBWJqYRLEkroEY3hyCi7cxbcNw +yj7vgf4oN5mLiufXV+7uFQHO71+9pHpZ3uL8GBvjL0dog6HAbVbFv/tTyQwLi0IC +jxRbmgnhAMJallFnHrQ9Ab2F0uvbiG9qY9rMybRJEHw2q7RWGqlHWLMEPfro9FNq +2wr/b+ExKDgEqcZnBegRqCWTzEeb7wgAzBPASPQGGk1xFgCHZmRJg64u16bqM3/x +WdAtzB0j+GRUQEU/EK5bksCw6UH5Yat3HC/ZR4MHxpuyGKzXG/MfpoCZQSBKAe46 +nCt6haMGWsHJHjvhIwaP5X6PEqi08tUsm+T64IjkxGoMVk2kfDOWwcBtLdkHKcR8 +MhOZD9kCk0vqruyO5EbfNw+k8oa7HcoMgzU0qi4msbqBgwUNYsj6sDfGbvZnktah +vvjax7KJaUwaAFr8koxQbmOsmqxrCnWge2vQ/plp3B3ReJ7ZpRS9rUQRMOYGTfOK +ZCPYzWGmH+S31gvGNNX4CNbF8FHQwyiesLOJ9SqDUI5zyuSNd1khUC+HrlsZ62Fr -----END CERTIFICATE REQUEST----- diff --git a/tests/ssl/ca/server.key b/tests/ssl/ca/server.key index 72d86984f..e6b2c1893 100644 --- a/tests/ssl/ca/server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pobjf9nR0QiJiw5HM5egVLIMt8fVStozp66 +5jhvQOJ5sJJRThdsCnN2egyQyMRt9rKbsGEGSDvNh/OUlEl9zUCaL8IG1/HOAPNn +fHcMqjdFdI9WbwpyWwHC200yI5A4f/ahCQKCAQBzvRvFnWW7msb4ZqLMZlI8ygYy +5fh0xw9oKhhLwKKKeS5SYMI1q5+3bv/RUGEd5uWaQ3c5ZzqAqyF8hug52pX+s8+1 +WQEDs6sR8o+KEVznXgtF6qG3wMbwCV0ZrC1C+c0/ZUfB7+Cbv/N0tuD8VOgnOzSV +wqmBYKSF3+pWxMKY557e6TnOaQc2tdGmWRyP9Hscz7lOUOOeiYFl1BttebQHdBzp +AicrBMG41aYQM9GKLktHv7CvV+B/O93tQITH7JeI9nqdNsGASadz0FEcPwO8w4Vt +aNidm3FNjBLz4HI/vZctunodkLpFylfJOtHk+J0oZqjXh0Pnz1SRN53HDrp7 -----END RSA PRIVATE KEY----- From 0c5db42fcd0890eab966f335a1bc8c858255b962 Mon Sep 17 00:00:00 2001 From: simov Date: Tue, 15 May 2018 14:29:03 +0300 Subject: [PATCH 445/490] Skip status code 105 on Node > v10 --- tests/test-gzip.js | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/tests/test-gzip.js b/tests/test-gzip.js index df0d2d6a0..933b7bae0 100644 --- a/tests/test-gzip.js +++ b/tests/test-gzip.js @@ -270,28 +270,23 @@ tape('do not try to pipe HEAD request responses', function (t) { tape('do not try to pipe responses with no body', function (t) { var options = { url: server.url + '/foo', gzip: true } - options.headers = {code: 105} - request.post(options, function (err, res, body) { - t.equal(err, null) - t.equal(res.headers.code, '105') - t.equal(body, '') + // skip 105 on Node >= v10 + var statusCodes = process.version.split('.')[0].slice(1) >= 10 + ? [204, 304] : [105, 204, 304] - options.headers = {code: 204} + ;(function next (index) { + if (index === statusCodes.length) { + t.end() + return + } + options.headers = {code: statusCodes[index]} request.post(options, function (err, res, body) { t.equal(err, null) - t.equal(res.headers.code, '204') + t.equal(res.headers.code, statusCodes[index].toString()) t.equal(body, '') - - options.headers = {code: 304} - request.post(options, function (err, res, body) { - t.equal(err, null) - t.equal(res.headers.code, '304') - t.equal(body, '') - - t.end() - }) + next(++index) }) - }) + })(0) }) tape('cleanup', function (t) { From e47ce95a7581bd3ca555903d3492cc8da683ed93 Mon Sep 17 00:00:00 2001 From: simov Date: Tue, 15 May 2018 14:34:13 +0300 Subject: [PATCH 446/490] Add Node v10 build target explicitly --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index f3fc327d7..9ea82aa50 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ language: node_js node_js: - node + - 10 - 8 - 6 - 4 From 386c7d8878a9d534a4c4d6b446f991d42b395067 Mon Sep 17 00:00:00 2001 From: simov Date: Tue, 15 May 2018 14:59:48 +0300 Subject: [PATCH 447/490] 2.86.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f00a1f86f..1e2fe4af3 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.85.1", + "version": "2.86.0", "author": "Mikeal Rogers ", "repository": { "type": "git", From 8f2fd4d4d576833eb8379cd4f7b66a8c7cdf79f3 Mon Sep 17 00:00:00 2001 From: simov Date: Tue, 15 May 2018 15:06:01 +0300 Subject: [PATCH 448/490] Update changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f9e8a2e1..059d98d2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ## Change Log +### v2.86.0 (2018/05/15) +- [#2885](https://github.com/request/request/pull/2885) Remove redundant code (for Node.js 0.9.4 and below) and dependency (@ChALkeR) +- [#2942](https://github.com/request/request/pull/2942) Make Test GREEN Again! (@simov) +- [#2923](https://github.com/request/request/pull/2923) Alterations for failing CI tests (@gareth-robinson) + ### v2.85.0 (2018/03/12) - [#2880](https://github.com/request/request/pull/2880) Revert "Update hawk to 7.0.7 (#2880)" (@simov) From a7f0a36f0442ff36249773d506d425e49e06ef0f Mon Sep 17 00:00:00 2001 From: simov Date: Tue, 15 May 2018 15:06:29 +0300 Subject: [PATCH 449/490] 2.86.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1e2fe4af3..79f815821 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.86.0", + "version": "2.86.1", "author": "Mikeal Rogers ", "repository": { "type": "git", From a6741d415aba31cd01e9c4544c96f84ea6ed11e3 Mon Sep 17 00:00:00 2001 From: Eran Hammer Date: Sat, 19 May 2018 07:47:46 -0700 Subject: [PATCH 450/490] Replace hawk dependency with a local implemenation (#2943) * Replace hawk dependency with local implementation * Fix access * Fix access * Improve coverage * Improve coverage * Improve coverage * Fix access * Fix style --- lib/hawk.js | 89 +++++++++++++++++++++++ package.json | 1 - request.js | 4 +- tests/test-hawk.js | 178 +++++++++++++++++++++++++++++++++++++++------ 4 files changed, 246 insertions(+), 26 deletions(-) create mode 100644 lib/hawk.js diff --git a/lib/hawk.js b/lib/hawk.js new file mode 100644 index 000000000..de48a9851 --- /dev/null +++ b/lib/hawk.js @@ -0,0 +1,89 @@ +'use strict' + +var crypto = require('crypto') + +function randomString (size) { + var bits = (size + 1) * 6 + var buffer = crypto.randomBytes(Math.ceil(bits / 8)) + var string = buffer.toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '') + return string.slice(0, size) +} + +function calculatePayloadHash (payload, algorithm, contentType) { + var hash = crypto.createHash(algorithm) + hash.update('hawk.1.payload\n') + hash.update((contentType ? contentType.split(';')[0].trim().toLowerCase() : '') + '\n') + hash.update(payload || '') + hash.update('\n') + return hash.digest('base64') +} + +exports.calculateMac = function (credentials, opts) { + var normalized = 'hawk.1.header\n' + + opts.ts + '\n' + + opts.nonce + '\n' + + (opts.method || '').toUpperCase() + '\n' + + opts.resource + '\n' + + opts.host.toLowerCase() + '\n' + + opts.port + '\n' + + (opts.hash || '') + '\n' + + if (opts.ext) { + normalized = normalized + opts.ext.replace('\\', '\\\\').replace('\n', '\\n') + } + + normalized = normalized + '\n' + + if (opts.app) { + normalized = normalized + opts.app + '\n' + (opts.dlg || '') + '\n' + } + + var hmac = crypto.createHmac(credentials.algorithm, credentials.key).update(normalized) + var digest = hmac.digest('base64') + return digest +} + +exports.header = function (uri, method, opts) { + var timestamp = opts.timestamp || Math.floor((Date.now() + (opts.localtimeOffsetMsec || 0)) / 1000) + var credentials = opts.credentials + if (!credentials || !credentials.id || !credentials.key || !credentials.algorithm) { + return '' + } + + if (['sha1', 'sha256'].indexOf(credentials.algorithm) === -1) { + return '' + } + + var artifacts = { + ts: timestamp, + nonce: opts.nonce || randomString(6), + method: method, + resource: uri.pathname + (uri.search || ''), + host: uri.hostname, + port: uri.port || (uri.protocol === 'http:' ? 80 : 443), + hash: opts.hash, + ext: opts.ext, + app: opts.app, + dlg: opts.dlg + } + + if (!artifacts.hash && (opts.payload || opts.payload === '')) { + artifacts.hash = calculatePayloadHash(opts.payload, credentials.algorithm, opts.contentType) + } + + var mac = exports.calculateMac(credentials, artifacts) + + var hasExt = artifacts.ext !== null && artifacts.ext !== undefined && artifacts.ext !== '' + var header = 'Hawk id="' + credentials.id + + '", ts="' + artifacts.ts + + '", nonce="' + artifacts.nonce + + (artifacts.hash ? '", hash="' + artifacts.hash : '') + + (hasExt ? '", ext="' + artifacts.ext.replace(/\\/g, '\\\\').replace(/"/g, '\\"') : '') + + '", mac="' + mac + '"' + + if (artifacts.app) { + header = header + ', app="' + artifacts.app + (artifacts.dlg ? '", dlg="' + artifacts.dlg : '') + '"' + } + + return header +} diff --git a/package.json b/package.json index 79f815821..aeb5426de 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,6 @@ "forever-agent": "~0.6.1", "form-data": "~2.3.1", "har-validator": "~5.0.3", - "hawk": "~6.0.2", "http-signature": "~1.2.0", "is-typedarray": "~1.0.0", "isstream": "~0.1.2", diff --git a/request.js b/request.js index c93258b3b..668d9a81e 100644 --- a/request.js +++ b/request.js @@ -6,7 +6,6 @@ var url = require('url') var util = require('util') var stream = require('stream') var zlib = require('zlib') -var hawk = require('hawk') var aws2 = require('aws-sign2') var aws4 = require('aws4') var httpSignature = require('http-signature') @@ -24,6 +23,7 @@ var Querystring = require('./lib/querystring').Querystring var Har = require('./lib/har').Har var Auth = require('./lib/auth').Auth var OAuth = require('./lib/oauth').OAuth +var hawk = require('./lib/hawk') var Multipart = require('./lib/multipart').Multipart var Redirect = require('./lib/redirect').Redirect var Tunnel = require('./lib/tunnel').Tunnel @@ -1420,7 +1420,7 @@ Request.prototype.httpSignature = function (opts) { } Request.prototype.hawk = function (opts) { var self = this - self.setHeader('Authorization', hawk.client.header(self.uri, self.method, opts).field) + self.setHeader('Authorization', hawk.header(self.uri, self.method, opts)) } Request.prototype.oauth = function (_oauth) { var self = this diff --git a/tests/test-hawk.js b/tests/test-hawk.js index 34db8da25..3765908cf 100644 --- a/tests/test-hawk.js +++ b/tests/test-hawk.js @@ -2,27 +2,15 @@ var http = require('http') var request = require('../index') -var hawk = require('hawk') +var hawk = require('../lib/hawk') var tape = require('tape') var assert = require('assert') var server = http.createServer(function (req, res) { - var getCred = function (id, callback) { - assert.equal(id, 'dh37fgj492je') - var credentials = { - key: 'werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn', - algorithm: 'sha256', - user: 'Steve' - } - return callback(null, credentials) - } - - hawk.server.authenticate(req, getCred, {}, function (err, credentials, attributes) { - res.writeHead(err ? 401 : 200, { - 'Content-Type': 'text/plain' - }) - res.end(err ? 'Shoosh!' : 'Hello ' + credentials.user) + res.writeHead(200, { + 'Content-Type': 'text/plain' }) + res.end(authenticate(req)) }) tape('setup', function (t) { @@ -32,18 +20,124 @@ tape('setup', function (t) { }) }) -tape('hawk', function (t) { - var creds = { - key: 'werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn', - algorithm: 'sha256', - id: 'dh37fgj492je' - } +var creds = { + key: 'werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn', + algorithm: 'sha256', + id: 'dh37fgj492je' +} + +tape('hawk-get', function (t) { request(server.url, { hawk: { credentials: creds } }, function (err, res, body) { t.equal(err, null) t.equal(res.statusCode, 200) - t.equal(body, 'Hello Steve') + t.equal(body, 'OK') + t.end() + }) +}) + +tape('hawk-post', function (t) { + request.post({ url: server.url, body: 'hello', hawk: { credentials: creds, payload: 'hello' } }, function (err, res, body) { + t.equal(err, null) + t.equal(res.statusCode, 200) + t.equal(body, 'OK') + t.end() + }) +}) + +tape('hawk-ext', function (t) { + request(server.url, { + hawk: { credentials: creds, ext: 'test' } + }, function (err, res, body) { + t.equal(err, null) + t.equal(res.statusCode, 200) + t.equal(body, 'OK') + t.end() + }) +}) + +tape('hawk-app', function (t) { + request(server.url, { + hawk: { credentials: creds, app: 'test' } + }, function (err, res, body) { + t.equal(err, null) + t.equal(res.statusCode, 200) + t.equal(body, 'OK') + t.end() + }) +}) + +tape('hawk-app+dlg', function (t) { + request(server.url, { + hawk: { credentials: creds, app: 'test', dlg: 'asd' } + }, function (err, res, body) { + t.equal(err, null) + t.equal(res.statusCode, 200) + t.equal(body, 'OK') + t.end() + }) +}) + +tape('hawk-missing-creds', function (t) { + request(server.url, { + hawk: {} + }, function (err, res, body) { + t.equal(err, null) + t.equal(res.statusCode, 200) + t.equal(body, 'FAIL') + t.end() + }) +}) + +tape('hawk-missing-creds-id', function (t) { + request(server.url, { + hawk: { + credentials: {} + } + }, function (err, res, body) { + t.equal(err, null) + t.equal(res.statusCode, 200) + t.equal(body, 'FAIL') + t.end() + }) +}) + +tape('hawk-missing-creds-key', function (t) { + request(server.url, { + hawk: { + credentials: { id: 'asd' } + } + }, function (err, res, body) { + t.equal(err, null) + t.equal(res.statusCode, 200) + t.equal(body, 'FAIL') + t.end() + }) +}) + +tape('hawk-missing-creds-algo', function (t) { + request(server.url, { + hawk: { + credentials: { key: '123', id: '123' } + } + }, function (err, res, body) { + t.equal(err, null) + t.equal(res.statusCode, 200) + t.equal(body, 'FAIL') + t.end() + }) +}) + +tape('hawk-invalid-creds-algo', function (t) { + request(server.url, { + hawk: { + credentials: { key: '123', id: '123', algorithm: 'xx' } + } + }, function (err, res, body) { + t.equal(err, null) + t.equal(res.statusCode, 200) + t.equal(body, 'FAIL') t.end() }) }) @@ -53,3 +147,41 @@ tape('cleanup', function (t) { t.end() }) }) + +function authenticate (req) { + if (!req.headers.authorization) { + return 'FAIL' + } + + var headerParts = req.headers.authorization.match(/^(\w+)(?:\s+(.*))?$/) + assert.equal(headerParts[1], 'Hawk') + var attributes = {} + headerParts[2].replace(/(\w+)="([^"\\]*)"\s*(?:,\s*|$)/g, function ($0, $1, $2) { attributes[$1] = $2 }) + var hostParts = req.headers.host.split(':') + + const artifacts = { + method: req.method, + host: hostParts[0], + port: (hostParts[1] ? hostParts[1] : (req.connection && req.connection.encrypted ? 443 : 80)), + resource: req.url, + ts: attributes.ts, + nonce: attributes.nonce, + hash: attributes.hash, + ext: attributes.ext, + app: attributes.app, + dlg: attributes.dlg, + mac: attributes.mac, + id: attributes.id + } + + assert.equal(attributes.id, 'dh37fgj492je') + var credentials = { + key: 'werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn', + algorithm: 'sha256', + user: 'Steve' + } + + const mac = hawk.calculateMac(credentials, artifacts) + assert.equal(mac, attributes.mac) + return 'OK' +} From de1ed5a8baba66c8bdd8d73f20cc43aa3f9521e4 Mon Sep 17 00:00:00 2001 From: simov Date: Mon, 21 May 2018 10:32:22 +0300 Subject: [PATCH 451/490] 2.87.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index aeb5426de..7817e7a46 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.86.1", + "version": "2.87.0", "author": "Mikeal Rogers ", "repository": { "type": "git", From 02fc5b1f0123173c308a79c43e804f6fcbefbbaf Mon Sep 17 00:00:00 2001 From: simov Date: Mon, 21 May 2018 10:34:52 +0300 Subject: [PATCH 452/490] Update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 059d98d2f..751514d28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## Change Log +### v2.87.0 (2018/05/21) +- [#2943](https://github.com/request/request/pull/2943) Replace hawk dependency with a local implemenation (#2943) (@hueniverse) + ### v2.86.0 (2018/05/15) - [#2885](https://github.com/request/request/pull/2885) Remove redundant code (for Node.js 0.9.4 and below) and dependency (@ChALkeR) - [#2942](https://github.com/request/request/pull/2942) Make Test GREEN Again! (@simov) From 536f0e76b249e4545c3ba2ac75e643146ebf3824 Mon Sep 17 00:00:00 2001 From: simov Date: Mon, 21 May 2018 10:35:16 +0300 Subject: [PATCH 453/490] 2.87.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7817e7a46..0c25ddc94 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.87.0", + "version": "2.87.1", "author": "Mikeal Rogers ", "repository": { "type": "git", From bd1641471edb8b9c4b4f84855c7041e0e7af9ee8 Mon Sep 17 00:00:00 2001 From: simov Date: Sun, 8 Jul 2018 14:52:21 +0300 Subject: [PATCH 454/490] Update test certificates --- tests/ssl/ca/ca.srl | 2 +- tests/ssl/ca/client-enc.key | 52 ++++++++++---------- tests/ssl/ca/client.crt | 24 ++++----- tests/ssl/ca/client.csr | 26 +++++----- tests/ssl/ca/client.key | 50 +++++++++---------- tests/ssl/ca/localhost.crt | 24 ++++----- tests/ssl/ca/localhost.csr | 26 +++++----- tests/ssl/ca/localhost.key | 50 +++++++++---------- tests/ssl/ca/server.crt | 34 ++++++------- tests/ssl/ca/server.csr | 46 ++++++++--------- tests/ssl/ca/server.key | 98 ++++++++++++++++++------------------- 11 files changed, 216 insertions(+), 216 deletions(-) diff --git a/tests/ssl/ca/ca.srl b/tests/ssl/ca/ca.srl index 641a1184a..fdbe36f83 100644 --- a/tests/ssl/ca/ca.srl +++ b/tests/ssl/ca/ca.srl @@ -1 +1 @@ -ADF62016AA40C9C4 +ADF62016AA40C9C5 diff --git a/tests/ssl/ca/client-enc.key b/tests/ssl/ca/client-enc.key index e0f5348df..a53067b1e 100644 --- a/tests/ssl/ca/client-enc.key +++ b/tests/ssl/ca/client-enc.key @@ -1,30 +1,30 @@ -----BEGIN RSA PRIVATE KEY----- Proc-Type: 4,ENCRYPTED -DEK-Info: AES-128-CBC,DFE9B15161553AFAA662AC7EACFB6D35 +DEK-Info: AES-128-CBC,7FD4AC5078EE99FCA866A397D64EAC81 -zGaKZze08HgD7HDV+s9etBsPelQ9o8iMslZNi5NKtyyG54ivITgZpVmPVr164+J7 -xJPDbHPLvW+a5K8gyNrZKrRuZHBWcggN3IPzTP1Q02nIb4uhgJUHFSOOspYKWZwD -KnBOUKO52y7FFYF1ZnLdJBjN1+ImjR5H/3EI51YirNis+9fKtYHCRGRC9BpA3Mub -ccxETSAc22ZP7yXyY+JRXx4AikTPiOX5b574MLj1o4BH+Snb8T4EnvNoDcg7rwl0 -01UGdOLFy+ZecLOXAtn3Ta4n+G5SkHX/09Z57RbtNGwRXyynYCYAy6+Sx+sn5+QL -6L1wzk766iOq1a84jqz+SWEVA/HMHsNivtx0vom1GfqQwLLjaSW5T+dAD1ZEClqs -IFAj41wNdOwKxvHTTUeNIud0XWSYlmdbF1VUOdtbOzeCtz99pEpC6HeghtgZlNuD -IzdlrLU8jrjDMVNrBF7fYQ4Lje1j5G83vZWMQF2/MjIExOcbAV7SkFIcVuBdnSZG -zYKAqR++NvwQWxSEHoBbkl+KRibojdfpzPFdm9HThUxILeWr7RjQ5CVohIC+ZBiv -AsJx1K0IHxAcbteniZGTK2OkhDCWBcGd0mAgi6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9nPvw58yWtVSOF1Ws5Are/nhJz5Yto8Rh89rnKw6N/L1/oF9nwdiy +2/xx4SiO3UiYQJ+EpiEfoBzup17ZrwWgcGSoWR+3wzt0Ci0VzrdbpKzrIUKLHr8V +5QrdBb0Z0qzHODc6e/k92n+py1XXQ0gyLhuk6YngzkKADcAQFlh8ry0/izEOeMKe +RP9huGEX/KSVkWg5F9d1s+49YbYXkhWbrninLu2SUTs02E04+Y9xuyFqXZRU0PzZ +J/zn/FS/Uby0G5vhj7J5G1nOCHrqS0xI3QF4CVmXE3NWj0w3XwypDwVW6aG2gvrm +Bql/YGL2PC9c74rN/OnIrW0VprWh61+QNUqL+4yTP864HxGw9cAiSU2NLiAf7vye +yAKzUf2c9ZNqpafmiPRzg772yPIemPthNUNXV4AuH33LRz5V7mUYqExnAOTNi+FR +XE98PcNiGCkrdX+VyqQq77SB52O0tHuNyAk+DE0siz3XbJtTXGPSHjNXc2gNWc9n -----END RSA PRIVATE KEY----- diff --git a/tests/ssl/ca/client.crt b/tests/ssl/ca/client.crt index b5f687042..b3994f69a 100644 --- a/tests/ssl/ca/client.crt +++ b/tests/ssl/ca/client.crt @@ -1,20 +1,20 @@ -----BEGIN CERTIFICATE----- -MIIDLjCCApcCCQCt9iAWqkDJwzANBgkqhkiG9w0BAQUFADCBojELMAkGA1UEBhMC +MIIDLjCCApcCCQCt9iAWqkDJxDANBgkqhkiG9w0BAQsFADCBojELMAkGA1UEBhMC VVMxCzAJBgNVBAgTAkNBMRAwDgYDVQQHEwdPYWtsYW5kMRAwDgYDVQQKEwdyZXF1 ZXN0MSYwJAYDVQQLEx1yZXF1ZXN0IENlcnRpZmljYXRlIEF1dGhvcml0eTESMBAG A1UEAxMJcmVxdWVzdENBMSYwJAYJKoZIhvcNAQkBFhdtaWtlYWxAbWlrZWFscm9n -ZXJzLmNvbTAeFw0xNTA4MDMxNjM5MDJaFw0xODA4MDIxNjM5MDJaMIGPMQswCQYD +ZXJzLmNvbTAeFw0xODA3MDgxMTQ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Y5IHj4MJcx +qNpJbgMWZ8vDUY1Uf9JNQbrl1lKYeDFzhE3j+1uAPV711srJLvCUqoXPbfS1KKAJ +AJQcheBzd4Ul6wWULBCMLGPw3j6xOoBz6iKwAn+qOQgro2QQpidj/gkFAgMBAAEw +DQYJKoZIhvcNAQELBQADgYEAXopA8nlbYxyKoJeNXKX/+sWtbqYxzfxVo/6iOFMX +3ZSggFFMKCw7pEVgXy4nONNR98C4ga74lo6ljUY+B3xGQxEDYwK1xVgekA2XfQYJ +/ygAdoliF8BEkQ8b9ZoIwmBAIZRQO9b0DzucycvCag7km0O2uWJYQGzFIOQCxJ+v +9r0= -----END CERTIFICATE----- diff --git a/tests/ssl/ca/client.csr b/tests/ssl/ca/client.csr index 0bb6f2e10..17b366ac5 100644 --- a/tests/ssl/ca/client.csr +++ b/tests/ssl/ca/client.csr @@ -2,17 +2,17 @@ MIIC+DCCAeACAQAwgY8xCzAJBgNVBAYTAlVTMQswCQYDVQQIDAJDQTEQMA4GA1UE BwwHT2FrbGFuZDEQMA4GA1UECgwHcmVxdWVzdDEaMBgGA1UECwwRcmVxdWVzdEBs b2NhbGhvc3QxEzARBgNVBAMMClRlc3RDbGllbnQxHjAcBgkqhkiG9w0BCQEWD2Rv -Lm5vdEBlbWFpbC5tZTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANhK -SviWyzGiXjLRD/WaP1LUUBnupnH2mYrpyoEqaF1Qun1G6JxhRQbbUdsA/oQBq3ON -HfcoCAiUHWOkB9MS35GrJGsA512NiMFadVWOMPJK8AHAEAJ7ACeGkAqq4Rm6koBK -EBm27wbdbZbtdO1kyTJb//oQu7WxmiMGhn0zVMfsQ24bu+MtrsNUd3qqq1nJUUPw -WMA3/J6t8mbnu30r2HoeZl/C/UhPc8K3K0rATK1rExMMEm5d6frwuiazOUReXYqc -edI2gRGmg3Q3FAiP7izIN/rnFMeQnkS/ZlwZY6oxk0ps76bElhfmvi6TwZy6C0Pk -jeshVfyxk0qtAXO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C1tJtxj0hAt4qg +Vr1HJQ67V4d2w3BIzq8wTmvBD//ofwydweYXWd7F1zcLgO36HcA8Na4eko6m0dpw +jRbxD1hyrXGkC1CkD43TnZWkIpARXtWzv2G9iaUGyVsVvRrAyts8+ZRu1SGNfdkG +HmBqEzn8mMBc92OYO2OGf/CkueSPivJ0JrbxWKktjytpsBUWwnwBsO/vwDQ= -----END CERTIFICATE REQUEST----- diff --git a/tests/ssl/ca/client.key b/tests/ssl/ca/client.key index 4148e25ad..46542e683 100644 --- a/tests/ssl/ca/client.key +++ b/tests/ssl/ca/client.key @@ -1,27 +1,27 @@ -----BEGIN RSA PRIVATE KEY----- -MIIEpAIBAAKCAQEA2EpK+JbLMaJeMtEP9Zo/UtRQGe6mcfaZiunKgSpoXVC6fUbo -nGFFBttR2wD+hAGrc40d9ygICJQdY6QH0xLfkaskawDnXY2IwVp1VY4w8krwAcAQ -AnsAJ4aQCqrhGbqSgEoQGbbvBt1tlu107WTJMlv/+hC7tbGaIwaGfTNUx+xDbhu7 -4y2uw1R3eqqrWclRQ/BYwDf8nq3yZue7fSvYeh5mX8L9SE9zwrcrSsBMrWsTEwwS -bl3p+vC6JrM5RF5dipx50jaBEaaDdDcUCI/uLMg3+ucUx5CeRL9mXBljqjGTSmzv -psSWF+a+LpPBnLoLQ+SN6yFV/LGTSq0Bc6RZwQIDAQABAoIBAGEj7Mv9HcFrBReZ -oatS3YHb7SXYc1TXxloHanXckAbpDPja8fnaDeBofDj6F1U+UryQ8pZgmksQCqsH -rqPz5AlObgrI2yC/Ql5kvDHyrLUFRwniMs6KY6Vc4DCKUpL1onqPyO9jo7LXnDKe -71b3Xw2JGEw9W7Dc1TdJ5PkyJq+q7wlvrGuXvr6gjDZGNFjc4qD2p3UkGzV/AVa/ -DFY2EJcP0H3SSYPpjN3GAPDelBG/5a/kGLp2U+9wxK682/ZKORuS0d+/AZY3XX3l -WTy4a0Lmmeunyy/fkMuI5MkNTiTaU90FnivMrLq/9j2HWJCu8QKwwM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PJfLuVxTpSRjhvqgThqO +ke05XRbUYI+yEGQF7Lz7940CgYBz06+UQTo3DjK6A6cXOcQ7sYiH8o+z9Ss26ImV +zeWAnV0NjZ6jfc//EaBq0WQT0wqopRng+83t5+Iz2ACbXW8iQ+wb4tpE7ZWPQ4+k +EHi8xGfMpg9vpFQhzr407yrWAaRalfABu8SJG8bLjQYZQbV2mE+no6Nm7DSifW0N +J8MFxwKBgQDlNxXCIFtNNLpCUV6mHryOseCF5GYdHcqozS85ea4DkGJPwHxt9/Ev +t+aFdki2eROSv5bFZv8IGR+7+h80x3fuWtjPRX4acG35voLDw+VKUkmLr3Haw1TO +XQdHNklrXAWWSfvdQjnPg+80/7ecDZyRPIlKvehxpfj91duxoVPRLQ== -----END RSA PRIVATE KEY----- diff --git a/tests/ssl/ca/localhost.crt b/tests/ssl/ca/localhost.crt index 8beb1fc3c..788557a68 100644 --- a/tests/ssl/ca/localhost.crt +++ b/tests/ssl/ca/localhost.crt @@ -1,20 +1,20 @@ -----BEGIN CERTIFICATE----- -MIIDLTCCApYCCQCt9iAWqkDJwzANBgkqhkiG9w0BAQUFADCBojELMAkGA1UEBhMC +MIIDLTCCApYCCQCt9iAWqkDJxDANBgkqhkiG9w0BAQsFADCBojELMAkGA1UEBhMC VVMxCzAJBgNVBAgTAkNBMRAwDgYDVQQHEwdPYWtsYW5kMRAwDgYDVQQKEwdyZXF1 ZXN0MSYwJAYDVQQLEx1yZXF1ZXN0IENlcnRpZmljYXRlIEF1dGhvcml0eTESMBAG A1UEAxMJcmVxdWVzdENBMSYwJAYJKoZIhvcNAQkBFhdtaWtlYWxAbWlrZWFscm9n -ZXJzLmNvbTAeFw0xNTA4MDMxNjM5NThaFw0xODA4MDIxNjM5NThaMIGOMQswCQYD +ZXJzLmNvbTAeFw0xODA3MDgxMTQ5MjlaFw0yMTA3MDcxMTQ5MjlaMIGOMQswCQYD VQQGEwJVUzELMAkGA1UECAwCQ0ExEDAOBgNVBAcMB09ha2xhbmQxEDAOBg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7 +GSngACB3En3ndP71ry6sxwova3Yb4Qeei1S/JonIr+KDTlmko8SXtnkCAwEAATAN +BgkqhkiG9w0BAQsFAAOBgQCpn2KTeSNsI95wVwDaXS4zkb4FtsFdG4368Bt0tKSc +HUlv8OL+h+gJOSfap+0WbY/cBMzGym+mS8MZFXYpDEmknyuSv+Rqs3DEP5nkBZWb +HaaIv1UrUF6XHh/C6kToNXRjZQCKYu2TWiqeA1psdBZBMJPwnvKiG+FKr+fZUAEv +Ug== -----END CERTIFICATE----- diff --git a/tests/ssl/ca/localhost.csr b/tests/ssl/ca/localhost.csr index 27036fd03..22f60936c 100644 --- a/tests/ssl/ca/localhost.csr +++ b/tests/ssl/ca/localhost.csr @@ -2,17 +2,17 @@ MIIC9zCCAd8CAQAwgY4xCzAJBgNVBAYTAlVTMQswCQYDVQQIDAJDQTEQMA4GA1UE BwwHT2FrbGFuZDEQMA4GA1UECgwHcmVxdWVzdDEaMBgGA1UECwwRcmVxdWVzdEBs b2NhbGhvc3QxEjAQBgNVBAMMCWxvY2FsaG9zdDEeMBwGCSqGSIb3DQEJARYPZG8u -bm90QGVtYWlsLm1lMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArl35 -98SpzKRa/87o4u+x2/fLaH+MrZGUThJKCqEKhLYnhfTwHosYc6z4hww60ZXb10vL -/Ccwp2pVz8KoZ3QoHrORURFa3QeZyhPcBN4hyzyTI76L74tAH7lg1xJuZdkTiF78 -6gxYsnAsXNsLNIcJkZ262cA7ymV1XUBYwpidykNCPFU4vYmLayAkVrwl+XZzpvOl -gnEetb5t1aGrtCMiozhO1xGSZbg0YyZ/aw2dMLmm8jr9sW9BJKBhDlmNHrK28XF7 -KjRzDJblrNN2CRHNcdqfabYOHhuRwu71F5FW4no/p8BOtRAP3WYzzkFvxDOf4ves -4pK4ByaDHzCtMfKN5QIDAQABoCMwIQYJKoZIhvcNAQkHMRQMEnBhc3N3b3JkIGNo -YWxsZW5nZTANBgkqhkiG9w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D1mMSh08V9/54UcGVDoG5A+BZJx0Eq9ALirJnFXj96lpVc1VRQ4R7tRA+qFaJr7R +017go+qy2ZS7SMoTB2eA6M7eitfurQaBcBntPzAqq6nkRNOekzSYYFtYvg== -----END CERTIFICATE REQUEST----- diff --git a/tests/ssl/ca/localhost.key b/tests/ssl/ca/localhost.key index 260c6a340..eccebad34 100644 --- a/tests/ssl/ca/localhost.key +++ b/tests/ssl/ca/localhost.key @@ -1,27 +1,27 @@ -----BEGIN RSA PRIVATE KEY----- -MIIEowIBAAKCAQEArl3598SpzKRa/87o4u+x2/fLaH+MrZGUThJKCqEKhLYnhfTw -HosYc6z4hww60ZXb10vL/Ccwp2pVz8KoZ3QoHrORURFa3QeZyhPcBN4hyzyTI76L -74tAH7lg1xJuZdkTiF786gxYsnAsXNsLNIcJkZ262cA7ymV1XUBYwpidykNCPFU4 -vYmLayAkVrwl+XZzpvOlgnEetb5t1aGrtCMiozhO1xGSZbg0YyZ/aw2dMLmm8jr9 -sW9BJKBhDlmNHrK28XF7KjRzDJblrNN2CRHNcdqfabYOHhuRwu71F5FW4no/p8BO -tRAP3WYzzkFvxDOf4ves4pK4ByaDHzCtMfKN5QIDAQABAoIBAHTuJoxGQQwwB6pW -agyNazu0755TMtbOsqKsVyTLnA8lTFnjyQbihnJEQ6HkzKjyEyxM8y1UZqdOgt9B -jcdauPDlwISZ29Ivn61JJhnJkOYG6DFnPdZVDpp3qX5xKMF6EkQ4VujpgK2g1c8r -QVdnWz5ghQYziKUQ5uSzGxLcX6xb1Pc/YOr1Vy8agBjNy5Fnre4Dgv2w0ki7JL2d -x9LA0Qe+JDbGb/rDy3Xl1msNboglWNANtQIq+kWiujvqpBijdP2Os3KvyaKGy8V3 -gB750rV6mWtflDA2KEt0hTnDqRtBj3Y/i1RqYux5bs1KaIMxdNhRwyS/6BQt7+rg -F535GSECgYEA1DMv3tKtnFrGA78Htsy6TjtCC0P4jwZw2Xj+pLEu2KInw1JMMSzQ -rpkkFhBOlkg8Nh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inXDK8rKHZrZJfYObDIC0GMYmeE +X0M+P1De15XDi01dvfzopMoLcOCGbyujIRPB3zhuNK0auw37MSwd7XsALBxmJBa3 +MBBqfQKBgQDWKUZQQ+ctq4VMSTddgvD6kT2A2Wlr7Eph5wyYC+2oX6IqFtMzYnQT +0eCGGM3WFhdEGwqxYWhKCKuPLBnrM/wig9WibBkNtP/n+2vP9sHK0p3/O6tkkpcq +PvF9QWP+2mDwcoh11z7ZD+C83nq08GwqnHHh0X/RtAjWSTWdLEwkLg== -----END RSA PRIVATE KEY----- diff --git a/tests/ssl/ca/server.crt b/tests/ssl/ca/server.crt index 14d53d494..ac7b35ff6 100644 --- a/tests/ssl/ca/server.crt +++ b/tests/ssl/ca/server.crt @@ -1,25 +1,25 @@ -----BEGIN CERTIFICATE----- -MIIEQjCCA6sCCQCt9iAWqkDJxDANBgkqhkiG9w0BAQsFADCBojELMAkGA1UEBhMC +MIIEQjCCA6sCCQCt9iAWqkDJxTANBgkqhkiG9w0BAQsFADCBojELMAkGA1UEBhMC VVMxCzAJBgNVBAgTAkNBMRAwDgYDVQQHEwdPYWtsYW5kMRAwDgYDVQQKEwdyZXF1 ZXN0MSYwJAYDVQQLEx1yZXF1ZXN0IENlcnRpZmljYXRlIEF1dGhvcml0eTESMBAG A1UEAxMJcmVxdWVzdENBMSYwJAYJKoZIhvcNAQkBFhdtaWtlYWxAbWlrZWFscm9n -ZXJzLmNvbTAeFw0xODA1MTUxMTEwNTRaFw0xODA2MTQxMTEwNTRaMIGjMQswCQYD +ZXJzLmNvbTAeFw0xODA3MDgxMTQ5MzlaFw0xODA4MDcxMTQ5MzlaMIGjMQswCQYD VQQGEwJVUzELMAkGA1UECAwCQ0ExEDAOBgNVBAcMB09ha2xhbmQxEDAOBgNVBAoM B3JlcXVlc3QxEDAOBgNVBAsMB3Rlc3RpbmcxKTAnBgNVBAMMIHRlc3RpbmcucmVx dWVzdC5taWtlYWxyb2dlcnMuY29tMSYwJAYJKoZIhvcNAQkBFhdt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cO9pnCHELvQyVgvlk1Tx5FXunmB3odoxobM37wqzw1Bb +/JyU58+C/kPDVz5ixp5FIBgQCBM7t6VrFvANqe63FCFhwSptdJQHpOJlBZaZ2rRY +cjN8MyoaeLpUpra094N2VCWMaNw2vvY8sCJBj59E+0FScX4obFHmkEX0W1eccS4+ +U6Dd82eLN6bPPhspWlq1XsOny4et5Ik8XHfWJ/alRAml2RdDFzV9aWYIg2LIv2wB +jlnNRX6jve+3+5SkrrnsFZWZO+vSNdqCMUp3pCepwrZo3lal+Yz6Of1jmEtmHGUG +agUwdmg2Fka1HOAKhSXepFaBsM8CJbLBAVUFRmufXBiOxRc2a8+OheHV33TU/V7Z +PdBfpvKX55Qqnm6ekFY2h4LvxNge2WVCVErIvPig+PJLlsm9gHV/KIqZvmJM4j5L +W4towjRfIE4Qw+DoTGcDnCbwRuqcSehFftKYfLPRuAoiAhXPIllE2WD/rwMqRFqW +0jfiHdRYu9AamNJYIJjRAY88iTRrb2/28acMvbz9Lg8jA13kVD3TEETvBX9meEOx +5tnr+nilcoZDdzHsB78mDdX9sQbN9Ic0alFcp92zH7Qw6YBK/6JcFXKECqDn+2J5 +Q9kuI0A2XKMXCn8U8tToL2DRASB7hyi8N3Y9un3nAgMBAAEwDQYJKoZIhvcNAQEL +BQADgYEAF/dmc81+FQWLhrT07oC3UWacbP8LJGigDM18cijn4JgBM/un1AOdaZON +oUP2NQefuB12t6xjAXmY+JuhZqojUjK8OkehKiCUR0x25KYOPyaHLTp7+p9x9aJB +ifN/qMN/ONiAO+ZDvKdFmlEOPzm/oTyzvIY9X3UqxSfjzfLGsN8= -----END CERTIFICATE----- diff --git a/tests/ssl/ca/server.csr b/tests/ssl/ca/server.csr index 218a5ffa9..76b6a1e72 100644 --- a/tests/ssl/ca/server.csr +++ b/tests/ssl/ca/server.csr @@ -3,27 +3,27 @@ MIIFDDCCAvQCAQAwgaMxCzAJBgNVBAYTAlVTMQswCQYDVQQIDAJDQTEQMA4GA1UE BwwHT2FrbGF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ST----- diff --git a/tests/ssl/ca/server.key b/tests/ssl/ca/server.key index e6b2c1893..d84eacccc 100644 --- a/tests/ssl/ca/server.key +++ b/tests/ssl/ca/server.key @@ -1,51 +1,51 @@ -----BEGIN RSA PRIVATE KEY----- -MIIJKQIBAAKCAgEAwA5sRvt8ujjSOFS/YP+4jJI3ZR9S3ZEqs8VBprssdTKJA2a2 -6JmP2VKDqZeg81C1/QQHq1iVNm2T3T3YyJAUlnxPyjcin2Dm/Fs/0iXSFkVMEG/h -86ZpJCnf4jr+a7hhUcmKHS7EYFSLrDNf/ha9CXXseWOyRrzgZ2gJykCC78eBZ6e/ -sX3ISKE6Db8e4F4fW4SKSWsF1A4eB6z+YSiFQoWCwV37lbEr8uDwAhYjUEXkkhUX -mF7J1jkNJUChXWHAZtI4KjCL70oqxuLKZag3RKuPMSTQxmVd2l0P6dZsivaSu3UV -qt/3jOGjQjUjdkaZxrrZxlfn/qkD6VajYzcjDMdLOGcy9Mt45SuUQLReLuDgh26i -mayXak9XyzT+HwpRnToNEgRb55tDEffprusD4IZOr/AxaH1iU3qFVoCAgYXzqOw7 -BlEoDW1mWaNRnuHUPzlQtu2uSkOMaGc69f9sKVD+CzRlumAkDRE0VCOGaICxYmEJ -+Z1UZPDYSPPqye0Z5RFoldOQIhEWP5vx/kaM+G8YllbskShJp2etj3RKVvcEtUVt -t4rBU35u3cd1UNrKzc9DIciciNx0+7E/o9/BZ0ZpnUx9F3qDk19S0+A+2vtCf+v6 -CIO5WZQ4229MVa5kDc0Y4wJlxWTx4TaPiSgYfl1sUFyl6AcGtuxxm52hAksCAwEA -AQKCAgEAguQRhVr2SZBaLUwM1lXR9/Pazw9HEXxTJwvjz3c3OHSFjozdUa7+q7Uh -yF5vsgQq09KAS5Xms56ArMLu0NnpPhpg4scq0IZhRlIGL/nYsZbu3TDzRHQAqkXj -sLJWHSIfKXd6qqLp8WENhAHLhUcH9L+qt5xrruwg4Di2m2HWGwbUOcnIynWYH2/K -Of4sU+ux4VR2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Han3Wwn9s2F+80Joh1XvRgKYknBH+DRRygJeKqqVlybnp26g== -----END RSA PRIVATE KEY----- From 45ffc4b536043e85e0850edf35ba47067c0dbada Mon Sep 17 00:00:00 2001 From: Vikhyat Korrapati Date: Mon, 16 Jul 2018 14:11:04 -0700 Subject: [PATCH 455/490] Improve AWS SigV4 support. (#2791) This makes the following changes to the AWS SigV4 signing functionality: 1. Sign all request headers instead of just Content-Type. 2. Allow specifying a service name. --- README.md | 2 +- request.js | 7 ++++--- tests/test-aws.js | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 81ffd95ef..b91623d2e 100644 --- a/README.md +++ b/README.md @@ -772,7 +772,7 @@ The first argument can be either a `url` or an `options` object. The only requir - `auth` - a hash containing values `user` || `username`, `pass` || `password`, and `sendImmediately` (optional). See documentation above. - `oauth` - options for OAuth HMAC-SHA1 signing. See documentation above. - `hawk` - options for [Hawk signing](https://github.com/hueniverse/hawk). The `credentials` key must contain the necessary signing info, [see hawk docs for details](https://github.com/hueniverse/hawk#usage-example). -- `aws` - `object` containing AWS signing information. Should have the properties `key`, `secret`, and optionally `session` (note that this only works for services that require session as part of the canonical string). Also requires the property `bucket`, unless you’re specifying your `bucket` as part of the path, or the request doesn’t use a bucket (i.e. GET Services). If you want to use AWS sign version 4 use the parameter `sign_version` with value `4` otherwise the default is version 2. **Note:** you need to `npm install aws4` first. +- `aws` - `object` containing AWS signing information. Should have the properties `key`, `secret`, and optionally `session` (note that this only works for services that require session as part of the canonical string). Also requires the property `bucket`, unless you’re specifying your `bucket` as part of the path, or the request doesn’t use a bucket (i.e. GET Services). If you want to use AWS sign version 4 use the parameter `sign_version` with value `4` otherwise the default is version 2. If you are using SigV4, you can also include a `service` property that specifies the service name. **Note:** you need to `npm install aws4` first. - `httpSignature` - options for the [HTTP Signature Scheme](https://github.com/joyent/node-http-signature/blob/master/http_signing.md) using [Joyent's library](https://github.com/joyent/node-http-signature). The `keyId` and `key` properties must be specified. See the docs for other options. --- diff --git a/request.js b/request.js index 668d9a81e..9d3fc3e92 100644 --- a/request.js +++ b/request.js @@ -1358,11 +1358,12 @@ Request.prototype.aws = function (opts, now) { host: self.uri.host, path: self.uri.path, method: self.method, - headers: { - 'content-type': self.getHeader('content-type') || '' - }, + headers: self.headers, body: self.body } + if (opts.service) { + options.service = opts.service + } var signRes = aws4.sign(options, { accessKeyId: opts.key, secretAccessKey: opts.secret, diff --git a/tests/test-aws.js b/tests/test-aws.js index 214003974..44f4f0b04 100644 --- a/tests/test-aws.js +++ b/tests/test-aws.js @@ -77,6 +77,45 @@ tape('aws-sign4 options with session token', function (t) { }) }) +tape('aws-sign4 options with service', function (t) { + var serviceName = 'UNIQUE_SERVICE_NAME' + var options = { + url: s.url + path, + aws: { + key: 'my_key', + secret: 'my_secret', + sign_version: 4, + service: serviceName + }, + json: true + } + request(options, function (err, res, body) { + t.error(err) + t.ok(body.authorization.includes(serviceName)) + t.end() + }) +}) + +tape('aws-sign4 with additional headers', function (t) { + var options = { + url: s.url + path, + headers: { + 'X-Custom-Header': 'custom' + }, + aws: { + key: 'my_key', + secret: 'my_secret', + sign_version: 4 + }, + json: true + } + request(options, function (err, res, body) { + t.error(err) + t.ok(body.authorization.includes('x-custom-header')) + t.end() + }) +}) + tape('cleanup', function (t) { s.close(function () { t.end() From a92e138d897d78ce19dd70bd1ad271c7f9c6a23d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?GP=20=E2=9C=85?= Date: Wed, 18 Jul 2018 23:16:26 +0530 Subject: [PATCH 456/490] #515, #2894 Strip port suffix from Host header if the protocol is known. (#2904) * Strip port suffix from Host header if the protocol is known. This partially revert ff6d6c6e7a3b2c36618b5d1db662e10c929696e3, and still works for IPv6 addresses as well. * Port is a string out of url.parse(). See https://nodejs.org/api/url.html#url_url_port * Port is a string out of url.parse(). See https://nodejs.org/api/url.html#url_url_port * Add tests for the new Host header changes. --- request.js | 10 ++++++--- tests/test-headers.js | 50 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 3 deletions(-) diff --git a/request.js b/request.js index 9d3fc3e92..90bed4f4a 100644 --- a/request.js +++ b/request.js @@ -287,10 +287,14 @@ Request.prototype.init = function (options) { self.setHost = false if (!self.hasHeader('host')) { var hostHeaderName = self.originalHostHeaderName || 'host' - // When used with an IPv6 address, `host` will provide - // the correct bracketed format, unlike using `hostname` and - // optionally adding the `port` when necessary. self.setHeader(hostHeaderName, self.uri.host) + // Drop :port suffix from Host header if known protocol. + if (self.uri.port) { + if ((self.uri.port === '80' && self.uri.protocol === 'http:') || + (self.uri.port === '443' && self.uri.protocol === 'https:')) { + self.setHeader(hostHeaderName, self.uri.hostname) + } + } self.setHost = true } diff --git a/tests/test-headers.js b/tests/test-headers.js index b80c9b312..59faae87e 100644 --- a/tests/test-headers.js +++ b/tests/test-headers.js @@ -180,6 +180,56 @@ tape('undefined headers', function (t) { }) }) +tape('preserve port in host header if non-standard port', function (t) { + var r = request({ + url: s.url + '/headers.json' + }, function (err, res, body) { + t.equal(err, null) + t.equal(r.originalHost, 'localhost:' + s.port) + t.end() + }) +}) + +tape('strip port in host header if explicit standard port (:80) & protocol (HTTP)', function (t) { + var r = request({ + url: 'http://localhost:80/headers.json' + }, function (err, res, body) { + t.notEqual(err, null) + t.equal(r.req.socket._host, 'localhost') + t.end() + }) +}) + +tape('strip port in host header if explicit standard port (:443) & protocol (HTTPS)', function (t) { + var r = request({ + url: 'https://localhost:443/headers.json' + }, function (err, res, body) { + t.notEqual(err, null) + t.equal(r.req.socket._host, 'localhost') + t.end() + }) +}) + +tape('strip port in host header if implicit standard port & protocol (HTTP)', function (t) { + var r = request({ + url: 'http://localhost/headers.json' + }, function (err, res, body) { + t.notEqual(err, null) + t.equal(r.req.socket._host, 'localhost') + t.end() + }) +}) + +tape('strip port in host header if implicit standard port & protocol (HTTPS)', function (t) { + var r = request({ + url: 'https://localhost/headers.json' + }, function (err, res, body) { + t.notEqual(err, null) + t.equal(r.req.socket._host, 'localhost') + t.end() + }) +}) + var isExpectedHeaderCharacterError = function (headerName, err) { return err.message === 'The header content contains invalid characters' || err.message === ('Invalid character in header content ["' + headerName + '"]') From cd848afbdbac78b656847c75be1c0a9daf619045 Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 2 Aug 2018 20:55:40 +0300 Subject: [PATCH 457/490] These are not going to fail if there is a server listening on those ports --- tests/test-headers.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/tests/test-headers.js b/tests/test-headers.js index 59faae87e..68b748691 100644 --- a/tests/test-headers.js +++ b/tests/test-headers.js @@ -193,8 +193,7 @@ tape('preserve port in host header if non-standard port', function (t) { tape('strip port in host header if explicit standard port (:80) & protocol (HTTP)', function (t) { var r = request({ url: 'http://localhost:80/headers.json' - }, function (err, res, body) { - t.notEqual(err, null) + }, function (_err, res, body) { t.equal(r.req.socket._host, 'localhost') t.end() }) @@ -203,8 +202,7 @@ tape('strip port in host header if explicit standard port (:80) & protocol (HTTP tape('strip port in host header if explicit standard port (:443) & protocol (HTTPS)', function (t) { var r = request({ url: 'https://localhost:443/headers.json' - }, function (err, res, body) { - t.notEqual(err, null) + }, function (_err, res, body) { t.equal(r.req.socket._host, 'localhost') t.end() }) @@ -213,8 +211,7 @@ tape('strip port in host header if explicit standard port (:443) & protocol (HTT tape('strip port in host header if implicit standard port & protocol (HTTP)', function (t) { var r = request({ url: 'http://localhost/headers.json' - }, function (err, res, body) { - t.notEqual(err, null) + }, function (_err, res, body) { t.equal(r.req.socket._host, 'localhost') t.end() }) @@ -223,8 +220,7 @@ tape('strip port in host header if implicit standard port & protocol (HTTP)', fu tape('strip port in host header if implicit standard port & protocol (HTTPS)', function (t) { var r = request({ url: 'https://localhost/headers.json' - }, function (err, res, body) { - t.notEqual(err, null) + }, function (_err, res, body) { t.equal(r.req.socket._host, 'localhost') t.end() }) From 628ff5e3c9a242bb82805c368fc5b6f942d9af70 Mon Sep 17 00:00:00 2001 From: Dan Lecocq Date: Thu, 2 Aug 2018 12:23:29 -0600 Subject: [PATCH 458/490] Update to oauth-sign 0.9.0 --- package.json | 2 +- tests/test-oauth.js | 48 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 0c25ddc94..bc9a2602a 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "isstream": "~0.1.2", "json-stringify-safe": "~5.0.1", "mime-types": "~2.1.17", - "oauth-sign": "~0.8.2", + "oauth-sign": "~0.9.0", "performance-now": "^2.1.0", "qs": "~6.5.1", "safe-buffer": "^5.1.1", diff --git a/tests/test-oauth.js b/tests/test-oauth.js index 2dd40bb9c..0358375ed 100644 --- a/tests/test-oauth.js +++ b/tests/test-oauth.js @@ -21,13 +21,17 @@ function getSignature (r) { // Tests from Twitter documentation https://dev.twitter.com/docs/auth/oauth var hmacsign = oauth.hmacsign +var hmacsign256 = oauth.hmacsign256 var rsasign = oauth.rsasign var rsaPrivatePEM = fs.readFileSync(path.join(__dirname, 'ssl', 'test.key')) var reqsign +var reqsign256 var reqsignRSA var accsign +var accsign256 var accsignRSA var upsign +var upsign256 var upsignRSA tape('reqsign', function (t) { @@ -44,6 +48,20 @@ tape('reqsign', function (t) { t.end() }) +tape('reqsign256', function (t) { + reqsign256 = hmacsign256('POST', 'https://api.twitter.com/oauth/request_token', + { oauth_callback: 'http://localhost:3005/the_dance/process_callback?service_provider_id=11', + oauth_consumer_key: 'GDdmIQH6jhtmLUypg82g', + oauth_nonce: 'QP70eNmVz8jvdPevU3oJD2AfF7R7odC2XJcn4XlZJqk', + oauth_signature_method: 'HMAC-SHA256', + oauth_timestamp: '1272323042', + oauth_version: '1.0' + }, 'MCD8BKwGdgPHvAuvgvz4EQpqDAtx89grbuNMRd7Eh98') + + t.equal(reqsign256, 'N0KBpiPbuPIMx2B77eIg7tNfGNF81iq3bcO9RO6lH+k=') + t.end() +}) + tape('reqsignRSA', function (t) { reqsignRSA = rsasign('POST', 'https://api.twitter.com/oauth/request_token', { oauth_callback: 'http://localhost:3005/the_dance/process_callback?service_provider_id=11', @@ -73,6 +91,21 @@ tape('accsign', function (t) { t.end() }) +tape('accsign256', function (t) { + accsign256 = hmacsign256('POST', 'https://api.twitter.com/oauth/access_token', + { oauth_consumer_key: 'GDdmIQH6jhtmLUypg82g', + oauth_nonce: '9zWH6qe0qG7Lc1telCn7FhUbLyVdjEaL3MO5uHxn8', + oauth_signature_method: 'HMAC-SHA256', + oauth_token: '8ldIZyxQeVrFZXFOZH5tAwj6vzJYuLQpl0WUEYtWc', + oauth_timestamp: '1272323047', + oauth_verifier: 'pDNg57prOHapMbhv25RNf75lVRd6JDsni1AJJIDYoTY', + oauth_version: '1.0' + }, 'MCD8BKwGdgPHvAuvgvz4EQpqDAtx89grbuNMRd7Eh98', 'x6qpRnlEmW9JbQn4PQVVeVG8ZLPEx6A0TOebgwcuA') + + t.equal(accsign256, 'y7S9eUhA0tC9/YfRzCPqkg3/bUdYRDpZ93Xi51AvhjQ=') + t.end() +}) + tape('accsignRSA', function (t) { accsignRSA = rsasign('POST', 'https://api.twitter.com/oauth/access_token', { oauth_consumer_key: 'GDdmIQH6jhtmLUypg82g', @@ -103,6 +136,21 @@ tape('upsign', function (t) { t.end() }) +tape('upsign256', function (t) { + upsign256 = hmacsign256('POST', 'http://api.twitter.com/1/statuses/update.json', + { oauth_consumer_key: 'GDdmIQH6jhtmLUypg82g', + oauth_nonce: 'oElnnMTQIZvqvlfXM56aBLAf5noGD0AQR3Fmi7Q6Y', + oauth_signature_method: 'HMAC-SHA256', + oauth_token: '819797-Jxq8aYUDRmykzVKrgoLhXSq67TEa5ruc4GJC2rWimw', + oauth_timestamp: '1272325550', + oauth_version: '1.0', + status: 'setting up my twitter 私のさえずりを設定する' + }, 'MCD8BKwGdgPHvAuvgvz4EQpqDAtx89grbuNMRd7Eh98', 'J6zix3FfA9LofH0awS24M3HcBYXO5nI1iYe8EfBA') + + t.equal(upsign256, 'xYhKjozxc3NYef7C26WU+gORdhEURdZRxSDzRttEKH0=') + t.end() +}) + tape('upsignRSA', function (t) { upsignRSA = rsasign('POST', 'http://api.twitter.com/1/statuses/update.json', { oauth_consumer_key: 'GDdmIQH6jhtmLUypg82g', From 7b685511edbfdb909814473c3fccde3fb285503d Mon Sep 17 00:00:00 2001 From: OJ Kwon Date: Sun, 5 Aug 2018 12:29:48 -0700 Subject: [PATCH 459/490] fix(uuid): import versioned uuid --- lib/auth.js | 2 +- lib/multipart.js | 2 +- lib/oauth.js | 2 +- package.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/auth.js b/lib/auth.js index 42f9adaec..f5edf32c3 100644 --- a/lib/auth.js +++ b/lib/auth.js @@ -1,7 +1,7 @@ 'use strict' var caseless = require('caseless') -var uuid = require('uuid') +var uuid = require('uuid/v4') var helpers = require('./helpers') var md5 = helpers.md5 diff --git a/lib/multipart.js b/lib/multipart.js index d6b981277..6a009bc13 100644 --- a/lib/multipart.js +++ b/lib/multipart.js @@ -1,6 +1,6 @@ 'use strict' -var uuid = require('uuid') +var uuid = require('uuid/v4') var CombinedStream = require('combined-stream') var isstream = require('isstream') var Buffer = require('safe-buffer').Buffer diff --git a/lib/oauth.js b/lib/oauth.js index 01c626282..96de72b8e 100644 --- a/lib/oauth.js +++ b/lib/oauth.js @@ -3,7 +3,7 @@ var url = require('url') var qs = require('qs') var caseless = require('caseless') -var uuid = require('uuid') +var uuid = require('uuid/v4') var oauth = require('oauth-sign') var crypto = require('crypto') var Buffer = require('safe-buffer').Buffer diff --git a/package.json b/package.json index bc9a2602a..37b9f89ef 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "safe-buffer": "^5.1.1", "tough-cookie": "~2.3.3", "tunnel-agent": "^0.6.0", - "uuid": "^3.1.0" + "uuid": "^3.3.2" }, "scripts": { "test": "npm run lint && npm run test-ci && npm run test-browser", From bd22e217f1590804ebfea031d158f2a486b0c985 Mon Sep 17 00:00:00 2001 From: Mikeal Rogers Date: Fri, 10 Aug 2018 09:23:28 -0700 Subject: [PATCH 460/490] fix: massive dependency upgrade, fixes all production vulnerabilities --- package.json | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 37b9f89ef..9b187b678 100644 --- a/package.json +++ b/package.json @@ -28,23 +28,23 @@ ], "dependencies": { "aws-sign2": "~0.7.0", - "aws4": "^1.6.0", + "aws4": "^1.8.0", "caseless": "~0.12.0", - "combined-stream": "~1.0.5", - "extend": "~3.0.1", + "combined-stream": "~1.0.6", + "extend": "~3.0.2", "forever-agent": "~0.6.1", - "form-data": "~2.3.1", - "har-validator": "~5.0.3", + "form-data": "~2.3.2", + "har-validator": "~5.1.0", "http-signature": "~1.2.0", "is-typedarray": "~1.0.0", "isstream": "~0.1.2", "json-stringify-safe": "~5.0.1", - "mime-types": "~2.1.17", + "mime-types": "~2.1.19", "oauth-sign": "~0.9.0", "performance-now": "^2.1.0", - "qs": "~6.5.1", - "safe-buffer": "^5.1.1", - "tough-cookie": "~2.3.3", + "qs": "~6.5.2", + "safe-buffer": "^5.1.2", + "tough-cookie": "~2.4.3", "tunnel-agent": "^0.6.0", "uuid": "^3.3.2" }, @@ -60,11 +60,11 @@ "browserify": "^13.0.1", "browserify-istanbul": "^2.0.0", "buffer-equal": "^1.0.0", - "codecov": "^2.0.2", - "coveralls": "^2.11.4", + "codecov": "^3.0.4", + "coveralls": "^3.0.2", "function-bind": "^1.0.2", "istanbul": "^0.4.0", - "karma": "^1.1.1", + "karma": "^3.0.0", "karma-browserify": "^5.0.1", "karma-cli": "^1.0.0", "karma-coverage": "^1.0.0", From 642024036379239a7fa29c27ef7bb4dd3fa3b3a4 Mon Sep 17 00:00:00 2001 From: Mikeal Rogers Date: Fri, 10 Aug 2018 09:23:52 -0700 Subject: [PATCH 461/490] 2.88.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9b187b678..9a9792a58 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.87.1", + "version": "2.88.0", "author": "Mikeal Rogers ", "repository": { "type": "git", From 8162961dfdb73dc35a5a4bfeefb858c2ed2ccbb7 Mon Sep 17 00:00:00 2001 From: Mikeal Rogers Date: Fri, 10 Aug 2018 09:27:09 -0700 Subject: [PATCH 462/490] 2.88.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9a9792a58..1a3be32b2 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.88.0", + "version": "2.88.1", "author": "Mikeal Rogers ", "repository": { "type": "git", From bf3e2651a0750b4c1e06e689daf99da8dd19ce55 Mon Sep 17 00:00:00 2001 From: Chance Hudson Date: Wed, 21 Nov 2018 11:27:48 -0600 Subject: [PATCH 463/490] fix #3054, Bump har-validator version to 5.1.3 (#3055) It seems that a new version of har-validator (5.1.2) may have been published, and then deleted. This PR explicitly sets the version to the latest patch, 5.1.3. Closes #3054 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1a3be32b2..49b68d397 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "extend": "~3.0.2", "forever-agent": "~0.6.1", "form-data": "~2.3.2", - "har-validator": "~5.1.0", + "har-validator": "~5.1.3", "http-signature": "~1.2.0", "is-typedarray": "~1.0.0", "isstream": "~0.1.2", From 7c42a7f8806d9c79694ba21ee78222d1c6a8d548 Mon Sep 17 00:00:00 2001 From: Francis Gulotta Date: Thu, 22 Nov 2018 00:03:08 -0500 Subject: [PATCH 464/490] chore: Add probot-stale https://probot.github.io/apps/stale/ There are a few years of stale issues and prs. This bot will close issues over a year old and give people a chance to respond if they think the issue should stay open. After a manual review of more recent issues, we should tighten this down to 60 or 90 days. --- .github/stale.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .github/stale.yml diff --git a/.github/stale.yml b/.github/stale.yml new file mode 100644 index 000000000..576b3c928 --- /dev/null +++ b/.github/stale.yml @@ -0,0 +1,17 @@ +# Number of days of inactivity before an issue becomes stale +daysUntilStale: 365 +# Number of days of inactivity before a stale issue is closed +daysUntilClose: 7 +# Issues with these labels will never be considered stale +exemptLabels: + - "Up for consideration" + - greenkeeper +# Label to use when marking an issue as stale +staleLabel: stale +# Comment to post when marking an issue as stale. Set to `false` to disable +markComment: > + This issue has been automatically marked as stale because it has not had + recent activity. It will be closed if no further activity occurs. Thank you + for your contributions. +# Comment to post when closing a stale issue. Set to `false` to disable +closeComment: false From 48bdabd9de57008accde1798df3b036c7e1103f8 Mon Sep 17 00:00:00 2001 From: Francis Gulotta Date: Thu, 22 Nov 2018 09:56:14 -0500 Subject: [PATCH 465/490] Add neverstale label to stalebot config --- .github/stale.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/stale.yml b/.github/stale.yml index 576b3c928..f2d911797 100644 --- a/.github/stale.yml +++ b/.github/stale.yml @@ -6,6 +6,7 @@ daysUntilClose: 7 exemptLabels: - "Up for consideration" - greenkeeper + - neverstale # Label to use when marking an issue as stale staleLabel: stale # Comment to post when marking an issue as stale. Set to `false` to disable From 1befd90b4b5ea11149b4f1d23c2c6773196da863 Mon Sep 17 00:00:00 2001 From: Francis Gulotta Date: Thu, 22 Nov 2018 10:33:09 -0500 Subject: [PATCH 466/490] fix: SSL Certs (#3062) - Small readme talking about the issue - Generate all certs for 10 years - one command to update all of them --- tests/ssl/ca/README.md | 8 +++ tests/ssl/ca/ca.srl | 2 +- tests/ssl/ca/client-enc.key | 52 +++++++++---------- tests/ssl/ca/client.crt | 24 ++++----- tests/ssl/ca/client.csr | 26 +++++----- tests/ssl/ca/client.key | 50 +++++++++--------- tests/ssl/ca/gen-all-certs.sh | 6 +++ tests/ssl/ca/gen-client.sh | 1 + tests/ssl/ca/gen-localhost.sh | 3 +- tests/ssl/ca/gen-server.sh | 13 +++-- tests/ssl/ca/localhost.crt | 24 ++++----- tests/ssl/ca/localhost.csr | 26 +++++----- tests/ssl/ca/localhost.key | 50 +++++++++--------- tests/ssl/ca/server.crt | 34 ++++++------ tests/ssl/ca/server.csr | 46 ++++++++-------- tests/ssl/ca/server.key | 98 +++++++++++++++++------------------ 16 files changed, 242 insertions(+), 221 deletions(-) create mode 100644 tests/ssl/ca/README.md create mode 100755 tests/ssl/ca/gen-all-certs.sh diff --git a/tests/ssl/ca/README.md b/tests/ssl/ca/README.md new file mode 100644 index 000000000..f92eb0708 --- /dev/null +++ b/tests/ssl/ca/README.md @@ -0,0 +1,8 @@ +# Generating SSL Certs for tests + +Certs are generated for TLS tests. The localhost, client and server certs for use in test are generated by running; +``` +./gen-all-certs.sh +``` + +They should last 10 years, but can be updated at any time. diff --git a/tests/ssl/ca/ca.srl b/tests/ssl/ca/ca.srl index fdbe36f83..28a2de0e1 100644 --- a/tests/ssl/ca/ca.srl +++ b/tests/ssl/ca/ca.srl @@ -1 +1 @@ -ADF62016AA40C9C5 +ADF62016AA40C9C7 diff --git a/tests/ssl/ca/client-enc.key b/tests/ssl/ca/client-enc.key index a53067b1e..19fb73b2f 100644 --- a/tests/ssl/ca/client-enc.key +++ b/tests/ssl/ca/client-enc.key @@ -1,30 +1,30 @@ -----BEGIN RSA PRIVATE KEY----- Proc-Type: 4,ENCRYPTED -DEK-Info: AES-128-CBC,7FD4AC5078EE99FCA866A397D64EAC81 +DEK-Info: AES-128-CBC,F383CD86ECED9F72E8A8A5671B9B478F -+CpgDIrsR4ZjXY5uo4rG8WxFgwnElNlj4c9ujgUgyx1vwerNYn59MKruDi2oMUHc -jDyN68zSiRIc2zuXnfHPtUUbt4CN1Xy2DOCZ0Fkrr4hNOlwpP6IZYJcjTJ+evnIO -EeayFEYoZhqyPgnGleWwNpOEc/33jsXup/DQHfmi0ot6rfdg1kpT/pAhhYE2ivQo -mfdAizNAluyM2yggdEmRJoWrC+YAxb5fW1wAQFT5YOS+t5TBlCphj18JhsEbeKZg -eS1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fk +EcJTWnXVf09J0YbnCHGblNi8MwRi7MCoqmGXHGTxwmpB0gdXuUJCigmm8xSMRqSr +To8La6apf/QujfSHcxBXnf8JCFO6v59SUMDhx2oce/gYRTejx7L+f/UhVo4EvRF6 +W92pNDCkjeJKU2nNwsV/HeAJml81xxCYQA80PsVMu/27inkDSSP4egapcXr0T1OV +ic+VTR4Tl3g9hI4YBL43+hsJWaxVMpT022ZB6bcTgYFTDQcoAwilOoadF+rVxer/ +ry8ORowY5GRH+zlLE3zetn87EAijwux2/QhnGE3eDFc0FbI008wzRQwhqV/S22yF +XYKh5ni5Xg2tguUMuBC8hr9xjpUe3nP7u/W45f/0BCE6eeJzXTunMWTrBCigMzEq +7OvmIhz7sqb18NC68z4Fj5vmpSqf8//RCyE7Sk0pX7VgSIKX92qopqi/5yroQwFf +jLanlxi4QRBLTBJoXnm+I5kh6dEbV0OaUskKwXqW5T2wAgOx5O6TTK+ZeFGyLSMW +eJY6UnT/6vWAY10O5JiieRbzBaGGJgAQ1fTZYs16F3kbKYR9YvrQKi0ACo2pkYs8 +1FvblxhmpMNRjpvOSpb+71vVgk8hD/v5XaVvVC4Wrm6gnsjlNZD0vQjcOWs1Q/a/ +jWKeB/gTUMIa5CWdzNRvSq2Cvgu5FJYf5qIdii7+FOgDv5VKgUugP5ZHHDQ1iwMZ +o8NfMheG2x5ottq1m7VFS8IB+pWjJfsxSFtybJ8rdHzlbmEQyPzWYCWIQXPVvpNs +oBm36btgWMrzQTjDrt+WKhkuau0NacTZqjugpCJKimBQ/lLYiuxjItUoWKn0mQO4 -----END RSA PRIVATE KEY----- diff --git a/tests/ssl/ca/client.crt b/tests/ssl/ca/client.crt index b3994f69a..ab641d916 100644 --- a/tests/ssl/ca/client.crt +++ b/tests/ssl/ca/client.crt @@ -1,20 +1,20 @@ -----BEGIN CERTIFICATE----- -MIIDLjCCApcCCQCt9iAWqkDJxDANBgkqhkiG9w0BAQsFADCBojELMAkGA1UEBhMC +MIIDLjCCApcCCQCt9i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wK1xVgekA2XfQYJ -/ygAdoliF8BEkQ8b9ZoIwmBAIZRQO9b0DzucycvCag7km0O2uWJYQGzFIOQCxJ+v -9r0= +CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDFNIUKI5I/cOYMv7dYJzPMNEpd9d80 +lXueDWOtFflpKpnt3ssCk+pFIxlbnlBnFl1CIkpjAY9pqB4WoGpDARkkW0RqVleZ +mlxBRMwfkzzTriURb0PtB7P7iRp+lcr+uraJg4sP9xEpZbq/CO1q584EQmiANVL3 +NAPdXf2kP91lUy+F5gZgZqkuPtDRXk1jqxTswRLqBmP5ublM/b9ZQS2Jmih7rVL4 +FiTo6E2DdjSYiZ1cQKSBw3rFWhiFLe3R2BjqK+/uD/hDdcT9sEtdqxLyLqFFBKLa +cYcHcnZOMaohmN8vup26D199r5VP6cJvAh93XfxpCiNDl/S4KSCDq5G5AgMBAAEw +DQYJKoZIhvcNAQEFBQADgYEAjINjRQxACmbp77ymVwaiUiy9YXbXLSsu8auZYDlu +LqiZMIjm6hOOHZPlCC7QXBBRyUKXQnRC4+mOxWfcMwEztYqrX51fP/hVB0aF7hXg +hcn0Ge65N9P8Kby6k/2ha/NQW7I17Sgg1PrvN5BkDFnZBrhNwZbzWwxwezifUwob +ITQ= -----END CERTIFICATE----- diff --git a/tests/ssl/ca/client.csr b/tests/ssl/ca/client.csr index 17b366ac5..6bb0449be 100644 --- a/tests/ssl/ca/client.csr +++ b/tests/ssl/ca/client.csr @@ -2,17 +2,17 @@ MIIC+DCCAeACAQAwgY8xCzAJBgNVBAYTAlVTMQswCQYDVQQIDAJDQTEQMA4GA1UE BwwHT2FrbGFuZDEQMA4GA1UECgwHcmVxdWVzdDEaMBgGA1UECwwRcmVxdWVzdEBs b2NhbGhvc3QxEzARBgNVBAMMClRlc3RDbGllbnQxHjAcBgkqhkiG9w0BCQEWD2Rv -Lm5vdEBlbWFpbC5tZTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANEP -caZ50Atm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HDesVaGIUt7dHYGOor +7+4P+EN1xP2wS12rEvIuoUUEotpxhwdydk4xqiGY3y+6nboPX32vlU/pwm8CH3dd +/GkKI0OX9LgpIIOrkbkCAwEAAaAjMCEGCSqGSIb3DQEJBzEUDBJwYXNzd29yZCBj +aGFsbGVuZ2UwDQYJKoZIhvcNAQELBQADggEBALppUGqe3AVfnD28k8SPXI8LMl16 +0VJWabujQVe1ycDZb/T+9Lcy5Xc6PKhn2yb4da/f528j3M1DsOafTUk+aqOaKHce +o83TCZEdysKjntKQHTBWFT1lf1iOSsD7mT1GOaFmmc81Z6pUUjN8WNk7ybfPoLfb +b+MNKkEqVVw1Ta/TeKGbc+K4Xi/T7VAAP2pJRY9ftrjDm1nciGJHu9NGyjAc8TQB +YabIRAD7sdZkOWR0RSk06gJDqQGNqhn0tjzruDRdrtv5l1UiSPrrnyTOd75mZwXj +LFs5qIQT5W/LRLJ4BkW3YNSiwFJxQ8a4DddYhkd+CadefQtRdgEI3+GhNcQ= -----END CERTIFICATE REQUEST----- diff --git a/tests/ssl/ca/client.key b/tests/ssl/ca/client.key index 46542e683..c21878c96 100644 --- a/tests/ssl/ca/client.key +++ b/tests/ssl/ca/client.key @@ -1,27 +1,27 @@ -----BEGIN RSA PRIVATE KEY----- -MIIEpAIBAAKCAQEA0Q9xpnnQC2aQwl0O/AthIZ9Efhe45+HGzkzhzgShmxRG9uSL -O5B1kHweAGzoFy7P0usfA4BRzSq+YiKB4iXq0iHhkUybSzZybF35+3PTmbQcJkd3 -rokDv3rz+x0iWb3peK4W/vKUTH9jAMQQtA+s+eom5Z1CyWqIaowz7/Q9/IO0SO2F -bqytOX48J8AdtfxkWIfr5uancO/DfgkzD9q2OSB4+DCXMajaSW4DFmfLw1GNVH/S -TUG65dZSmHgxc4RN4/tbgD1e9dbKyS7wlKqFz230tSigCQCUHIXgc3eFJesFlCwQ -jCxj8N4+sTqAc+oisAJ/qjkIK6NkEKYnY/4JBQIDAQABAoIBAF7P3EEd2YZyG5Cq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EAzFv+ +rDPOp4pK0LPeDwSDUflasq7Dc52xcWfYupajAvK/4pzeDr07Frv8gh+EhhCp4kwN +YtmHJ0KfE0R4Ijh8LH5MNhl2YBhTCqp3NZf3jhdiPTDRHMNfUq5aUbercU5Yi1W/ +FrqBeTbid1k7tHV/EqwWqcYQBVdFuSjuUkA1UJkCgYEA4UT5wkRUBzZ3cDUQwRVx +cFfE+pydP3MMjVZUy4gdvpqNbZO+X1ykpEB8IkseeSn8oETc1IbFb1JCXKfYZJKA +6BlWAt2+7dYHyeTUUUbgSEnssIyqmqVIVmBe3Ft/o4cI+Pu1SZSXLLtD5jUCB5Hi +ezZCxQSSqgCwQtLjxRL8CkECgYEAwI6OUUQfnM454J0ax5vBASSryWHS2MXlxK3N +EUOPJeAF3klhExJK8wj+zL1V6d0ZthljI5lEOEIWEdmaOORwXJxEw1UKrVE+Lfah +jOY8ZK6z6mRtJWUSFJ4kjIs8B++Cjwekno3uIYENstdp4ogzzCxKzn3J6r5o/CcN +KINHuUECgYB82O06BuRuSWYYM3qHxgo4bKqIQYHZKI528p90bMSyTH7M2sXcGR+z +ADcs1Ald0acyJkI4IpzBs+YK+WVihQKuSh69YGKKru0xq0hONN8j2pgphVDS0hbk +bMzyxx1QHK9cRVAXFdiqeQ36U3f70enItxXvOYGwWGvD5v7bCpYuCA== -----END RSA PRIVATE KEY----- diff --git a/tests/ssl/ca/gen-all-certs.sh b/tests/ssl/ca/gen-all-certs.sh new file mode 100755 index 000000000..b3a572582 --- /dev/null +++ b/tests/ssl/ca/gen-all-certs.sh @@ -0,0 +1,6 @@ +#!/bin/sh +set -ex + +./gen-server.sh +./gen-client.sh +./gen-localhost.sh diff --git a/tests/ssl/ca/gen-client.sh b/tests/ssl/ca/gen-client.sh index ed2fcfb38..1d5cfd203 100755 --- a/tests/ssl/ca/gen-client.sh +++ b/tests/ssl/ca/gen-client.sh @@ -1,4 +1,5 @@ #!/bin/sh +set -ex # Adapted from: # http://nodejs.org/api/tls.html diff --git a/tests/ssl/ca/gen-localhost.sh b/tests/ssl/ca/gen-localhost.sh index 9c48673c4..5dbd04b53 100755 --- a/tests/ssl/ca/gen-localhost.sh +++ b/tests/ssl/ca/gen-localhost.sh @@ -1,4 +1,5 @@ #!/bin/sh +set -ex # Adapted from: # http://nodejs.org/api/tls.html @@ -18,4 +19,4 @@ openssl x509 -req \ -set_serial 0x`cat ca.srl` \ -passin 'pass:password' \ -out localhost.crt \ - -days 1095 + -days 3650 diff --git a/tests/ssl/ca/gen-server.sh b/tests/ssl/ca/gen-server.sh index d80e586ac..4223ddc7c 100755 --- a/tests/ssl/ca/gen-server.sh +++ b/tests/ssl/ca/gen-server.sh @@ -1,5 +1,5 @@ #!/bin/sh - +set -ex # fixes: # Error: error:140AB18F:SSL routines:SSL_CTX_use_certificate:ee key too small # on Node > v10 @@ -8,6 +8,11 @@ openssl genrsa 4096 > server.key openssl req -new -nodes -sha256 -key server.key -config server.cnf -out server.csr -openssl x509 -req -sha256 -in server.csr -CA ca.crt -CAkey ca.key -out server.crt - -# password: password +openssl x509 -req \ + -sha256 \ + -in server.csr \ + -CA ca.crt \ + -CAkey ca.key \ + -out server.crt \ + -passin 'pass:password' \ + -days 3650 diff --git a/tests/ssl/ca/localhost.crt b/tests/ssl/ca/localhost.crt index 788557a68..4a0fe1003 100644 --- a/tests/ssl/ca/localhost.crt +++ b/tests/ssl/ca/localhost.crt @@ -1,20 +1,20 @@ -----BEGIN CERTIFICATE----- -MIIDLTCCApYCCQCt9iAWqkDJxDANBgkqhkiG9w0BAQsFADCBojELMAkGA1UEBhMC +MIIDLTCCApYCCQCt9iAWqkDJxzANBgkqhkiG9w0BAQUFADCBojELMAkGA1UEBhMC VVMxCzAJBgNVBAgTAkNBMRAwDgYDVQQHEwdPYWtsYW5kMRAwDgYDVQQKEwdyZXF1 ZXN0MSYwJAYDVQQLEx1yZXF1ZXN0IENlcnRpZmljYXRlIEF1dGhvcml0eTESMBAG A1UEAxMJcmVxdWVzdENBMSYwJAYJKo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Fecjkt0Zc12p8OS +UN94MBzyCyaFlDWxoneP17FFBgMD0/qDbYAYgwRE308TFlnA4rbI0g3f5/Ft7bhj +dd18Sw0/p0RoIdr7FezM5chSW62AwJ/QHEmjZt/VXzs1ITMG1549r5T1fngw5x+G +eTG1HagM6/CMrtLk0nXTDRR469A0n0ZgdXdSBnN3igSyVIy9gaUGjrXhs2GImnvL +LqzgYUSxVIopI9T0umbKGtoVp79RIU+P59di0ybtiAI8P1CElj0bpT8CAwEAATAN +BgkqhkiG9w0BAQUFAAOBgQAeTesuuLfnlqqVE0sq6kl+Va2MnJJSvgHuadCaSnr3 +EvieJYiE5uydesI7nSBTs9z873RBFlLdAXx/FyShRSnVB/WaNZP9lb97oyWeTj21 +q0nTXHSZFOb9nRdtwyLmX9L6EO2KAbNSxmAdt8ZJd2FZNahHXDEiNtwemzNVlkw8 +bQ== -----END CERTIFICATE----- diff --git a/tests/ssl/ca/localhost.csr b/tests/ssl/ca/localhost.csr index 22f60936c..44aed654b 100644 --- a/tests/ssl/ca/localhost.csr +++ b/tests/ssl/ca/localhost.csr @@ -2,17 +2,17 @@ MIIC9zCCAd8CAQAwgY4xCzAJBgNVBAYTAlVTMQswCQYDVQQIDAJDQTEQMA4GA1UE BwwHT2FrbGFuZDEQMA4GA1UECgwHcmVxdWVzdDEaMBgGA1UECwwRcmVxdWVzdEBs b2NhbGhvc3QxEjAQBgNVBAMMCWxvY2FsaG9zdDEeMBwGCSqGSIb3DQEJARYPZG8u -bm90QGVtYWlsLm1lMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqhMQ -hENWVwEtoSCB8Th6ixEWMuFzSyBrc2UsL/rtPqEA3b/FsfXIJCm+urReCLkUxcWn -SuQWpwtI4RDiZAf/AW1uPn4htON5m+/Z3sbkn7eFjsAsIOgyXBvSJ9fzDmozA9qI -Z2TuXRan8zzUgAvJXIqsrCU5WpO2L/aGaFAEcZUshOyj9BoYl6cKcnu2RnqcVhim -zRvayXzreM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ysXMYA9BOffqO4VCsw3 +7/4DEZtqvNIbRB2zLkzcAOUq/kwPr0pQ8AX1YjotAMIONI1R1Gr4ttlbUfbtqfOH +zk7d+wfYUKrUlqGCD0E0EKNRtn76lJD3r5CQtLbeAd3d+b5bpsHVYErsAyrWqkOx +gRnYmAX3vLDoXFZwp0L3577MJLEzjnV+uPrJVtF4I4wDxU7qoaC5wYE8oExE+2MA +POYO+6GYWOPnIViVGnkbZXlRkBufD9cLcMhKVSo2nfNiFqZm1+nTcf9EC8ILdqtb +JkMcBHNBje6KTC3Ue2vJkKg61hbVoj/MoYo63UeXA1ACOjvfnE8cMP4pjw== -----END CERTIFICATE REQUEST----- diff --git a/tests/ssl/ca/localhost.key b/tests/ssl/ca/localhost.key index eccebad34..211578ddb 100644 --- a/tests/ssl/ca/localhost.key +++ b/tests/ssl/ca/localhost.key @@ -1,27 +1,27 @@ -----BEGIN RSA PRIVATE KEY----- -MIIEpAIBAAKCAQEAqhMQhENWVwEtoSCB8Th6ixEWMuFzSyBrc2UsL/rtPqEA3b/F -sfXIJCm+urReCLkUxcWnSuQWpwtI4RDiZAf/AW1uPn4htON5m+/Z3sbkn7eFjsAs -IOgyXBvSJ9fzDmozA9qIZ2TuXRan8zzUgAvJXIqsrCU5WpO2L/aGaFAEcZUshOyj -9BoYl6cKcnu2RnqcVhimzRvayXzreMeeZp5j9BgZ0If42qefqfK5F8t6SNuhR9EA -iox/FqvBVHEFWDg31gu9P5CbRThm0IK4xdFooLlhGnmwr/sZKeAAIHcSfed0/vWv -LqzHCi9rdhvhB56LVL8miciv4oNOWaSjxJe2eQIDAQABAoIBAH3b++YVOujKC21o -9CCB7lXJwEbJBpw7Eqlj3q5nIHivh0eS6odG3uS8K9RZNBl6df/hxGqsnoLh2/4K -k675J+JzjBkdGG6XxF/8wJuXTotPsbuxRTbY/qOhRwWLTuiE+NnKOBVj4O3snT9o -7c0Qa+RbD2uZZHc+Rp357v9078TpLVO57DpSNpUDGBLzVkzrh2X9oRoqt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EoWf8 +k1huHKV3Rn5j5ZJuBeaw9wtKUEoWPAfBkjFsqty07Ba+mfnOwrmpK74xW2DvscaS +0XDsUrtJ3znbkWGbIBmq/qBJk5DBPBGvoU8SFcim2sp1jbVaq9Cv2Z0nGow7FEIA +NKddP7naqtuSktianf2KppepAoGBAPE6/dTjfkdQ5Rwmi8xW7qANNZifz4EpgUIf +OCC2c1YKIUKVZyllEyhWeDEX3x9hj8QVggKoTgx6vbPowVhEOmDEfSSFrzTdjMMv +HF6j1tlP9rni/EJJCWhowG0pnxKqp0NoiN6JR81i+iz22IgoOG+nrT9mHloDdaef +8/bxgOBLAoGBALMQ9GMCdm7wVOkPktz8enAkd2mt6+BHXtNgKaBvfWED7T+YEVtp +aw/0eSSnRh2RgnqVAw9HJOCGATecK/p/JrcTzbTYr1n7FzuXp7nX1eoi95sT5XLm +7b0/4EdL9dXGQP5PXxgMZY/Vbk3TD5fdUxam4QpA1opl+rEOYO+GhMFo -----END RSA PRIVATE KEY----- diff --git a/tests/ssl/ca/server.crt b/tests/ssl/ca/server.crt index ac7b35ff6..72a408fb7 100644 --- a/tests/ssl/ca/server.crt +++ b/tests/ssl/ca/server.crt @@ -1,25 +1,25 @@ -----BEGIN CERTIFICATE----- -MIIEQjCCA6sCCQCt9iAWqkDJxTANBgkqhkiG9w0BAQsFADCBojELMAkGA1UEBhMC +MIIEQjCCA6sCCQCt9iAWqkDJxzANBgkqhkiG9w0BAQsFADCBojELMAkGA1UEBhMC VVMxCzAJBgNVBAgTAkNBMRAwDgYDVQQHEwdPYWtsYW5kMRAwDgYDVQQKEwdyZXF1 ZXN0MSYwJAYDVQQLEx1yZXF1ZXN0IENlcnRpZmljYXRlIEF1dGhvcml0eTESMBAG A1UEAxMJcmVxdWVzdENBMSYwJAYJKoZIhvcNAQkBFhdtaWtlYWxAbWlrZWFscm9n -ZXJzLmNvbTAeFw0xODA3MDgxMTQ5MzlaFw0xODA4MDcxMTQ5MzlaMIGjMQswCQYD +ZXJzLmNvbT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0fPZDHHHoi+K/wQ= -----END CERTIFICATE----- diff --git a/tests/ssl/ca/server.csr b/tests/ssl/ca/server.csr index 76b6a1e72..55395d765 100644 --- a/tests/ssl/ca/server.csr +++ b/tests/ssl/ca/server.csr @@ -3,27 +3,27 @@ MIIFDDCCAvQCAQAwgaMxCzAJBgNVBAYTAlVTMQswCQYDVQQIDAJDQTEQMA4GA1UE BwwHT2FrbGFuZDEQMA4GA1UECgwHcmVxdWVzdDEQMA4GA1UECwwHdGVzdGluZzEp MCcGA1UEAwwgdGVzdGluZy5yZXF1ZXN0Lm1pa2VhbHJvZ2Vycy5jb20xJjAkBgkq hkiG9w0BCQEWF21pa2VhbEBtaWtlYWxyb2dlcnMuY29tMIICIjANBgkqhkiG9w0B -AQEFAAOCAg8AMIICCgKCAgEArOh5u4tHH5z/zzSaClff6jFw72mcIcQu9DJWC+WT -VPHkVe6eYHeh2jGhszfvCrPDUFv8nJTnz4L+Q8NXPmLGnkUgGBAIEzu3pWsW8A2p -7rcUIWHBKm10lAek4mUFlpnatFhyM3wzKhp4ulSmtrT3g3ZUJYxo3Da+9jywIkGP -n0T7QVJxfihsUeaQRfRbV5xxLj5ToN3zZ4s3ps8+GylaWrVew6fLh63kiTxcd9Yn -9qVECaXZF0MXNX1pZgiDYsi/bAGOWc1FfqO977f7lKSuuewVlZk769I12oIxSnek -J6nCtmjeVqX5jPo5/WOYS2YcZQZqBTB2aDYWRrUc4AqFJd6kVoGwzwIlssEBVQVG -a59cGI7FFzZrz46F4dXfdNT9Xtk90F+m8pfnlCqebp6QVjaHgu/E2B7ZZUJUSsi8 -+KD48kuWyb2AdX8oipm+YkziPktbi2jCNF8gThDD4OhMZwOcJvBG6pxJ6EV+0ph8 -s9G4CiICFc8iWUTZYP+vAypEWpbSN+Id1Fi70BqY0lggmNEBjzyJNGtvb/bxpwy9 -vP0uDyMDXeRUPdMQRO8Ff2Z4Q7Hm2ev6eKVyhkN3MewHvyYN1f2xBs30hzRqUVyn -3bMftDDpgEr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+o/6xOYnzJubCKWwHBtSfo7hjaGMDOGSzXTyNxqlzRW50zXpgAxIcf9XJ+Gq36++Q +QoyMKX6O2r6oHXSnF5ojDW6QOAfOSdrX5fc9uXsbVAGh5vYeLDcekZwGSZbZ608a +2P4ARIWNNOYBaGQsoElfPXRFqcU9SLB+qXEMMDde/y0FNWEOe+b+vlH1g14aiCSE -----END CERTIFICATE REQUEST----- diff --git a/tests/ssl/ca/server.key b/tests/ssl/ca/server.key index d84eacccc..9e9975700 100644 --- a/tests/ssl/ca/server.key +++ b/tests/ssl/ca/server.key @@ -1,51 +1,51 @@ -----BEGIN RSA PRIVATE KEY----- -MIIJJwIBAAKCAgEArOh5u4tHH5z/zzSaClff6jFw72mcIcQu9DJWC+WTVPHkVe6e -YHeh2jGhszfvCrPDUFv8nJTnz4L+Q8NXPmLGnkUgGBAIEzu3pWsW8A2p7rcUIWHB -Km10lAek4mUFlpnatFhyM3wzKhp4ulSmtrT3g3ZUJYxo3Da+9jywIkGPn0T7QVJx -fihsUeaQRfRbV5xxLj5ToN3zZ4s3ps8+GylaWrVew6fLh63kiTxcd9Yn9qVECaXZ -F0MXNX1pZgiDYsi/bAGOWc1FfqO977f7lKSuuewVlZk769I12oIxSnekJ6nCtmje -VqX5jPo5/WOYS2YcZQZqBTB2aDYWRrUc4AqFJd6kVoGwzwIlssEBVQVGa59cGI7F -FzZrz46F4dXfdNT9Xtk90F+m8pfnlCqebp6QVjaHgu/E2B7ZZUJUSsi8+KD48kuW -yb2AdX8oipm+YkziPktbi2jCNF8gThDD4OhMZwOcJvBG6pxJ6EV+0ph8s9G4CiIC -Fc8iWUTZYP+vAypEWpbSN+Id1Fi70BqY0lggmNEBjzyJNGtvb/bxpwy9vP0uDyMD -XeRUPdMQRO8Ff2Z4Q7Hm2ev6eKVyhkN3MewHvyYN1f2xBs30hzRqUVyn3bMftDDp -gEr/olwVcoQKoOf7YnlD2S4jQDZcoxcKfxTy1OgvYNEBIHuHKLw3dj26fecCAwEA -AQKC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gCA9AKIyF +IAgYpcQrlMAl07jjzSl47R/0BDOe/jzmH7JqpFQOfw9e7U0XThgaVEVHSF9qJVRS +LlFUhijpG14Qyr8gwfR3RrnO7TKfdXW3GX/5ts0Oac9B+gOMkrksNalgLHnOZSzO +JuiTAH7CdUt1OC0NaaCBZiI3A5C1Gn1J9vskW4yCwhW0UNnW4h7m+eru0ok= -----END RSA PRIVATE KEY----- From 418623cf6d786c7f7a87c1285fa8bd97af1cc826 Mon Sep 17 00:00:00 2001 From: SneakyFish5 <32284796+SneakyFish5@users.noreply.github.com> Date: Wed, 15 Aug 2018 11:23:39 -0500 Subject: [PATCH 467/490] Drop support for Node.js v4 (Fix #2917) --- .travis.yml | 1 - package.json | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9ea82aa50..9c9940a2b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,6 @@ node_js: - 10 - 8 - 6 - - 4 after_script: - npm run test-cov diff --git a/package.json b/package.json index 49b68d397..d9b1047ce 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ }, "license": "Apache-2.0", "engines": { - "node": ">= 4" + "node": ">= 6" }, "main": "index.js", "files": [ From e476ce5762e752874675a83193121639485045f0 Mon Sep 17 00:00:00 2001 From: George Hafiz Date: Fri, 23 Nov 2018 03:29:48 +0000 Subject: [PATCH 468/490] Update README.md (#2644) Added a paragraph of text to the TLS section, on the use of the `ca` option, explicitly detailing how to get SSL certificates that consist of more than one issuer to successfully verify. It was not made clear that `ca` can be an array, and that in fact this is necessary (AFAICT) when you want to accept a certificate that has been signed by multiple issuers, common in internal environments. --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index b91623d2e..64ccb52c6 100644 --- a/README.md +++ b/README.md @@ -675,6 +675,25 @@ request.get({ }); ``` +The `ca` value can be an array of certificates, in the event you have a private or internal corporate public-key infrastructure hierarchy. For example, if you want to connect to https://api.some-server.com which presents a key chain consisting of: +1. its own public key, which is signed by: +2. an intermediate "Corp Issuing Server", that is in turn signed by: +3. a root CA "Corp Root CA"; + +you can configure your request as follows: + +```js +request.get({ + url: 'https://api.some-server.com/', + agentOptions: { + ca: [ + fs.readFileSync('Corp Issuing Server.pem'), + fs.readFileSync('Corp Root CA.pem') + ] + } +}); +``` + [back to top](#table-of-contents) From 20314472619e4bd06c9ebefa27215f596366a97b Mon Sep 17 00:00:00 2001 From: Maciej Adwent Date: Thu, 22 Nov 2018 19:37:15 -0800 Subject: [PATCH 469/490] Fix link to HAR 1.2 Section Anchor (#2674) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 64ccb52c6..d1b705771 100644 --- a/README.md +++ b/README.md @@ -866,7 +866,7 @@ default in Linux can be anywhere from 20-120 seconds][linux-timeout]). - `download`: Duration of HTTP download (`timings.end` - `timings.response`) - `total`: Duration entire HTTP round-trip (`timings.end`) -- `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)* +- `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-12) for details)* - `callback` - alternatively pass the request's callback in the options object The callback argument gets 3 arguments: From 8d189197531b56b32e2397585bddd2bb22221dc4 Mon Sep 17 00:00:00 2001 From: jsx Date: Fri, 23 Nov 2018 09:09:18 +0530 Subject: [PATCH 470/490] Update README to mention util.promisify() (#2824) Update README.md to mention that util.promisify can be used to convert a regular function that takes a callback to return a promise instead. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index d1b705771..2e4293234 100644 --- a/README.md +++ b/README.md @@ -152,6 +152,8 @@ Several alternative interfaces are provided by the request team, including: - [`request-promise-native`](https://github.com/request/request-promise-native) (uses native Promises) - [`request-promise-any`](https://github.com/request/request-promise-any) (uses [any-promise](https://www.npmjs.com/package/any-promise) Promises) +Also, [`util.promisify`](https://nodejs.org/api/util.html#util_util_promisify_original), which is available from Node.js v8.0 can be used to convert a regular function that takes a callback to return a promise instead. + [back to top](#table-of-contents) From 641527de7ab9058ce424153bed220c879fb8c081 Mon Sep 17 00:00:00 2001 From: Huachao Mao Date: Fri, 23 Nov 2018 11:49:24 +0800 Subject: [PATCH 471/490] Update cookie store API link (#2750) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2e4293234..f7202aca7 100644 --- a/README.md +++ b/README.md @@ -1101,7 +1101,7 @@ request('http://www.google.com', function() { The cookie store must be a [`tough-cookie`](https://github.com/SalesforceEng/tough-cookie) store and it must support synchronous operations; see the -[`CookieStore` API docs](https://github.com/SalesforceEng/tough-cookie#cookiestore-api) +[`CookieStore` API docs](https://github.com/SalesforceEng/tough-cookie#api) for details. To inspect your cookie jar after a request: From 297e39b1585c51795f60b5d4a7fd56fe0d052aed Mon Sep 17 00:00:00 2001 From: opeer Date: Fri, 23 Nov 2018 05:51:11 +0200 Subject: [PATCH 472/490] Update the documentation of timeout to reflect it controls timeout of socket inactivity (#2728) --- README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f7202aca7..20a02922e 100644 --- a/README.md +++ b/README.md @@ -823,11 +823,12 @@ The first argument can be either a `url` or an `options` object. The only requir work around this, either use [`request.defaults`](#requestdefaultsoptions) 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 -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]). +- `timeout` - integer containing number of milliseconds, controls two timeouts + - Time to wait for a 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]). + - Sets the socket to timeout after `timeout` milliseconds of inactivity on the socket. [linux-timeout]: http://www.sekuda.com/overriding_the_default_linux_kernel_20_second_tcp_socket_connect_timeout From 2737161f36c4b7bf1daa969d9cf90426572cb654 Mon Sep 17 00:00:00 2001 From: Rolf Koenders Date: Fri, 23 Nov 2018 05:02:25 +0100 Subject: [PATCH 473/490] Verify that body is not empty (#2701) --- tests/test-pipes.js | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test-pipes.js b/tests/test-pipes.js index 0ee3dd6c8..adeaa5006 100644 --- a/tests/test-pipes.js +++ b/tests/test-pipes.js @@ -295,6 +295,7 @@ tape('one-line proxy', function (t) { }, function (err, res, body) { t.equal(err, null) t.equal(res.headers['x-oneline-proxy'], 'yup') + t.notEqual(body, null) t.end() }) }) From 39e3d50709edaf79ef035916be852a3fa532ef3b Mon Sep 17 00:00:00 2001 From: Francis Gulotta Date: Fri, 23 Nov 2018 13:56:20 -0500 Subject: [PATCH 474/490] add bug label to stale.yml --- .github/stale.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/stale.yml b/.github/stale.yml index f2d911797..ad26df134 100644 --- a/.github/stale.yml +++ b/.github/stale.yml @@ -7,6 +7,7 @@ exemptLabels: - "Up for consideration" - greenkeeper - neverstale + - bug # Label to use when marking an issue as stale staleLabel: stale # Comment to post when marking an issue as stale. Set to `false` to disable From 5ee89063cdbc3d5f27c2fc1c7232ad35148c94ac Mon Sep 17 00:00:00 2001 From: Alessandro Miliucci Date: Fri, 23 Nov 2018 20:03:53 +0100 Subject: [PATCH 475/490] Documented response.caseless.get() (#2995) --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 20a02922e..bff861572 100644 --- a/README.md +++ b/README.md @@ -940,6 +940,17 @@ Function that creates a new cookie jar. request.jar() ``` +### response.caseless.get('header-name') + +Function that returns the specified response header field using a [case-insensitive match](https://tools.ietf.org/html/rfc7230#section-3.2) + +```js +request('http://www.google.com', function (error, response, body) { + // print the Content-Type header even if the server returned it as 'content-type' (lowercase) + console.log('Content-Type is:', response.caseless.get('Content-Type')); +}); +``` + [back to top](#table-of-contents) From 81b171b5f714b6f6b3e673f52e0ef1c888f71c3c Mon Sep 17 00:00:00 2001 From: Emmanuel DEMEY Date: Fri, 23 Nov 2018 23:48:45 -0500 Subject: [PATCH 476/490] fix: use const instead of var in the README (#3046) --- README.md | 72 +++++++++++++++++++++++++++---------------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index bff861572..ce5791000 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Request is designed to be the simplest way possible to make http calls. It supports HTTPS and follows redirects by default. ```js -var request = require('request'); +const request = require('request'); request('http://www.google.com', function (error, response, body) { console.log('error:', error); // Print the error if one occurred console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received @@ -110,7 +110,7 @@ You can also `pipe()` from `http.ServerRequest` instances, as well as to `http.S ```js http.createServer(function (req, resp) { if (req.url === '/doodle.png') { - var x = request('http://mysite.com/doodle.png') + const x = request('http://mysite.com/doodle.png') req.pipe(x) x.pipe(resp) } @@ -126,7 +126,7 @@ req.pipe(request('http://mysite.com/doodle.png')).pipe(resp) Also, none of this new functionality conflicts with requests previous features, it just expands them. ```js -var r = request.defaults({'proxy':'http://localproxy.com'}) +const r = request.defaults({'proxy':'http://localproxy.com'}) http.createServer(function (req, resp) { if (req.url === '/doodle.png') { @@ -185,7 +185,7 @@ For `multipart/form-data` we use the [form-data](https://github.com/form-data/fo ```js -var formData = { +const formData = { // Pass a simple key-value pair my_field: 'my_value', // Pass data via Buffers @@ -220,8 +220,8 @@ For advanced cases, you can access the form-data object itself via `r.form()`. T ```js // NOTE: Advanced use-case, for normal use see 'formData' usage above -var r = request.post('http://service.com/upload', function optionalCallback(err, httpResponse, body) {...}) -var form = r.form(); +const r = request.post('http://service.com/upload', function optionalCallback(err, httpResponse, body) {...}) +const form = r.form(); form.append('my_field', 'my_value'); form.append('my_buffer', Buffer.from([1, 2, 3])); form.append('custom_file', fs.createReadStream(__dirname + '/unicycle.jpg'), {filename: 'unicycle.jpg'}); @@ -316,11 +316,11 @@ detailed in [RFC 1738](http://www.ietf.org/rfc/rfc1738.txt). Simply pass the `user:password` before the host with an `@` sign: ```js -var username = 'username', +const username = 'username', password = 'password', url = 'http://' + username + ':' + password + '@some.server.com'; -request({url: url}, function (error, response, body) { +request({url}, function (error, response, body) { // Do more stuff with 'body' here }); ``` @@ -349,9 +349,9 @@ of stars and forks for the request repository. This requires a custom `User-Agent` header as well as https. ```js -var request = require('request'); +const request = require('request'); -var options = { +const options = { url: 'https://api.github.com/repos/request/request', headers: { 'User-Agent': 'request' @@ -360,7 +360,7 @@ var options = { function callback(error, response, body) { if (!error && response.statusCode == 200) { - var info = JSON.parse(body); + const info = JSON.parse(body); console.log(info.stargazers_count + " Stars"); console.log(info.forks_count + " Forks"); } @@ -384,7 +384,7 @@ default signing algorithm is ```js // OAuth1.0 - 3-legged server side flow (Twitter example) // step 1 -var qs = require('querystring') +const qs = require('querystring') , oauth = { callback: 'http://mysite.com/callback/' , consumer_key: CONSUMER_KEY @@ -399,14 +399,14 @@ request.post({url:url, oauth:oauth}, function (e, r, body) { // verified with twitter that they are authorizing your app. // step 2 - var req_data = qs.parse(body) - var uri = 'https://api.twitter.com/oauth/authenticate' + const req_data = qs.parse(body) + const uri = 'https://api.twitter.com/oauth/authenticate' + '?' + qs.stringify({oauth_token: req_data.oauth_token}) // redirect the user to the authorize uri // step 3 // after the user is redirected back to your server - var auth_data = qs.parse(body) + const auth_data = qs.parse(body) , oauth = { consumer_key: CONSUMER_KEY , consumer_secret: CONSUMER_SECRET @@ -418,7 +418,7 @@ request.post({url:url, oauth:oauth}, function (e, r, body) { ; request.post({url:url, oauth:oauth}, function (e, r, body) { // ready to make signed requests on behalf of the user - var perm_data = qs.parse(body) + const perm_data = qs.parse(body) , oauth = { consumer_key: CONSUMER_KEY , consumer_secret: CONSUMER_SECRET @@ -607,14 +607,14 @@ TLS/SSL Protocol options, such as `cert`, `key` and `passphrase`, can be set directly in `options` object, in the `agentOptions` property of the `options` object, or even in `https.globalAgent.options`. Keep in mind that, although `agentOptions` allows for a slightly wider range of configurations, the recommended way is via `options` object directly, as using `agentOptions` or `https.globalAgent.options` would not be applied in the same way in proxied environments (as data travels through a TLS connection instead of an http/https agent). ```js -var fs = require('fs') +const fs = require('fs') , path = require('path') , certFile = path.resolve(__dirname, 'ssl/client.crt') , keyFile = path.resolve(__dirname, 'ssl/client.key') , caFile = path.resolve(__dirname, 'ssl/ca.cert.pem') , request = require('request'); -var options = { +const options = { url: 'https://api.some-server.com/', cert: fs.readFileSync(certFile), key: fs.readFileSync(keyFile), @@ -631,13 +631,13 @@ In the example below, we call an API that requires client side SSL certificate (in PEM format) with passphrase protected private key (in PEM format) and disable the SSLv3 protocol: ```js -var fs = require('fs') +const fs = require('fs') , path = require('path') , certFile = path.resolve(__dirname, 'ssl/client.crt') , keyFile = path.resolve(__dirname, 'ssl/client.key') , request = require('request'); -var options = { +const options = { url: 'https://api.some-server.com/', agentOptions: { cert: fs.readFileSync(certFile), @@ -708,7 +708,7 @@ The `options.har` property will override the values: `url`, `method`, `qs`, `hea A validation step will check if the HAR Request format matches the latest spec (v1.2) and will skip parsing if not matching. ```js - var request = require('request') + const request = require('request') request({ // will be ignored method: 'GET', @@ -902,13 +902,13 @@ instead, it **returns a wrapper** that has your default settings applied to it. For example: ```js //requests using baseRequest() will set the 'x-token' header -var baseRequest = request.defaults({ +const baseRequest = request.defaults({ headers: {'x-token': 'my-token'} }) //requests using specialRequest() will include the 'x-token' header set in //baseRequest and will also include the 'special' header -var specialRequest = baseRequest.defaults({ +const specialRequest = baseRequest.defaults({ headers: {special: 'special value'} }) ``` @@ -1008,7 +1008,7 @@ request.get('http://10.255.255.1', {timeout: 1500}, function(err) { ## Examples: ```js - var request = require('request') + const request = require('request') , rand = Math.floor(Math.random()*100000000).toString() ; request( @@ -1039,7 +1039,7 @@ while the response object is unmodified and will contain compressed data if the server sent a compressed response. ```js - var request = require('request') + const request = require('request') request( { method: 'GET' , uri: 'http://www.google.com' @@ -1067,7 +1067,7 @@ the server sent a compressed response. Cookies are disabled by default (else, they would be used in subsequent requests). To enable cookies, set `jar` to `true` (either in `defaults` or `options`). ```js -var request = request.defaults({jar: true}) +const request = request.defaults({jar: true}) request('http://www.google.com', function () { request('http://images.google.com') }) @@ -1076,8 +1076,8 @@ request('http://www.google.com', function () { To use a custom cookie jar (instead of `request`’s global cookie jar), set `jar` to an instance of `request.jar()` (either in `defaults` or `options`) ```js -var j = request.jar() -var request = request.defaults({jar:j}) +const j = request.jar() +const request = request.defaults({jar:j}) request('http://www.google.com', function () { request('http://images.google.com') }) @@ -1086,9 +1086,9 @@ request('http://www.google.com', function () { OR ```js -var j = request.jar(); -var cookie = request.cookie('key1=value1'); -var url = 'http://www.google.com'; +const j = request.jar(); +const cookie = request.cookie('key1=value1'); +const url = 'http://www.google.com'; j.setCookie(cookie, url); request({url: url, jar: j}, function () { request('http://images.google.com') @@ -1101,9 +1101,9 @@ which supports saving to and restoring from JSON files), pass it as a parameter to `request.jar()`: ```js -var FileCookieStore = require('tough-cookie-filestore'); +const FileCookieStore = require('tough-cookie-filestore'); // NOTE - currently the 'cookies.json' file must already exist! -var j = request.jar(new FileCookieStore('cookies.json')); +const j = request.jar(new FileCookieStore('cookies.json')); request = request.defaults({ jar : j }) request('http://www.google.com', function() { request('http://images.google.com') @@ -1119,10 +1119,10 @@ for details. To inspect your cookie jar after a request: ```js -var j = request.jar() +const j = request.jar() request({url: 'http://www.google.com', jar: j}, function () { - var cookie_string = j.getCookieString(url); // "key1=value1; key2=value2; ..." - var cookies = j.getCookies(url); + const cookie_string = j.getCookieString(url); // "key1=value1; key2=value2; ..." + const cookies = j.getCookies(url); // [{key: 'key1', value: 'value1', domain: "www.google.com", ...}, ...] }) ``` From 167065e2350fcb58fbfb7f4d8be03f8a9d30997f Mon Sep 17 00:00:00 2001 From: Francis Gulotta Date: Fri, 23 Nov 2018 23:49:11 -0500 Subject: [PATCH 477/490] chore: ensure piped body is exactly the same (#3064) --- tests/test-pipes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-pipes.js b/tests/test-pipes.js index adeaa5006..dab7cb311 100644 --- a/tests/test-pipes.js +++ b/tests/test-pipes.js @@ -295,7 +295,7 @@ tape('one-line proxy', function (t) { }, function (err, res, body) { t.equal(err, null) t.equal(res.headers['x-oneline-proxy'], 'yup') - t.notEqual(body, null) + t.equal(body, fs.readFileSync(path.join(__dirname, 'googledoodle.jpg')).toString()) t.end() }) }) From 2bc3cc4c99efe51f2667a419c34ff5f0c8408551 Mon Sep 17 00:00:00 2001 From: Pete Gonzalez Date: Sat, 1 Dec 2018 08:19:35 -0800 Subject: [PATCH 478/490] Workaround for GitHub issue #2807 (#2808) --- request.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/request.js b/request.js index 90bed4f4a..d4b13cc93 100644 --- a/request.js +++ b/request.js @@ -878,6 +878,16 @@ Request.prototype.onRequestError = function (error) { clearTimeout(self.timeoutTimer) self.timeoutTimer = null } + + // This is a workaround for a race condition caused by the way that lib/redirect.js + // calls Request.init() when processing an HTTP redirect: + // https://github.com/request/request/issues/2807 + // Somehow we end up with an ECONNRESET error from a socket that has already + // been destroyed and returned to the pool. + if (self.req && self.req.socket && self.req.socket.destroyed) { + return + } + self.emit('error', error) } From b3926a3a57a61c117295731e4be64005cb88259e Mon Sep 17 00:00:00 2001 From: Francis Gulotta Date: Sat, 1 Dec 2018 11:53:58 -0500 Subject: [PATCH 479/490] Revert "Workaround for GitHub issue #2807 (#2808)" (#3075) This reverts commit 2bc3cc4c99efe51f2667a419c34ff5f0c8408551. --- request.js | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/request.js b/request.js index d4b13cc93..90bed4f4a 100644 --- a/request.js +++ b/request.js @@ -878,16 +878,6 @@ Request.prototype.onRequestError = function (error) { clearTimeout(self.timeoutTimer) self.timeoutTimer = null } - - // This is a workaround for a race condition caused by the way that lib/redirect.js - // calls Request.init() when processing an HTTP redirect: - // https://github.com/request/request/issues/2807 - // Somehow we end up with an ECONNRESET error from a socket that has already - // been destroyed and returned to the pool. - if (self.req && self.req.socket && self.req.socket.destroyed) { - return - } - self.emit('error', error) } From e81c9b1dadffe692ac6797fbf7e0bdba557ebfdc Mon Sep 17 00:00:00 2001 From: Alvin Smith Date: Thu, 13 Dec 2018 11:29:06 +1300 Subject: [PATCH 480/490] fix: expression minor bugs (#3074) --- lib/auth.js | 2 +- lib/har.js | 2 +- request.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/auth.js b/lib/auth.js index f5edf32c3..02f203869 100644 --- a/lib/auth.js +++ b/lib/auth.js @@ -62,7 +62,7 @@ Auth.prototype.digest = function (method, path, authHeader) { var challenge = {} var re = /([a-z0-9_-]+)=(?:"([^"]+)"|([a-z0-9_-]+))/gi - for (;;) { + while (true) { var match = re.exec(authHeader) if (!match) { break diff --git a/lib/har.js b/lib/har.js index 2f660309d..0dedee444 100644 --- a/lib/har.js +++ b/lib/har.js @@ -172,7 +172,7 @@ Har.prototype.options = function (options) { req.postData.params.forEach(function (param) { var attachment = {} - if (!param.fileName && !param.fileName && !param.contentType) { + if (!param.fileName && !param.contentType) { options.formData[param.name] = param.value return } diff --git a/request.js b/request.js index 90bed4f4a..0162f4455 100644 --- a/request.js +++ b/request.js @@ -1448,7 +1448,7 @@ Request.prototype.jar = function (jar) { cookies = false self._disableCookies = true } else { - var targetCookieJar = (jar && jar.getCookieString) ? jar : globalCookieJar + var targetCookieJar = jar.getCookieString ? jar : globalCookieJar var urihref = self.uri.href // fetch cookie in the Specified host if (targetCookieJar) { From be7882b0bb6cdb0971f76c2a5b11d5a8767a22e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricky=20=E6=B3=BD=E9=98=B3?= Date: Thu, 13 Dec 2018 11:13:05 +0800 Subject: [PATCH 481/490] optimize:do unnecessary processing when changing options to null (#2972) --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index f9b480a1d..d50f9917b 100755 --- a/index.js +++ b/index.js @@ -27,7 +27,7 @@ function initParams (uri, options, callback) { } var params = {} - if (typeof options === 'object') { + if (options !== null && typeof options === 'object') { extend(params, options, {uri: uri}) } else if (typeof uri === 'string') { extend(params, {uri: uri}) From 670b5630675b838917b62c3addaf8de091970dfe Mon Sep 17 00:00:00 2001 From: grabus Date: Sun, 23 Dec 2018 21:23:45 +0200 Subject: [PATCH 482/490] chore: Update to tough-cookie 2.5.0 (#3089) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d9b1047ce..57a9c5454 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "performance-now": "^2.1.0", "qs": "~6.5.2", "safe-buffer": "^5.1.2", - "tough-cookie": "~2.4.3", + "tough-cookie": "~2.5.0", "tunnel-agent": "^0.6.0", "uuid": "^3.3.2" }, From df346d8531ac4b8c360df301f228d5767d0e374e Mon Sep 17 00:00:00 2001 From: Francis Gulotta Date: Mon, 24 Dec 2018 14:26:59 -0500 Subject: [PATCH 483/490] fix: Clear timeout on `#abort()` (#3090) * Added `#clearTimeout()` method. * Call `#clearTimeout()` when aborting request. * pr review notes --- request.js | 22 ++++++++++++---------- tests/test-timeout.js | 9 +++++++++ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/request.js b/request.js index 0162f4455..198b76093 100644 --- a/request.js +++ b/request.js @@ -828,8 +828,7 @@ Request.prototype.start = function () { if (isConnecting) { var onReqSockConnect = function () { socket.removeListener('connect', onReqSockConnect) - clearTimeout(self.timeoutTimer) - self.timeoutTimer = null + self.clearTimeout() setReqTimeout() } @@ -874,10 +873,7 @@ Request.prototype.onRequestError = function (error) { self.req.end() return } - if (self.timeout && self.timeoutTimer) { - clearTimeout(self.timeoutTimer) - self.timeoutTimer = null - } + self.clearTimeout() self.emit('error', error) } @@ -964,10 +960,7 @@ Request.prototype.onRequestResponse = function (response) { if (self.setHost) { self.removeHeader('host') } - if (self.timeout && self.timeoutTimer) { - clearTimeout(self.timeoutTimer) - self.timeoutTimer = null - } + self.clearTimeout() var targetCookieJar = (self._jar && self._jar.setCookie) ? self._jar : globalCookieJar var addCookie = function (cookie) { @@ -1172,6 +1165,7 @@ Request.prototype.abort = function () { self.response.destroy() } + self.clearTimeout() self.emit('abort') } @@ -1532,6 +1526,7 @@ Request.prototype.resume = function () { } Request.prototype.destroy = function () { var self = this + this.clearTimeout() if (!self._ended) { self.end() } else if (self.response) { @@ -1539,6 +1534,13 @@ Request.prototype.destroy = function () { } } +Request.prototype.clearTimeout = function () { + if (this.timeoutTimer) { + clearTimeout(this.timeoutTimer) + this.timeoutTimer = null + } +} + Request.defaultProxyHeaderWhiteList = Tunnel.defaultProxyHeaderWhiteList.slice() diff --git a/tests/test-timeout.js b/tests/test-timeout.js index 2ab0639c4..c87775d3c 100644 --- a/tests/test-timeout.js +++ b/tests/test-timeout.js @@ -244,6 +244,15 @@ tape('request timeout with keep-alive connection', function (t) { }) }) +tape('calling abort clears the timeout', function (t) { + const req = request({ url: s.url + '/timeout', timeout: 2500 }) + setTimeout(function () { + req.abort() + t.equal(req.timeoutTimer, null) + t.end() + }, 5) +}) + tape('cleanup', function (t) { s.close(function () { t.end() From a9557c9e7de2c57d92d9bab68a416a87d255cd3d Mon Sep 17 00:00:00 2001 From: Zach Bloomquist Date: Fri, 15 Feb 2019 17:41:15 -0500 Subject: [PATCH 484/490] Update outdated link in comment (#3109) --- lib/getProxyFromURI.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/getProxyFromURI.js b/lib/getProxyFromURI.js index 4633ba5f6..0b9b18e5a 100644 --- a/lib/getProxyFromURI.js +++ b/lib/getProxyFromURI.js @@ -40,7 +40,7 @@ function uriInNoProxy (uri, noProxy) { function getProxyFromURI (uri) { // Decide the proper request proxy to use based on the request URI object and the // environmental variables (NO_PROXY, HTTP_PROXY, etc.) - // respect NO_PROXY environment variables (see: http://lynx.isc.org/current/breakout/lynx_help/keystrokes/environments.html) + // respect NO_PROXY environment variables (see: https://lynx.invisible-island.net/lynx2.8.7/breakout/lynx_help/keystrokes/environments.html) var noProxy = process.env.NO_PROXY || process.env.no_proxy || '' From 7195b5064aac02532d4546c9ebcd1ec2508e6223 Mon Sep 17 00:00:00 2001 From: Jared Suttles Date: Mon, 25 Feb 2019 21:18:29 -0500 Subject: [PATCH 485/490] docs: adjust readme timeout argument description to be clearer (#3115) --- README.md | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ce5791000..e89abc6a5 100644 --- a/README.md +++ b/README.md @@ -823,12 +823,9 @@ The first argument can be either a `url` or an `options` object. The only requir work around this, either use [`request.defaults`](#requestdefaultsoptions) with your pool options or create the pool object with the `maxSockets` property outside of the loop. -- `timeout` - integer containing number of milliseconds, controls two timeouts - - Time to wait for a 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]). - - Sets the socket to timeout after `timeout` milliseconds of inactivity on the socket. +- `timeout` - integer containing number of milliseconds, controls two timeouts. + - **Read timeout**: Time to wait for a server to send response headers (and start the response body) before aborting the request. + - **Connection timeout**: Sets the socket to timeout after `timeout` milliseconds of inactivity. Note that increasing the timeout beyond the OS-wide TCP connection timeout will not have any effect ([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 From b0e9abb2f21a47783f96a8a408acc22ec51c1824 Mon Sep 17 00:00:00 2001 From: Tadashi Shigeoka Date: Mon, 1 Apr 2019 22:46:01 +0900 Subject: [PATCH 486/490] docs: :memo: Updated the Change Log for v2.88.0 (2018/08/10) (#3008) Used the following command: ``` github-changes -o request -r request -b master --date-format '(YYYY/MM/DD)' --only-pulls --use-commit-body --auth ``` --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 751514d28..d3ffcd00d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ ## Change Log +### v2.88.0 (2018/08/10) +- [#2996](https://github.com/request/request/pull/2996) fix(uuid): import versioned uuid (@kwonoj) +- [#2994](https://github.com/request/request/pull/2994) Update to oauth-sign 0.9.0 (@dlecocq) +- [#2993](https://github.com/request/request/pull/2993) Fix header tests (@simov) +- [#2904](https://github.com/request/request/pull/2904) #515, #2894 Strip port suffix from Host header if the protocol is known. (#2904) (@paambaati) +- [#2791](https://github.com/request/request/pull/2791) Improve AWS SigV4 support. (#2791) (@vikhyat) +- [#2977](https://github.com/request/request/pull/2977) Update test certificates (@simov) + ### v2.87.0 (2018/05/21) - [#2943](https://github.com/request/request/pull/2943) Replace hawk dependency with a local implemenation (#2943) (@hueniverse) From b3a218dc7b5689ce25be171e047f0d4f0eef8919 Mon Sep 17 00:00:00 2001 From: odykyi <24225497+odykyi@users.noreply.github.com> Date: Thu, 4 Apr 2019 03:30:35 +0300 Subject: [PATCH 487/490] Update README.md (#3023) --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e89abc6a5..b71ea6428 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Request is designed to be the simplest way possible to make http calls. It suppo ```js const request = require('request'); request('http://www.google.com', function (error, response, body) { - console.log('error:', error); // Print the error if one occurred + console.error('error:', error); // Print the error if one occurred console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received console.log('body:', body); // Print the HTML for the Google homepage. }); @@ -86,7 +86,7 @@ To easily handle errors when streaming requests, listen to the `error` event bef request .get('http://mysite.com/doodle.png') .on('error', function(err) { - console.log(err) + console.error(err) }) .pipe(fs.createWriteStream('doodle.png')) ``` From 212570b6971a732b8dd9f3c73354bcdda158a737 Mon Sep 17 00:00:00 2001 From: Andres Rojas Date: Wed, 29 May 2019 21:53:20 +0200 Subject: [PATCH 488/490] Use nyc instead of istanbul (#3169) * Use nyc instead of istanbul istanbul package is not longer maintained * Have nyc output an lcov coverage report --- .gitignore | 1 + package.json | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 9a254ab59..214a2ec7c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ coverage .idea npm-debug.log package-lock.json +.nyc_output \ No newline at end of file diff --git a/package.json b/package.json index 57a9c5454..86e4266bf 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ "scripts": { "test": "npm run lint && npm run test-ci && npm run test-browser", "test-ci": "taper tests/test-*.js", - "test-cov": "istanbul cover tape tests/test-*.js", + "test-cov": "nyc --reporter=lcov tape tests/test-*.js", "test-browser": "node tests/browser/start.js", "lint": "standard" }, @@ -63,13 +63,13 @@ "codecov": "^3.0.4", "coveralls": "^3.0.2", "function-bind": "^1.0.2", - "istanbul": "^0.4.0", "karma": "^3.0.0", "karma-browserify": "^5.0.1", "karma-cli": "^1.0.0", "karma-coverage": "^1.0.0", "karma-phantomjs-launcher": "^1.0.0", "karma-tap": "^3.0.1", + "nyc": "^14.1.1", "phantomjs-prebuilt": "^2.1.3", "rimraf": "^2.2.8", "server-destroy": "^1.0.1", From aded7e4f8e57f6f33cf39d65634bfb822bfcb2c8 Mon Sep 17 00:00:00 2001 From: Mikeal Rogers Date: Tue, 11 Feb 2020 08:33:22 -0800 Subject: [PATCH 489/490] doc: note full deprecation (#3267) --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index b71ea6428..9da0eb7d8 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,9 @@ +# Deprecated! + +As of Feb 11th 2020, request is fully deprecated. No new changes are expected land. In fact, none have landed for some time. + +For more information about why request is deprecated and possible alternatives refer to +[this issue](https://github.com/request/request/issues/3142). # Request - Simplified HTTP client From 3c0cddc7c8eb60b470e9519da85896ed7ee0081e Mon Sep 17 00:00:00 2001 From: Gregor Martynus Date: Tue, 11 Feb 2020 15:39:46 -0800 Subject: [PATCH 490/490] README: typo in deprecation message (#3268) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9da0eb7d8..42290d5ce 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Deprecated! -As of Feb 11th 2020, request is fully deprecated. No new changes are expected land. In fact, none have landed for some time. +As of Feb 11th 2020, request is fully deprecated. No new changes are expected to land. In fact, none have landed for some time. For more information about why request is deprecated and possible alternatives refer to [this issue](https://github.com/request/request/issues/3142).