@@ -105,27 +105,26 @@ def extract_method_header(headers):
105105
106106def is_informational_response (headers ):
107107 """
108- Searches a header block for a :status header to confirm that a given
108+ Searches headers list for a :status header to confirm that a given
109109 collection of headers are an informational response. Assumes the header
110- block is well formed: that is, that the HTTP/2 special headers are first
111- in the block, and so that it can stop looking when it finds the first
112- header field whose name does not begin with a colon.
110+ are well formed and encoded as bytes : that is, that the HTTP/2 special
111+ headers are first in the block, and so that it can stop looking when it
112+ finds the first header field whose name does not begin with a colon.
113113
114- :param headers: The HTTP/2 header block .
114+ :param headers: The HTTP/2 headers .
115115 :returns: A boolean indicating if this is an informational response.
116116 """
117117 for n , v in headers :
118- # If we find a non-special header, we're done here: stop looping.
118+ if not isinstance (n , bytes ) or not isinstance (v , bytes ):
119+ raise ProtocolError (f"header not bytes: { n = :r} , { v = :r} " ) # pragma: no cover
119120
120- if n and n [ 0 ] != SIGIL :
121+ if not n . startswith ( b':' ) :
121122 return False
122-
123- # This isn't the status header, bail.
124123 if n != b':status' :
124+ # If we find a non-special header, we're done here: stop looping.
125125 continue
126-
127126 # If the first digit is a 1, we've got informational headers.
128- return v [ 0 ] == INFORMATIONAL_START
127+ return v . startswith ( b'1' )
129128
130129
131130def guard_increment_window (current , increment ):
@@ -515,14 +514,14 @@ def utf8_encode_headers(headers):
515514 tuples that preserve the original type of the header tuple for tuple and
516515 any ``HeaderTuple``.
517516 """
518- return [
519- (
520- header . __class__ (_to_bytes (header [0 ]), _to_bytes (header [1 ]))
521- if isinstance (header , HeaderTuple )
522- else ( _to_bytes ( header [0 ]), _to_bytes ( header [1 ]))
523- )
524- for header in headers
525- ]
517+ encoded_headers = []
518+ for header in headers :
519+ h = (_to_bytes (header [0 ]), _to_bytes (header [1 ]))
520+ if isinstance (header , HeaderTuple ):
521+ encoded_headers . append ( header . __class__ ( h [0 ], h [1 ]))
522+ else :
523+ encoded_headers . append ( h )
524+ return encoded_headers
526525
527526
528527def _lowercase_header_names (headers , hdr_validation_flags ):
0 commit comments