diff --git a/lib/http-proxy/common.js b/lib/http-proxy/common.js index 15e0392..679812a 100644 --- a/lib/http-proxy/common.js +++ b/lib/http-proxy/common.js @@ -3,7 +3,13 @@ var common = exports, extend = require('util')._extend, required = require('requires-port'); -var upgradeHeader = /(^|,)\s*upgrade\s*($|,)/i; +var upgradeHeader = /(^|,)\s*upgrade\s*($|,)/i, + isSSL = /^https|wss/; + +/** + * Simple Regex for testing if protocol is https + */ +common.isSSL = isSSL; /** * Copies the right headers from `options` and `req` to * `outgoing` which is then used to fire the proxied @@ -26,7 +32,7 @@ var upgradeHeader = /(^|,)\s*upgrade\s*($|,)/i; common.setupOutgoing = function(outgoing, options, req, forward) { outgoing.port = options[forward || 'target'].port || - (~['https:', 'wss:'].indexOf(options[forward || 'target'].protocol) ? 443 : 80); + (isSSL.test(options[forward || 'target'].protocol) ? 443 : 80); ['host', 'hostname', 'socketPath'].forEach( function(e) { outgoing[e] = options[forward || 'target'][e]; } @@ -39,7 +45,7 @@ common.setupOutgoing = function(outgoing, options, req, forward) { extend(outgoing.headers, options.headers); } - if (~['https:', 'wss:'].indexOf(options[forward || 'target'].protocol)) { + if (isSSL.test(options[forward || 'target'].protocol)) { outgoing.rejectUnauthorized = (typeof options.secure === "undefined") ? true : options.secure; } diff --git a/lib/http-proxy/passes/ws-incoming.js b/lib/http-proxy/passes/ws-incoming.js index c8a5f20..9ad8060 100644 --- a/lib/http-proxy/passes/ws-incoming.js +++ b/lib/http-proxy/passes/ws-incoming.js @@ -84,7 +84,7 @@ var passes = exports; if (head && head.length) socket.unshift(head); - var proxyReq = (~['https:', 'wss:'].indexOf(options.target.protocol) ? https : http).request( + var proxyReq = (common.isSSL.test(options.target.protocol) ? https : http).request( common.setupOutgoing(options.ssl || {}, options, req) ); // Error Handler