@@ -71,13 +71,13 @@ def __init__(
71
71
server_max_window_bits : Optional [int ] = None ,
72
72
) -> None :
73
73
self .client_no_context_takeover = client_no_context_takeover
74
- if client_max_window_bits is None :
75
- client_max_window_bits = self .DEFAULT_CLIENT_MAX_WINDOW_BITS
76
- self .client_max_window_bits = client_max_window_bits
77
74
self .server_no_context_takeover = server_no_context_takeover
78
- if server_max_window_bits is None :
79
- server_max_window_bits = self .DEFAULT_SERVER_MAX_WINDOW_BITS
80
- self .server_max_window_bits = server_max_window_bits
75
+ self ._client_max_window_bits = self .DEFAULT_CLIENT_MAX_WINDOW_BITS
76
+ self ._server_max_window_bits = self .DEFAULT_SERVER_MAX_WINDOW_BITS
77
+ if client_max_window_bits is not None :
78
+ self .client_max_window_bits = client_max_window_bits
79
+ if server_max_window_bits is not None :
80
+ self .server_max_window_bits = server_max_window_bits
81
81
82
82
self ._compressor : Optional [zlib ._Compress ] = None # noqa
83
83
self ._decompressor : Optional [zlib ._Decompress ] = None # noqa
@@ -90,6 +90,26 @@ def __init__(
90
90
91
91
self ._enabled = False
92
92
93
+ @property
94
+ def client_max_window_bits (self ) -> int :
95
+ return self ._client_max_window_bits
96
+
97
+ @client_max_window_bits .setter
98
+ def client_max_window_bits (self , value : int ) -> None :
99
+ if value < 9 or value > 15 :
100
+ raise ValueError ("Window size must be between 9 and 15 inclusive" )
101
+ self ._client_max_window_bits = value
102
+
103
+ @property
104
+ def server_max_window_bits (self ) -> int :
105
+ return self ._server_max_window_bits
106
+
107
+ @server_max_window_bits .setter
108
+ def server_max_window_bits (self , value : int ) -> None :
109
+ if value < 9 or value > 15 :
110
+ raise ValueError ("Window size must be between 9 and 15 inclusive" )
111
+ self ._server_max_window_bits = value
112
+
93
113
def _compressible_opcode (self , opcode : Opcode ) -> bool :
94
114
return opcode in (Opcode .TEXT , Opcode .BINARY , Opcode .CONTINUATION )
95
115
@@ -127,7 +147,6 @@ def _parse_params(self, params: str) -> Tuple[Optional[int], Optional[int]]:
127
147
client_max_window_bits = None
128
148
server_max_window_bits = None
129
149
130
- print (params )
131
150
bits = [b .strip () for b in params .split (";" )]
132
151
for bit in bits [1 :]:
133
152
if bit .startswith ("client_no_context_takeover" ):
@@ -147,25 +166,27 @@ def _parse_params(self, params: str) -> Tuple[Optional[int], Optional[int]]:
147
166
148
167
return client_max_window_bits , server_max_window_bits
149
168
150
- def accept (self , offer : str ) -> Union [bool , str ]:
169
+ def accept (self , offer : str ) -> Union [bool , None , str ]:
151
170
client_max_window_bits , server_max_window_bits = self ._parse_params (offer )
152
171
153
- self ._enabled = True
154
-
155
172
parameters = []
156
173
157
174
if self .client_no_context_takeover :
158
175
parameters .append ("client_no_context_takeover" )
159
- if client_max_window_bits is not None :
160
- parameters .append ("client_max_window_bits=%d" % client_max_window_bits )
161
- self .client_max_window_bits = client_max_window_bits
162
176
if self .server_no_context_takeover :
163
177
parameters .append ("server_no_context_takeover" )
164
- if server_max_window_bits is not None :
165
- parameters .append ("server_max_window_bits=%d" % server_max_window_bits )
166
- self .server_max_window_bits = server_max_window_bits
167
-
168
- return "; " .join (parameters )
178
+ try :
179
+ if client_max_window_bits is not None :
180
+ parameters .append ("client_max_window_bits=%d" % client_max_window_bits )
181
+ self .client_max_window_bits = client_max_window_bits
182
+ if server_max_window_bits is not None :
183
+ parameters .append ("server_max_window_bits=%d" % server_max_window_bits )
184
+ self .server_max_window_bits = server_max_window_bits
185
+ except ValueError :
186
+ return None
187
+ else :
188
+ self ._enabled = True
189
+ return "; " .join (parameters )
169
190
170
191
def frame_inbound_header (
171
192
self ,
@@ -257,7 +278,6 @@ def frame_outbound(
257
278
bits = self .client_max_window_bits
258
279
else :
259
280
bits = self .server_max_window_bits
260
- print (bits , self .client_max_window_bits , self .server_max_window_bits )
261
281
self ._compressor = zlib .compressobj (
262
282
zlib .Z_DEFAULT_COMPRESSION , zlib .DEFLATED , - int (bits )
263
283
)
0 commit comments