Ticket #376: django-modpython.2.patch
| File django-modpython.2.patch, 4.2 kB (added by Andrew Fedorov, 10 months ago) |
|---|
-
django/core/handlers/modpython.py
old new 43 43 44 44 def is_secure(self): 45 45 # Note: modpython 3.2.10+ has req.is_https(), but we need to support previous versions 46 return 'HTTPS' in self._req.subprocess_envand self._req.subprocess_env['HTTPS'] == 'on'46 return self._req.subprocess_env.has_key('HTTPS') and self._req.subprocess_env['HTTPS'] == 'on' 47 47 48 48 def _load_post_and_files(self): 49 49 "Populates self._post and self._files" 50 if 'content-type' in self._req.headers_inand self._req.headers_in['content-type'].startswith('multipart'):50 if self._req.headers_in.has_key('content-type') and self._req.headers_in['content-type'].startswith('multipart'): 51 51 self._post, self._files = http.parse_file_upload(self._req.headers_in, self.raw_post_data) 52 52 else: 53 53 self._post, self._files = http.QueryDict(self.raw_post_data, encoding=self._encoding), datastructures.MultiValueDict() … … 75 75 76 76 def _get_cookies(self): 77 77 if not hasattr(self, '_cookies'): 78 self._cookies = http.parse_cookie(self._req.headers_in.get('cookie', '')) 78 if not self._req.headers_in.has_key('cookie'): 79 self._req.headers_in['cookie'] = '' 80 self._cookies = http.parse_cookie(self._req.headers_in['cookie']) 79 81 return self._cookies 80 82 81 83 def _set_cookies(self, cookies): … … 89 91 def _get_meta(self): 90 92 "Lazy loader that returns self.META dictionary" 91 93 if not hasattr(self, '_meta'): 94 if hasattr(self._req, 'ap_auth_type'): 95 auth_type = self._req.ap_auth_type 96 elif hasattr(self._req.connection, 'ap_auth_type'): 97 auth_type = self._req.connection.ap_auth_type 98 else: 99 auth_type = None 100 if hasattr(self._req, 'user'): 101 user = self._req.user 102 elif hasattr(self._req.connection, 'user'): 103 user = self._req.connection.user 104 else: 105 user = None 92 106 self._meta = { 93 'AUTH_TYPE': self._req.ap_auth_type,107 'AUTH_TYPE': auth_type, 94 108 'CONTENT_LENGTH': self._req.clength, # This may be wrong 95 109 'CONTENT_TYPE': self._req.content_type, # This may be wrong 96 110 'GATEWAY_INTERFACE': 'CGI/1.1', … … 100 114 'REMOTE_ADDR': self._req.connection.remote_ip, 101 115 'REMOTE_HOST': None, # DNS lookups not supported 102 116 'REMOTE_IDENT': self._req.connection.remote_logname, 103 'REMOTE_USER': self._req.user,117 'REMOTE_USER': user, 104 118 'REQUEST_METHOD': self._req.method, 105 119 'SCRIPT_NAME': None, # Not supported 106 120 'SERVER_NAME': self._req.server.server_hostname, … … 108 122 'SERVER_PROTOCOL': self._req.protocol, 109 123 'SERVER_SOFTWARE': 'mod_python' 110 124 } 111 for key , value in self._req.headers_in.items():112 key = 'HTTP_' + key.upper().replace('-', '_')113 self._meta[ key] = value125 for key in self._req.headers_in.keys(): 126 meta_key = 'HTTP_' + key.upper().replace('-', '_') 127 self._meta[meta_key] = self._req.headers_in[key] 114 128 return self._meta 115 129 116 130 def _get_raw_post_data(self): … … 165 179 for c in response.cookies.values(): 166 180 req.headers_out.add('Set-Cookie', c.output(header='')) 167 181 req.status = response.status_code 182 if hasattr(req, 'send_http_header'): 183 req.send_http_header() 168 184 try: 169 185 for chunk in response: 170 186 req.write(chunk)
