14
14
var passes = exports ;
15
15
16
16
[
17
- /*
18
- * WebSocket requests must have the `GET` method and
19
- * the `upgrade:websocket` header
20
- */
21
- function checkMethodAndHeader ( req , res , options ) {
22
- if ( req . method !== 'GET' || req . headers . upgrade . toLowerCase ( ) !== 'websocket' ) {
23
- req . end ( ) ;
24
- // Return true to prevent the next passes to be executed
25
- return true ;
26
- }
27
- } ,
28
-
29
- /**
30
- * Sets `x-forwarded-*` headers if specified in config.
31
- *
32
- */
33
-
34
- function XHeaders ( req , res , options ) {
35
- if ( ! options . xfwd ) return ;
36
-
37
- var values = {
38
- for : req . connection . remoteAddress || req . socket . remoteAddress ,
39
- port : req . connection . remotePort || req . socket . remotePort ,
40
- proto : req . connection . pair ? 'wss' : 'ws'
41
- } ;
42
-
43
- [ 'for' , 'port' , 'proto' ] . forEach ( function ( header ) {
44
- req . headers [ 'x-forwarded-' + header ] =
45
- ( req . headers [ 'x-forwarded-' + header ] || '' ) +
46
- ( req . headers [ 'x-forwarded-' + header ] ? ',' : '' ) +
47
- values [ header ]
48
- } ) ;
17
+ /**
18
+ * WebSocket requests must have the `GET` method and
19
+ * the `upgrade:websocket` header
20
+ */
21
+
22
+ function checkMethodAndHeader ( req , res , options ) {
23
+ if ( req . method !== 'GET' || req . headers . upgrade . toLowerCase ( ) !== 'websocket' ) {
24
+ req . end ( ) ;
25
+
26
+ return true ;
49
27
}
50
- ] . forEach ( function ( func ) {
51
- passes [ func . name ] = func ;
52
- } ) ;
28
+ } ,
29
+
30
+ /**
31
+ * Sets `x-forwarded-*` headers if specified in config.
32
+ *
33
+ */
34
+
35
+ function XHeaders ( req , res , options ) {
36
+ if ( ! options . xfwd ) return ;
37
+
38
+ var values = {
39
+ for : req . connection . remoteAddress || req . socket . remoteAddress ,
40
+ port : req . connection . remotePort || req . socket . remotePort ,
41
+ proto : req . connection . pair ? 'wss' : 'ws'
42
+ } ;
43
+
44
+ [ 'for' , 'port' , 'proto' ] . forEach ( function ( header ) {
45
+ req . headers [ 'x-forwarded-' + header ] =
46
+ ( req . headers [ 'x-forwarded-' + header ] || '' ) +
47
+ ( req . headers [ 'x-forwarded-' + header ] ? ',' : '' ) +
48
+ values [ header ]
49
+ } ) ;
50
+ } ,
51
+
52
+ /**
53
+ *
54
+ *
55
+ */
56
+ function stream ( req , res , options , instance ) {
57
+ req . pipe ( new WebsocketStream ( options , instance ) ) . pipe ( res ) ;
58
+ }
59
+
60
+ ] // <--
61
+ . forEach ( function ( func ) {
62
+ passes [ func . name ] = func ;
63
+ } ) ;
0 commit comments