Last active
April 2, 2018 15:36
-
-
Save scripting/c12569ed806744f0c6f531cbd4c02f21 to your computer and use it in GitHub Desktop.
A simple Node function to dereference a URL, to find out what it points to through redirects.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const request = require ("request"); | |
function derefUrl (url, callback) { | |
var theRequest = { | |
method: "HEAD", | |
url: url, | |
followAllRedirects: true | |
}; | |
request (theRequest, function (err, response) { | |
if (err) { | |
callback (err); | |
} | |
else { | |
callback (undefined, response.request.href); | |
} | |
}); | |
} | |
derefUrl ("http://www.scripting.com/rss.xml", function (err, urlDeref) { | |
console.log (urlDeref); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very cool!
I wrote something similar in PHP a while ago. (99% just cURL) https://tim.hithlonde.com/2016/get-final-url-after-redirects/
Now I kind of want a library of just this kind of function in all the various languages out there. :)