Browse Source

Add `url` to response (#236)

* Add `url` to response

Fixes #235.
node-7
Kevin Mårtensson 8 years ago
committed by Vsevolod Strukchinsky
parent
commit
7e8af3362b
  1. 5
      index.js
  2. 2
      readme.md
  3. 4
      test/http.js

5
index.js

@ -33,10 +33,7 @@ function requestAsEventEmitter(opts) {
const req = fn.request(opts, res => {
const 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

@ -56,7 +56,7 @@ It's a `GET` request by default, but can be changed in `options`.
#### got(url, [options])
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.
##### url

4
test/http.js

@ -83,6 +83,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