Skip to content

Commit fc73b3b

Browse files
committed
[ws] add options to transform client and server streams
1 parent a3fe02d commit fc73b3b

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,8 @@ proxyServer.listen(8015);
373373
}
374374
```
375375
* **headers**: object with extra headers to be added to target requests.
376+
* **wsClientTransformStream**: if set, data from client websocket will be piped through this stream before being sent to the server, allowing you to influence the request data
377+
* **wsServerTransformStream**: if set, data from server websocket will be piped through this stream before being sent to the client, allowing you to influence the response data
376378
* **proxyTimeout**: timeout (in millis) for outgoing proxy requests
377379
* **timeout**: timeout (in millis) for incoming requests
378380
* **followRedirects**: true/false, Default: false - specify whether you want to follow redirects

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,21 @@ module.exports = {
142142
//
143143
socket.write(createHttpHeader('HTTP/1.1 101 Switching Protocols', proxyRes.headers));
144144

145-
proxySocket.pipe(socket).pipe(proxySocket);
145+
let proxyStream = proxySocket;
146+
147+
if (options.wsServerTransformStream) {
148+
options.wsServerTransformStream.on('error', onOutgoingError);
149+
proxyStream = proxyStream.pipe(options.wsServerTransformStream);
150+
}
151+
152+
proxyStream = proxyStream.pipe(socket);
153+
154+
if (options.wsClientTransformStream) {
155+
options.wsClientTransformStream.on('error', onOutgoingError);
156+
proxyStream = proxyStream.pipe(options.wsClientTransformStream);
157+
}
158+
159+
proxyStream.pipe(proxySocket);
146160

147161
server.emit('open', proxySocket);
148162
server.emit('proxySocket', proxySocket); //DEPRECATED.

0 commit comments

Comments
 (0)