Browse Source

Emit response event only on final request

Closes #75
http2
Vsevolod Strukchinsky 10 years ago
committed by Sindre Sorhus
parent
commit
79f1390727
  1. 8
      index.js
  2. 2
      readme.md

8
index.js

@ -138,10 +138,6 @@ function got(url, opts, cb) {
var statusCode = response.statusCode;
var res = response;
if (proxy) {
proxy.emit('response', res);
}
// auto-redirect only for GET and HEAD methods
if (isRedirect(statusCode) && 'location' in res.headers && (opts.method === 'GET' || opts.method === 'HEAD')) {
// discard response
@ -163,6 +159,10 @@ function got(url, opts, cb) {
return;
}
if (proxy) {
proxy.emit('response', res);
}
if (['gzip', 'deflate'].indexOf(res.headers['content-encoding']) !== -1) {
res = res.pipe(zlib.createUnzip());
}

2
readme.md

@ -128,7 +128,7 @@ When in stream mode, you can listen for events:
##### .on('response', response)
`response` event to get the response object.
`response` event to get the response object of the final request.
##### .on('redirect', response, nextOptions)

Loading…
Cancel
Save