﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
112	WSGI requires a HTTP reason in the status	sune.kirkeby@…	Adrian Holovaty	"The WSGI-spec clearly requires a reason-phrase when calling start_response, and Apache breaks proxied responses that are missing the reason phrase. So the Django wsgi-adapter is quite broken in the respect.

Below is a patch which fixes this.

The mapping of HTTP reason-phrases is incomplete, but at least now Django works when being proxied by Apache.

{{{
Index: core/handlers/wsgi.py
===================================================================
--- core/handlers/wsgi.py       (revision 241)
+++ core/handlers/wsgi.py       (working copy)
@@ -1,6 +1,12 @@
 from django.utils import datastructures, httpwrappers
 from pprint import pformat

+reasons = {
+    200: 'Ok',
+    404: 'Not found',
+    500: 'Internal Server Error',
+}
+
 class WSGIRequest(httpwrappers.HttpRequest):
     def __init__(self, environ):
         self.environ = environ
@@ -121,7 +127,7 @@
         for middleware_method in self._response_middleware:
             response = middleware_method(request, response)

-        status = str(response.status_code) + ' ' # TODO: Extra space here is a hack.
+        status = '%d %s' % (response.status_code, reasons.get(response.status_code, 'Unknown status-code'))
         response_headers = response.headers
         if response.cookies:
             response_headers['Set-Cookie'] = response.cookies.output(header='')
}}}"	defect	closed	Core (Other)		normal	fixed	wsgi		Unreviewed	0	0	0	0	0	0
