Skip to content

Commit

Permalink
Merge pull request sanic-org#756 from qwesda/master
Browse files Browse the repository at this point in the history
fixes sanic-org#755 fragmented headers
  • Loading branch information
r0fls authored Jul 1, 2017
2 parents b6ac3ef + b141fec commit 1e75265
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions sanic/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def __init__(self, *, loop, request_handler, error_handler,
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
Expand Down Expand Up @@ -173,14 +174,25 @@ def data_received(self, data):
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

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.headers.append((name.decode().casefold(), value.decode()))
self._header_fragment = b''

def on_headers_complete(self):
self.request = self.request_class(
Expand Down

0 comments on commit 1e75265

Please sign in to comment.