Projet

Général

Profil

« Précédent | Suivant » 

Révision ae61b7a4

Ajouté par Jérôme Schneider il y a environ 12 ans

Fix #946: Mandaye could now decompress http response

  • config.py: add option auto_decompress which allow mandaye to
    decompress response * dispatcher.py: support decompression * http.py: add decompress method in Response class

Voir les différences:

mandaye/config.py
35 35
email_from = 'traceback@entrouvert.com'
36 36
email_to = ['admin@localhost']
37 37

  
38
# Ask Mandaye to auto decompress a response message
39
# Decompress response only if you load a filter
40
auto_decompress = True
41

  
38 42
# Encrypt external passwords with a secret
39 43
# You should install pycypto to use this feature
40 44
encrypt_ext_password = False
mandaye/dispatcher.py
4 4
from urlparse import urlparse
5 5
from importlib import import_module
6 6

  
7
from mandaye import config
7 8
from mandaye.log import logger
8 9
from mandaye.filters.default import MandayeFilter
9 10
from mandaye.response import _500, _302
......
69 70
                'response': None,
70 71
                'target': None,
71 72
                'redirect': None,
73
                'decompress': config.auto_decompress
72 74
                }
73 75

  
74 76
        if not mapping:
......
157 159
        return request
158 160

  
159 161
    def mod_response(self, request, response):
160
        """ Modify the response
162
        """ Modify the response. This will load on_response filters.
161 163
        request: the Mandaye request
162 164
        response: MandayeResponse object with cookies, headers and HTML
163 165
        you can modify the cookies and the HTTP headers """
......
173 175
                    logger.debug("Don't load filter %s (content-type %s doesn't match)" % (hook['filter'], content_type))
174 176
                    continue
175 177

  
176
            response.decompress()
178
            if self.req_mapping['decompress']:
179
                response.decompress()
177 180

  
178 181
            new_response = self._call_hook(hook, request, response)
179 182
            if new_response:
mandaye/http.py
6 6
import Cookie
7 7
import gzip
8 8
import StringIO
9
import zlib
9 10

  
10 11
class HTTPHeader(dict):
11 12
    """ Mandaye class to manage HTTP header
......
132 133
            gzipper = gzip.GzipFile(fileobj=self.msg)
133 134
            self.msg = gzipper.read()
134 135
            del self.headers['content-encoding']
136
        elif encoding.lower() == 'deflate':
137
            try:
138
                msg = zlib.decompress(self.msg, -zlib.MAX_WBITS)
139
            except zlib.error:
140
                msg = zlib.decompress(data)
141
            self.msg = msg
135 142
        else:
136 143
            logger.warning("%s unsupported content encoding format" % encoding)
137 144

  

Formats disponibles : Unified diff