Skip to content

Commit 40b26a9

Browse files
kevvafloatdrop
authored andcommitted
Add url to response (#236)
* Add `url` to response Fixes #235.
1 parent 5c71272 commit 40b26a9

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

index.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ function requestAsEventEmitter(opts) {
3737
var req = fn.request(opts, function (res) {
3838
var statusCode = res.statusCode;
3939

40-
if (redirectUrl) {
41-
res.url = redirectUrl;
42-
}
43-
40+
res.url = redirectUrl || requestUrl;
4441
res.requestUrl = requestUrl;
4542

4643
if (isRedirect(statusCode) && opts.followRedirect && 'location' in res.headers && (opts.method === 'GET' || opts.method === 'HEAD')) {

readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ It's a `GET` request by default, but can be changed in `options`.
6060

6161
#### got(url, [options], [callback])
6262

63-
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.
63+
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.
6464

6565
Otherwise calls callback with `response` object (same as in previous case).
6666

test/http.js

+4
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ test('requestUrl response when sending url as param', async t => {
8080
t.is((await got({hostname: s.host, port: s.port})).requestUrl, `${s.url}/`);
8181
});
8282

83+
test('response contains url', async t => {
84+
t.is((await got(s.url)).url, `${s.url}/`);
85+
});
86+
8387
test.after('cleanup', async () => {
8488
await s.close();
8589
});

0 commit comments

Comments
 (0)