changeset 914:110a00c181de beta

Added force https option into config files
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 05 Jan 2011 23:39:26 +0100
parents d173938d711b
children 35e701dc801e
files development.ini production.ini rhodecode/config/deployment.ini_tmpl rhodecode/config/middleware.py rhodecode/lib/__init__.py rhodecode/lib/celerylib/__init__.py rhodecode/lib/middleware/https_fixup.py
diffstat 7 files changed, 41 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/development.ini	Tue Jan 04 00:26:26 2011 +0100
+++ b/development.ini	Wed Jan 05 23:39:26 2011 +0100
@@ -46,6 +46,7 @@
 cache_dir = %(here)s/data
 index_dir = %(here)s/data/index
 cut_off_limit = 256000
+force_https = false
 
 ####################################
 ###        CELERY CONFIG        ####
--- a/production.ini	Tue Jan 04 00:26:26 2011 +0100
+++ b/production.ini	Wed Jan 05 23:39:26 2011 +0100
@@ -46,6 +46,7 @@
 cache_dir = %(here)s/data
 index_dir = %(here)s/data/index
 cut_off_limit = 256000
+force_https = false
 
 ####################################
 ###        CELERY CONFIG        ####
--- a/rhodecode/config/deployment.ini_tmpl	Tue Jan 04 00:26:26 2011 +0100
+++ b/rhodecode/config/deployment.ini_tmpl	Wed Jan 05 23:39:26 2011 +0100
@@ -47,6 +47,7 @@
 index_dir = %(here)s/data/index
 app_instance_uuid = ${app_instance_uuid}
 cut_off_limit = 256000
+force_https = false 
 
 ####################################
 ###        CELERY CONFIG        ####
--- a/rhodecode/config/middleware.py	Tue Jan 04 00:26:26 2011 +0100
+++ b/rhodecode/config/middleware.py	Wed Jan 05 23:39:26 2011 +0100
@@ -59,7 +59,7 @@
             app = StatusCodeRedirect(app, [400, 401, 403, 404, 500])
 
     #enable https redirets based on HTTP_X_URL_SCHEME set by proxy
-    app = HttpsFixup(app)
+    app = HttpsFixup(app, config)
 
     # Establish the Registry for this application
     app = RegistryManager(app)
--- a/rhodecode/lib/__init__.py	Tue Jan 04 00:26:26 2011 +0100
+++ b/rhodecode/lib/__init__.py	Wed Jan 05 23:39:26 2011 +0100
@@ -0,0 +1,29 @@
+# -*- coding: utf-8 -*-
+"""
+    rhodecode.lib.__init__
+    ~~~~~~~~~~~~~~~~~~~~~~~
+
+    Some simple helper functions
+    
+    :created_on: Jan 5, 2011
+    :author: marcink
+    :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>    
+    :license: GPLv3, see COPYING for more details.
+"""
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; version 2
+# of the License or (at your opinion) any later version of the license.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA  02110-1301, USA.
+
+def str2bool(v):
+    return v.lower() in ["yes", "true", "t", "1"] if v else None
--- a/rhodecode/lib/celerylib/__init__.py	Tue Jan 04 00:26:26 2011 +0100
+++ b/rhodecode/lib/celerylib/__init__.py	Wed Jan 05 23:39:26 2011 +0100
@@ -35,15 +35,13 @@
 from decorator import decorator
 from vcs.utils.lazy import LazyProperty
 
+from rhodecode.lib import str2bool
 from rhodecode.lib.pidlock import DaemonLock, LockHeld
 
 from pylons import  config
 
 log = logging.getLogger(__name__)
 
-def str2bool(v):
-    return v.lower() in ["yes", "true", "t", "1"] if v else None
-
 try:
     CELERY_ON = str2bool(config['app_conf'].get('use_celery'))
 except KeyError:
--- a/rhodecode/lib/middleware/https_fixup.py	Tue Jan 04 00:26:26 2011 +0100
+++ b/rhodecode/lib/middleware/https_fixup.py	Wed Jan 05 23:39:26 2011 +0100
@@ -25,9 +25,12 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 # MA  02110-1301, USA.
 
+from rhodecode.lib import str2bool
+
 class HttpsFixup(object):
-    def __init__(self, app):
+    def __init__(self, app, config):
         self.application = app
+        self.config = config
 
     def __call__(self, environ, start_response):
         self.__fixup(environ)
@@ -41,6 +44,9 @@
         """
         proto = environ.get('HTTP_X_URL_SCHEME')
 
+        if str2bool(self.config.get('force_https')):
+            proto = 'https'
+
         if proto == 'https':
             environ['wsgi.url_scheme'] = proto
         else: