Skip to content

Instantly share code, notes, and snippets.

@MarkBlah
Created May 27, 2018 05:28
Show Gist options
  • Save MarkBlah/0567ace944f999e6672ed9a1d9d255e7 to your computer and use it in GitHub Desktop.
Save MarkBlah/0567ace944f999e6672ed9a1d9d255e7 to your computer and use it in GitHub Desktop.
fix for slither on macOS
var http = require('http'),
httpProxy = require('http-proxy');
var crypto = require('crypto');
var proxy = httpProxy.createServer({
//target: 'ws://139.99.130.166:444',
target: 'ws://139.99.130.217:444',
preserveHeaderKeyCase: false,
ws: true
}).listen(4444);
proxy.on('proxyReqWs', function (proxyReq, req, res) {
console.log ('hello ReqWs');
console.log('RAW Req from the target', JSON.stringify(req.headers));
var sha1 = crypto.createHash('sha1');
var key = req.headers['sec-websocket-key'];
sha1.update(key + '258EAFA5-E914-47DA-95CA-C5AB0DC85B11');
var acceptKey = sha1.digest('base64');
console.log("expected response: ", acceptKey);
proxyReq.on('upgrade', function(proxyRes, proxySocket, proxyHead) {
console.log ("we are in upgrade", JSON.stringify (proxyRes.headers));
proxyRes.headers['sec-websocket-accept'] = acceptKey;
});
});
proxy.on('close', function (res, socket, head) {
// view disconnected websocket connections
console.log ('Disconnect: ', JSON.stringify(head));
console.log('Client disconnected');
});
console.log("ok, now point slither to: localhost:4444");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment