diff --git a/django/core/handlers/wsgi.py b/django/core/handlers/wsgi.py
index 7d2ee44..3b0273f 100644
|
a
|
b
|
class WSGIHandler(base.BaseHandler):
|
| 238 | 238 | signals.request_finished.send(sender=self.__class__) |
| 239 | 239 | |
| 240 | 240 | try: |
| 241 | | status_text = STATUS_CODE_TEXT[response.status_code] |
| | 241 | status_text = response.status_text or STATUS_CODE_TEXT[response.status_code] |
| 242 | 242 | except KeyError: |
| 243 | 243 | status_text = 'UNKNOWN STATUS CODE' |
| 244 | 244 | status = '%s %s' % (response.status_code, status_text) |
diff --git a/django/http/__init__.py b/django/http/__init__.py
index 49acd57..0b1d279 100644
|
a
|
b
|
class HttpResponseBase(object):
|
| 537 | 537 | """ |
| 538 | 538 | |
| 539 | 539 | status_code = 200 |
| | 540 | status_text = None |
| 540 | 541 | |
| 541 | 542 | def __init__(self, content_type=None, status=None, mimetype=None): |
| 542 | 543 | # _headers is a mapping of the lower-case name to the original case of |
| … |
… |
class HttpResponseBase(object):
|
| 554 | 555 | self._charset) |
| 555 | 556 | self.cookies = SimpleCookie() |
| 556 | 557 | if status: |
| 557 | | self.status_code = status |
| | 558 | if isinstance(status, (list, tuple)): |
| | 559 | self.status_code, self.status_text = status |
| | 560 | else: |
| | 561 | self.status_code = status |
| 558 | 562 | |
| 559 | 563 | self['Content-Type'] = content_type |
| 560 | 564 | |
diff --git a/docs/ref/request-response.txt b/docs/ref/request-response.txt
index 89d0fe8..cc0fc51 100644
|
a
|
b
|
Attributes
|
| 622 | 622 | |
| 623 | 623 | The `HTTP Status code`_ for the response. |
| 624 | 624 | |
| | 625 | .. attribute:: HttpResponse.status_text |
| | 626 | |
| | 627 | .. versionadded:: 1.5 |
| | 628 | |
| | 629 | The `HTTP Status code`_ text for the response. This is the human readable |
| | 630 | string passed with the status code in the status line. If not provided, the |
| | 631 | standard text corresponding to ``status_code`` is used. |
| | 632 | |
| 625 | 633 | .. attribute:: HttpResponse.streaming |
| 626 | 634 | |
| 627 | 635 | This is always ``False``. |
| … |
… |
Methods
|
| 650 | 658 | |
| 651 | 659 | Historically, this parameter was called ``mimetype`` (now deprecated). |
| 652 | 660 | |
| 653 | | ``status`` is the `HTTP Status code`_ for the response. |
| | 661 | ``status`` is either the `HTTP Status code`_ for the response or a tuple |
| | 662 | containing the status code together with a customized status text. For |
| | 663 | example:: |
| | 664 | |
| | 665 | status=(404, "We are so sorry, this page has not been found") |
| 654 | 666 | |
| 655 | 667 | |
| 656 | 668 | .. method:: HttpResponse.__setitem__(header, value) |
diff --git a/tests/regressiontests/httpwrappers/tests.py b/tests/regressiontests/httpwrappers/tests.py
index bfb4ae1..33e1d88 100644
|
a
|
b
|
class HttpResponseTests(unittest.TestCase):
|
| 283 | 283 | self.assertRaises(BadHeaderError, r.__setitem__, 'test\rstr', 'test') |
| 284 | 284 | self.assertRaises(BadHeaderError, r.__setitem__, 'test\nstr', 'test') |
| 285 | 285 | |
| | 286 | def test_status(self): |
| | 287 | """ |
| | 288 | Test setting of status code and status text |
| | 289 | """ |
| | 290 | r = HttpResponse() |
| | 291 | self.assertEqual(r.status_code, 200) |
| | 292 | self.assertEqual(r.status_text, None) |
| | 293 | r = HttpResponse(status=(202, "Thanks!")) |
| | 294 | self.assertEqual(r.status_code, 202) |
| | 295 | self.assertEqual(r.status_text, "Thanks!") |
| | 296 | |
| 286 | 297 | def test_dict_behavior(self): |
| 287 | 298 | """ |
| 288 | 299 | Test for bug #14020: Make HttpResponse.get work like dict.get |
diff --git a/tests/regressiontests/wsgi/tests.py b/tests/regressiontests/wsgi/tests.py
index 6c1483d..4a6ec97 100644
|
a
|
b
|
class WSGITest(TestCase):
|
| 42 | 42 | bytes(response), |
| 43 | 43 | b"Content-Type: text/html; charset=utf-8\r\n\r\nHello World!") |
| 44 | 44 | |
| | 45 | def test_custom_status(self): |
| | 46 | application = get_wsgi_application() |
| | 47 | environ = RequestFactory().get('/status/').environ |
| | 48 | |
| | 49 | response_data = {} |
| | 50 | |
| | 51 | def start_response(status, headers): |
| | 52 | response_data["status"] = status |
| | 53 | response_data["headers"] = headers |
| | 54 | |
| | 55 | response = application(environ, start_response) |
| | 56 | |
| | 57 | self.assertEqual(response_data["status"], "220 Pretty good") |
| | 58 | |
| 45 | 59 | |
| 46 | 60 | class GetInternalWSGIApplicationTest(unittest.TestCase): |
| 47 | 61 | @override_settings(WSGI_APPLICATION="regressiontests.wsgi.wsgi.application") |
diff --git a/tests/regressiontests/wsgi/urls.py b/tests/regressiontests/wsgi/urls.py
index 9639f0f..f8d40d6 100644
|
a
|
b
|
from django.http import HttpResponse
|
| 4 | 4 | def helloworld(request): |
| 5 | 5 | return HttpResponse("Hello World!") |
| 6 | 6 | |
| | 7 | def custom_status(request): |
| | 8 | return HttpResponse("Hello", status=[220, "Pretty good"]) |
| | 9 | |
| 7 | 10 | urlpatterns = patterns( |
| 8 | 11 | "", |
| 9 | | url("^$", helloworld) |
| | 12 | url("^$", helloworld), |
| | 13 | url("^status/$", custom_status), |
| 10 | 14 | ) |