Logo Search packages:      
Sourcecode: zope-cachefu version File versions  Download package

def CacheSetup::content::header_set::HeaderSet::getHeaders (   self,
  expr_context 
)

Returns a list of caching headers in (key, value) tuples

Definition at line 245 of file header_set.py.

00245                                       :
        """Returns a list of caching headers in (key, value) tuples"""
        pcs = getToolByName(self, CACHE_TOOL_ID)
        headers_to_add = []
        headers_to_remove = []

        last_modified = self.getLastModified()
        if last_modified == 'yes':
            mod_time = self.getLastModifiedValue(expr_context)
            if type(mod_time) is type(''):
                mod_time = DateTime(mod_time)
            if mod_time is not None:
                mod_time_st = rfc1123_date(mod_time.timeTime())
                headers_to_add.append(('Last-modified', mod_time_st))
        elif last_modified == 'delete':
            headers_to_remove.append('Last-modified')

        if self.getEtag():
            etag = self.getEtagValue(expr_context)
            if etag is not None:
                headers_to_add.append(('ETag', etag))

        vary = self.getVaryValue(expr_context)
        if vary:
            headers_to_add.append(('Vary', vary))

        # a list of cache-control tokens
        control = []

        max_age = self.getMaxAge()
        if max_age is not None:
            now = expr_context.vars['time']
            if max_age > 0:
                expiration_time = now.timeTime() + max_age
            else:
                # immediate expiration requires that the client clock be precisely synchronized
                # since this is not guaranteed, we'll set the expiration time to 10 years ago
                expiration_time = now.timeTime() - 10*365*24*3600
            exp_time_st = rfc1123_date(expiration_time)
            headers_to_add.append(('Expires', exp_time_st))
            control.append('max-age=%d' % max_age)

        s_max_age = self.getSMaxAge()
        if s_max_age is not None:
            if pcs.hasPurgeableProxy():
                control.append('s-maxage=%d' % s_max_age)

        if self.getNoCache():
            control.append('no-cache')
            # The following is for HTTP 1.0 clients
            headers_to_add.append(('Pragma', 'no-cache'))

        if self.getNoStore():
            control.append('no-store')

        if self.getPublic():
            control.append('public')

        if self.getPrivate():
            control.append('private')

        if self.getMustRevalidate():
            control.append('must-revalidate')

        if self.getProxyRevalidate():
            if pcs.hasPurgeableProxy():
                control.append('proxy-revalidate')

        if self.getNoTransform():
            control.append('no-transform')

        pre_check = self.getPreCheck()
        if pre_check is not None:
            control.append('pre-check=%d' % pre_check)

        post_check = self.getPostCheck()
        if post_check is not None:
            control.append('post-check=%d' % post_check)

        if control:
            headers_to_add.append(('Cache-control', ', '.join(control)))

        # add debugging information
        rule = expr_context.vars['rule']
        headers_to_add.append(('X-Caching-Rule-Id', rule.getId()))
        headers_to_add.append(('X-Header-Set-Id', self.getId()))

        return (headers_to_add, headers_to_remove)

atapi.registerType(HeaderSet)
atapi.registerType(HeaderSet)


Generated by  Doxygen 1.6.0   Back to index