Skip to main content

websocket-proxy

Sets the largest WebSocket message, per direction, a ws or wss upstream may exchange.

Category Other protocolsAdd it to Route, Service, Consumer, Consumer group, Global rule, Plugin configEngine plugin websocket-proxyPriority 511

What it does​

websocket-proxy sets the largest single WebSocket message the gateway takes in each direction. Client message limit holds a message from the client, and Upstream message limit one from the backend. Left unset, a limit of 65,535 bytes applies to each.

It acts on a route whose upstream speaks WebSocket, with the scheme ws or wss, and the route itself needs Websocket on.

When to use it​

  • A live order-tracking feed in the mobile app, where the backend pushes snapshots larger than 65,535 bytes.
  • A support chat for partners, where a client message never needs more than 16384 bytes and a larger one is a mistake or misuse.
  • Clients that send small commands while the backend answers with large updates, so each direction needs a limit of its own.

Not for the size of an ordinary HTTP request body — see client-control (Controls the client request body size) or how many connections one client holds open — see limit-conn (Limits concurrent connections per key).

Set it up​

Limit the size of a WebSocket message in each direction​

Both values sit below the 65,535 bytes that apply when nothing is set; the route needs Websocket on and a ws or wss upstream.

Set Client message limit to 16384 and set Upstream message limit to 32768.

websocket-proxy · as the console saves it
{
"client_max_payload_len": 16384,
"upstream_max_payload_len": 32768
}

Things to know​

  • The limits apply to the messages a ws or wss upstream exchanges.
  • A route lets a request upgrade its connection to WebSocket only with Websocket on.
  • Client message limit — A limit of 0 is refused when you save.
  • AdviceSet each limit a little above the largest message your clients and your backend send in normal use.

Settings​

The fields as the console shows them, section by section.

Client message limitclient_max_payload_leninteger

The largest single message, in bytes, accepted from the client; unset, the library limit of 65,535 applies.

1 to 2147483647
Upstream message limitupstream_max_payload_leninteger

The largest single message, in bytes, accepted from the target; unset, the library limit of 65,535 applies.

1 to 2147483647

Every plugin also has Enabled, Priority, Filter, Error response and Pre-function: see Plugin execution settings.

G8 dev · Apache APISIX® 3.19.0
Apache, Apache APISIX and APISIX are trademarks of The Apache Software Foundation.
Facts
Category
Other protocols
Add it to
Route, Service, Consumer, Consumer group, Global rule, Plugin config
Engine plugin
websocket-proxy
Priority
511