Просмотр исходного кода

Fix wsgidav https "move" problem.

Guénaël Muller 6 лет назад
Родитель
Сommit
18a9ee1f8d
2 измененных файлов: 22 добавлений и 0 удалений
  1. 2 0
      tracim/tracim/lib/daemons.py
  2. 20 0
      tracim/tracim/lib/utils.py

+ 2 - 0
tracim/tracim/lib/daemons.py Просмотреть файл

@@ -19,6 +19,7 @@ from tracim.lib.base import logger
19 19
 from tracim.lib.exceptions import AlreadyRunningDaemon
20 20
 
21 21
 from tracim.lib.utils import get_rq_queue
22
+from tracim.lib.utils import TracimEnforceHTTPS
22 23
 from tracim.lib.email_fetcher import MailFetcher
23 24
 
24 25
 
@@ -394,6 +395,7 @@ class WsgiDavDaemon(Daemon):
394 395
         from tracim.lib.webdav.utils import TracimWsgiDavDebugFilter
395 396
 
396 397
         config['middleware_stack'] = [
398
+            TracimEnforceHTTPS,
397 399
             WsgiDavDirBrowser,
398 400
             TracimHTTPAuthenticator,
399 401
             ErrorPrinter,

+ 20 - 0
tracim/tracim/lib/utils.py Просмотреть файл

@@ -17,6 +17,7 @@ from tg.util import lazify
17 17
 from redis import Redis
18 18
 from rq import Queue
19 19
 
20
+from wsgidav.middleware import BaseMiddleware
20 21
 from tracim.lib.base import logger
21 22
 from webob import Response
22 23
 from webob.exc import WSGIHTTPException
@@ -180,3 +181,22 @@ def get_rq_queue(queue_name: str= 'default') -> Queue:
180 181
         port=cfg.EMAIL_SENDER_REDIS_PORT,
181 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)