Browse Source

Add `url` to response (#236)

* Add `url` to response

Fixes #235.
v5.x
Kevin Mårtensson 8 years ago
committed by Vsevolod Strukchinsky
parent
commit
40b26a96fa
  1. 5
      index.js
  2. 2
      readme.md
  3. 4
      test/http.js

5
index.js

@ -37,10 +37,7 @@ function requestAsEventEmitter(opts) {
var req = fn.request(opts, function (res) {
var statusCode = res.statusCode;
if (redirectUrl) {
res.url = redirectUrl;
}
res.url = redirectUrl || requestUrl;
res.requestUrl = requestUrl;
if (isRedirect(statusCode) && opts.followRedirect && 'location' in res.headers && (opts.method === 'GET' || opts.method === 'HEAD')) {

2
readme.md

@ -60,7 +60,7 @@ It's a `GET` request by default, but can be changed in `options`.
#### got(url, [options], [callback])
Returns a Promise for a `response` object with a `body` property, a `url` property with the final URL after redirects, and a `requestUrl` property with the original request URL.
Returns a Promise for a `response` object with a `body` property, a `url` property with the request URL or the final URL after redirects, and a `requestUrl` property with the original request URL.
Otherwise calls callback with `response` object (same as in previous case).

4
test/http.js

@ -80,6 +80,10 @@ test('requestUrl response when sending url as param', async t => {
t.is((await got({hostname: s.host, port: s.port})).requestUrl, `${s.url}/`);
});
test('response contains url', async t => {
t.is((await got(s.url)).url, `${s.url}/`);
});
test.after('cleanup', async () => {
await s.close();
});

Loading…
Cancel
Save