Skip to content

Commit

Permalink
fix url and responseUrl properties on gzip'ed response
Browse files Browse the repository at this point in the history
Closes #240
  • Loading branch information
floatdrop committed Nov 2, 2016
1 parent 4f4ebd7 commit 984cd79
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ function requestAsEventEmitter(opts) {
const req = fn.request(opts, res => {
const statusCode = res.statusCode;

res.url = redirectUrl || requestUrl;
res.requestUrl = requestUrl;

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

Expand All @@ -55,7 +52,11 @@ function requestAsEventEmitter(opts) {
}

setImmediate(() => {
ee.emit('response', typeof unzipResponse === 'function' && req.method !== 'HEAD' ? unzipResponse(res) : res);
const response = typeof unzipResponse === 'function' && req.method !== 'HEAD' ? unzipResponse(res) : res;

This comment has been minimized.

Copy link
@sindresorhus

sindresorhus Nov 2, 2016

Owner

Maybe we should just copy over all custom properties too in unzip-response?

This comment has been minimized.

Copy link
@sindresorhus

sindresorhus Nov 2, 2016

Owner

Lol. Never mind. Just noticed sindresorhus/decompress-response#6

response.url = redirectUrl || requestUrl;
response.requestUrl = requestUrl;

ee.emit('response', response);
});
});

Expand Down
6 changes: 6 additions & 0 deletions test/gzip.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ test('ignore missing data', async t => {
t.is((await got(`${s.url}/missing-data`)).body, testContent);
});

test('has url and requestUrl properties', async t => {
const res = await got(s.url);
t.truthy(res.url);
t.truthy(res.requestUrl);
});

test.after('cleanup', async () => {
await s.close();
});

0 comments on commit 984cd79

Please sign in to comment.