Skip to content

Instantly share code, notes, and snippets.

@sh1mmer
Forked from anonymous/urlunwrapper
Created September 2, 2010 18:08
Show Gist options
  • Save sh1mmer/562642 to your computer and use it in GitHub Desktop.
Save sh1mmer/562642 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(req, res) {
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!
var body = response.headers.location;
res.writeHead(200, { 'Content-Length': body.length, 'Content-Type': 'text/plain' };
res.end(body);
});
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