-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathproxy-pump.js
35 lines (31 loc) · 992 Bytes
/
proxy-pump.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
var util = require("util"),
http = require("http"),
url = require("url"),
util = require("util"),
path = require("path"),
fs = require("fs");
var port = parseInt(process.argv[2]) || 8081;
var options = function(request) {
var uri = url.parse(request.url);
var opt = {
host: uri.hostname,
port: uri.port || 80,
path: uri.pathname,
method: request.method,
headers: request.headers
};
opt.headers['connection'] = 'keep-alive';
return opt;
}
http.createServer(function(request, response) {
util.log("--> " + request.url);
var remoteRequest = http.request(options(request), function (remoteResponse) {
response.writeHead(remoteResponse.statusCode, remoteResponse.headers);
remoteResponse.on('end', function () {
util.log("<-- " + response.statusCode + " " + request.url);
});
util.pump(remoteResponse, response);
});
util.pump(request, remoteRequest);
}).listen(port);
util.log('Listening on port ' + port);