]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Be less picky about line endings in headers in httpclient.
authorBen Darnell <ben@bendarnell.com>
Mon, 9 Aug 2010 21:33:32 +0000 (14:33 -0700)
committerBen Darnell <ben@bendarnell.com>
Mon, 9 Aug 2010 21:33:32 +0000 (14:33 -0700)
HTTP requires that lines end with \r\n, but some buggy servers (including
news.ycombinator.com) just use \n.  Libcurl tolerates this and sends the
line as-is to the header callback, so we need to be prepared to handle
either form.

tornado/httpclient.py

index 8894a64a5cd544dd3dec48432d34ca126637328d..6cba70dae30072a36bc553773db7311da6a89f6f 100644 (file)
@@ -579,10 +579,12 @@ def _curl_setup_request(curl, request, buffer, headers):
 
 
 def _curl_header_callback(headers, header_line):
+    # header_line as returned by curl includes the end-of-line characters.
+    header_line = header_line.strip()
     if header_line.startswith("HTTP/"):
         headers.clear()
         return
-    if header_line == "\r\n":
+    if not header_line:
         return
     headers.parse_line(header_line)