当前位置: 首页>>代码示例>>Python>>正文


Python Response.pragma方法代码示例

本文整理汇总了Python中werkzeug.wrappers.Response.pragma方法的典型用法代码示例。如果您正苦于以下问题:Python Response.pragma方法的具体用法?Python Response.pragma怎么用?Python Response.pragma使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在werkzeug.wrappers.Response的用法示例。


在下文中一共展示了Response.pragma方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _getStaticResponse

# 需要导入模块: from werkzeug.wrappers import Response [as 别名]
# 或者: from werkzeug.wrappers.Response import pragma [as 别名]
    def _getStaticResponse(self):
        
        rs = Response()
        
        # find the static resource
        path = [self.static_path]
        path.extend(self.requested_path.split('/'))
        path = os.path.join(*path)
        
        # check last modified 
        modified_real = datetime.fromtimestamp(os.stat(path).st_mtime)
        
        # check if cache is in browser and if it is new enough
        if self.request.if_modified_since:
            if modified_real <= self.request.if_modified_since:
                # the cache is usable -> not modified status
                rs.status_code=304
                return rs
            
        # cache is old, proceed serving
        with open(path, 'r') as fh:
            rs.data = fh.read()
        rs.content_length = len(rs.data)
        
        
        # set content type
        try:
            ext = path.split(".")[-1].lower()
        except IndexError:
            rs.content_type="text/text"
        else:
            rs.content_type = self._types.get(ext, 'text/text')
        
        # set cache headers
        rs.pragma = 'public'
        rs.headers['Cache-Control']= "max-age=%d" % (24*3600)

        expires = datetime.now()+timedelta(days=1)
        
        rs.headers['Expires'] = http_date(expires)
        rs.headers['Last-Modified'] = http_date(modified_real)

        return rs
开发者ID:petrushev,项目名称:plate,代码行数:45,代码来源:web.py


注:本文中的werkzeug.wrappers.Response.pragma方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。