使用CherryPy的HTTPS到HTTP [英] HTTPS to HTTP using CherryPy
本文介绍了使用CherryPy的HTTPS到HTTP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
CherryPy是否可以将HTTP重定向到HTTPS。让我们举例说下面的代码是 http://example.com ,如果有人通过 https://example.com 我希望将它们重定向到普通的HTTP URL(可能是301重定向?)我该如何做到这一点?
Is it possible for CherryPy to redirect HTTP to HTTPS. Lets for example say the code below is http://example.com if someone visits via https://example.com I want them to be redirected to the plain HTTP URL (301 redirect maybe?) how do I accomplish this?
#!/usr/bin/env python
from pprint import pformat
from cherrypy import wsgiserver
def app(environ, start_response):
status = '200 OK'
response_headers = [('Content-type', 'text/plain')]
start_response(status, response_headers)
return [pformat(environ)]
server = wsgiserver.CherryPyWSGIServer(('0.0.0.0', 80), app)
try:
server.start()
except KeyboardInterrupt:
server.stop()
推荐答案
您可以检查 request.scheme
如果是https,那么您可以提出重定向。
You can check the request.scheme
if it is "https" then you can raise a redirect.
这篇关于使用CherryPy的HTTPS到HTTP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文