Skip to content

Commit 9ff2c10

Browse files
sortiecommit-bot@chromium.org
authored andcommitted
[dart:io] Clarify CompressionOptions null window bits means default window.
CompressionOptions's clientMaxWindowBits and serverMaxWindowBits are null by default, indicating that no particular window size is negotiated in the protocol, instead implying that the connection can handle a default window size of 15 (32,768 bytes) (RFC 7692 7.1.2.1 and 7.1.2.2). This change clarifies the documentation for the clientMaxWindowBits and serverMaxWindowBits fields by stating they can be null to request the protocol's default window size. The current implementation's behavior is reasonable. It could be changed to explicitly say 15 instead of null, but it's more efficient to omit the request for 15 bits from the protocol since it's default, and it's fine to allow callers to explicitly request 15 bits since the code already allows this behavior. This change simply codifies the existing behavior in the documentation. The co19 test LibTest/io/CompressionOptions/DEFAULT_A01_t01 was written based off the misleading documentation. An issue to test the intended behavior was filed at <dart-lang/co19#364>. Closes #29436 Change-Id: If7645e7d5abd59715fd1eb0bfe8cbb877d776402 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/103813 Commit-Queue: Jonas Termansen <[email protected]> Reviewed-by: Lasse R.H. Nielsen <[email protected]>
1 parent 8a57c1d commit 9ff2c10

File tree

1 file changed

+44
-17
lines changed

1 file changed

+44
-17
lines changed

sdk/lib/_http/websocket.dart

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,51 +50,78 @@ abstract class WebSocketStatus {
5050
static const int RESERVED_1015 = reserved1015;
5151
}
5252

53-
/**
54-
* The [CompressionOptions] class allows you to control
55-
* the options of WebSocket compression.
56-
*/
53+
/// Options controlling compression in a [WebSocket].
54+
///
55+
/// A [CompressionOptions] instance can be passed to [WebSocket.connect], or
56+
/// used in other similar places where [WebSocket] compression is configured.
57+
///
58+
/// In most cases the default [compressionDefault] is sufficient, but in some
59+
/// situations, it might be desirable to use different compression parameters,
60+
/// for example to preserve memory on small devices.
5761
class CompressionOptions {
58-
/// Default WebSocket Compression options.
62+
/// Default [WebSocket] compression configuration.
5963
///
60-
/// Compression will be enabled with the following options:
64+
/// Enables compression with default window sizes and no reuse. This is the
65+
/// default options used by [WebSocket.connect] if no [CompressionOptions] is
66+
/// supplied.
6167
///
6268
/// * `clientNoContextTakeover`: false
6369
/// * `serverNoContextTakeover`: false
64-
/// * `clientMaxWindowBits`: 15
65-
/// * `serverMaxWindowBits`: 15
70+
/// * `clientMaxWindowBits`: null (default maximal window size of 15 bits)
71+
/// * `serverMaxWindowBits`: null (default maximal window size of 15 bits)
6672
static const CompressionOptions compressionDefault =
6773
const CompressionOptions();
6874
@Deprecated("Use compressionDefault instead")
6975
static const CompressionOptions DEFAULT = compressionDefault;
7076

71-
/// Disables WebSocket Compression.
77+
/// No-compression configuration.
78+
///
79+
/// Disables compression when used as compression configuration for a
80+
/// [WebSocket].
7281
static const CompressionOptions compressionOff =
7382
const CompressionOptions(enabled: false);
7483
@Deprecated("Use compressionOff instead")
7584
static const CompressionOptions OFF = compressionOff;
7685

77-
/// Controls whether the client will reuse its compression instances.
86+
/// Whether the client will reuse its compression instances.
7887
final bool clientNoContextTakeover;
7988

80-
/// Controls whether the server will reuse its compression instances.
89+
/// Whether the server will reuse its compression instances.
8190
final bool serverNoContextTakeover;
8291

83-
/// Determines the max window bits for the client.
92+
/// The maximal window size bit count requested by the client.
93+
///
94+
/// The windows size for the compression is always a power of two, so the
95+
/// number of bits precisely determines the window size.
96+
///
97+
/// If set to `null`, the client has no preference, and the compression can
98+
/// use up to its default maximum window size of 15 bits depending on the
99+
/// server's preference.
84100
final int clientMaxWindowBits;
85101

86-
/// Determines the max window bits for the server.
102+
/// The maximal window size bit count requested by the server.
103+
///
104+
/// The windows size for the compression is always a power of two, so the
105+
/// number of bits precisely determines the window size.
106+
///
107+
/// If set to `null`, the server has no preference, and the compression can
108+
/// use up to its default maximum window size of 15 bits depending on the
109+
/// client's preference.
87110
final int serverMaxWindowBits;
88111

89-
/// Enables or disables WebSocket compression.
112+
/// Whether WebSocket compression is enabled.
113+
///
114+
/// If not enabled, the remaining fields have no effect, and the
115+
/// [compressionOff] instance can, and should, be reused instead of creating a
116+
/// new instance with compression disabled.
90117
final bool enabled;
91118

92119
const CompressionOptions(
93-
{this.clientNoContextTakeover: false,
94-
this.serverNoContextTakeover: false,
120+
{this.clientNoContextTakeover = false,
121+
this.serverNoContextTakeover = false,
95122
this.clientMaxWindowBits,
96123
this.serverMaxWindowBits,
97-
this.enabled: true});
124+
this.enabled = true});
98125

99126
/// Parses list of requested server headers to return server compression
100127
/// response headers.

0 commit comments

Comments
 (0)