Limit the messages total size for websocket using Direct Forwarding #1815
-
Hi, I am using the Direct forwarding following example: https://github.com/microsoft/reverse-proxy/tree/release/latest/samples/ReverseProxy.Direct.Sample, and looks good, but want to know whether there is a way to limit the total message size tunning transferred through the wss channel. Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
AFAIK We don't have anything built-in for that. You would need to delve into the forwarder logic to count the bytes transferred. |
Beta Was this translation helpful? Give feedback.
-
YARP treats a WebSocket connection as an opaque data stream - we don't try to parse/reencode messages (except for telemetry purposes). But you can still count the total number of bytes. https://gist.github.com/MihaZupan/a5b0e514337b1ceb74fe03f97e3183ad is an example of how you may limit the size of a WebSocket connection and abort it if it exceeds a given size. Note that this will just close the transport connection, it won't be a graceful WebSocket close for the client. If that is not acceptable for your clients, you would have to parse the WebSocket traffic and insert a proper close message instead. |
Beta Was this translation helpful? Give feedback.
YARP treats a WebSocket connection as an opaque data stream - we don't try to parse/reencode messages (except for telemetry purposes). But you can still count the total number of bytes.
You can look at the WebSocketTelemetry middleware for inspiration as to how you can intercept the WebSocket stream.
https://gist.github.com/MihaZupan/a5b0e514337b1ceb74fe03f97e3183ad is an example of how you may limit the size of a WebSocket connection and abort it if it exceeds a given size. Note that this will just close the transport connection, it won't be a graceful WebSocket close for the client.
If that is not acceptable for your clients, you would have to parse the WebSocket traffic and insert a pr…