Created
March 18, 2014 14:53
-
-
Save bancek/9621681 to your computer and use it in GitHub Desktop.
HTTPS proxy
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
net = require('net') | |
tls = require('tls') | |
stream = require('stream') | |
if process.argv.length != 4 | |
console.log 'Usage: https_proxy host port' | |
process.exit(1) | |
class Printer extends stream.Transform | |
_transform: (chunk, encoding, done) => | |
process.stdout.write(chunk) | |
@push(chunk) | |
done() | |
server = net.createServer((socket) -> | |
opts = | |
host: process.argv[2] | |
port: process.argv[3] - 0 | |
rejectUnauthorized: no | |
client = tls.connect(opts, -> | |
socket.pipe(new Printer()).pipe(client) | |
client.pipe(new Printer()).pipe(socket) | |
) | |
client.on 'end', -> socket.end() | |
client.on 'error', -> socket.end() | |
socket.on 'end', -> client.end() | |
socket.on 'error', -> client.end() | |
) | |
port = 1337 | |
server.listen port, '127.0.0.1' | |
console.log 'Proxy listening on 127.0.0.1:' + port |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment