@@ -221,6 +221,22 @@ def test_putrequest_sends_data(self):
221
221
assert len (sock .queue ) == 2
222
222
assert c ._out_flow_control_window == 65535 - len (b'hello' )
223
223
224
+ def test_request_with_utf8_bytes_body (self ):
225
+ c = HTTP20Connection ('www.google.com' )
226
+ c ._sock = DummySocket ()
227
+ body = '你好' if is_py2 else '你好' .encode ('utf-8' )
228
+ c .request ('GET' , '/' , body = body )
229
+
230
+ assert c ._out_flow_control_window == 65535 - len (body )
231
+
232
+ def test_request_with_unicode_body (self ):
233
+ c = HTTP20Connection ('www.google.com' )
234
+ c ._sock = DummySocket ()
235
+ body = '你好' .decode ('unicode-escape' ) if is_py2 else '你好'
236
+ c .request ('GET' , '/' , body = body )
237
+
238
+ assert c ._out_flow_control_window == 65535 - len (body .encode ('utf-8' ))
239
+
224
240
def test_different_request_headers (self ):
225
241
sock = DummySocket ()
226
242
@@ -581,7 +597,7 @@ def test_recv_cb_n_times(self):
581
597
582
598
def consume_single_frame ():
583
599
mutable ['counter' ] += 1
584
-
600
+
585
601
c ._consume_single_frame = consume_single_frame
586
602
c ._recv_cb ()
587
603
@@ -779,7 +795,7 @@ def test_streams_can_replace_none_headers(self):
779
795
(b"name" , b"value" ),
780
796
(b"other_name" , b"other_value" )
781
797
]
782
-
798
+
783
799
def test_stream_opening_sends_headers (self ):
784
800
def data_callback (frame ):
785
801
assert isinstance (frame , HeadersFrame )
@@ -1548,7 +1564,7 @@ def test_connection_error_when_send_out_of_range_frame(self):
1548
1564
class NullEncoder (object ):
1549
1565
@staticmethod
1550
1566
def encode (headers ):
1551
-
1567
+
1552
1568
def to_str (v ):
1553
1569
if is_py2 :
1554
1570
return str (v )
@@ -1557,7 +1573,7 @@ def to_str(v):
1557
1573
v = str (v , 'utf-8' )
1558
1574
return v
1559
1575
1560
- return '\n ' .join ("%s%s" % (to_str (name ), to_str (val ))
1576
+ return '\n ' .join ("%s%s" % (to_str (name ), to_str (val ))
1561
1577
for name , val in headers )
1562
1578
1563
1579
0 commit comments