mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-08-04 21:39:04 +00:00
update
This commit is contained in:
28
lib/requestHandler.js
Normal file
28
lib/requestHandler.js
Normal file
@@ -0,0 +1,28 @@
|
||||
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;
|
||||
Reference in New Issue
Block a user