Skip to content

Commit

Permalink
Fix #138: validate HTTP headers.
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaker committed Aug 23, 2014
1 parent 5582dd3 commit 187b4b7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions cyclone/httpserver.py
Expand Up @@ -155,12 +155,16 @@ def _on_headers(self, data):
if not version.startswith("HTTP/"):
raise _BadRequestException(
"Malformed HTTP version in HTTP Request-Line")
headers = httputil.HTTPHeaders.parse(data[eol:])
try:
headers = httputil.HTTPHeaders.parse(data[eol:])
content_length = int(headers.get("Content-Length", 0))
except ValueError:
raise _BadRequestException(
"Malformed HTTP headers")
self._request = HTTPRequest(
connection=self, method=method, uri=uri, version=version,
headers=headers, remote_ip=self._remote_ip)

content_length = int(headers.get("Content-Length", 0))
if content_length:
if headers.get("Expect") == "100-continue":
self.transport.write("HTTP/1.1 100 (Continue)\r\n\r\n")
Expand Down

0 comments on commit 187b4b7

Please sign in to comment.