Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: modules/rietveld/files/wrapper.py

Issue 29321013: Issue 2682 - Fix GAE dispatcher default port handling (Closed)
Patch Set: Issue 2682 - Fix GAE dispatcher default port handling Created June 23, 2015, 8:06 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: modules/rietveld/files/wrapper.py
diff --git a/modules/rietveld/files/wrapper.py b/modules/rietveld/files/wrapper.py
index 34ed099a19360cef1cb0bebdc184d0fd77ce1468..ea191713422ec3347b5150e99c9011f6c5ea1784 100644
--- a/modules/rietveld/files/wrapper.py
+++ b/modules/rietveld/files/wrapper.py
@@ -203,6 +203,26 @@ def enable_oauth2(client_id, client_secret, admins):
user_service_stub.UserServiceStub._Dynamic_GetOAuthUser = _Dynamic_GetOAuthUser
+def dispatch_tasks_to_user_port():
Sebastian Noack 2015/06/23 09:40:27 This function name is inaccurate. This function do
Wladimir Palant 2015/06/23 09:53:09 I'd rather go with fix_target_resolution().
mathias 2015/06/23 10:13:18 Done.
mathias 2015/06/23 10:13:18 Done.
+ """
+ By default, the dispatcher assumes port 80 for target authorities that
+ only contain a hostname but no port part. This hard-coded behavior is
+ altered in function dispatch_tasks_to_user_port() so that the port given
+ as --port option to the appserver-script is used instead. Without this
+ monkey-patch, dispatching tasks from an application run behind a HTTP
+ proxy server on port 80 will fail, because applications will omit the
+ default port when addressing resources.
+ """
+ from google.appengine.tools.devappserver2.dispatcher import Dispatcher
+ resolve_target = Dispatcher._resolve_target
+
+ def callback(dispatcher, authority, path):
Sebastian Noack 2015/06/23 09:40:27 It's arguable whether a method override should be
Wladimir Palant 2015/06/23 09:53:09 Also, please keep the parameter names of the origi
mathias 2015/06/23 10:13:17 Done.
mathias 2015/06/23 10:13:17 Done.
+ hostname, port = authority.split(":") if ":" in authority else (authority, dispatcher._port)
Sebastian Noack 2015/06/23 09:40:27 It seems that the logic here can be simplified:
Wladimir Palant 2015/06/23 09:53:10 Actually, that's not quite it. The dispatcher assu
mathias 2015/06/23 10:13:18 Overwriting function arguments is something I cons
mathias 2015/06/23 10:13:18 It's not 443 either, we do not allow unauthorized
Sebastian Noack 2015/06/23 11:34:05 I don't think that a bogus dislike of overwriting
mathias 2015/06/23 11:53:45 Again labeling something bogus without any rationa
Sebastian Noack 2015/06/23 12:00:23 Interesting, since labeling something "bad practic
+ new_authority = "%s:%d" % (hostname, port)
+ result = resolve_target(dispatcher, new_authority, path)
+ return result
Wladimir Palant 2015/06/23 09:53:10 Nit: drop the intermediate result variable? ret
mathias 2015/06/23 10:32:42 Again something I consider bad practice. Without t
Sebastian Noack 2015/06/23 11:34:05 Frankly, I agree with Wladimir here. Bloating your
mathias 2015/06/23 11:53:45 Let me point out at "bloating" is way over the top
Wladimir Palant 2015/06/23 11:58:07 Yes, this is primarily a matter of opinion which i
+
+ Dispatcher._resolve_target = callback
if __name__ == '__main__':
engine_dir = '/opt/google_appengine'
@@ -223,5 +243,6 @@ if __name__ == '__main__':
config.get('oauth2', 'client_secret'),
config.get('main', 'admins').split()
)
+ dispatch_tasks_to_user_port()
execfile(script_file)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld