felangel / felangel/web_socket_client
feat: allow disabling native WebSocket compression per client
- 主要语言
- Dart
- 星标
- 177
- 派生
- 44
- PR 合并指标
- 30 天内没有已合并 PR
描述
**Description**
Please expose a per-client option to disable WebSocket compression on native platforms while retaining this library's automatic reconnection and connection-state handling.
The native connector calls `dart:io`'s `WebSocket.connect` without a `compression` argument, which uses `CompressionOptions.compressionDefault`. The public `WebSocket` constructor has neither a compression option nor a custom connection factory, so consumers cannot pass `CompressionOptions.compressionOff` through to the underlying socket. Any automatic reconnect must also preserve that choice.
This came up in NDK: https://github.com/relaystr/ndk/issues/820. Long-running, memory-sensitive clients connecting to multiple Nostr relays need to choose between compression-related memory/CPU overhead and bandwidth. That issue includes workload-specific measurements; this request does not assume compression is a memory leak or that disabling it benefits every application. Without an upstream option, downstream libraries need to maintain a modified copy of the client to expose this setting.
**Proposed API**
```dart
final socket = WebSocket(
Uri.parse('wss://relay.example.com'),
compressionEnabled: false,
);
```
Use `bool compressionEnabled = true` to preserve existing behavior and avoid exposing `dart:io` types through the cross-platform API. Store the flag on the client and forward it through the platform connectors on every connection attempt. The native connector maps it to `CompressionOptions.compressionDefault` or `CompressionOptions.compressionOff`.
On the web, document that the flag is ignored: the browser WebSocket API controls compression negotiation and does not expose a switch to disable it.
**Requirements**
- [ ] Existing clients retain default compression negotiation.
- [ ] Native clients can disable compression per instance, without changing other clients.
- [ ] Automatic reconnects preserve the configured setting.
- [ ] Text/binary messages, headers, and subprotocols continue to work.
- [ ] The API remains web-compatible and documents the browser limitation.
- [ ] Regression tests inspect both request and response handshake headers against a compression-capable local server, including after reconnect.
**Additional Context**
Related downstream issue: https://github.com/relaystr/ndk/issues/820
I will submit a small implementation with tests and documentation. No changes to backoff or connection lifecycle logic are needed.
贡献指南
这个仓库没有索引到贡献指南
评估
这个 Issue 还没有评估数据。