Mercurial > kallithea
annotate pylons_app/lib/middleware/https_fixup.py @ 388:3bcf9529d221
Added new application settings,Push ssl and repositories path
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Thu, 05 Aug 2010 22:31:23 +0200 |
parents | 3782a6d698af |
children |
rev | line source |
---|---|
252
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
204
diff
changeset
|
1 #!/usr/bin/env python |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
204
diff
changeset
|
2 # encoding: utf-8 |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
204
diff
changeset
|
3 # middleware to handle https correctly |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
204
diff
changeset
|
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
204
diff
changeset
|
5 |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
204
diff
changeset
|
6 # This program is free software; you can redistribute it and/or |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
204
diff
changeset
|
7 # modify it under the terms of the GNU General Public License |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
204
diff
changeset
|
8 # as published by the Free Software Foundation; version 2 |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
204
diff
changeset
|
9 # of the License or (at your opinion) any later version of the license. |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
204
diff
changeset
|
10 # |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
204
diff
changeset
|
11 # This program is distributed in the hope that it will be useful, |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
204
diff
changeset
|
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
204
diff
changeset
|
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
204
diff
changeset
|
14 # GNU General Public License for more details. |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
204
diff
changeset
|
15 # |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
204
diff
changeset
|
16 # You should have received a copy of the GNU General Public License |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
204
diff
changeset
|
17 # along with this program; if not, write to the Free Software |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
204
diff
changeset
|
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
204
diff
changeset
|
19 # MA 02110-1301, USA. |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
204
diff
changeset
|
20 |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
204
diff
changeset
|
21 """ |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
204
diff
changeset
|
22 Created on May 23, 2010 |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
204
diff
changeset
|
23 |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
204
diff
changeset
|
24 @author: marcink |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
204
diff
changeset
|
25 """ |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
204
diff
changeset
|
26 |
204
a8ea3ce3cdc4
Created middleware package. Crated special middleware to handle https requests redirections.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
27 class HttpsFixup(object): |
a8ea3ce3cdc4
Created middleware package. Crated special middleware to handle https requests redirections.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
28 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
|
29 self.application = app |
a8ea3ce3cdc4
Created middleware package. Crated special middleware to handle https requests redirections.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
30 |
a8ea3ce3cdc4
Created middleware package. Crated special middleware to handle https requests redirections.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
31 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
|
32 self.__fixup(environ) |
a8ea3ce3cdc4
Created middleware package. Crated special middleware to handle https requests redirections.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
33 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
|
34 |
a8ea3ce3cdc4
Created middleware package. Crated special middleware to handle https requests redirections.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
35 |
a8ea3ce3cdc4
Created middleware package. Crated special middleware to handle https requests redirections.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
36 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
|
37 """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
|
38 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
|
39 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
|
40 """ |
a8ea3ce3cdc4
Created middleware package. Crated special middleware to handle https requests redirections.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
41 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
|
42 |
a8ea3ce3cdc4
Created middleware package. Crated special middleware to handle https requests redirections.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
43 if proto == 'https': |
a8ea3ce3cdc4
Created middleware package. Crated special middleware to handle https requests redirections.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
44 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
|
45 else: |
a8ea3ce3cdc4
Created middleware package. Crated special middleware to handle https requests redirections.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
46 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
|
47 return None |