Skip to content

Commit 91f32ed

Browse files
committed
Merge pull request #71 from joeferner/remove-use-named-socket
Remove useNamedSocket option
2 parents 29f7147 + ad246a6 commit 91f32ed

File tree

2 files changed

+11
-25
lines changed

2 files changed

+11
-25
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ __Arguments__
122122
* httpsAgent - The [https.Agent](https://nodejs.org/api/https.html#https_class_https_agent) to use when making https requests. Useful for chaining proxys. (default: internal Agent)
123123
* forceSNI - force use of [SNI](https://en.wikipedia.org/wiki/Server_Name_Indication) by the client. Allow node-http-mitm-proxy to handle all HTTPS requests with a single internal server.
124124
* httpsPort - The port or named socket for https server to listen on. _(forceSNI must be enabled)_
125-
* useNamedSocket - use named socket (i.e. unix socket or named pipe) instead of TCP ports for internal server(s)
126125

127126
__Example__
128127

lib/proxy.js

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ Proxy.prototype.listen = function(options, callback) {
5454
if (this.forceSNI && !this.silent) {
5555
console.log('SNI enabled. Clients not supporting SNI may fail');
5656
}
57-
this.useNamedSocket = !!options.useNamedSocket;
5857
this.httpsPort = this.forceSNI ? options.httpsPort : undefined;
5958
this.sslCaDir = options.sslCaDir || path.resolve(process.cwd(), '.http-mitm-proxy');
6059
ca.create(this.sslCaDir, function(err, ca) {
@@ -73,13 +72,13 @@ Proxy.prototype.listen = function(options, callback) {
7372
self.wsServer.on('connection', self._onWebSocketServerConnect.bind(self, false));
7473
if (self.forceSNI) {
7574
// start the single HTTPS server now
76-
self._createHttpsServer({}, function(portOrSocket, httpsServer, wssServer) {
75+
self._createHttpsServer({}, function(port, httpsServer, wssServer) {
7776
if (!self.silent) {
78-
console.log('https server started on '+portOrSocket);
77+
console.log('https server started on '+port);
7978
}
8079
self.httpsServer = httpsServer;
8180
self.wssServer = wssServer;
82-
self.httpsPort = portOrSocket;
81+
self.httpsPort = port;
8382
self.httpServer.listen(self.httpPort, callback);
8483
});
8584
} else {
@@ -99,9 +98,8 @@ Proxy.prototype._createHttpsServer = function (options, callback) {
9998
httpsServer.on('request', this._onHttpServerRequest.bind(this, true));
10099
var wssServer = new WebSocket.Server({ server: httpsServer });
101100
wssServer.on('connection', this._onWebSocketServerConnect.bind(this, true));
102-
var portOrSocket = this.httpsPort || (this.useNamedSocket ? Proxy.newNamedSocket() : undefined);
103-
httpsServer.listen(portOrSocket, function() {
104-
if (callback) callback(portOrSocket || httpsServer.address().port, httpsServer, wssServer);
101+
httpsServer.listen(this.httpsPort || undefined, function() {
102+
if (callback) callback(httpsServer.address().port, httpsServer, wssServer);
105103
});
106104
};
107105

@@ -319,9 +317,9 @@ Proxy.prototype._onHttpServerConnect = function(req, socket, head) {
319317
return makeConnection(this.httpPort);
320318
}
321319

322-
function makeConnection(portOrSocket) {
320+
function makeConnection(port) {
323321
// open a TCP connection to the remote host
324-
var conn = net.connect(portOrSocket, function() {
322+
var conn = net.connect(port, function() {
325323
// create a tunnel between the two hosts
326324
socket.pipe(conn);
327325
conn.pipe(socket);
@@ -410,19 +408,19 @@ Proxy.prototype._onHttpServerConnect = function(req, socket, head) {
410408
if (!self.silent) {
411409
console.log('starting server for ' + hostname);
412410
}
413-
self._createHttpsServer(results.httpsOptions, function(portOrSocket, httpsServer, wssServer) {
411+
self._createHttpsServer(results.httpsOptions, function(port, httpsServer, wssServer) {
414412
if (!self.silent) {
415-
console.log('https server started for %s on %s', hostname, portOrSocket);
413+
console.log('https server started for %s on %s', hostname, port);
416414
}
417415
var sslServer = {
418416
server: httpsServer,
419417
wsServer: wssServer,
420-
port: portOrSocket
418+
port: port
421419
};
422420
hosts.forEach(function(host) {
423421
self.sslServers[hostname] = sslServer;
424422
});
425-
return callback(null, portOrSocket);
423+
return callback(null, port);
426424
});
427425
}
428426
});
@@ -1023,15 +1021,4 @@ Proxy.filterAndCanonizeHeaders = function(originalHeaders) {
10231021
headers[canonizedKey] = originalHeaders[key];
10241022
}
10251023
return headers;
1026-
};
1027-
1028-
Proxy.NAMED_SOCKET_PREFIX = 'mitm-proxy-' + Math.random().toString(36).substring(2, 10);
1029-
Proxy.NAMED_SOCKET_INDEX = 0;
1030-
Proxy.newNamedSocket = function() {
1031-
var socketName = Proxy.NAMED_SOCKET_PREFIX + "-" + Proxy.NAMED_SOCKET_INDEX++;
1032-
if (/^win/.test(process.platform)) {
1033-
return '\\\\.\\pipe\\' + socketName + '-sock';
1034-
} else {
1035-
return path.join(os.tmpdir(), socketName+".sock")
1036-
}
10371024
};

0 commit comments

Comments
 (0)