From: dano Date: Sun, 11 May 2014 02:08:18 +0000 (-0400) Subject: Improve custom reason code support. X-Git-Tag: v4.0.0b1~56^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=93b81576ed91c2deab56ad9e12f7b42bb91171fd;p=thirdparty%2Ftornado.git Improve custom reason code support. Adds support for custom reason messages to curl_httpclient. Make custom reason code HTTPError.message if one is available. --- diff --git a/tornado/curl_httpclient.py b/tornado/curl_httpclient.py index 0df7a7eea..3fc171593 100644 --- a/tornado/curl_httpclient.py +++ b/tornado/curl_httpclient.py @@ -23,6 +23,7 @@ import logging import pycurl import threading import time +import re from tornado import httputil from tornado import ioloop @@ -268,6 +269,7 @@ class CurlAsyncHTTPClient(AsyncHTTPClient): info["callback"](HTTPResponse( request=info["request"], code=code, headers=info["headers"], buffer=buffer, effective_url=effective_url, error=error, + reason=info['headers'].get("reason", None), request_time=time.time() - info["curl_start_time"], time_info=time_info)) except Exception: @@ -470,7 +472,9 @@ def _curl_header_callback(headers, header_line): header_line = header_line.strip() if header_line.startswith("HTTP/"): headers.clear() - return + m = re.search("HTTP\/\S*\s*\d+\s*(.*?)\s*$", header_line) + if m: + header_line = "Reason: %s" % m.group(1) if not header_line: return headers.parse_line(header_line) diff --git a/tornado/httpclient.py b/tornado/httpclient.py index 34716d53d..2a7965b40 100644 --- a/tornado/httpclient.py +++ b/tornado/httpclient.py @@ -502,7 +502,8 @@ class HTTPResponse(object): self.effective_url = effective_url if error is None: if self.code < 200 or self.code >= 300: - self.error = HTTPError(self.code, response=self) + self.error = HTTPError(self.code, message=self.reason, + response=self) else: self.error = None else: