From 53a04309ffe2496f711fbbeba0dd48771a7d98ed Mon Sep 17 00:00:00 2001 From: Daniel Schwarz Date: Sat, 27 May 2017 16:28:57 +0200 Subject: [PATCH] add header_fragment handeling --- sanic/server.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/sanic/server.py b/sanic/server.py index c2950ad0..653b2ad9 100644 --- a/sanic/server.py +++ b/sanic/server.py @@ -98,6 +98,7 @@ class HttpProtocol(asyncio.Protocol): self._request_handler_task = None self._request_stream_task = None self._keep_alive = keep_alive + self._header_fragment = b'' @property def keep_alive(self): @@ -164,14 +165,20 @@ class HttpProtocol(asyncio.Protocol): self.url = url def on_header(self, name, value): - print(f'header "{name}": "{value}"') + log.debug('on_header', name, value) - if name and value: - if name == b'Content-Length' and int(value) > self.request_max_size: + self._header_fragment += name + + if value is not None: + if self._header_fragment == b'Content-Length' and int(value) > self.request_max_size: exception = PayloadTooLarge('Payload Too Large') self.write_error(exception) - self.headers.append((name.decode().casefold(), value.decode())) + self.headers.append((self._header_fragment.decode().casefold(), value.decode())) + + log.debug('added header', self._header_fragment, value) + + self._header_fragment = b'' def on_headers_complete(self): self.request = self.request_class(