GeezerVison is showing github.com — Document Netty WebSocket compression · playframework/playframework@0b5c7a5
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: documentation/manual/releases/release31/Highlights31.md +14Lines changed: 14 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -6,6 +6,20 @@ This section highlights the new features of Play 3.1. If you want to learn about | 6 | 6 |
| 7 | 7 | ## Other Additions | 8 | 8 |
| | 9 | +### Netty WebSocket Compression | | 10 | + | | 11 | +The Play Netty server backend now supports WebSocket compression using the RFC 7692 `permessage-deflate` extension. | | 12 | + | | 13 | +Compression is enabled by default and is negotiated during the WebSocket handshake when the client offers `permessage-deflate` in the `Sec-WebSocket-Extensions` header. Applications can disable WebSocket compression for all server backends with: | | 14 | + | | 15 | +```hocon | | 16 | +play.server.websocket.compression.enabled = false | | 17 | +``` | | 18 | + | | 19 | +The Netty backend also exposes Netty-specific tuning options under `play.server.netty.websocket.compression`, including the compression level, negotiated window-size behavior, context-takeover behavior, and the decompression allocation limit. By default, the allocation limit follows `play.server.websocket.frame.maxLength`. | | 20 | + | | 21 | +For more details, see the [[Scala WebSocket documentation|ScalaWebSockets#Configuring-WebSocket-compression]] and [[Java WebSocket documentation|JavaWebSockets#Configuring-WebSocket-compression]]. | | 22 | + | 9 | 23 | ### WebSocket Subprotocol Selection | 10 | 24 |
| 11 | 25 | Play now lets applications explicitly select the WebSocket subprotocol that is sent back in the successful `101 Switching Protocols` response. | |
Collapse file Copy file name to clipboardExpand all lines: documentation/manual/working/javaGuide/main/async/JavaWebSockets.md +14Lines changed: 14 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -120,6 +120,20 @@ This configuration gives you more control of WebSocket frame length and can be a | 120 | 120 |
| 121 | 121 | The configuration above applies to WebSocket data frames. WebSocket Close frames, on the other hand, are control frames and have a smaller payload limit defined by [RFC 6455 section 5.5](https://www.rfc-editor.org/rfc/rfc6455#section-5.5). If a Close frame includes a status code, the status code uses 2 bytes, leaving at most 123 UTF-8 bytes for the close reason. Play truncates longer close reasons before sending them. Status codes `1005`, `1006`, and `1015` are reserved by [RFC 6455 section 7.4.1](https://www.rfc-editor.org/rfc/rfc6455#section-7.4.1) and should not be sent by application code as WebSocket Close frame status codes. | 122 | 122 |
| | 123 | +## Configuring WebSocket compression | | 124 | + | | 125 | +The Netty server backend supports WebSocket compression using the RFC 7692 `permessage-deflate` extension. Compression is enabled by default and is negotiated during the WebSocket handshake when the client offers `permessage-deflate` in the `Sec-WebSocket-Extensions` header. | | 126 | + | | 127 | +You can disable WebSocket compression for all server backends with: | | 128 | + | | 129 | +``` | | 130 | +play.server.websocket.compression.enabled = false | | 131 | +``` | | 132 | + | | 133 | +When using the Netty backend, Netty-specific compression settings are available under `play.server.netty.websocket.compression`. These settings include the compression level, negotiated window-size behavior, context-takeover behavior, and the maximum decompression allocation. By default, `play.server.netty.websocket.compression.maxAllocation` uses `play.server.websocket.frame.maxLength`, so the same limit applies to decompressed WebSocket messages. | | 134 | + | | 135 | +> **Note:** WebSocket compression can increase CPU and memory usage. If messages include secrets alongside attacker-controlled data, consider whether compression is appropriate for that endpoint. Under the `play.server.netty.websocket` config parent, Netty's default context-takeover settings are `compression.perMessageDeflate.allowServerNoContext = false` and `compression.perMessageDeflate.preferredClientNoContext = false`. For a more conservative setup, set them to `true` so the server may accept `server_no_context_takeover` when the client requests it, and so Netty requests `client_no_context_takeover` when the client supports it. | | 136 | +
| 123 | 137 | ## Configuring keep-alive Frames | 124 | 138 |
| 125 | 139 | First of all, if a client sends a `ping` Frame to the Play backend server, it automatically answers with a `pong` frame. This is a requirement according to [RFC 6455 Section 5.5.2](https://www.rfc-editor.org/rfc/rfc6455#section-5.5.2), therefore this is hardcoded within Play, you don't need to set up or configure anything. | |
Collapse file Copy file name to clipboardExpand all lines: documentation/manual/working/scalaGuide/main/async/ScalaWebSockets.md +14Lines changed: 14 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -122,6 +122,20 @@ This configuration gives you more control of WebSocket frame length and can be a | 122 | 122 |
| 123 | 123 | The configuration above applies to WebSocket data frames. WebSocket Close frames, on the other hand, are control frames and have a smaller payload limit defined by [RFC 6455 section 5.5](https://www.rfc-editor.org/rfc/rfc6455#section-5.5). If a Close frame includes a status code, the status code uses 2 bytes, leaving at most 123 UTF-8 bytes for the close reason. Play truncates longer close reasons before sending them. Status codes `1005`, `1006`, and `1015` are reserved by [RFC 6455 section 7.4.1](https://www.rfc-editor.org/rfc/rfc6455#section-7.4.1) and should not be sent by application code as WebSocket Close frame status codes. | 124 | 124 |
| | 125 | +## Configuring WebSocket compression | | 126 | + | | 127 | +The Netty server backend supports WebSocket compression using the RFC 7692 `permessage-deflate` extension. Compression is enabled by default and is negotiated during the WebSocket handshake when the client offers `permessage-deflate` in the `Sec-WebSocket-Extensions` header. | | 128 | + | | 129 | +You can disable WebSocket compression for all server backends with: | | 130 | + | | 131 | +``` | | 132 | +play.server.websocket.compression.enabled = false | | 133 | +``` | | 134 | + | | 135 | +When using the Netty backend, Netty-specific compression settings are available under `play.server.netty.websocket.compression`. These settings include the compression level, negotiated window-size behavior, context-takeover behavior, and the maximum decompression allocation. By default, `play.server.netty.websocket.compression.maxAllocation` uses `play.server.websocket.frame.maxLength`, so the same limit applies to decompressed WebSocket messages. | | 136 | + | | 137 | +> **Note:** WebSocket compression can increase CPU and memory usage. If messages include secrets alongside attacker-controlled data, consider whether compression is appropriate for that endpoint. Under the `play.server.netty.websocket` config parent, Netty's default context-takeover settings are `compression.perMessageDeflate.allowServerNoContext = false` and `compression.perMessageDeflate.preferredClientNoContext = false`. For a more conservative setup, set them to `true` so the server may accept `server_no_context_takeover` when the client requests it, and so Netty requests `client_no_context_takeover` when the client supports it. | | 138 | +
| 125 | 139 | ## Configuring keep-alive Frames | 126 | 140 |
| 127 | 141 | First of all, if a client sends a `ping` Frame to the Play backend server, it automatically answers with a `pong` frame. This is a requirement according to [RFC 6455 Section 5.5.2](https://www.rfc-editor.org/rfc/rfc6455#section-5.5.2), therefore this is hardcoded within Play, you don't need to set up or configure anything. | |
|