diff -uprN django.orig/core/handlers/modpython.py django/core/handlers/modpython.py
old
|
new
|
class ModPythonRequest(http.HttpRequest)
|
47 | 47 | return self._req.is_https() |
48 | 48 | except AttributeError: |
49 | 49 | # mod_python < 3.2.10 doesn't have req.is_https(). |
50 | | return self._req.subprocess_env.get('HTTPS', '').lower() in ('on', '1') |
| 50 | return self._req.subprocess_env.has_key('HTTPS') and self._req.subprocess_env['HTTPS'].lower() in ('on', '1') |
51 | 51 | |
52 | 52 | def _load_post_and_files(self): |
53 | 53 | "Populates self._post and self._files" |
54 | | if 'content-type' in self._req.headers_in and self._req.headers_in['content-type'].startswith('multipart'): |
| 54 | if self._req.headers_in.has_key('content-type') and self._req.headers_in['content-type'].startswith('multipart'): |
55 | 55 | self._post, self._files = http.parse_file_upload(self._req.headers_in, self.raw_post_data) |
56 | 56 | else: |
57 | 57 | self._post, self._files = http.QueryDict(self.raw_post_data, encoding=self._encoding), datastructures.MultiValueDict() |
… |
… |
class ModPythonRequest(http.HttpRequest)
|
79 | 79 | |
80 | 80 | def _get_cookies(self): |
81 | 81 | if not hasattr(self, '_cookies'): |
82 | | self._cookies = http.parse_cookie(self._req.headers_in.get('cookie', '')) |
| 82 | # mod_python2 Table object does not have get() method |
| 83 | if not self._req.headers_in.has_key('cookie'): |
| 84 | self._req.headers_in['cookie'] = '' |
| 85 | self._cookies = http.parse_cookie(self._req.headers_in['cookie']) |
83 | 86 | return self._cookies |
84 | 87 | |
85 | 88 | def _set_cookies(self, cookies): |
… |
… |
class ModPythonRequest(http.HttpRequest)
|
93 | 96 | def _get_meta(self): |
94 | 97 | "Lazy loader that returns self.META dictionary" |
95 | 98 | if not hasattr(self, '_meta'): |
| 99 | # ap_uath_type and user are members of request object in |
| 100 | # mod_python3, but members of request.connection in mod_python2 |
| 101 | if hasattr(self._req, 'ap_auth_type'): |
| 102 | auth_type = self._req.ap_auth_type |
| 103 | elif hasattr(self._req.connection, 'ap_auth_type'): |
| 104 | auth_type = self._req.connection.ap_auth_type |
| 105 | else: |
| 106 | auth_type = None |
| 107 | if hasattr(self._req, 'user'): |
| 108 | user = self._req.user |
| 109 | elif hasattr(self._req.connection, 'user'): |
| 110 | user = self._req.connection.user |
| 111 | else: |
| 112 | user = None |
96 | 113 | self._meta = { |
97 | | 'AUTH_TYPE': self._req.ap_auth_type, |
| 114 | 'AUTH_TYPE': auth_type, |
98 | 115 | 'CONTENT_LENGTH': self._req.clength, # This may be wrong |
99 | 116 | 'CONTENT_TYPE': self._req.content_type, # This may be wrong |
100 | 117 | 'GATEWAY_INTERFACE': 'CGI/1.1', |
… |
… |
class ModPythonRequest(http.HttpRequest)
|
104 | 121 | 'REMOTE_ADDR': self._req.connection.remote_ip, |
105 | 122 | 'REMOTE_HOST': None, # DNS lookups not supported |
106 | 123 | 'REMOTE_IDENT': self._req.connection.remote_logname, |
107 | | 'REMOTE_USER': self._req.user, |
| 124 | 'REMOTE_USER': user, |
108 | 125 | 'REQUEST_METHOD': self._req.method, |
109 | 126 | 'SCRIPT_NAME': None, # Not supported |
110 | 127 | 'SERVER_NAME': self._req.server.server_hostname, |
… |
… |
class ModPythonRequest(http.HttpRequest)
|
112 | 129 | 'SERVER_PROTOCOL': self._req.protocol, |
113 | 130 | 'SERVER_SOFTWARE': 'mod_python' |
114 | 131 | } |
115 | | for key, value in self._req.headers_in.items(): |
116 | | key = 'HTTP_' + key.upper().replace('-', '_') |
117 | | self._meta[key] = value |
| 132 | for key in self._req.headers_in.keys(): |
| 133 | meta_key = 'HTTP_' + key.upper().replace('-', '_') |
| 134 | self._meta[meta_key] = self._req.headers_in[key] |
118 | 135 | return self._meta |
119 | 136 | |
120 | 137 | def _get_raw_post_data(self): |
… |
… |
class ModPythonHandler(BaseHandler):
|
176 | 193 | req.headers_out.add('Set-Cookie', c.output(header='')) |
177 | 194 | req.status = response.status_code |
178 | 195 | try: |
| 196 | if hasattr(req, 'send_http_header'): |
| 197 | # This method exists only in mod_python2 and must be called |
| 198 | # before any data transfer |
| 199 | req.send_http_header() |
179 | 200 | for chunk in response: |
180 | 201 | req.write(chunk) |
181 | 202 | finally: |