本文整理汇总了Python中pyramid.response.Response.headers[b'X-Accel-Redirect']方法的典型用法代码示例。如果您正苦于以下问题:Python Response.headers[b'X-Accel-Redirect']方法的具体用法?Python Response.headers[b'X-Accel-Redirect']怎么用?Python Response.headers[b'X-Accel-Redirect']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.response.Response
的用法示例。
在下文中一共展示了Response.headers[b'X-Accel-Redirect']方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_file
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import headers[b'X-Accel-Redirect'] [as 别名]
def get_file(request):
# TODO: Add a route that enables the call to have the filename
# appended to the end. This is so that gmail can read the services
# Read more here:
# http://stackoverflow.com/questions/20903967/gmails-new-image-caching-is-breaking-image-links-in-newsletter
ctx = request.context
document = ctx._instance
f = File.get(document.id)
if f.infected:
raise HTTPNotAcceptable("Infected with a virus")
escaped_double_quotes_filename = (f.title
.replace(u'"', u'\\"')
.encode('iso-8859-1', 'replace'))
url_quoted_utf8_filename = url_quote(f.title.encode('utf-8'))
handoff_to_nginx = asbool(config.get('handoff_to_nginx', False))
if handoff_to_nginx:
kwargs = dict(body='')
else:
if 'Range' in request.headers:
raise HTTPRequestRangeNotSatisfiable()
fs = open(f.path, 'rb')
app_iter = None
environ = request.environ
if 'wsgi.file_wrapper' in environ:
app_iter = environ['wsgi.file_wrapper'](fs, _BLOCK_SIZE)
if app_iter is None:
app_iter = FileIter(fs, _BLOCK_SIZE)
kwargs=dict(app_iter=app_iter)
r = Response(
content_length=f.size,
content_type=str(f.mime_type),
last_modified=f.creation_date,
expires=datetime.now()+timedelta(days=365),
accept_ranges="bytes" if handoff_to_nginx else "none",
content_disposition=
'attachment; filename="%s"; filename*=utf-8\'\'%s' # RFC 6266
% (escaped_double_quotes_filename, url_quoted_utf8_filename),
**kwargs
)
if handoff_to_nginx:
r.headers[b'X-Accel-Redirect'] = f.handoff_url
return r