本文整理匯總了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)