(obj, extra_context)
Set cache headers according to cache policy manager for the obj.
Set cache headers according to cache policy manager for the obj.
Set cache headers according to cache policy manager for the obj .
def _setCacheHeaders(obj, extra_context):
    """Set cache headers according to cache policy manager for the obj."""
    REQUEST = getattr(obj, 'REQUEST', None)
    if REQUEST is not None:
        call_count = getattr(REQUEST, SUBTEMPLATE, 1) - 1
        setattr(REQUEST, SUBTEMPLATE, call_count)
        if call_count != 0:
            return

        # cleanup
        delattr(REQUEST, SUBTEMPLATE)

        content = aq_parent(obj)
        manager = queryUtility(ICachingPolicyManager)
        if manager is None:
            return

        view_name = obj.getId()
        headers = manager.getHTTPCachingHeaders(
                          content, view_name, extra_context
                          )
        RESPONSE = REQUEST['RESPONSE']
        for key, value in headers:
            if key == 'ETag':
                RESPONSE.setHeader(key, value, literal=1)
            # PATCH BEGIN: respect existing Cache-Control header if exists
            if key.lower() == 'cache-control':
                cache_control = RESPONSE.getHeader('cache-control')
                if cache_control:
                    existing_key_list = \
                        [e.split('=', 2)[0].strip().lower() for e in \
                         cache_control.split(',')]
                    for e in value.split(','):
                        if e.split('=', 2)[0].strip().lower() not in existing_key_list:
                            cache_control += ', %s' % e.strip()
                else:
                    cache_control = value
                RESPONSE.setHeader(key, cache_control)
            # PATCH END
            else:
                RESPONSE.setHeader(key, value)
        if headers:
            RESPONSE.setHeader('X-Cache-Headers-Set-By',
                               'CachingPolicyManager: %s' %
                               '/'.join(manager.getPhysicalPath()))
def _setCacheHeaders ( obj , extra_context ) : REQUEST = getattr ( obj , 'REQUEST' , None ) if REQUEST is not None : call_count = getattr ( REQUEST , SUBTEMPLATE , 1 ) - 1 setattr ( REQUEST , SUBTEMPLATE , call_count ) if call_count != 0 : return # cleanup delattr ( REQUEST , SUBTEMPLATE ) content = aq_parent ( obj ) manager = queryUtility ( ICachingPolicyManager ) if manager is None : return view_name = obj . getId ( ) headers = manager . getHTTPCachingHeaders ( content , view_name , extra_context ) RESPONSE = REQUEST [ 'RESPONSE' ] for key , value in headers : if key == 'ETag' : RESPONSE . setHeader ( key , value , literal = 1 ) # PATCH BEGIN: respect existing Cache-Control header if exists if key . lower ( ) == 'cache-control' : cache_control = RESPONSE . getHeader ( 'cache-control' ) if cache_control : existing_key_list = [ e . split ( '=' , 2 ) [ 0 ] . strip ( ) . lower ( ) for e in cache_control . split ( ',' ) ] for e in value . split ( ',' ) : if e . split ( '=' , 2 ) [ 0 ] . strip ( ) . lower ( ) not in existing_key_list : cache_control += ', %s' % e . strip ( ) else : cache_control = value RESPONSE . setHeader ( key , cache_control ) # PATCH END else : RESPONSE . setHeader ( key , value ) if headers : RESPONSE . setHeader ( 'X-Cache-Headers-Set-By' , 'CachingPolicyManager: %s' % '/' . join ( manager . getPhysicalPath ( ) ) )