@@ -22,6 +22,11 @@ var passes = exports;
22
22
/**
23
23
* WebSocket requests must have the `GET` method and
24
24
* the `upgrade:websocket` header
25
+ *
26
+ * @param {ClientRequest } Req Request object
27
+ * @param {Socket} Websocket
28
+ *
29
+ * @api private
25
30
*/
26
31
27
32
function checkMethodAndHeader ( req , socket ) {
@@ -35,8 +40,14 @@ function checkMethodAndHeader (req, socket) {
35
40
} ,
36
41
37
42
/**
38
- * Setup socket
43
+ * Set the proper configuration for sockets,
44
+ * set no delay and set keep alive, also set
45
+ * the timeout to 0.
39
46
*
47
+ * @param {ClientRequest } Req Request object
48
+ * @param {Socket} Websocket
49
+ *
50
+ * @api private
40
51
*/
41
52
42
53
function setupSocket ( req , socket ) {
@@ -49,6 +60,11 @@ function setupSocket(req, socket) {
49
60
/**
50
61
* Sets `x-forwarded-*` headers if specified in config.
51
62
*
63
+ * @param {ClientRequest } Req Request object
64
+ * @param {Socket} Websocket
65
+ * @param {Object } Options Config object passed to the proxy
66
+ *
67
+ * @api private
52
68
*/
53
69
54
70
function XHeaders ( req , socket , options ) {
@@ -69,8 +85,14 @@ function XHeaders(req, socket, options) {
69
85
} ,
70
86
71
87
/**
88
+ * Does the actual proxying. Make the request and upgrade it
89
+ * send the Switching Protocols request and pipe the sockets.
72
90
*
91
+ * @param {ClientRequest } Req Request object
92
+ * @param {Socket} Websocket
93
+ * @param {Object } Options Config object passed to the proxy
73
94
*
95
+ * @api private
74
96
*/
75
97
function stream ( req , socket , options , head ) {
76
98
common . setupSocket ( socket ) ;
@@ -81,11 +103,14 @@ function stream(req, socket, options, head) {
81
103
var proxyReq = ( ~ [ 'https:' , 'wss:' ] . indexOf ( options . target . protocol ) ? https : http ) . request (
82
104
common . setupOutgoing ( options . ssl || { } , options , req )
83
105
) ;
106
+ // Error Handler
84
107
proxyReq . on ( 'error' , function ( err ) {
85
108
var ev = 'caronte:outgoing:ws:' ;
109
+ // If no error listeners, so throw the error.
86
110
if ( options . ee . listeners ( ev + 'error' ) . length == 0 ) {
87
111
throw err ;
88
112
}
113
+ // Also emit the error events
89
114
options . ee . emit ( ev + 'error' , err , req , socket , head ) ;
90
115
} ) ;
91
116
0 commit comments