Codebase list python-hpack / dc348dc
Support passing HeaderTuple to HPACK encoder. Cory Benfield 8 years ago
1 changed file(s) with 15 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
160160 block.
161161
162162 :param headers: The headers to encode. Must be either an iterable of
163 tuples or a ``dict``.
163 tuples, an iterable of :class:`HeaderTuple
164 <hpack.struct.HeaderTuple>`, or a ``dict``.
164165
165166 If an iterable of tuples, the tuples may be either
166167 two-tuples or three-tuples. If they are two-tuples, the
171172 added to header tables anywhere. If not present,
172173 ``sensitive`` defaults to ``False``.
173174
175 If an iterable of :class:`HeaderTuple
176 <hpack.struct.HeaderTuple>`, the tuples must always be
177 two-tuples. Instead of using ``sensitive`` as a third
178 tuple entry, use :class:`NeverIndexedHeaderTuple
179 <hpack.struct.NeverIndexedHeaderTuple>` to request that
180 the field never be indexed.
181
174182 .. warning:: HTTP/2 requires that all special headers
175183 (headers whose names begin with ``:`` characters)
176184 appear at the *start* of the header block. While
213221
214222 # Add each header to the header block
215223 for header in headers:
216 sensitive = header[2] if len(header) > 2 else False
224 sensitive = False
225 if isinstance(header, HeaderTuple):
226 sensitive = not header.indexable
227 elif len(header) > 2:
228 sensitive = header[2]
229
217230 header = (_to_bytes(header[0]), _to_bytes(header[1]))
218231 header_block.append(self.add(header, sensitive, huffman))
219232