-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
38 lines (31 loc) · 1.17 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var http = require('http'),
httpProxy = require('http-proxy'),
url = require("url"),
proxy = new httpProxy.RoutingProxy();
http.createServer(function (req, res) {
var headers = req.headers,
host = headers.host,
port = 80;
if (host.indexOf(":") > 0) {
var parts = host.split(":");
host = parts[0];
port = parts[1] || port;
}
// Build the request info text
var urlParts = url.parse(req.url),
infoText = req.method + " " + urlParts.pathname + " HTTP/" + req.httpVersion + "\n";
infoText += "Host: " + host + "\n";
infoText += "User-Agent: " + headers["user-agent"] + "\n";
infoText += "Accept: " + headers.accept + "\n";
infoText += "Accept-Language: " + headers["accept-language"] + "\n";
infoText += "Accept-Encoding: " + headers["accept-encoding"] + "\n";
infoText += "Accept-Charset: " + headers["accept-charset"] + "\n";
infoText += "Proxy-Connection: " + headers["proxy-connection"] + "\n";
infoText += "Referer: " + (headers.referer || "") + "\n";
infoText += "Cookie: " + headers.cookie + "\n";
console.log(infoText);
proxy.proxyRequest(req, res, {
host: host,
port: port
});
}).listen(8001);