From 1f4d4c7c64e1f6434f0c89f15108f2005b5849b7 Mon Sep 17 00:00:00 2001 From: Benedikt Reinartz Date: Wed, 26 Oct 2016 11:58:22 +0200 Subject: [PATCH] Fix invalid invocations of errors.LineTooLong. --- aiohttp/errors.py | 2 +- aiohttp/protocol.py | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/aiohttp/errors.py b/aiohttp/errors.py index 85c6eed7ba9..79e86e94da4 100644 --- a/aiohttp/errors.py +++ b/aiohttp/errors.py @@ -134,7 +134,7 @@ class LineTooLong(BadHttpMessage): def __init__(self, line, limit='Unknown'): super().__init__( - "got more than %s bytes when reading %s" % (limit, line)) + "Got more than %s bytes when reading %s." % (limit, line)) class InvalidHeader(BadHttpMessage): diff --git a/aiohttp/protocol.py b/aiohttp/protocol.py index 457f0cf5897..0cf7cf47f83 100644 --- a/aiohttp/protocol.py +++ b/aiohttp/protocol.py @@ -102,7 +102,8 @@ def parse_headers(self, lines): header_length += len(line) if header_length > self.max_field_size: raise errors.LineTooLong( - 'limit request headers fields size') + 'request header field %s' % bname.decode("utf8"), + self.max_field_size) bvalue.append(line) # next line @@ -113,7 +114,8 @@ def parse_headers(self, lines): else: if header_length > self.max_field_size: raise errors.LineTooLong( - 'limit request headers fields size') + 'request header field %s' % bname.decode("utf8"), + self.max_field_size) bvalue = bvalue.strip() @@ -173,7 +175,7 @@ def __call__(self, out, buf): raw_data = yield from buf.readuntil( b'\r\n\r\n', self.max_headers) except errors.LineLimitExceededParserError as exc: - raise errors.LineTooLong(exc.limit) from None + raise errors.LineTooLong('request header', exc.limit) from None lines = raw_data.split(b'\r\n') @@ -227,7 +229,7 @@ def __call__(self, out, buf): raw_data = yield from buf.readuntil( b'\r\n\r\n', self.max_line_size + self.max_headers) except errors.LineLimitExceededParserError as exc: - raise errors.LineTooLong(exc.limit) from None + raise errors.LineTooLong('response header', exc.limit) from None lines = raw_data.split(b'\r\n')