@@ -48,6 +48,7 @@ def frame_buffer():
48
48
49
49
50
50
class TestHyperConnection (object ):
51
+
51
52
def test_connections_accept_hosts_and_ports (self ):
52
53
c = HTTP20Connection (host = 'www.google.com' , port = 8080 )
53
54
assert c .host == 'www.google.com'
@@ -499,6 +500,7 @@ def test_headers_with_continuation(self):
499
500
500
501
def test_send_tolerate_peer_gone (self ):
501
502
class ErrorSocket (DummySocket ):
503
+
502
504
def sendall (self , data ):
503
505
raise socket .error (errno .EPIPE )
504
506
@@ -700,7 +702,8 @@ def test_incrementing_window_after_close(self):
700
702
assert len (originally_sent_data ) + 1 == len (c ._sock .queue )
701
703
702
704
703
- class TestServerPush (object ):
705
+ class FrameEncoderMixin (object ):
706
+
704
707
def setup_method (self , method ):
705
708
self .frames = []
706
709
self .encoder = Encoder ()
@@ -732,6 +735,9 @@ def add_data_frame(self, stream_id, data, end_stream=False):
732
735
frame .flags .add ('END_STREAM' )
733
736
self .frames .append (frame )
734
737
738
+
739
+ class TestServerPush (FrameEncoderMixin ):
740
+
735
741
def request (self , enable_push = True ):
736
742
self .conn = HTTP20Connection ('www.google.com' , enable_push = enable_push )
737
743
self .conn ._sock = DummySocket ()
@@ -957,6 +963,7 @@ def test_pushed_requests_ignore_unexpected_headers(self):
957
963
958
964
959
965
class TestResponse (object ):
966
+
960
967
def test_status_is_stripped_from_headers (self ):
961
968
headers = HTTPHeaderMap ([(':status' , '200' )])
962
969
resp = HTTP20Response (headers , None )
@@ -1107,6 +1114,7 @@ def test_response_version(self):
1107
1114
1108
1115
1109
1116
class TestHTTP20Adapter (object ):
1117
+
1110
1118
def test_adapter_reuses_connections (self ):
1111
1119
a = HTTP20Adapter ()
1112
1120
conn1 = a .get_connection ('http2bin.org' , 80 , 'http' )
@@ -1130,6 +1138,7 @@ def test_adapter_accept_client_certificate(self):
1130
1138
1131
1139
1132
1140
class TestUtilities (object ):
1141
+
1133
1142
def test_combining_repeated_headers (self ):
1134
1143
test_headers = [
1135
1144
(b'key1' , b'val1' ),
@@ -1303,44 +1312,14 @@ def test_resetting_streams_after_close(self):
1303
1312
c ._single_read ()
1304
1313
1305
1314
1306
- class TestUpgradingPush (object ):
1315
+ class TestUpgradingPush (FrameEncoderMixin ):
1307
1316
http101 = (b"HTTP/1.1 101 Switching Protocols\r \n "
1308
1317
b"Connection: upgrade\r \n "
1309
1318
b"Upgrade: h2c\r \n "
1310
1319
b"\r \n " )
1311
1320
1312
- def setup_method (self , method ):
1313
- self .frames = [SettingsFrame (0 )] # Server side preface
1314
- self .encoder = Encoder ()
1315
- self .conn = None
1316
-
1317
- def add_push_frame (self , stream_id , promised_stream_id , headers ,
1318
- end_block = True ):
1319
- frame = PushPromiseFrame (stream_id )
1320
- frame .promised_stream_id = promised_stream_id
1321
- frame .data = self .encoder .encode (headers )
1322
- if end_block :
1323
- frame .flags .add ('END_HEADERS' )
1324
- self .frames .append (frame )
1325
-
1326
- def add_headers_frame (self , stream_id , headers , end_block = True ,
1327
- end_stream = False ):
1328
- frame = HeadersFrame (stream_id )
1329
- frame .data = self .encoder .encode (headers )
1330
- if end_block :
1331
- frame .flags .add ('END_HEADERS' )
1332
- if end_stream :
1333
- frame .flags .add ('END_STREAM' )
1334
- self .frames .append (frame )
1335
-
1336
- def add_data_frame (self , stream_id , data , end_stream = False ):
1337
- frame = DataFrame (stream_id )
1338
- frame .data = data
1339
- if end_stream :
1340
- frame .flags .add ('END_STREAM' )
1341
- self .frames .append (frame )
1342
-
1343
1321
def request (self , enable_push = True ):
1322
+ self .frames = [SettingsFrame (0 )] + self .frames # Server side preface
1344
1323
self .conn = HTTPConnection ('www.google.com' , enable_push = enable_push )
1345
1324
self .conn ._conn ._sock = DummySocket ()
1346
1325
self .conn ._conn ._sock .buffer = BytesIO (
@@ -1487,6 +1466,7 @@ def test_reset_pushed_streams_when_push_disabled(self):
1487
1466
1488
1467
# Some utility classes for the tests.
1489
1468
class NullEncoder (object ):
1469
+
1490
1470
@staticmethod
1491
1471
def encode (headers ):
1492
1472
@@ -1503,6 +1483,7 @@ def to_str(v):
1503
1483
1504
1484
1505
1485
class FixedDecoder (object ):
1486
+
1506
1487
def __init__ (self , result ):
1507
1488
self .result = result
1508
1489
@@ -1511,6 +1492,7 @@ def decode(self, headers):
1511
1492
1512
1493
1513
1494
class DummySocket (object ):
1495
+
1514
1496
def __init__ (self ):
1515
1497
self .queue = []
1516
1498
self ._buffer = BytesIO ()
@@ -1548,6 +1530,7 @@ def fill(self):
1548
1530
1549
1531
1550
1532
class DummyStream (object ):
1533
+
1551
1534
def __init__ (self , data , trailers = None ):
1552
1535
self .data = data
1553
1536
self .data_frames = []
0 commit comments