Skip to content

Commit 77c8aeb

Browse files
fix close method
1 parent 2f51af1 commit 77c8aeb

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

lib/proxy.js

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,20 @@ Proxy.prototype._createHttpsServer = function (options, callback) {
100100

101101
Proxy.prototype.close = function () {
102102
var self = this;
103-
self.httpServer.close();
104-
(Object.keys(this.sslServers)).forEach(function (srvName) {
105-
self.sslServers[srvName].server.close();
106-
delete self.sslServers[srvName];
107-
});
103+
this.httpServer.close();
104+
delete this.httpServer;
105+
if (self.forceSNI) {
106+
this.httpsServer.close();
107+
delete this.httpsServer;
108+
delete this.wssServer;
109+
delete this.sslServers;
110+
} else {
111+
(Object.keys(this.sslServers)).forEach(function (srvName) {
112+
var server = self.sslServers[srvName].server;
113+
if (server) server.close();
114+
delete self.sslServers[srvName];
115+
});
116+
}
108117
return this;
109118
};
110119

@@ -281,13 +290,15 @@ Proxy.prototype._onHttpServerConnect = function(req, socket, head) {
281290
}
282291
sem.take(function() {
283292
if (self.sslServers[hostname]) {
284-
process.nextTick(sem.leave.bind(sem));
285-
return makeConnection(self.sslServers[hostname].port);
293+
process.nextTick(sem.leave.bind(sem));
294+
return makeConnection(self.sslServers[hostname].port);
286295
}
287296
if (self.sslServers[wilcardHost]) {
288-
process.nextTick(sem.leave.bind(sem));
289-
self.sslServers[hostname] = self.sslServers[wilcardHost];
290-
return makeConnection(self.sslServers[hostname].port);
297+
process.nextTick(sem.leave.bind(sem));
298+
self.sslServers[hostname] = {
299+
port: self.sslServers[wilcardHost]
300+
};
301+
return makeConnection(self.sslServers[hostname].port);
291302
}
292303
getHttpsServer(hostname, function(err, port) {
293304
process.nextTick(sem.leave.bind(sem));
@@ -990,7 +1001,7 @@ Proxy.parseHost = function(hostString, defaultPort) {
9901001
Proxy.filterAndCanonizeHeaders = function(originalHeaders) {
9911002
var headers = {};
9921003
for (var key in originalHeaders) {
993-
var canonizedKey = key.trim();
1004+
var canonizedKey = key.trim();
9941005
if (/^public\-key\-pins/i.test(canonizedKey)) {
9951006
// KPKP header => filter
9961007
continue;

0 commit comments

Comments
 (0)