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

event for 'final' redirect #75

Closed
max-mapper opened this issue Jun 23, 2015 · 3 comments
Closed

event for 'final' redirect #75

max-mapper opened this issue Jun 23, 2015 · 3 comments
Milestone

Comments

@max-mapper
Copy link

im porting some request code over that looks like this

req.on('response', handle)

in request, handle gets called when the 'final' redirect gets called, so e.g. if the first response was actually a 302, and the 2nd one is the a 200, only the 200 response will be emitted as the response event.

in got, response is emitted each time their is a response, because if this line is truthy multiple times, the recursive call in there causes it to emit many times

the problem I have is that I only care about the last response, but there doesn't seem to be an event for that, but maybe i'm missing something!

@max-mapper
Copy link
Author

BTW my workaround is currently

var isRedirect = require('is-redirect')
request.on('response', function(res) {
  if (isRedirect(res.statusCode)) return // hack for https://github.com/sindresorhus/got/issues/75
  // handle final response here
}

@floatdrop
Copy link
Contributor

Since got already have redirect event - may be it make sense to emit response on 'non-redirect' responses.

@max-mapper
Copy link
Author

@floatdrop +1 to that idea!

@floatdrop floatdrop modified the milestone: 4.0.0 Jun 24, 2015
floatdrop added a commit that referenced this issue Jun 30, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants