# HG changeset patch # User Marcin Kuzminski # Date 1367020076 -7200 # Node ID 9c91d3e4a11c5ab985ad2bea0fc1fea52ae57e0b # Parent 5135f14b316e4c0062c21fd2459eee7f436a190b fix broken handling of adding an htsts. Modifing response/request was having trouble in some redirect cases diff -r 5135f14b316e -r 9c91d3e4a11c rhodecode/lib/middleware/https_fixup.py --- a/rhodecode/lib/middleware/https_fixup.py Fri Apr 26 14:14:46 2013 +0200 +++ b/rhodecode/lib/middleware/https_fixup.py Sat Apr 27 01:47:56 2013 +0200 @@ -23,7 +23,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from pylons.controllers.util import Request from rhodecode.lib.utils2 import str2bool @@ -36,15 +35,15 @@ def __call__(self, environ, start_response): self.__fixup(environ) debug = str2bool(self.config.get('debug')) - if str2bool(self.config.get('use_htsts')) and not debug: - req = Request(environ, self.application) - resp = req.get_response(self.application) - if environ['wsgi.url_scheme'] == 'https': - resp.headers['Strict-Transport-Security'] = \ - 'max-age=8640000; includeSubDomains' - return resp(environ, start_response) + is_ssl = environ['wsgi.url_scheme'] == 'https' - return self.application(environ, start_response) + def custom_start_response(status, headers, exc_info=None): + if is_ssl and str2bool(self.config.get('use_htsts')) and not debug: + headers.append(('Strict-Transport-Security', + 'max-age=8640000; includeSubDomains')) + return start_response(status, headers, exc_info) + + return self.application(environ, custom_start_response) def __fixup(self, environ): """