-
-
Notifications
You must be signed in to change notification settings - Fork 150
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
Add a variable that tells you if it redirected or not #6
Comments
In regards to the same issue, is it possible to pass the last redirected URL to the response argument in the callback? http.request(url1, function(response) {
console.log(response.currentURL); //or similar. Maybe I just overlooked something?
}); |
I've figured it out. function redirectCallback (reqUrl, redirect) {
return function (res) {
//these two following lines:
res.currentURL = reqUrl; //will have the last redirected url
res.redirectCount = redirect.count -1; //will include the number of redirects Therefore the in the request response callback you can fetch them as in the previous comment: http.request(url1, function(response) {
console.log(response.currentURL);
console.log(response.redirectCount);
}); Btw, awesome module! |
+1 for this. |
Actually not changing the status code would be good enough, I think. We know the initial url because we make the request, so I don't need other people to tell me my initial request url. If the status code can still be 30x, not changing it to 200, that would be good enough. |
I found a workaround: var redirectedUrl = res.headers['content-location'];
console.log(redirectedUrl, originalUrl);
if (redirectedUrl && redirectedUrl !== originalUrl) {
// redirected;
} else {
// not redirected;
} |
This refactors the code significantly an closes a number of outstanding issues. Closes follow-redirects#15 - remove underscore as dependency. Closes follow-redirects#8 - some options not copied between requests. Closes follow-redirects#6 - add variable that tells you if it redirected.
Would be useful to have a way to know if the url you passed redirected to another or not.
The text was updated successfully, but these errors were encountered: