annotate pylons_app/lib/middleware/https_fixup.py @ 204:a8ea3ce3cdc4

Created middleware package. Crated special middleware to handle https requests redirections.
author Marcin Kuzminski <marcin@python-works.com>
date Sun, 23 May 2010 00:54:22 +0200
parents
children 3782a6d698af
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
204
a8ea3ce3cdc4 Created middleware package. Crated special middleware to handle https requests redirections.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1 class HttpsFixup(object):
a8ea3ce3cdc4 Created middleware package. Crated special middleware to handle https requests redirections.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2 def __init__(self, app):
a8ea3ce3cdc4 Created middleware package. Crated special middleware to handle https requests redirections.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3 self.application = app
a8ea3ce3cdc4 Created middleware package. Crated special middleware to handle https requests redirections.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
4
a8ea3ce3cdc4 Created middleware package. Crated special middleware to handle https requests redirections.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
5 def __call__(self, environ, start_response):
a8ea3ce3cdc4 Created middleware package. Crated special middleware to handle https requests redirections.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
6 self.__fixup(environ)
a8ea3ce3cdc4 Created middleware package. Crated special middleware to handle https requests redirections.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
7 return self.application(environ, start_response)
a8ea3ce3cdc4 Created middleware package. Crated special middleware to handle https requests redirections.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
8
a8ea3ce3cdc4 Created middleware package. Crated special middleware to handle https requests redirections.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
9
a8ea3ce3cdc4 Created middleware package. Crated special middleware to handle https requests redirections.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
10 def __fixup(self, environ):
a8ea3ce3cdc4 Created middleware package. Crated special middleware to handle https requests redirections.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
11 """Function to fixup the environ as needed. In order to use this
a8ea3ce3cdc4 Created middleware package. Crated special middleware to handle https requests redirections.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
12 middleware you should set this header inside your
a8ea3ce3cdc4 Created middleware package. Crated special middleware to handle https requests redirections.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
13 proxy ie. nginx, apache etc.
a8ea3ce3cdc4 Created middleware package. Crated special middleware to handle https requests redirections.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
14 """
a8ea3ce3cdc4 Created middleware package. Crated special middleware to handle https requests redirections.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
15 proto = environ.get('HTTP_X_URL_SCHEME')
a8ea3ce3cdc4 Created middleware package. Crated special middleware to handle https requests redirections.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
16
a8ea3ce3cdc4 Created middleware package. Crated special middleware to handle https requests redirections.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
17 if proto == 'https':
a8ea3ce3cdc4 Created middleware package. Crated special middleware to handle https requests redirections.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
18 environ['wsgi.url_scheme'] = proto
a8ea3ce3cdc4 Created middleware package. Crated special middleware to handle https requests redirections.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
19 else:
a8ea3ce3cdc4 Created middleware package. Crated special middleware to handle https requests redirections.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
20 environ['wsgi.url_scheme'] = 'http'
a8ea3ce3cdc4 Created middleware package. Crated special middleware to handle https requests redirections.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
21 return None