Skip to content

Instantly share code, notes, and snippets.

Created September 2, 2010 18:06
Show Gist options
  • Save anonymous/562641 to your computer and use it in GitHub Desktop.
Save anonymous/562641 to your computer and use it in GitHub Desktop.
var sys = require("sys"),
http = require("http"),
url = require("url"),
path = require("path"),
fs = require("fs");
function getHostname(str) {
var re = new RegExp('^(?:f|ht)tp(?:s)?\://([^/]+)', 'im');
return str.match(re)[1].toString();
}
var urlUnwrapper = function() {
this.server = http.createServer(function(request, response) {
var uri = url.parse(request.url);
var host = getHostname(uri.query);
var visitURL = url.parse(uri.query);
var client = http.createClient(80, host);
var request = client.request('GET', visitURL.pathname,
{'host': host});
request.end();
request.on('response', function (response) {
console.log(response.headers.location);
// I want to print this location to the browser!
});
response.sendHeader(200);
response.write('well fuck');
response.close();
}).listen(8080);
}();
sys.puts("Server running at http://localhost:8080/");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment