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

Commit

Permalink
Fix memoization of request target parses
Browse files Browse the repository at this point in the history
It wasn't working because the symbols were created anew in each call
to Request.target_form.
  • Loading branch information
vfaronov committed Jul 16, 2017
1 parent d98f1b3 commit e49a39f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Added
- HTTPolice can now use much less memory when parsing long TCP streams.
- Similarly, large HTML reports need much less memory to produce.
- Checks for the `Forwarded`_ header (notices `1296`_, `1297`_).
- Minor speedup in case when request URLs often repeat.

.. _Forwarded: https://tools.ietf.org/html/rfc7239
.. _chunk extensions: https://tools.ietf.org/html/rfc7230#section-4.1.1
Expand Down
4 changes: 1 addition & 3 deletions httpolice/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,7 @@ def parse(data, symbol, complain=None, fail_notice_id=None,

_memo = OrderedDict()

# This value was obtained by running on a large tcpflow input and increasing
# until it stopped getting faster.
MEMO_LIMIT = 200
MEMO_LIMIT = 500


def _splice_annotations(data, annotations):
Expand Down
12 changes: 8 additions & 4 deletions httpolice/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
from httpolice.util.text import force_unicode


normal_target = mark(origin_form) | mark(absolute_form)
options_target = mark(origin_form) | mark(asterisk_form) | mark(absolute_form)
connect_target = mark(authority_form)


class Request(message.Message):

def __init__(self, scheme, method, target, version, header_entries,
Expand Down Expand Up @@ -118,12 +123,11 @@ def __repr__(self):
@derived_property
def target_form(self):
if self.method == m.CONNECT:
symbol = mark(authority_form)
symbol = connect_target
elif self.method == m.OPTIONS:
symbol = (mark(origin_form) | mark(asterisk_form) |
mark(absolute_form))
symbol = options_target
else:
symbol = mark(origin_form) | mark(absolute_form)
symbol = normal_target
r = parse(self.target, symbol, self.complain, 1045,
place=u'request target')
if okay(r):
Expand Down

0 comments on commit e49a39f

Please sign in to comment.