Skip to content
This repository has been archived by the owner on Mar 29, 2022. It is now read-only.

Commit

Permalink
Do not consider headers of 103 (Early Hints) as its own
Browse files Browse the repository at this point in the history
  • Loading branch information
vfaronov committed Feb 2, 2018
1 parent 8cdd442 commit 92503b0
Show file tree
Hide file tree
Showing 5 changed files with 224 additions and 125 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Added
- Checks for quoted commas and semicolons that might confuse a naive parser
(notices `1299`_, `1300`_).
- Checks for `immutable responses`_ (notices `1301`_, `1302`_, `1303`_).
- `Early hints`_ are now recognized (due to their idiosyncratic semantics,
they avoid many checks that are applied to all other responses).
- Check for no Transfer-Encoding in response to HTTP/1.0 (notice `1306`_).
- Check for 100 (Continue) before switching protocols (notice `1305`_).
- Check that the sequence of responses to a request makes sense
Expand All @@ -24,6 +26,7 @@ Added
.. _1305: http://httpolice.readthedocs.io/page/notices.html#1305
.. _1306: http://httpolice.readthedocs.io/page/notices.html#1306
.. _immutable responses: https://tools.ietf.org/html/rfc8246
.. _Early hints: https://tools.ietf.org/html/rfc8297

Fixed
-----
Expand Down
36 changes: 22 additions & 14 deletions httpolice/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from httpolice.blackboard import Blackboard, derived_property
from httpolice.codings import decode_brotli, decode_deflate, decode_gzip
from httpolice.header import HeadersView
from httpolice.known import cc, h, media, tc, upgrade, warn
from httpolice.known import cc, h, media, st, tc, upgrade, warn
from httpolice.parse import parse
from httpolice.structure import (FieldName, HeaderEntry, HTTPVersion,
Unavailable, http2, http11, okay)
Expand Down Expand Up @@ -318,9 +318,6 @@ def check_message(msg):
u'charset' in headers.content_type.param:
complain(1280, header=headers.content_type)

if headers.upgrade.is_present and u'upgrade' not in headers.connection:
complain(1050)

if headers.date > datetime.utcnow() + timedelta(seconds=10):
complain(1109)

Expand All @@ -330,25 +327,36 @@ def check_message(msg):
if okay(warning.date) and headers.date != warning.date:
complain(1164, code=warning.code)

for pragma in headers.pragma:
if pragma != u'no-cache':
complain(1160, pragma=pragma.item)

for protocol in headers.upgrade:
if protocol.item == u'h2':
complain(1228)
if protocol.item == upgrade.h2c and msg.is_tls:
complain(1233)

if getattr(msg, 'status', None) == st.early_hints:
# 103 (Early Hints) responses are weird in that the headers they carry
# do not apply to themselves (RFC 8297 Section 2) but only to the final
# response (and then only speculatively). For such responses, we limit
# ourselves to checks that do not rely on having a complete and
# self-consistent message header block.
return

if headers.upgrade.is_present and u'upgrade' not in headers.connection:
complain(1050)

if msg.transformed_by_proxy:
if warn.transformation_applied not in headers.warning:
complain(1191)
if headers.cache_control.no_transform:
complain(1192)

for pragma in headers.pragma:
if pragma != u'no-cache':
complain(1160, pragma=pragma.item)

if version == http2:
for hdr in headers:
if hdr.name in [h.connection, h.transfer_encoding, h.keep_alive]:
complain(1244, header=hdr)
elif hdr.name == h.upgrade:
complain(1245)

for protocol in headers.upgrade:
if protocol.item == u'h2':
complain(1228)
if protocol.item == upgrade.h2c and msg.is_tls:
complain(1233)

0 comments on commit 92503b0

Please sign in to comment.