@@ -76,7 +76,7 @@ module.exports = {
76
76
*
77
77
* @api private
78
78
*/
79
- stream : function stream ( req , socket , options , head , server , clb ) {
79
+ stream : async function stream ( req , socket , options , head , server , clb ) {
80
80
81
81
var createHttpHeader = function ( line , headers ) {
82
82
return Object . keys ( headers ) . reduce ( function ( head , key ) {
@@ -105,7 +105,7 @@ module.exports = {
105
105
) ;
106
106
107
107
// Enable developers to modify the proxyReq before headers are sent
108
- if ( server ) { server . emit ( 'proxyReqWs' , proxyReq , req , socket , options , head ) ; }
108
+ // if (server) { server.emit('proxyReqWs', proxyReq, req, socket, options, head); }
109
109
110
110
// Error Handler
111
111
proxyReq . on ( 'error' , onOutgoingError ) ;
@@ -146,6 +146,24 @@ module.exports = {
146
146
147
147
server . emit ( 'open' , proxySocket ) ;
148
148
server . emit ( 'proxySocket' , proxySocket ) ; //DEPRECATED.
149
+
150
+
151
+ // Enable developers to modify the proxyReq before headers are sent
152
+ if ( server ) {
153
+ // Provides a way for the event handler to communicate back to the emitter when it finishes its async handling
154
+ let asyncHandler
155
+ const asyncContext = ( callback ) => {
156
+ asyncHandler = callback
157
+ }
158
+
159
+ server . emit ( 'proxyReqWs' , proxyReq , req , socket , options , head , asyncContext ) ;
160
+
161
+ if ( asyncHandler ) {
162
+ await asyncHandler ( )
163
+ }
164
+ }
165
+
166
+ proxyReq . end ( ) ;
149
167
} ) ;
150
168
151
169
return proxyReq . end ( ) ; // XXX: CHECK IF THIS IS THIS CORRECT
0 commit comments