Skip to content
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

Merged
merged 5 commits into from
Jun 25, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ function asPromise(opts) {
const limitStatusCode = opts.followRedirect ? 299 : 399;

res.body = data;
res.requestUrl = opts.href;

if (opts.json && res.body) {
try {
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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, that resolves to `response` object with `body` property, a `url` property that contains the final URL after redirects and a `requestUrl` that contains the URL requested originally
Copy link
Owner

@sindresorhus sindresorhus Jun 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use this instead:

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

Expand Down Expand Up @@ -127,7 +127,7 @@ Option accepts `function` with `retry` and `error` arguments. Function must retu

###### followRedirect

Type: `boolean`
Type: `boolean`
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't change this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a trailing space

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luanmuniz this will remove line breake before Default. You can see it in md preview.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just added a <br> like in the other lines

Default: `true`

Defines if redirect responses should be followed automatically.
Expand Down
4 changes: 4 additions & 0 deletions test/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ 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}/`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test with object {host: s.host, port: s.port} as argument?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luanmuniz yup.

});

test('error with code', async t => {
try {
await got(`${s.url}/404`);
Expand Down
5 changes: 5 additions & 0 deletions test/redirects.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ test('redirect response contains new url', async t => {
t.is(url, `${http.url}/`);
});

test('redirect response contains old url', async t => {
const requestUrl = (await got(`${http.url}/finite`)).requestUrl;
t.is(requestUrl, `${http.url}/finite`);
});

test.after('cleanup', async () => {
await http.close();
await https.close();
Expand Down