Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Apply my own suggested changes from pull request #555.

  • Loading branch information...
commit e5805a959ca96fc237d4681235ea6f1af0edfee4 1 parent 719215b
@bdarnell bdarnell authored
Showing with 15 additions and 13 deletions.
  1. +5 −3 tornado/httpclient.py
  2. +10 −8 tornado/web.py
  3. +0 −2  tornado/wsgi.py
View
8 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:
View
18 tornado/web.py
@@ -231,7 +231,7 @@ def clear(self):
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 @@ def set_status(self, status_code, reason=None):
: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 @@ def write_error(self, status_code, **kwargs):
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 @@ def _execute(self, transforms, *args, **kwargs):
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 @@ def __init__(self, status_code, log_message=None, *args, **kwargs):
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:
View
2  tornado/wsgi.py
@@ -115,8 +115,6 @@ def __call__(self, environ, start_response):
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"):
Please sign in to comment.
Something went wrong with that request. Please try again.