Skip to content

Commit c044856

Browse files
committed
[fix] use simple regex instead of indexOf to check the protocol to support without the colon fixes #711
1 parent 2086e49 commit c044856

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

lib/http-proxy/common.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ var common = exports,
33
extend = require('util')._extend,
44
required = require('requires-port');
55

6-
var upgradeHeader = /(^|,)\s*upgrade\s*($|,)/i;
6+
var upgradeHeader = /(^|,)\s*upgrade\s*($|,)/i,
7+
isSSL = /^https|wss/;
8+
9+
/**
10+
* Simple Regex for testing if protocol is https
11+
*/
12+
common.isSSL = isSSL;
713
/**
814
* Copies the right headers from `options` and `req` to
915
* `outgoing` which is then used to fire the proxied
@@ -26,7 +32,7 @@ var upgradeHeader = /(^|,)\s*upgrade\s*($|,)/i;
2632

2733
common.setupOutgoing = function(outgoing, options, req, forward) {
2834
outgoing.port = options[forward || 'target'].port ||
29-
(~['https:', 'wss:'].indexOf(options[forward || 'target'].protocol) ? 443 : 80);
35+
(isSSL.test(options[forward || 'target'].protocol) ? 443 : 80);
3036

3137
['host', 'hostname', 'socketPath'].forEach(
3238
function(e) { outgoing[e] = options[forward || 'target'][e]; }
@@ -39,7 +45,7 @@ common.setupOutgoing = function(outgoing, options, req, forward) {
3945
extend(outgoing.headers, options.headers);
4046
}
4147

42-
if (~['https:', 'wss:'].indexOf(options[forward || 'target'].protocol)) {
48+
if (isSSL.test(options[forward || 'target'].protocol)) {
4349
outgoing.rejectUnauthorized = (typeof options.secure === "undefined") ? true : options.secure;
4450
}
4551

lib/http-proxy/passes/ws-incoming.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ var passes = exports;
8484
if (head && head.length) socket.unshift(head);
8585

8686

87-
var proxyReq = (~['https:', 'wss:'].indexOf(options.target.protocol) ? https : http).request(
87+
var proxyReq = (common.isSSL.test(options.target.protocol) ? https : http).request(
8888
common.setupOutgoing(options.ssl || {}, options, req)
8989
);
9090
// Error Handler

0 commit comments

Comments
 (0)