Ticket #376: django-modpython.2.patch

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

Universal mod_python (2.x, 3.x) handler, synced with svn code (with ap_auth_type and user for mod_python2.x).

  • 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            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
    92106            self._meta = {
    93                 'AUTH_TYPE':         self._req.ap_auth_type,
     107                'AUTH_TYPE':         auth_type,
    94108                'CONTENT_LENGTH':    self._req.clength, # This may be wrong
    95109                'CONTENT_TYPE':      self._req.content_type, # This may be wrong
    96110                'GATEWAY_INTERFACE': 'CGI/1.1',
    class ModPythonRequest(http.HttpRequest)  
    100114                'REMOTE_ADDR':       self._req.connection.remote_ip,
    101115                'REMOTE_HOST':       None, # DNS lookups not supported
    102116                'REMOTE_IDENT':      self._req.connection.remote_logname,
    103                 'REMOTE_USER':       self._req.user,
     117                'REMOTE_USER':       user,
    104118                'REQUEST_METHOD':    self._req.method,
    105119                'SCRIPT_NAME':       None, # Not supported
    106120                'SERVER_NAME':       self._req.server.server_hostname,
    class ModPythonRequest(http.HttpRequest)  
    108122                'SERVER_PROTOCOL':   self._req.protocol,
    109123                'SERVER_SOFTWARE':   'mod_python'
    110124            }
    111             for key, value in self._req.headers_in.items():
    112                 key = 'HTTP_' + key.upper().replace('-', '_')
    113                 self._meta[key] = value
     125            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]
    114128        return self._meta
    115129
    116130    def _get_raw_post_data(self):
    class ModPythonHandler(BaseHandler):  
    165179        for c in response.cookies.values():
    166180            req.headers_out.add('Set-Cookie', c.output(header=''))
    167181        req.status = response.status_code
     182        if hasattr(req, 'send_http_header'):
     183            req.send_http_header()
    168184        try:
    169185            for chunk in response:
    170186                req.write(chunk)
Back to Top