From: Ben Darnell Date: Mon, 24 Sep 2012 04:21:38 +0000 (-0400) Subject: Apply my own suggested changes from pull request #555. X-Git-Tag: v3.0.0~270 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e5805a959ca96fc237d4681235ea6f1af0edfee4;p=thirdparty%2Ftornado.git Apply my own suggested changes from pull request #555. --- diff --git a/tornado/httpclient.py b/tornado/httpclient.py index 7426ea52d..a381f9bde 100644 --- a/tornado/httpclient.py +++ b/tornado/httpclient.py @@ -332,6 +332,8 @@ class HTTPResponse(object): * code: numeric HTTP status code, e.g. 200 or 404 * reason: human-readable reason phrase describing the status code + (with curl_httpclient, this is a default value rather than the + server's actual response) * headers: httputil.HTTPHeaders object @@ -349,12 +351,12 @@ class HTTPResponse(object): plus 'queue', which is the delay (if any) introduced by waiting for a slot under AsyncHTTPClient's max_clients setting. """ - def __init__(self, request, code, reason=None, headers=None, buffer=None, + def __init__(self, request, code, headers=None, buffer=None, effective_url=None, error=None, request_time=None, - time_info=None): + time_info=None, reason=None): self.request = request self.code = code - self.reason = reason + self.reason = reason or httplib.responses.get(code, "Unknown") if headers is not None: self.headers = headers else: diff --git a/tornado/web.py b/tornado/web.py index 87b52e926..21508e70e 100644 --- a/tornado/web.py +++ b/tornado/web.py @@ -231,7 +231,7 @@ class RequestHandler(object): self.set_header("Connection", "Keep-Alive") self._write_buffer = [] self._status_code = 200 - self._reason = None + self._reason = httplib.responses[200] def set_default_headers(self): """Override this to set HTTP headers at the beginning of the request. @@ -251,10 +251,14 @@ class RequestHandler(object): :arg string reason: Human-readable reason phrase describing the status code. If ``None``, it will be filled in from `httplib.responses`. """ - if reason is None and status_code not in httplib.responses: - raise ValueError("unknown status code %d", status_code) self._status_code = status_code - self._reason = escape.native_str(reason) + if reason is not None: + self._reason = escape.native_str(reason) + else: + try: + self._reason = httplib.responses[status_code] + except KeyError: + raise ValueError("unknown status code %d", status_code) def get_status(self): """Returns the status code for our response.""" @@ -807,7 +811,7 @@ class RequestHandler(object): self.finish("%(code)d: %(message)s" "%(code)d: %(message)s" % { "code": status_code, - "message": self._reason or httplib.responses[status_code], + "message": self._reason, }) @property @@ -1065,8 +1069,6 @@ class RequestHandler(object): def _generate_headers(self): reason = self._reason - if reason is None: - reason = httplib.responses[self._status_code] lines = [utf8(self.request.version + " " + str(self._status_code) + " " + reason)] @@ -1506,7 +1508,7 @@ class HTTPError(Exception): def __str__(self): message = "HTTP %d: %s" % ( self.status_code, - self.reason or httplib.responses[self.status_code]) + self.reason or httplib.responses.get(self.status_code, 'Unknown')) if self.log_message: return message + " (" + (self.log_message % self.args) + ")" else: diff --git a/tornado/wsgi.py b/tornado/wsgi.py index 8cd6c7ef9..3cb08502e 100644 --- a/tornado/wsgi.py +++ b/tornado/wsgi.py @@ -115,8 +115,6 @@ class WSGIApplication(web.Application): handler = web.Application.__call__(self, HTTPRequest(environ)) assert handler._finished reason = handler._reason - if reason is None: - reason = httplib.responses[handler._status_code] status = str(handler._status_code) + " " + reason headers = handler._headers.items() + handler._list_headers if hasattr(handler, "_new_cookie"):