Skip to content

Commit 006ba47

Browse files
committed
fix: rename interceptor opts and evetns
1 parent 046e84b commit 006ba47

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -395,27 +395,28 @@ proxyServer.listen(8015);
395395
396396
};
397397
```
398-
* **wsInterceptServerMsg**: Is a handler which is called when a websocket message is intercepted on its way to the server. It takes two arguments: `data` - is a websocket message and flags (fin, mask, compress, binary). If falsy value is returned then nothing will be sended to the target server.
399-
```
398+
* **wsInterceptClientMsg**: Is a handler which is called when a websocket message is intercepted on its way to the server from the client. It takes two arguments: `data` - is a websocket message and flags (fin, mask, compress, binary). If falsy value is returned then nothing will be sended to the client.
399+
```
400400
const proxy = new HttpProxy({
401401
...
402-
wsInterceptServerMsg: (data, flags) {
402+
wsInterceptClientMsg: (data, flags) {
403403
return typeof data === 'string ? data.toUpperCase() : data;
404404
}
405405
...
406406
})
407407
```
408-
* **wsInterceptClientMsg**: Is a handler which is called when a websocket message is intercepted on its way to the client. It takes two arguments: `data` - is a websocket message and flags (fin, mask, compress, binary). If falsy value is returned then nothing will be sended to the client.
409-
```
408+
* **wsInterceptServerMsg**: Is a handler which is called when a websocket message is intercepted on its way to the client from the server. It takes two arguments: `data` - is a websocket message and flags (fin, mask, compress, binary). If falsy value is returned then nothing will be sended to the target server.
409+
```
410410
const proxy = new HttpProxy({
411411
...
412-
wsInterceptClientMsg: (data, flags) {
412+
wsInterceptServerMsg: (data, flags) {
413413
return typeof data === 'string ? data.toUpperCase() : data;
414414
}
415415
...
416416
})
417417
```
418418
419+
419420
**NOTE:**
420421
`options.ws` and `options.ssl` are optional.
421422
`options.target` and `options.forward` cannot both be missing
@@ -434,8 +435,8 @@ If you are using the `proxyServer.listen` method, the following options are also
434435
* `proxyReq`: This event is emitted before the data is sent. It gives you a chance to alter the proxyReq request object. Applies to "web" connections
435436
* `proxyReqWs`: This event is emitted before the data is sent. It gives you a chance to alter the proxyReq request object. Applies to "websocket" connections
436437
* `proxyRes`: This event is emitted if the request to the target got a response.
437-
* `wsServerMsg`: This event is emitted after websocket message is sended to the server.
438-
* `wsClientMsg`: This event is emitted after webscoket mesage is sended to the client.
438+
* `wsClientMsg`: This event is emitted after webscoket mesage is sended from the client to the server.
439+
* `wsServerMsg`: This event is emitted after websocket message is sended from the server to the client.
439440
* `open`: This event is emitted once the proxy websocket was created and piped into the target websocket.
440441
* `close`: This event is emitted once the proxy websocket was closed.
441442
* (DEPRECATED) `proxySocket`: Deprecated in favor of `open`.

lib/http-proxy/ws/interceptor.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,37 +69,37 @@ module.exports = class Interceptor {
6969
};
7070
}
7171

72-
_interceptServerMessages() {
72+
_interceptClientMessages() {
7373
const receiver = new Receiver(this._clientExtenstions);
7474
const sender = new Sender(this._proxySocket, this._serverExtenstions);
7575

7676
// frame must be masked when send from client to server - https://tools.ietf.org/html/rfc6455#section-5.3
7777
const options = {mask: true};
78-
const dataSender = this._getDataSender({sender, event: 'wsServerMsg', options});
78+
const dataSender = this._getDataSender({sender, event: 'wsClientMsg', options});
7979

80-
receiver.ontext = getMsgHandler({interceptor: this._options.wsInterceptServerMsg, dataSender, binary: false});
81-
receiver.onbinary = getMsgHandler({interceptor: this._options.wsInterceptServerMsg, dataSender, binary: true});
80+
receiver.ontext = getMsgHandler({interceptor: this._options.wsInterceptClientMsg, dataSender, binary: false});
81+
receiver.onbinary = getMsgHandler({interceptor: this._options.wsInterceptClientMsg, dataSender, binary: true});
8282
receiver.onclose = (code, msg, {masked: mask}) => sender.close(code, msg, mask);
8383

8484
this._socket.on('data', (data) => receiver.add(data));
8585
}
8686

87-
_interceptClientMessages() {
87+
_interceptServerMessages() {
8888
const receiver = new Receiver(this._serverExtenstions);
8989
const sender = new Sender(this._socket, this._clientExtenstions);
9090

9191
const options = {mask: false};
92-
const dataSender = this._getDataSender({sender, event: 'wsClientMsg', options});
92+
const dataSender = this._getDataSender({sender, event: 'wsServerMsg', options});
9393

94-
receiver.ontext = getMsgHandler({interceptor: this._options.wsInterceptClientMsg, dataSender, binary: false});
95-
receiver.onbinary = getMsgHandler({interceptor: this._options.wsInterceptClientMsg, dataSender, binary: true});
94+
receiver.ontext = getMsgHandler({interceptor: this._options.wsInterceptServerMsg, dataSender, binary: false});
95+
receiver.onbinary = getMsgHandler({interceptor: this._options.wsInterceptServerMsg, dataSender, binary: true});
9696
receiver.onclose = (code, msg, {masked: mask}) => sender.close(code, msg, mask);
9797

9898
this._proxySocket.on('data', (data) => receiver.add(data));
9999
}
100100

101101
startDataTransfer() {
102-
this._interceptServerMessages();
103102
this._interceptClientMessages();
103+
this._interceptServerMessages();
104104
}
105105
};

0 commit comments

Comments
 (0)