Permalink
Browse files

Support local HTTP Proxy.

* Update local.js

* Update local.js

* Update package.json

* Update local.coffee

* Update local.js
  • Loading branch information...
bigbagboom authored and mrluanma committed Aug 24, 2016
1 parent b8b5beb commit ba248ff89484eae6c04daeb38d3d021413b9958d
Showing with 62 additions and 7 deletions.
  1. +27 −5 local.js
  2. +2 −1 package.json
  3. +33 −1 src/local.coffee
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -3,7 +3,8 @@
"version": "0.9.10",
"dependencies": {
"minimist": "^1.2.0",
"ws": "^0.8.0"
"https-proxy-agent": "^1.0.0",
"ws": "^1.0.1"
},
"engines": {
"node": "4.x"
View
@@ -5,6 +5,7 @@ fs = require("fs")
path = require("path")
WebSocket = require('ws')
parseArgs = require("minimist")
HttpsProxyAgent = require('https-proxy-agent')
Encryptor = require("./encrypt").Encryptor
options =
@@ -41,6 +42,12 @@ timeout = Math.floor(config.timeout * 1000)
if METHOD.toLowerCase() in ["", "null", "table"]
METHOD = null
HTTPPROXY = process.env.http_proxy
if HTTPPROXY
console.log "http proxy:", HTTPPROXY
prepareServer = (address) ->
serverUrl = url.parse address
@@ -133,7 +140,32 @@ server = net.createServer (connection) ->
buf.writeInt16BE remotePort, 8
connection.write buf
# connect to remote server
ws = new WebSocket aServer, protocol: "binary"
# ws = new WebSocket aServer, protocol: "binary"
if HTTPPROXY
# WebSocket endpoint for the proxy to connect to
endpoint = aServer
parsed = url.parse(endpoint)
#console.log('attempting to connect to WebSocket %j', endpoint);
# create an instance of the `HttpsProxyAgent` class with the proxy server information
opts = url.parse(HTTPPROXY)
# IMPORTANT! Set the `secureEndpoint` option to `false` when connecting
# over "ws://", but `true` when connecting over "wss://"
opts.secureEndpoint = parsed.protocol ? parsed.protocol == 'wss:' : false
agent = new HttpsProxyAgent(opts)
ws = new WebSocket(aServer, {
protocol: "binary",
agent: agent
});
else
ws = new WebSocket(aServer, {
protocol: "binary"
});
ws.on "open", ->
ws._socket.on "error", (e) ->
console.log "remote #{remoteAddr}:#{remotePort} #{e}"

0 comments on commit ba248ff

Please sign in to comment.