mikeal/request — pull request #496 by Cauldrath (2013-03-29 15:24:03+00:00)
Title: Added transformRedirects option

This option allows you to alter redirects before they are executed. This would mostly be used when you don't know the final url you are trying to hit, but want to append query parameters onto it. Using this function has the advantage over catching each individual request and appending the query yourself in both ease of use and taking advantage of any optimizations/error handling request already has in place for redirects.

Example usage:
```javascript
var search="?query=somedata";
request({
url: "http://www.test.com"+search,
followRedirect: true,
transformRedirects: function(url) {
return url+search;
}
},function(error,response,body) {
res.send(body);
});
```

For comparison, this is the current alternative I am using:
```javascript
function requestTransform(options,transform,callback) {
request(options,function(error,response,body) {
var redirect=response.headers.location;
if(redirect!==undefined) {
options.url=transform(redirect);
requestTransform(options,transform,callback);
}
else {
callback(error,response,body);
}
})
}
```