Created
February 21, 2010 17:46
-
-
Save teramako/310430 to your computer and use it in GitHub Desktop.
get Redirected URL - Vimperator Plugin
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
/* | |
* get Redirected URL - Vimperator Plugin | |
* Command: | |
* :testurl {URL} | |
*/ | |
function getRedirectedURL(url){ | |
if (typeof url != "string") | |
throw new TypeError("url must be string"); | |
let uri = util.newURI(url); | |
if (!uri.schemeIs("http") && !uri.schemeIs("https")) | |
return uri.spec; | |
let channel = services.get("io") | |
.newChannelFromURI(uri) | |
.QueryInterface(Ci.nsIHttpChannel); | |
let stream = channel.open(); | |
stream.close(); | |
let res = [url, channel.responseStatus, channel.responseStatusText]; | |
switch(channel.responseStatus){ | |
case 301: | |
case 302: | |
case 307: | |
res.push(channel.getResponseHeader("Location")); | |
} | |
return res.join(" "); | |
} | |
commands.addUserCommand(["testurl"], "get redirected url", | |
function(args){ | |
liberator.echo(getRedirectedURL(args[0]), true); | |
}, { | |
argCount: 1, | |
}, true); | |
// vim: sw=2 ts=2 et: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment