Created
July 20, 2017 03:47
-
-
Save chenminhua/3bba7765c0eb474fb81dcf403ed138d1 to your computer and use it in GitHub Desktop.
This file contains 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 net = require('net'); | |
var url = require('url'); | |
function request(cReq, cRes) { | |
var u = url.parse(cReq.url); | |
var options = { | |
hostname : u.hostname, | |
port : u.port || 80, | |
path : u.path, | |
method : cReq.method, | |
headers : cReq.headers | |
}; | |
console.log(options) | |
var pReq = http.request(options, function(pRes) { | |
cRes.writeHead(pRes.statusCode, pRes.headers); | |
pRes.pipe(cRes); | |
}).on('error', function(e) { | |
cRes.end(); | |
}); | |
cReq.pipe(pReq); | |
} | |
http.createServer().on('request', request).listen(8888, '0.0.0.0'); |
This file contains 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
const http = require('http'); | |
const net = require('net'); | |
const url = require('url'); | |
const connect = (cReq, cSock) => { | |
const u = url.parse('https://' + cReq.url); | |
console.log(u) | |
const pSock = net.connect(u.port, u.hostname, () => { | |
cSock.write('HTTP/1.1 200 Connection Established\r\n\r\n'); | |
pSock.pipe(cSock); | |
}).on('error', (e) => { | |
console.log(e) | |
cSock.end(); | |
}); | |
cSock.pipe(pSock); | |
} | |
http.createServer().on('connect', connect).listen(8888, '0.0.0.0'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment