Browse Source

Merge pull request #2 from floatdrop/head-method

Passing response object to callback
http2
Sindre Sorhus 11 years ago
parent
commit
f472e70b26
  1. 4
      index.js
  2. 2
      readme.md
  3. 8
      test.js

4
index.js

@ -38,7 +38,7 @@ module.exports = function (url, opts, cb) {
return; return;
} }
get(urlLib.resolve(url, res.headers.location), cb); get(urlLib.resolve(url, res.headers.location), opts, cb);
return; return;
} }
@ -63,7 +63,7 @@ module.exports = function (url, opts, cb) {
res.once('error', cb); res.once('error', cb);
res.once('end', function () { res.once('end', function () {
cb(null, ret); cb(null, ret, res);
}); });
}).once('error', cb); }).once('error', cb);
}; };

2
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. 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 ## License

8
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) { it('should support gzip', function (done) {
got('http://sindresorhus.com', function (err, data) { got('http://sindresorhus.com', function (err, data) {
assert(!err, err); assert(!err, err);

Loading…
Cancel
Save