diff --git a/sanic/server.py b/sanic/server.py index fd31680e..81b56bad 100644 --- a/sanic/server.py +++ b/sanic/server.py @@ -99,6 +99,7 @@ class HttpProtocol(asyncio.Protocol): self._request_handler_task = None self._request_stream_task = None self._keep_alive = keep_alive + self._header_fragment = b'' self.state = state if state else {} if 'requests_count' not in self.state: self.state['requests_count'] = 0 @@ -173,14 +174,25 @@ class HttpProtocol(asyncio.Protocol): self.write_error(exception) def on_url(self, url): - self.url = url + if not self.url: + self.url = url + else: + self.url += url def on_header(self, name, value): - if name == b'Content-Length' and int(value) > self.request_max_size: - exception = PayloadTooLarge('Payload Too Large') - self.write_error(exception) + self._header_fragment += name - self.headers.append((name.decode().casefold(), value.decode())) + 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( + (self._header_fragment.decode().casefold(), + value.decode())) + + self._header_fragment = b'' def on_headers_complete(self): self.request = self.request_class(