• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

allura


Commit MetaInfo

修訂d73f8fb8fcdec1425010461c29ae9046a8e36f61 (tree)
時間2010-08-07 06:43:03
作者Rick Copeland <rcopeland@geek...>
CommiterRick Copeland

Log Message

[#770] - never send http/https redirects for static-looking resources

Change Summary

差異

--- a/pyforge/development.ini
+++ b/pyforge/development.ini
@@ -50,6 +50,7 @@ auth.ldap.admin_password = secret
5050 # Set the locations of some static resources
5151 # script_name is the path that is handled by the application
5252 # url_base is the prefix that references to the static resources should have
53+no_redirect.pattern = /nf/\d+/_(ew|static)_/.*
5354 ew.script_name = /nf/%(build_key)s/_ew_/
5455 ew.url_base = /nf/%(build_key)s/_ew_/
5556 # ew.url_base = ://a.fsdn.com/allura/nf/%(build_key)s/_ew_/
--- a/pyforge/pyforge/config/middleware.py
+++ b/pyforge/pyforge/config/middleware.py
@@ -11,7 +11,9 @@ import ming
1111 from pyforge.config.app_cfg import base_config
1212 from pyforge.config.environment import load_environment
1313 from pyforge.config.app_cfg import ForgeConfig
14-from pyforge.lib.custom_middleware import StatsMiddleware, SSLMiddleware, StaticFilesMiddleware
14+from pyforge.lib.custom_middleware import StatsMiddleware
15+from pyforge.lib.custom_middleware import SSLMiddleware
16+from pyforge.lib.custom_middleware import StaticFilesMiddleware
1517
1618 __all__ = ['make_app']
1719
@@ -63,7 +65,7 @@ def _make_core_app(root, global_conf, full_stack=True, **app_conf):
6365 app = StatsMiddleware(app, stats_config)
6466
6567 if asbool(app_conf.get('auth.method', 'local')=='sfx'):
66- app = SSLMiddleware(app)
68+ app = SSLMiddleware(app, app_conf.get('no_redirect.pattern'))
6769
6870 app = ew.ResourceMiddleware(
6971 app,
--- a/pyforge/pyforge/lib/custom_middleware.py
+++ b/pyforge/pyforge/lib/custom_middleware.py
@@ -1,4 +1,5 @@
11 import os
2+import re
23 import logging
34 from contextlib import contextmanager
45 from threading import local
@@ -121,15 +122,20 @@ class LoginRedirectMiddleware(object):
121122 start_response(status, headers, exc_info)
122123 return app_iter
123124
124-
125125 class SSLMiddleware(object):
126126 'Verify the https/http schema is correct'
127127
128- def __init__(self, app):
128+ def __init__(self, app, no_redirect_pattern=None):
129129 self.app = app
130+ if no_redirect_pattern:
131+ self._no_redirect_re = re.compile(no_redirect_pattern)
132+ else:
133+ self._no_redirect_re = re.compile('$$$')
130134
131135 def __call__(self, environ, start_response):
132136 req = Request(environ)
137+ if self._no_redirect_re.match(environ['PATH_INFO']):
138+ return req.get_response(self.app)(environ, start_response)
133139 resp = None
134140 try:
135141 request_uri = req.url