本文整理汇总了Python中pyramid.response.Response.headers["ETag"]方法的典型用法代码示例。如果您正苦于以下问题:Python Response.headers["ETag"]方法的具体用法?Python Response.headers["ETag"]怎么用?Python Response.headers["ETag"]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.response.Response
的用法示例。
在下文中一共展示了Response.headers["ETag"]方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_key
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import headers["ETag"] [as 别名]
def get_key(request):
"""Get the value of a key.
You must have a valid session and be authenticated as the target user.
"""
appid = request.matchdict["appid"].encode("utf8")
userid = request.matchdict["userid"].encode("utf8")
key = request.matchdict["key"].encode("utf8")
store = request.registry.getUtility(ISauropodBackend)
try:
item = store.getitem(appid, userid, key)
except KeyError:
raise HTTPNotFound()
r = Response(_item_to_json(item), content_type="application/json")
if item.etag:
r.headers["ETag"] = item.etag
return r
示例2: _imageView
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import headers["ETag"] [as 别名]
def _imageView(request, default_resp=None):
iid = request.matchdict["id"]
if iid == "default" and default_resp:
resp = default_resp
else:
session = request.DBSession
image = session.query(Image).filter(Image.id == int(iid)).first()
if not image:
raise HTTPNotFound()
resp = Response(content_type=image.mime_type, body=image.data)
hash = sha1()
hash.update(resp.body)
etag = hash.hexdigest()
if "If-None-Match" in request.headers and request.headers["If-None-Match"] == etag:
raise HTTPNotModified()
resp.headers["Cache-Control"] = "max-age=3600"
resp.headers["ETag"] = etag
return resp