Skip to content

Instantly share code, notes, and snippets.

@teramako
Created February 21, 2010 17:46
Show Gist options
  • Save teramako/310430 to your computer and use it in GitHub Desktop.
Save teramako/310430 to your computer and use it in GitHub Desktop.
get Redirected URL - Vimperator Plugin
/*
* 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