diff --git a/development.ini b/development.ini --- a/development.ini +++ b/development.ini @@ -46,6 +46,7 @@ lang=en cache_dir = %(here)s/data index_dir = %(here)s/data/index cut_off_limit = 256000 +force_https = false #################################### ### CELERY CONFIG #### diff --git a/production.ini b/production.ini --- a/production.ini +++ b/production.ini @@ -46,6 +46,7 @@ lang=en cache_dir = %(here)s/data index_dir = %(here)s/data/index cut_off_limit = 256000 +force_https = false #################################### ### CELERY CONFIG #### diff --git a/rhodecode/config/deployment.ini_tmpl b/rhodecode/config/deployment.ini_tmpl --- a/rhodecode/config/deployment.ini_tmpl +++ b/rhodecode/config/deployment.ini_tmpl @@ -47,6 +47,7 @@ cache_dir = %(here)s/data index_dir = %(here)s/data/index app_instance_uuid = ${app_instance_uuid} cut_off_limit = 256000 +force_https = false #################################### ### CELERY CONFIG #### diff --git a/rhodecode/config/middleware.py b/rhodecode/config/middleware.py --- a/rhodecode/config/middleware.py +++ b/rhodecode/config/middleware.py @@ -59,7 +59,7 @@ def make_app(global_conf, full_stack=Tru 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) diff --git a/rhodecode/lib/__init__.py b/rhodecode/lib/__init__.py --- a/rhodecode/lib/__init__.py +++ b/rhodecode/lib/__init__.py @@ -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 + :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 diff --git a/rhodecode/lib/celerylib/__init__.py b/rhodecode/lib/celerylib/__init__.py --- a/rhodecode/lib/celerylib/__init__.py +++ b/rhodecode/lib/celerylib/__init__.py @@ -35,15 +35,13 @@ from hashlib import md5 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: diff --git a/rhodecode/lib/middleware/https_fixup.py b/rhodecode/lib/middleware/https_fixup.py --- a/rhodecode/lib/middleware/https_fixup.py +++ b/rhodecode/lib/middleware/https_fixup.py @@ -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 @@ class HttpsFixup(object): """ 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: