@@ -221,6 +221,22 @@ def test_putrequest_sends_data(self):
221221 assert len (sock .queue ) == 2
222222 assert c ._out_flow_control_window == 65535 - len (b'hello' )
223223
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+
224240 def test_different_request_headers (self ):
225241 sock = DummySocket ()
226242
@@ -581,7 +597,7 @@ def test_recv_cb_n_times(self):
581597
582598 def consume_single_frame ():
583599 mutable ['counter' ] += 1
584-
600+
585601 c ._consume_single_frame = consume_single_frame
586602 c ._recv_cb ()
587603
@@ -779,7 +795,7 @@ def test_streams_can_replace_none_headers(self):
779795 (b"name" , b"value" ),
780796 (b"other_name" , b"other_value" )
781797 ]
782-
798+
783799 def test_stream_opening_sends_headers (self ):
784800 def data_callback (frame ):
785801 assert isinstance (frame , HeadersFrame )
@@ -1548,7 +1564,7 @@ def test_connection_error_when_send_out_of_range_frame(self):
15481564class NullEncoder (object ):
15491565 @staticmethod
15501566 def encode (headers ):
1551-
1567+
15521568 def to_str (v ):
15531569 if is_py2 :
15541570 return str (v )
@@ -1557,7 +1573,7 @@ def to_str(v):
15571573 v = str (v , 'utf-8' )
15581574 return v
15591575
1560- return '\n ' .join ("%s%s" % (to_str (name ), to_str (val ))
1576+ return '\n ' .join ("%s%s" % (to_str (name ), to_str (val ))
15611577 for name , val in headers )
15621578
15631579
0 commit comments