Skip to content

Instantly share code, notes, and snippets.

@chenminhua
Created July 20, 2017 03:47
Show Gist options
  • Save chenminhua/3bba7765c0eb474fb81dcf403ed138d1 to your computer and use it in GitHub Desktop.
Save chenminhua/3bba7765c0eb474fb81dcf403ed138d1 to your computer and use it in GitHub Desktop.
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');
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