Pyramid 调试工具栏通过 HTTP 而不是 HTTPS 提供静态内容 [英] Pyramid debug toolbar serving static content over HTTP instead of HTTPS

查看:34
本文介绍了Pyramid 调试工具栏通过 HTTP 而不是 HTTPS 提供静态内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的测试服务器上,我们使用 Pyramid 调试工具栏,但是,它会生成 http:// 指向静态内容(如其 CSS 和 JavaScript 文件)的链接,而其余内容则通过 HTTPS 提供.这会导致混合内容警告,并破坏所有功能.有没有办法强制它生成HTTPS链接?

On our test servers, we're using the Pyramid debug toolbar, however, it generates http:// links to static content (like its CSS and JavaScript files), while the rest of the content is served over HTTPS. This causes mixed content warnings, and it breaks all functionality. Is there a way to force it to generate HTTPS links?

我知道可以在 Chrome 中启用混合内容,这很有效,但对于整个 QA 团队来说,这不是一个可行的解决方案.

I know it's possible to enable mixed content in Chrome, and this works, but it's not a feasible solution for the entire QA team.

推荐答案

可能有更好/更简单的方法来实现这一点,但您可以做一件事来实现这一点,添加 _scheme='https' 每次调用 request.static_url() 的参数.

There might be better/simpler ways to achieve this, but one thing you can do to achieve this add the _scheme='https' parameter to each call to request.static_url().

为此,您当然可以编辑 pyramid/url.py,但您也可以在项目的 __init__.py 中执行此操作:

For that you can of course edit pyramid/url.py, but you can also do this in your projects' __init__.py:

from pyramid.url import URLMethodsMixin

URLMethodsMixin.static_url_org = URLMethodsMixin.static_url  # backup of original

def https_static_url(self, *args, **kw):
    kw['_scheme'] = 'https'  # add parameter forcing https
    return URLMethodsMixin.static_url_org(self, *args, **kw)  # call backup

URLMethodsMixin.static_url = https_static_url  # replace original with backup

static_url 的参数类似于 route_url.来自文档:

Parameters for static_url works like route_url. From the documentation:

注意,如果_scheme作为https传递,而_port没有传递,则_port值被假定为443.同样,如果_scheme作为http传递而_port没有传递,则_port值被假定为已作为 80 传递.为避免此行为,请始终在传递 _scheme 时显式传递 _port.设置 '_scheme' 自动强制端口 443

Note that if _scheme is passed as https, and _port is not passed, the _port value is assumed to have been passed as 443. Likewise, if _scheme is passed as http and _port is not passed, the _port value is assumed to have been passed as 80. To avoid this behavior, always explicitly pass _port whenever you pass _scheme. Setting '_scheme' automatically forces port 443

这篇关于Pyramid 调试工具栏通过 HTTP 而不是 HTTPS 提供静态内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆