mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
[fix] use simple regex instead of indexOf to check the protocol to support without the colon fixes #711
This commit is contained in:
parent
2086e4917c
commit
c04485671a
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user