I'm running a django app using twisted. I moved now from http to https. How can I add redirects from http to https in twisted?
相关问题
- Mechanize getting “Errno::ECONNRESET: Connection r
- Can ServiceStack JsonServiceClient send a get requ
- Tomcat and SSL Client certificate
- Can we add four protocols to ServicePointManager.S
- .NET Core gives unknown error while processing HTT
相关文章
- 请大神帮忙 post向https接口发送数据 部署到服务器为什么运行一会后就会报空指针
- ssl配置问题
- Intermittent “sslv3 alert handshake failure” under
- “SyntaxError: unexpected EOF while parsing” while
- Making a python program wait until Twisted deferre
- Making a two way SSL authentication between apache
- decrypt TLS 1.2 AES-GCM packet
- How to use Jetty with Let's Encrypt certificat
An easy way to generate redirects in Twisted Web is is with the Redirect resource. Instantiate it with a URL and put it into your resource hierarchy. If it is rendered, it will return a redirect response to that URL:
This will run a server which responds to a request for http://localhost:8080/ with a redirect to https://stackoverflow.com/.
If you're running Django in the WSGI container hosted on an HTTPS server, then you might have code that looks something like this:
You can run an additional HTTP server which generates the redirects you want by just adding some of the code from the first example to this second example:
To redirect from any given path on HTTP to the same path on the HTTPS (based on Jean-Paul's suggestions in response to my comment):
Then you can use
RedirectToScheme("https")
, in place of yourSite()
for the HTTP site that you want to redirect from.Note: If the HTTP that you want to redirect from is on a non-standard port, you will probably have a
:<port>
part in the the URLRequest that you'll also need to rewrite.