-
-
Notifications
You must be signed in to change notification settings - Fork 935
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a requestUrl
property to the response object
#205
Changes from 4 commits
fdfd200
0c2e7a0
e453885
cf56b75
2a609d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,7 +56,7 @@ It's a `GET` request by default, but can be changed in `options`. | |
|
||
#### got(url, [options]) | ||
|
||
Returns a Promise, that resolves to `response` object with `body` property and a `url` property (which contains the final URL after redirects). | ||
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. | ||
|
||
##### url | ||
|
||
|
@@ -127,7 +127,7 @@ Option accepts `function` with `retry` and `error` arguments. Function must retu | |
|
||
###### followRedirect | ||
|
||
Type: `boolean` | ||
Type: `boolean` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't change this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just a trailing space There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @luanmuniz this will remove line breake before There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just added a |
||
Default: `true` | ||
|
||
Defines if redirect responses should be followed automatically. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,11 @@ test('empty response', async t => { | |
t.is((await got(`${s.url}/empty`)).body, ''); | ||
}); | ||
|
||
test('requestUrl response', async t => { | ||
t.is((await got(s.url)).requestUrl, `${s.url}/`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a test with object There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think its done. Can you check if what i did is what you ask for? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @luanmuniz yup. |
||
t.is((await got(`${s.url}/empty`)).requestUrl, `${s.url}/empty`); | ||
}); | ||
|
||
test('error with code', async t => { | ||
try { | ||
await got(`${s.url}/404`); | ||
|
@@ -73,6 +78,11 @@ test('query option', async t => { | |
t.is((await got(s.url, {query: 'recent=true'})).body, 'recent'); | ||
}); | ||
|
||
test('requestUrl response when sending url as param', async t => { | ||
t.is((await got(s.url, {hostname: s.host, port: s.port})).requestUrl, `${s.url}/`); | ||
t.is((await got({hostname: s.host, port: s.port})).requestUrl, `${s.url}/`); | ||
}); | ||
|
||
test.after('cleanup', async () => { | ||
await s.close(); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't
res.requestUrl = urlLib.format(opts);
suffice?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, when sending an object we don't have
opts.href
andurlLib.format(opts)
don't return theopts.path
in it. I just put theopts.href
because if it exist we don't need to send to the functions. But it is removable.