本文整理汇总了Python中pyramid.response.FileResponse.md5_etag方法的典型用法代码示例。如果您正苦于以下问题:Python FileResponse.md5_etag方法的具体用法?Python FileResponse.md5_etag怎么用?Python FileResponse.md5_etag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.response.FileResponse
的用法示例。
在下文中一共展示了FileResponse.md5_etag方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: whitenoise_tween
# 需要导入模块: from pyramid.response import FileResponse [as 别名]
# 或者: from pyramid.response.FileResponse import md5_etag [as 别名]
def whitenoise_tween(request):
whn = request.registry.whitenoise
if whn.autorefresh:
static_file = whn.find_file(request.path_info)
else:
static_file = whn.files.get(request.path_info)
# We could not find a static file, so we'll just continue processing
# this as normal.
if static_file is None:
return handler(request)
request_headers = dict(kv for kv in request.environ.items() if kv[0].startswith("HTTP_"))
if request.method not in {"GET", "HEAD"}:
return HTTPMethodNotAllowed()
else:
path, headers = static_file.get_path_and_headers(request_headers)
headers = MultiDict(headers)
resp = FileResponse(
path,
request=request,
content_type=headers.pop("Content-Type", None),
content_encoding=headers.pop("Content-Encoding", None),
)
resp.md5_etag()
resp.headers.update(headers)
return resp