Added redirect event #497

Merged
merged 1 commit into from Apr 24, 2013

Projects

None yet

2 participants

@Cauldrath
Contributor

Similar to this pull request: #496

This instead emits an event which includes a function that allows altering the redirect.

Example usage:

var search="?query=somedata";
request({
  url: "http://www.test.com"+search,
  followRedirect: true,
},function(error,response,body) {
  res.send(body);
}).on('redirect',function(redirect,updateRedirect) {
    updateRedirect(url+search);
});
@mikeal
Member
mikeal commented Mar 29, 2013

why do you need (redirect, updateRedirect), why can't you just mutate the url of the request object? if we encourage that path then it's obvious how people could also manipulate headers and other options on redirect.

@Cauldrath
Contributor

True, I moved the event to right before it calls init so everything is set up for the next request at that point and removed the additional data.

@mikeal mikeal merged commit aabf460 into request:master Apr 24, 2013
@Cauldrath Cauldrath deleted the Cauldrath:redirectEvent branch Apr 24, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment