Last active
April 17, 2018 17:17
-
-
Save kira1928/bee5955220e76869d46a647a62cb014e to your computer and use it in GitHub Desktop.
simple nodejs http proxy
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
var http = require("http"); | |
var url = require("url"); | |
var proxy = http.createServer(function(request, response) { | |
request.headers.connection = "close"; | |
delete request.headers["proxy-connection"]; | |
delete request.headers["upgrade-insecure-requests"]; | |
delete request.headers['accept-encoding']; | |
var ori_url = url.parse(request.url); | |
var options = { | |
method: request.method, | |
path: ori_url.path, | |
hostname: ori_url.hostname, | |
port: ori_url.port || 80, | |
headers: request.headers | |
}; | |
var req = http.request(options, function(res) { | |
console.log(request.url); | |
res.pipe(response); | |
}); | |
switch (request.method) { | |
case "POST": | |
request.on('data', function (data) { | |
req.write(data); | |
}); | |
req.on('end', function () { | |
req.end(); | |
}); | |
break; | |
case "GET": | |
default: | |
req.end(); | |
break; | |
} | |
}).listen(9000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment