Skip to content

Commit

Permalink
Emit response event only on final request
Browse files Browse the repository at this point in the history
Closes #75
  • Loading branch information
floatdrop authored and sindresorhus committed Jun 30, 2015
1 parent 2a155a8 commit 79f1390
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
}
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 79f1390

Please sign in to comment.