]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Apply my own suggested changes from pull request #555.
authorBen Darnell <ben@bendarnell.com>
Mon, 24 Sep 2012 04:21:38 +0000 (00:21 -0400)
committerBen Darnell <ben@bendarnell.com>
Mon, 24 Sep 2012 04:21:38 +0000 (00:21 -0400)
tornado/httpclient.py
tornado/web.py
tornado/wsgi.py

index 7426ea52d0e59352301eb7e1050810362d7ab363..a381f9bde5378d134851d73d42073861418b2763 100644 (file)
@@ -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:
index 87b52e926397ac1b3b40713cbee8eb799fa61d31..21508e70ee675e85d3ffda84bd2a94274d4ff811 100644 (file)
@@ -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("<html><title>%(code)d: %(message)s</title>"
                         "<body>%(code)d: %(message)s</body></html>" % {
                     "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:
index 8cd6c7ef9b481d26a2f868b6f74a9577b28a9036..3cb08502ed1546c6f4065227bf0447415e50f404 100644 (file)
@@ -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"):