@@ -1874,6 +1874,23 @@ def test_fileno_not_implemented(self):
1874
1874
with pytest .raises (NotImplementedError ):
1875
1875
resp .fileno ()
1876
1876
1877
+ def test_trailers_are_read (self ):
1878
+ trailers = [('a' , 'b' ), ('c' , 'd' )]
1879
+ stream = DummyStream (b'' , trailers = trailers )
1880
+ resp = HTTP20Response ([(':status' , '200' )], stream )
1881
+
1882
+ # Cast to dict in both places because we roundtrip through a dict
1883
+ # anyway.
1884
+ assert dict (resp .gettrailers ()) == dict (trailers )
1885
+ assert resp .gettrailer ('a' ) == 'b'
1886
+ assert resp .gettrailer ('c' ) == 'd'
1887
+
1888
+ def test_gettrailer_defaults_correctly (self ):
1889
+ resp = HTTP20Response ([(':status' , '200' )], DummyStream (b'' ))
1890
+
1891
+ assert resp .gettrailer ('a' ) is None
1892
+ assert resp .gettrailer ('a' , 'b' ) == 'b'
1893
+
1877
1894
1878
1895
class TestHTTP20Adapter (object ):
1879
1896
def test_adapter_reuses_connections (self ):
@@ -1953,11 +1970,15 @@ def close(self):
1953
1970
pass
1954
1971
1955
1972
class DummyStream (object ):
1956
- def __init__ (self , data ):
1973
+ def __init__ (self , data , trailers = None ):
1957
1974
self .data = data
1958
1975
self .closed = False
1959
1976
self .response_headers = {}
1960
1977
self ._remote_closed = False
1978
+ self .trailers = trailers
1979
+
1980
+ if self .trailers is None :
1981
+ self .trailers = []
1961
1982
1962
1983
def _read (self , * args , ** kwargs ):
1963
1984
try :
@@ -1978,3 +1999,6 @@ def close(self):
1978
1999
self .closed = True
1979
2000
else :
1980
2001
assert False
2002
+
2003
+ def gettrailers (self ):
2004
+ return self .trailers
0 commit comments