From a8995f7da0111bbbefa17414afcf2c4267dc5c3d Mon Sep 17 00:00:00 2001 From: Vsevolod Strukchinsky Date: Tue, 5 Aug 2014 15:05:10 +0600 Subject: [PATCH] Passing response object to callback --- index.js | 4 ++-- readme.md | 2 +- test.js | 8 ++++++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index a5ed370..c45fa96 100644 --- a/index.js +++ b/index.js @@ -38,7 +38,7 @@ module.exports = function (url, opts, cb) { return; } - get(urlLib.resolve(url, res.headers.location), cb); + get(urlLib.resolve(url, res.headers.location), opts, cb); return; } @@ -63,7 +63,7 @@ module.exports = function (url, opts, cb) { res.once('error', cb); res.once('end', function () { - cb(null, ret); + cb(null, ret, res); }); }).once('error', cb); }; diff --git a/readme.md b/readme.md index b50df07..5617f0c 100644 --- a/readme.md +++ b/readme.md @@ -47,7 +47,7 @@ Type: `object` Any of the [`http.request`](http://nodejs.org/api/http.html#http_http_request_options_callback) options. -##### callback(err, data) +##### callback(err, data, res) ## License diff --git a/test.js b/test.js index 0dda9bd..d4a89d8 100644 --- a/test.js +++ b/test.js @@ -43,6 +43,14 @@ it('should support optional options', function (done) { }); }); +it('should get headers only with HEAD method', function (done) { + got('http://google.com', {method: 'HEAD'}, function (err, data, res) { + assert(!data, data); + assert.ok(res.headers); + done(); + }); +}); + it('should support gzip', function (done) { got('http://sindresorhus.com', function (err, data) { assert(!err, err);