File tree 1 file changed +52
-1
lines changed
1 file changed +52
-1
lines changed Original file line number Diff line number Diff line change 1
- // ws
1
+ /*!
2
+ * Array of passes.
3
+ *
4
+ * A `pass` is just a function that is executed on `req, res, options`
5
+ * so that you can easily add new checks while still keeping the base
6
+ * flexible.
7
+ */
8
+
9
+ /*
10
+ * Websockets Passes
11
+ *
12
+ */
13
+
14
+ var passes = exports ;
15
+
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
+ } ) ;
49
+ }
50
+ ] . forEach ( function ( func ) {
51
+ passes [ func . name ] = func ;
52
+ } ) ;
You can’t perform that action at this time.
0 commit comments