Browse Source

fix url and responseUrl properties on gzip'ed response

Closes #240
allow-304
Vsevolod Strukchinsky 8 years ago
parent
commit
984cd7943c
  1. 9
      index.js
  2. 6
      test/gzip.js

9
index.js

@ -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();
@ -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;
response.url = redirectUrl || requestUrl;
response.requestUrl = requestUrl;
ee.emit('response', response);
});
});

6
test/gzip.js

@ -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();
});

Loading…
Cancel
Save