Skip to content

Commit

Permalink
http parser non strict mode (#2332)
Browse files Browse the repository at this point in the history
* build http-parser in non strict mode by default, add environ variable to control this mode

* add test step with http-parser built in strict mode (non-strict mode everywhere else)

* export HTTP_PARSER_STRICT flag in _http_parser module

* add tests for http-parser strict/non-strict (url parsing) mode

* add news fragment

* revert all control flags (as they were mostly for testing)
  • Loading branch information
popravich authored and asvetlov committed Oct 17, 2017
1 parent 52981af commit 96412ae
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ cov-dev: .develop
@echo "Run without extensions"
@AIOHTTP_NO_EXTENSIONS=1 py.test --cov=aiohttp tests
@py.test --cov=aiohttp --cov-report=term --cov-report=html --cov-append tests
@echo "open file://`pwd`/coverage/index.html"
@echo "open file://`pwd`/coverage/index.html"

cov-ci-no-ext: .develop
@echo "Run without extensions"
Expand Down
1 change: 1 addition & 0 deletions changes/2332.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Build http-parser extension in non-strict mode by default.
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@

ext = '.pyx' if USE_CYTHON else '.c'


extensions = [Extension('aiohttp._websocket', ['aiohttp/_websocket' + ext]),
Extension('aiohttp._http_parser',
['aiohttp/_http_parser' + ext,
'vendor/http-parser/http_parser.c'],),
'vendor/http-parser/http_parser.c'],
define_macros=[('HTTP_PARSER_STRICT', 0)],
),
Extension('aiohttp._frozenlist',
['aiohttp/_frozenlist' + ext])]

Expand Down
13 changes: 13 additions & 0 deletions tests/test_http_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,19 @@ def test_partial_url(parser):
assert payload.is_eof()


def test_url_parse_non_strict_mode(parser):
payload = 'GET /test/тест HTTP/1.1\r\n\r\n'.encode('utf-8')
messages, upgrade, tail = parser.feed_data(payload)
assert len(messages) == 1

msg, payload = messages[0]

assert msg.method == 'GET'
assert msg.path == '/test/тест'
assert msg.version == (1, 1)
assert payload.is_eof()


class TestParsePayload(unittest.TestCase):

def setUp(self):
Expand Down

0 comments on commit 96412ae

Please sign in to comment.