mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-05-11 15:58:27 +00:00
28 lines
681 B
JavaScript
28 lines
681 B
JavaScript
|
var http = require("http"),
|
||
|
https = require("https");
|
||
|
|
||
|
function handler(req,userRes){
|
||
|
|
||
|
var ifHttps = !!req.connection.encrypted;
|
||
|
|
||
|
var options = {
|
||
|
hostname : req.headers.host,
|
||
|
port : req.port || (ifHttps ? 443 : 80),
|
||
|
path : req.url,
|
||
|
method : req.method,
|
||
|
headers : req.headers
|
||
|
};
|
||
|
|
||
|
var proxyReq = (ifHttps ? https : http).request(options, function(res) {
|
||
|
userRes.writeHead(res.statusCode,res.headers);
|
||
|
res.pipe(userRes);
|
||
|
});
|
||
|
|
||
|
proxyReq.on("error",function(e){
|
||
|
console.log("err with request :" + req.url);
|
||
|
userRes.end();
|
||
|
});
|
||
|
proxyReq.end();
|
||
|
}
|
||
|
|
||
|
module.exports = handler;
|