Ejemplo n.º 1
0
    def inner_func(request, response):
        if asbool(response.get(DIAZO_OFF_HEADER, 'no')):
            return response

        content_type = response.get('Content-Type', '')
        if not content_type:
            return response

        no_diazo = True
        for content_type in ALLOWED_CONTENT_TYPES:
            if content_type in response.get('Content-Type', ''):
                no_diazo = False
                break
        if no_diazo:
            return response

        content_encoding = response.get('Content-Encoding')
        if content_encoding in ('zip', 'deflate', 'compress',):
            return response

        if 300 <= response.status_code <= 399 or response.status_code in [204, 401]:
            return response

        if len(response.content) == 0:
            return response

        return process_response(request, response)
Ejemplo n.º 2
0
    def inner_func(request, response):
        if asbool(response.get(DIAZO_OFF_HEADER, 'no')):
            return response

        content_type = response.get('Content-Type', '')
        if not content_type:
            return response

        no_diazo = True
        for content_type in ALLOWED_CONTENT_TYPES:
            if content_type in response.get('Content-Type', ''):
                no_diazo = False
                break
        if no_diazo:
            return response

        content_encoding = response.get('Content-Encoding')
        if content_encoding in ('zip', 'deflate', 'compress',):
            return response

        if 300 <= response.status_code <= 399 or response.status_code in [204, 401]:
            return response

        if len(response.content) == 0:
            return response

        return process_response(request, response)
    def __init__(self, *args, **kw):
        """Initialise the extended Diazo middleware.

        By default, we read the Diazo rules location from
        the headers if they are present in the environment.
        Sanitise the headers at the door or prepare for unforeseen
        consequences!
        """
        if not 'rules' in kw:
            kw['rules'] = None
        self.read_headers = asbool(kw.get('read_headers', 'true'))

        super(ExtendedDiazoMiddleware, self).__init__(*args, **kw)