How to get initial uri of a redirected http request using mikeal/request

Problem

Using node.js mikeal/request i do a bunch of simultaneous requests. The requests allow redirects.

Some requests get redirected to other domains. i need the initial request uri inside the response callback, but there there is no hint to it inside the response object. hence i am looking for a way to inject the original uri to the response callback.

Any suggestions how to inject the original request uri to the callback?

var requestData = { uri: 'http://www.example.org' }; // redirects to example.com
request(requestData, function (error, response, body) { 
    console.log(<print inital url>)     
});
var requestData = { uri: 'http://www.example.com' }; // redirects to example.com
request(requestData, function (error, response, body) { 
    console.log(<print inital url>) 
});
Problem courtesy of: Martin Abraham

Solution

How about this:

request(requestData, function (error, response, body) { 
    console.log(this.uri);
}.bind({ uri: requestData.uri }));

Alternatively, you can use a closure to store the uri:

(function(uri){
    request(requestData, function (error, response, body) { 
        console.log(uri);
    });
})(requestData.uri);
Solution courtesy of: levi

Discussion

There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.