Ticket #376: django-modpython.patch

File django-modpython.patch, 4.0 KB (added by Andrew Fedorov, 17 years ago)

Universal mod_python (2.x, 3.x) handler, synced with svn code.

  • core/handlers/modpython.py

    diff -uprN django.orig/core/handlers/modpython.py django/core/handlers/modpython.py
    old new class ModPythonRequest(http.HttpRequest)  
    4343
    4444    def is_secure(self):
    4545        # Note: modpython 3.2.10+ has req.is_https(), but we need to support previous versions
    46         return 'HTTPS' in self._req.subprocess_env and self._req.subprocess_env['HTTPS'] == 'on'
     46        return self._req.subprocess_env.has_key('HTTPS') and self._req.subprocess_env['HTTPS'] == 'on'
    4747
    4848    def _load_post_and_files(self):
    4949        "Populates self._post and self._files"
    50         if 'content-type' in self._req.headers_in and 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'):
    5151            self._post, self._files = http.parse_file_upload(self._req.headers_in, self.raw_post_data)
    5252        else:
    5353            self._post, self._files = http.QueryDict(self.raw_post_data, encoding=self._encoding), datastructures.MultiValueDict()
    class ModPythonRequest(http.HttpRequest)  
    7575
    7676    def _get_cookies(self):
    7777        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'])
    7981        return self._cookies
    8082
    8183    def _set_cookies(self, cookies):
    class ModPythonRequest(http.HttpRequest)  
    8991    def _get_meta(self):
    9092        "Lazy loader that returns self.META dictionary"
    9193        if not hasattr(self, '_meta'):
     94            if hasattr(self._req, 'ap_auth_type'):
     95                auth_type = self._req.ap_auth_type
     96            else:
     97                auth_type = None
     98            if hasattr(self._req, 'user'):
     99                user = self._req.user
     100            else:
     101                user = None
    92102            self._meta = {
    93                 'AUTH_TYPE':         self._req.ap_auth_type,
     103                'AUTH_TYPE':         auth_type,
    94104                'CONTENT_LENGTH':    self._req.clength, # This may be wrong
    95105                'CONTENT_TYPE':      self._req.content_type, # This may be wrong
    96106                'GATEWAY_INTERFACE': 'CGI/1.1',
    class ModPythonRequest(http.HttpRequest)  
    100110                'REMOTE_ADDR':       self._req.connection.remote_ip,
    101111                'REMOTE_HOST':       None, # DNS lookups not supported
    102112                'REMOTE_IDENT':      self._req.connection.remote_logname,
    103                 'REMOTE_USER':       self._req.user,
     113                'REMOTE_USER':       user,
    104114                'REQUEST_METHOD':    self._req.method,
    105115                'SCRIPT_NAME':       None, # Not supported
    106116                'SERVER_NAME':       self._req.server.server_hostname,
    class ModPythonRequest(http.HttpRequest)  
    108118                'SERVER_PROTOCOL':   self._req.protocol,
    109119                'SERVER_SOFTWARE':   'mod_python'
    110120            }
    111             for key, value in self._req.headers_in.items():
    112                 key = 'HTTP_' + key.upper().replace('-', '_')
    113                 self._meta[key] = value
     121            for key in self._req.headers_in.keys():
     122                meta_key = 'HTTP_' + key.upper().replace('-', '_')
     123                self._meta[meta_key] = self._req.headers_in[key]
    114124        return self._meta
    115125
    116126    def _get_raw_post_data(self):
    class ModPythonHandler(BaseHandler):  
    165175        for c in response.cookies.values():
    166176            req.headers_out.add('Set-Cookie', c.output(header=''))
    167177        req.status = response.status_code
     178        if hasattr(req, 'send_http_header'):
     179            req.send_http_header()
    168180        try:
    169181            for chunk in response:
    170182                req.write(chunk)
Back to Top