@@ -18,132 +18,132 @@ web_o = Object.keys(web_o).map(function(pass) {
18
18
19
19
[ // <--
20
20
21
- /**
22
- * Sets `content-length` to '0' if request is of DELETE type.
23
- *
24
- * @param {ClientRequest } Req Request object
25
- * @param {IncomingMessage} Res Response object
26
- * @param {Object } Options Config object passed to the proxy
27
- *
28
- * @api private
29
- */
30
-
31
- function deleteLength ( req , res , options ) {
32
- if ( req . method === 'DELETE' && ! req . headers [ 'content-length' ] ) {
33
- req . headers [ 'content-length' ] = '0' ;
34
- }
35
- } ,
36
-
37
- /**
38
- * Sets timeout in request socket if it was specified in options.
39
- *
40
- * @param {ClientRequest } Req Request object
41
- * @param {IncomingMessage} Res Response object
42
- * @param {Object } Options Config object passed to the proxy
43
- *
44
- * @api private
45
- */
46
-
47
- function timeout ( req , res , options ) {
48
- if ( options . timeout ) {
49
- req . socket . setTimeout ( options . timeout ) ;
50
- }
51
- } ,
52
-
53
- /**
54
- * Sets `x-forwarded-*` headers if specified in config.
55
- *
56
- * @param {ClientRequest } Req Request object
57
- * @param {IncomingMessage} Res Response object
58
- * @param {Object } Options Config object passed to the proxy
59
- *
60
- * @api private
61
- */
62
-
63
- function XHeaders ( req , res , options ) {
64
- if ( ! options . xfwd ) return ;
65
-
66
- var values = {
67
- for : req . connection . remoteAddress || req . socket . remoteAddress ,
68
- port : req . connection . remotePort || req . socket . remotePort ,
69
- proto : req . isSpdy ? 'https' : ( req . connection . pair ? 'https' : 'http' )
70
- } ;
71
-
72
- [ 'for' , 'port' , 'proto' ] . forEach ( function ( header ) {
73
- req . headers [ 'x-forwarded-' + header ] =
74
- ( req . headers [ 'x-forwarded-' + header ] || '' ) +
75
- ( req . headers [ 'x-forwarded-' + header ] ? ',' : '' ) +
76
- values [ header ]
77
- } ) ;
78
- } ,
79
-
80
- /**
81
- * Does the actual proxying. If `forward` is enabled fires up
82
- * a ForwardStream, same happens for ProxyStream. The request
83
- * just dies otherwise.
84
- *
85
- * @param {ClientRequest } Req Request object
86
- * @param {IncomingMessage} Res Response object
87
- * @param {Object } Options Config object passed to the proxy
88
- *
89
- * @api private
90
- */
21
+ /**
22
+ * Sets `content-length` to '0' if request is of DELETE type.
23
+ *
24
+ * @param {ClientRequest } Req Request object
25
+ * @param {IncomingMessage} Res Response object
26
+ * @param {Object } Options Config object passed to the proxy
27
+ *
28
+ * @api private
29
+ */
30
+
31
+ function deleteLength ( req , res , options ) {
32
+ if ( req . method === 'DELETE' && ! req . headers [ 'content-length' ] ) {
33
+ req . headers [ 'content-length' ] = '0' ;
34
+ }
35
+ } ,
36
+
37
+ /**
38
+ * Sets timeout in request socket if it was specified in options.
39
+ *
40
+ * @param {ClientRequest } Req Request object
41
+ * @param {IncomingMessage} Res Response object
42
+ * @param {Object } Options Config object passed to the proxy
43
+ *
44
+ * @api private
45
+ */
46
+
47
+ function timeout ( req , res , options ) {
48
+ if ( options . timeout ) {
49
+ req . socket . setTimeout ( options . timeout ) ;
50
+ }
51
+ } ,
52
+
53
+ /**
54
+ * Sets `x-forwarded-*` headers if specified in config.
55
+ *
56
+ * @param {ClientRequest } Req Request object
57
+ * @param {IncomingMessage} Res Response object
58
+ * @param {Object } Options Config object passed to the proxy
59
+ *
60
+ * @api private
61
+ */
62
+
63
+ function XHeaders ( req , res , options ) {
64
+ if ( ! options . xfwd ) return ;
65
+
66
+ var values = {
67
+ for : req . connection . remoteAddress || req . socket . remoteAddress ,
68
+ port : req . connection . remotePort || req . socket . remotePort ,
69
+ proto : req . isSpdy ? 'https' : ( req . connection . pair ? 'https' : 'http' )
70
+ } ;
71
+
72
+ [ 'for' , 'port' , 'proto' ] . forEach ( function ( header ) {
73
+ req . headers [ 'x-forwarded-' + header ] =
74
+ ( req . headers [ 'x-forwarded-' + header ] || '' ) +
75
+ ( req . headers [ 'x-forwarded-' + header ] ? ',' : '' ) +
76
+ values [ header ] ;
77
+ } ) ;
78
+ } ,
79
+
80
+ /**
81
+ * Does the actual proxying. If `forward` is enabled fires up
82
+ * a ForwardStream, same happens for ProxyStream. The request
83
+ * just dies otherwise.
84
+ *
85
+ * @param {ClientRequest } Req Request object
86
+ * @param {IncomingMessage} Res Response object
87
+ * @param {Object } Options Config object passed to the proxy
88
+ *
89
+ * @api private
90
+ */
91
+
92
+ function stream ( req , res , options ) {
93
+ if ( options . forward ) {
94
+ // If forward enable, so just pipe the request
95
+ var forwardReq = ( options . forward . protocol === 'https:' ? https : http ) . request (
96
+ common . setupOutgoing ( options . ssl || { } , options , req , 'forward' )
97
+ ) ;
98
+ req . pipe ( forwardReq ) ;
99
+ return res . end ( ) ;
100
+ }
91
101
92
- function stream ( req , res , options ) {
93
- if ( options . forward ) {
94
- // If forward enable, so just pipe the request
95
- var forwardReq = ( options . forward . protocol === 'https:' ? https : http ) . request (
96
- common . setupOutgoing ( options . ssl || { } , options , req , 'forward' )
102
+ // Request initalization
103
+ var proxyReq = ( options . target . protocol === 'https:' ? https : http ) . request (
104
+ common . setupOutgoing ( options . ssl || { } , options , req )
97
105
) ;
98
- req . pipe ( forwardReq ) ;
99
- return res . end ( ) ;
100
- }
101
-
102
- // Request initalization
103
- var proxyReq = ( options . target . protocol === 'https:' ? https : http ) . request (
104
- common . setupOutgoing ( options . ssl || { } , options , req )
105
- ) ;
106
106
107
- // Error Handler
108
- proxyReq . on ( 'error' , function ( err ) {
109
- var ev = 'caronte:outgoing:web:' ;
110
- // If no error listeners, so throw the error.
111
- if ( options . ee . listeners ( ev + 'error' ) . length == 0 ) {
107
+ // Error Handler
108
+ proxyReq . on ( 'error' , function ( err ) {
109
+ var ev = 'caronte:outgoing:web:' ;
110
+ // If no error listeners, so throw the error.
111
+ if ( ! options . ee . listeners ( ev + 'error' ) . length ) {
112
112
throw err ;
113
- }
114
- // Also emit the error events
115
- options . ee . emit ( ev + 'error' , err , req , res ) ;
116
- } ) ;
113
+ }
114
+ // Also emit the error events
115
+ options . ee . emit ( ev + 'error' , err , req , res ) ;
116
+ } ) ;
117
117
118
- req . pipe ( proxyReq ) ;
118
+ req . pipe ( proxyReq ) ;
119
119
120
- proxyReq . on ( 'response' , function ( proxyRes ) {
121
- var ev = 'caronte:outgoing:web:' ;
120
+ proxyReq . on ( 'response' , function ( proxyRes ) {
121
+ var ev = 'caronte:outgoing:web:' ;
122
122
123
- options . ee . emit ( ev + 'begin' , req , res ) ;
123
+ options . ee . emit ( ev + 'begin' , req , res ) ;
124
124
125
- // When the previous request respond, we apply the
126
- // outgoing passes to the response
127
- web_o . some ( function ( pass ) {
128
- var evnt = ev + pass . name . toLowerCase ( ) + ':' ;
125
+ // When the previous request respond, we apply the
126
+ // outgoing passes to the response
127
+ web_o . some ( function ( pass ) {
128
+ var evnt = ev + pass . name . toLowerCase ( ) + ':' , val ;
129
129
130
- options . ee . emit ( evnt + 'begin' , req , res ) ;
131
- // Call the pass with the proxy response
132
- // pass(ClientRequest, IncomingMessage, proxyResponse)
133
- var val = pass ( req , res , proxyRes ) ;
134
- options . ee . emit ( evnt + 'end' ) ;
130
+ options . ee . emit ( evnt + 'begin' , req , res ) ;
131
+ // Call the pass with the proxy response
132
+ // pass(ClientRequest, IncomingMessage, proxyResponse)
133
+ val = pass ( req , res , proxyRes ) ;
134
+ options . ee . emit ( evnt + 'end' ) ;
135
135
136
- return val ;
137
- } ) ;
136
+ return val ;
137
+ } ) ;
138
138
139
- options . ee . emit ( ev + 'end' ) ;
139
+ options . ee . emit ( ev + 'end' ) ;
140
140
141
141
142
- proxyRes . pipe ( res ) ;
143
- } ) ;
142
+ proxyRes . pipe ( res ) ;
143
+ } ) ;
144
144
145
- //proxyReq.end();
146
- }
145
+ //proxyReq.end();
146
+ }
147
147
148
148
] // <--
149
149
. forEach ( function ( func ) {
0 commit comments