本文整理汇总了Python中werkzeug.Response.headers['ETag']方法的典型用法代码示例。如果您正苦于以下问题:Python Response.headers['ETag']方法的具体用法?Python Response.headers['ETag']怎么用?Python Response.headers['ETag']使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类werkzeug.Response
的用法示例。
在下文中一共展示了Response.headers['ETag']方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: response
# 需要导入模块: from werkzeug import Response [as 别名]
# 或者: from werkzeug.Response import headers['ETag'] [as 别名]
def response(self, request, data, etag=None, cache_policy=None):
"""Renders `data` to a JSON response.
An ETag may be specified. When it is not specified one will be generated
based on the data.
The caching policy can be optionally configured. By default it takes the
policy from the controller object: `cache_policy`.
"""
if etag is None and data is not None:
etag = self.etag(data)
# FIXME: Check content-type headers
if data is None:
if etag is None:
raise TypeError('response requires an etag when '
'the response body is None')
resp = Response(status=304, content_type='application/json')
else:
# Avoid sending the resource when an ETag matches
request_etags = parse_etags(
request.environ.get('HTTP_IF_NONE_MATCH'))
if request_etags.contains(etag):
resp = Response(status=304, content_type='application/json')
# Render the given data to a response object
else:
resp = Response(self.data_encoder.encode(data), content_type='application/json')
resp.headers['ETag'] = quote_etag(etag)
if cache_policy is None:
cache_policy = self.cache_policy
return cache_policy(resp)