Support passing HeaderTuple to HPACK encoder.
Cory Benfield
8 years ago
160 | 160 | block. |
161 | 161 | |
162 | 162 | :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``. | |
164 | 165 | |
165 | 166 | If an iterable of tuples, the tuples may be either |
166 | 167 | two-tuples or three-tuples. If they are two-tuples, the |
171 | 172 | added to header tables anywhere. If not present, |
172 | 173 | ``sensitive`` defaults to ``False``. |
173 | 174 | |
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 | ||
174 | 182 | .. warning:: HTTP/2 requires that all special headers |
175 | 183 | (headers whose names begin with ``:`` characters) |
176 | 184 | appear at the *start* of the header block. While |
213 | 221 | |
214 | 222 | # Add each header to the header block |
215 | 223 | 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 | ||
217 | 230 | header = (_to_bytes(header[0]), _to_bytes(header[1])) |
218 | 231 | header_block.append(self.add(header, sensitive, huffman)) |
219 | 232 |