本文整理汇总了Python中werkzeug.wrappers.Response.headers['Expires']方法的典型用法代码示例。如果您正苦于以下问题:Python Response.headers['Expires']方法的具体用法?Python Response.headers['Expires']怎么用?Python Response.headers['Expires']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类werkzeug.wrappers.Response
的用法示例。
在下文中一共展示了Response.headers['Expires']方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from werkzeug.wrappers import Response [as 别名]
# 或者: from werkzeug.wrappers.Response import headers['Expires'] [as 别名]
def get(self):
path = self.kwargs['path']
filename = os.path.join(self.static_dir, path)
if not os.path.isfile(filename):
raise NotFound
type, encoding = guess_type(filename)
type = type or 'application/octet-stream'
expiry = time.asctime(time.gmtime(time.time() + 3600))
response = Response(mimetype=type)
response.headers['Expires'] = expiry
response.headers['Cache-Control'] = 'public'
response.response = open(filename, 'rb')
return response
示例2: _getStaticResponse
# 需要导入模块: from werkzeug.wrappers import Response [as 别名]
# 或者: from werkzeug.wrappers.Response import headers['Expires'] [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