Skip to content

Commit

Permalink
support unlimit websocket single message (#1160)
Browse files Browse the repository at this point in the history
  • Loading branch information
suchen-sci committed Dec 6, 2023
1 parent 918d1bb commit 9e26c89
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
12 changes: 11 additions & 1 deletion docs/02.Tutorials/2.6.Websocket.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
## Design

- The `WebSocketProxy` is a filter of Easegress, and can be put into a pipeline.
- Easegress uses `github.com/golang/x/net/websocket` to implement
- Easegress uses `nhooyr.io/websocket` to implement
`WebSocketProxy` filter.

1. Spec
Expand All @@ -42,6 +42,16 @@ filters:
pools:
- servers:
- url: ws:https://127.0.0.1:12345
- url: ws:https://127.0.0.1:9095
- url: ws:https://127.0.0.1:9096
- url: ws:https://127.0.0.1:9097
loadBalance:
policy: roundRobin
# the max number of bytes to read for a single message in
# client/server connection.
# default is 32769, set -1 to disable limit.
clientMaxMsgSize: 32769
serverMaxMsgSize: 32769
```

* HTTPServer to route traffic to the websocket-pipeline:
Expand Down
6 changes: 6 additions & 0 deletions docs/07.Reference/7.02.Filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,12 @@ pools:
- url: ws:https://127.0.0.1:9095
- url: ws:https://127.0.0.1:9096
- url: ws:https://127.0.0.1:9097
loadBalance:
policy: roundRobin
# the max number of bytes to read for a single message in client/server connection.
# default is 32769, set -1 to disable limit.
clientMaxMsgSize: 32769
serverMaxMsgSize: 32769
```

Same as the `Proxy` filter:
Expand Down
4 changes: 2 additions & 2 deletions pkg/filters/proxies/httpproxy/wspool.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (sp *WebSocketServerPool) dialServer(svr *Server, req *httpprot.Request) (*
}

conn, _, err := websocket.Dial(stdctx.Background(), u, opts)
if err == nil && sp.spec.ServerMaxMsgSize > 0 {
if err == nil && (sp.spec.ServerMaxMsgSize > 0 || sp.spec.ServerMaxMsgSize == -1) {
conn.SetReadLimit(sp.spec.ServerMaxMsgSize)
}
return conn, err
Expand Down Expand Up @@ -204,7 +204,7 @@ func (sp *WebSocketServerPool) handle(ctx *context.Context) (result string) {
metric.StatusCode = http.StatusBadRequest
return resultClientError
}
if sp.spec.ClientMaxMsgSize > 0 {
if sp.spec.ClientMaxMsgSize > 0 || sp.spec.ClientMaxMsgSize == -1 {
clntConn.SetReadLimit(sp.spec.ClientMaxMsgSize)
}

Expand Down

0 comments on commit 9e26c89

Please sign in to comment.