Skip to content
This repository was archived by the owner on Jan 13, 2021. It is now read-only.

Commit fe2ce38

Browse files
committed
Merge pull request #111 from Lukasa/never-indexed
Support never-indexed header fields.
2 parents c5775cb + bc26bdc commit fe2ce38

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

HISTORY.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
Release History
22
===============
33

4+
Upcoming
5+
--------
6+
7+
*Bugfixes*
8+
9+
- Hyper now correctly handles 'never indexed' header fields. (`Issue #110`_)
10+
11+
.. _Issue #110: https://github.com/Lukasa/hyper/issues/110
12+
413
0.2.1 (2015-03-29)
514
------------------
615

hyper/http20/hpack.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -598,13 +598,13 @@ def _decode_literal(self, data, should_index):
598598

599599
# When should_index is true, if the low six bits of the first byte are
600600
# nonzero, the header name is indexed.
601-
# When should_index is false, if the first byte is nonzero the header
602-
# name is indexed.
601+
# When should_index is false, if the low four bits of the first byte
602+
# are nonzero the header name is indexed.
603603
if should_index:
604604
indexed_name = to_byte(data[0]) & 0x3F
605605
name_len = 6
606606
else:
607-
indexed_name = to_byte(data[0])
607+
indexed_name = to_byte(data[0]) & 0x0F
608608
name_len = 4
609609

610610
if indexed_name:

test/test_hyper.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,45 @@ def test_resizing_header_table(self):
931931
d.header_table_size = 40
932932
assert len(d.header_table) == 0
933933

934+
def test_apache_trafficserver(self):
935+
# This test reproduces the bug in #110, using exactly the same header
936+
# data.
937+
d = Decoder()
938+
data = (
939+
b'\x10\x07:status\x03200@\x06server\tATS/6.0.0'
940+
b'@\x04date\x1dTue, 31 Mar 2015 08:09:51 GMT'
941+
b'@\x0ccontent-type\ttext/html@\x0econtent-length\x0542468'
942+
b'@\rlast-modified\x1dTue, 31 Mar 2015 01:55:51 GMT'
943+
b'@\x04vary\x0fAccept-Encoding@\x04etag\x0f"5519fea7-a5e4"'
944+
b'@\x08x-served\x05Nginx@\x14x-subdomain-tryfiles\x04True'
945+
b'@\x07x-deity\thydra-lts@\raccept-ranges\x05bytes@\x03age\x010'
946+
b'@\x19strict-transport-security\rmax-age=86400'
947+
b'@\x03via2https/1.1 ATS (ApacheTrafficServer/6.0.0 [cSsNfU])'
948+
)
949+
expect = [
950+
(':status', '200'),
951+
('server', 'ATS/6.0.0'),
952+
('date', 'Tue, 31 Mar 2015 08:09:51 GMT'),
953+
('content-type', 'text/html'),
954+
('content-length', '42468'),
955+
('last-modified', 'Tue, 31 Mar 2015 01:55:51 GMT'),
956+
('vary', 'Accept-Encoding'),
957+
('etag', '"5519fea7-a5e4"'),
958+
('x-served', 'Nginx'),
959+
('x-subdomain-tryfiles', 'True'),
960+
('x-deity', 'hydra-lts'),
961+
('accept-ranges', 'bytes'),
962+
('age', '0'),
963+
('strict-transport-security', 'max-age=86400'),
964+
('via', 'https/1.1 ATS (ApacheTrafficServer/6.0.0 [cSsNfU])'),
965+
]
966+
967+
result = d.decode(data)
968+
969+
assert result == expect
970+
# The status header shouldn't be indexed.
971+
assert len(d.header_table) == len(expect) - 1
972+
934973

935974
class TestIntegerEncoding(object):
936975
# These tests are stolen from the HPACK spec.

0 commit comments

Comments
 (0)