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

Commit

Permalink
Merge branch '0.5.x'
Browse files Browse the repository at this point in the history
# Conflicts:
#	httpolice/__metadata__.py
  • Loading branch information
vfaronov committed Mar 24, 2017
2 parents 573b7f4 + 869d924 commit 7fd0dfc
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 11 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ This project adheres to `Semantic Versioning <http://semver.org/>`_
(which means it is unstable until 1.0).


0.5.2 - 2017-03-24
~~~~~~~~~~~~~~~~~~
- Fixed a few rare crashing bugs found with `american fuzzy lop`_.
- Fixed a couple cosmetic bugs in HTML reports.
- When parsing a message with an unknown `transfer coding`_, HTTPolice now
correctly skips any checks on its payload body (such as notice `1038`_).

.. _american fuzzy lop: http://lcamtuf.coredump.cx/afl/
.. _transfer coding: https://tools.ietf.org/html/rfc7230#section-4


0.5.1 - 2017-03-15
~~~~~~~~~~~~~~~~~~
- Fixed compatibility with `httpolice-devtool`_ (when you point it to a local
Expand Down
4 changes: 2 additions & 2 deletions httpolice/framing1.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,9 @@ def _decode_transfer_coding(msg, coding):
except Exception as e:
msg.complain(1027, coding=coding, error=e)
msg.body = Unavailable
elif okay(coding):
msg.complain(1003, coding=coding)
else:
if okay(coding):
msg.complain(1003, coding=coding)
msg.body = Unavailable


Expand Down
3 changes: 2 additions & 1 deletion httpolice/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ def xml_data(self):
except defusedxml.EntitiesForbidden:
self.complain(1275)
return Unavailable
except xml.etree.ElementTree.ParseError as e:
# http://bugs.python.org/issue29896
except (xml.etree.ElementTree.ParseError, UnicodeError) as e:
self.complain(1039, error=e)
return Unavailable
else:
Expand Down
9 changes: 4 additions & 5 deletions httpolice/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,9 +652,8 @@ def skip(self, n):
def consume_n_bytes(self, n):
r = self.peek(n)
if len(r) < n:
raise ParseError(name=self.name, point=self.point,
found=u'%d bytes' % len(r),
expected=[(u'%d bytes' % n,)])
raise ParseError(self.name, self.point, found=None,
expected=[(u'%d bytes' % n, None)])
else:
self.point += n
return r
Expand Down Expand Up @@ -740,8 +739,8 @@ def collect_annotations(self):
class ParseError(Exception):

def __init__(self, name, point, found, expected):
super(ParseError, self).__init__(u'unexpected %r at byte position %r' %
(found, point))
super(ParseError, self).__init__(
u'unexpected input at byte position %r' % point)
self.name = name
self.point = point
self.found = found
Expand Down
4 changes: 2 additions & 2 deletions httpolice/reports/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def _common_meta(document):
H.meta(charset=u'utf-8')
H.meta(name=u'generator', content=u'HTTPolice %s' % version)
H.style(type=u'text/css').add_raw_string(css_code)
H.base(_target=u'blank')
H.base(target=u'_blank')


def _render_exchanges(exchanges, trashcan):
Expand Down Expand Up @@ -288,7 +288,7 @@ def _render_known(obj):
text = printable(six.text_type(obj))
cite = known.citation(obj)
if cite:
with H.a(text, href=cite.url, title=None):
with H.a(text, href=cite.url):
title = known.title(obj, with_citation=True)
if title:
H.attr(title=title)
Expand Down
5 changes: 4 additions & 1 deletion httpolice/syntax/rfc7231.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,10 @@ def _obsolete_date(complain, r):
def _check_day_of_week(complain, r):
(claimed_dow, r) = r
if r is not Unavailable and r.weekday() != claimed_dow:
complain(1108, date=r.strftime(u'%Y-%m-%d'),
# Don't use `strftime` here because it raises `ValueError`
# on years < 1900 in Python 2.7. (Of course, year < 1900
# in ``Date`` is pathological, but that's no excuse to crash).
complain(1108, date=u'%04d-%02d-%02d' % (r.year, r.month, r.day),
claimed=_DAY_NAMES[claimed_dow],
actual=_DAY_NAMES[r.weekday()])
return r
Expand Down
21 changes: 21 additions & 0 deletions test/combined_data/1005_4
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
1005 1007

# The chunked stream is abruptly cut off before the indicated number of bytes.
# This used to crash HTTPolice when generating an HTML report.

======== BEGIN INBOUND STREAM ========
POST / HTTP/1.1
Host: example.com
Content-Type: text/plain
User-Agent: demo
Transfer-Encoding: chunked

1c
foo bar foo bar
======== BEGIN OUTBOUND STREAM ========
HTTP/1.1 200 OK
Date: Thu, 31 Dec 2015 18:26:56 GMT
Content-Type: text/plain
Content-Length: 14

Hello world!
16 changes: 16 additions & 0 deletions test/combined_data/1039_2
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
1039

# This used to crash HTTPolice.

======== BEGIN INBOUND STREAM ========
GET / HTTP/1.1
Host: example.com
User-Agent: demo

======== BEGIN OUTBOUND STREAM ========
HTTP/1.1 200 OK
Date: Thu, 31 Dec 2015 18:26:56 GMT
Content-Type: text/xml
Content-Length: 12

<resu�ts/>
16 changes: 16 additions & 0 deletions test/combined_data/1108_2
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
1108

# This used to crash HTTPolice on Python 2.7.

======== BEGIN INBOUND STREAM ========
GET / HTTP/1.1
Host: example.com
User-Agent: demo

======== BEGIN OUTBOUND STREAM ========
HTTP/1.1 200 OK
Date: Fri, 02 Aug 1015 18:26:56 GMT
Content-Type: text/plain
Content-Length: 14

Hello world!
5 changes: 5 additions & 0 deletions test/test_streams_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ def test_chunked_empty():
assert exch1.request.body == b''


def test_unknown_transfer_encoding():
[exch1] = load_from_file('1003_1')
assert exch1.responses[0].body is Unavailable


def test_implicit_response_framing():
[exch1] = load_from_file('1025_2')
assert exch1.responses[0].body == b'Hello world!\r\n'
Expand Down

0 comments on commit 7fd0dfc

Please sign in to comment.