@@ -3,7 +3,13 @@ var common = exports,
3
3
extend = require ( 'util' ) . _extend ,
4
4
required = require ( 'requires-port' ) ;
5
5
6
- var upgradeHeader = / ( ^ | , ) \s * u p g r a d e \s * ( $ | , ) / i;
6
+ var upgradeHeader = / ( ^ | , ) \s * u p g r a d e \s * ( $ | , ) / i,
7
+ isSSL = / ^ h t t p s | w s s / ;
8
+
9
+ /**
10
+ * Simple Regex for testing if protocol is https
11
+ */
12
+ common . isSSL = isSSL ;
7
13
/**
8
14
* Copies the right headers from `options` and `req` to
9
15
* `outgoing` which is then used to fire the proxied
@@ -26,7 +32,7 @@ var upgradeHeader = /(^|,)\s*upgrade\s*($|,)/i;
26
32
27
33
common . setupOutgoing = function ( outgoing , options , req , forward ) {
28
34
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 ) ;
30
36
31
37
[ 'host' , 'hostname' , 'socketPath' ] . forEach (
32
38
function ( e ) { outgoing [ e ] = options [ forward || 'target' ] [ e ] ; }
@@ -39,7 +45,7 @@ common.setupOutgoing = function(outgoing, options, req, forward) {
39
45
extend ( outgoing . headers , options . headers ) ;
40
46
}
41
47
42
- if ( ~ [ 'https:' , 'wss:' ] . indexOf ( options [ forward || 'target' ] . protocol ) ) {
48
+ if ( isSSL . test ( options [ forward || 'target' ] . protocol ) ) {
43
49
outgoing . rejectUnauthorized = ( typeof options . secure === "undefined" ) ? true : options . secure ;
44
50
}
45
51
0 commit comments