Original question
App Engine SDK 1.6.5
Python 2.7
webapp2
I have implemented webapp2 schemes to protect pages up to https. The problem is that when the user goes to http: // site / login instead of https: // site / login, they get a 404 error due to the scheme not recognizing the route.
example main.py
# Libraries import webapp2
I added another route / controller below the https route to catch http requests:
webapp2.Route(r'/login', RouteLogin)
RouteLogin.py
# Libraries import webapp2 class RouteLogin(webapp2.RequestHandler): def get(self): self.redirect('https://site.appspot.com/login')
This works, but there seems to be a better way to do this. Similar to using htaccess on an Apache web server. This is too much like hacking for me. I really don't like hardcoded URLs in my code. Not to mention that these are two requests that do not really matter for logging in, but there may be other examples when this ends up being too expensive.
NOTE 1. If you are considering this solution, keep in mind that using HTTPS schemes also means that you cannot use the dev console without removing SCHEME or setting the variable set to dev.
NOTE 2. I was able to get a programmatic way to serve HTTPS instead of HTTP. I was on the right track with a comment below, but he needs an argument.
webapp2.uri_for('login', _scheme='https')
This will give you the correct https://someapp.appspot.com/login url. Unfortunately, my main problem is not how to deal with people who enter the URL into the address bar without https, and get an error message if I do not use the hack above. Therefore, I'm still looking for a WSGI method for sending revenue requests to HTPPS.
Editing: Note 1 is added and the name is clarified, I thought it was obvious that I used WSGI from the source, not CGI.
Mark finch
source share