2 var http = require('http');
3 var dns = require('dns');
6 'Content-Type': 'application/json',
7 'Access-Control-Allow-Origin': '*'
10 http.createServer(function(req, res) {
11 var url = require('url').parse(req.url, true);
12 if(req.method === 'GET' && url.pathname === '/uri-info') {
13 console.log('query', url.query);
14 lookup(url.query, function(result) {
15 res.writeHead(200, HEADERS);
16 res.write(JSON.stringify(result));
19 } else if(req.method === 'POST' && url.pathname === '/send') {
20 console.log('send request', url.query);
21 var request = http.request(url.query);
22 request.on('response', function(response) {
23 console.log('have response');
24 var body = '', lastLength = 0;
25 response.on('data', function(chunk) {
27 if((body.length - lastLength) > 1024) {
28 console.log((body.length / 1024).toFixed(2) + ' kB');
29 lastLength = body.length;
32 response.on('end', function() {
34 res.writeHead(200, HEADERS);
35 res.write(JSON.stringify({
36 status: response.statusCode,
38 headers: response.headers
45 res.writeHead(404, HEADERS);
46 res.write('Not Found');
50 console.log('listening on 0.0.0.0:8088');
52 function lookup(query, callback) {
54 dns.resolve(query.host, function(error, result) {
58 query.addresses = result;