Skip to content
This repository was archived by the owner on Dec 4, 2023. It is now read-only.

Commit afc150c

Browse files
committed
Backport http-party#1407
1 parent 0f23930 commit afc150c

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

lib/http-proxy/passes/ws-incoming.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ module.exports = {
7676
*
7777
* @api private
7878
*/
79-
stream : function stream(req, socket, options, head, server, clb) {
79+
stream : async function stream(req, socket, options, head, server, clb) {
8080

8181
var createHttpHeader = function(line, headers) {
8282
return Object.keys(headers).reduce(function (head, key) {
@@ -105,7 +105,7 @@ module.exports = {
105105
);
106106

107107
// 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); }
109109

110110
// Error Handler
111111
proxyReq.on('error', onOutgoingError);
@@ -146,6 +146,24 @@ module.exports = {
146146

147147
server.emit('open', proxySocket);
148148
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();
149167
});
150168

151169
return proxyReq.end(); // XXX: CHECK IF THIS IS THIS CORRECT

0 commit comments

Comments
 (0)