Browse Source

Fix wsgidav https "move" problem.

Guénaël Muller 6 years ago
parent
commit
18a9ee1f8d
2 changed files with 22 additions and 0 deletions
  1. 2 0
      tracim/tracim/lib/daemons.py
  2. 20 0
      tracim/tracim/lib/utils.py

+ 2 - 0
tracim/tracim/lib/daemons.py View File

19
 from tracim.lib.exceptions import AlreadyRunningDaemon
19
 from tracim.lib.exceptions import AlreadyRunningDaemon
20
 
20
 
21
 from tracim.lib.utils import get_rq_queue
21
 from tracim.lib.utils import get_rq_queue
22
+from tracim.lib.utils import TracimEnforceHTTPS
22
 from tracim.lib.email_fetcher import MailFetcher
23
 from tracim.lib.email_fetcher import MailFetcher
23
 
24
 
24
 
25
 
394
         from tracim.lib.webdav.utils import TracimWsgiDavDebugFilter
395
         from tracim.lib.webdav.utils import TracimWsgiDavDebugFilter
395
 
396
 
396
         config['middleware_stack'] = [
397
         config['middleware_stack'] = [
398
+            TracimEnforceHTTPS,
397
             WsgiDavDirBrowser,
399
             WsgiDavDirBrowser,
398
             TracimHTTPAuthenticator,
400
             TracimHTTPAuthenticator,
399
             ErrorPrinter,
401
             ErrorPrinter,

+ 20 - 0
tracim/tracim/lib/utils.py View File

17
 from redis import Redis
17
 from redis import Redis
18
 from rq import Queue
18
 from rq import Queue
19
 
19
 
20
+from wsgidav.middleware import BaseMiddleware
20
 from tracim.lib.base import logger
21
 from tracim.lib.base import logger
21
 from webob import Response
22
 from webob import Response
22
 from webob.exc import WSGIHTTPException
23
 from webob.exc import WSGIHTTPException
180
         port=cfg.EMAIL_SENDER_REDIS_PORT,
181
         port=cfg.EMAIL_SENDER_REDIS_PORT,
181
         db=cfg.EMAIL_SENDER_REDIS_DB,
182
         db=cfg.EMAIL_SENDER_REDIS_DB,
182
     ))
183
     ))
184
+
185
+
186
+class TracimEnforceHTTPS(BaseMiddleware):
187
+
188
+    def __init__(self, application, config):
189
+        super().__init__(application, config)
190
+        self._application = application
191
+        self._config = config
192
+
193
+    def __call__(self, environ, start_response):
194
+        # TODO - G.M - 06-03-2018 - Check protocol from http header first
195
+        # see http://www.bortzmeyer.org/7239.html
196
+        # if this params doesn't exist, rely on tracim config
197
+        from tracim.config.app_cfg import CFG
198
+        cfg = CFG.get_instance()
199
+
200
+        if cfg.WEBSITE_BASE_URL.startswith('https'):
201
+            environ['wsgi.url_scheme'] = 'https'
202
+        return self._application(environ, start_response)