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

Side by Side 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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 from ConfigParser import SafeConfigParser 3 from ConfigParser import SafeConfigParser
4 import hashlib 4 import hashlib
5 import hmac 5 import hmac
6 import json 6 import json
7 import os 7 import os
8 import re 8 import re
9 import sys 9 import sys
10 import urllib 10 import urllib
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 196
197 response.set_email(email) 197 response.set_email(email)
198 response.set_user_id(user_id) 198 response.set_user_id(user_id)
199 response.set_auth_domain(user_service_stub._DEFAULT_AUTH_DOMAIN) 199 response.set_auth_domain(user_service_stub._DEFAULT_AUTH_DOMAIN)
200 response.set_is_admin(is_admin) 200 response.set_is_admin(is_admin)
201 response.set_client_id(client_id) 201 response.set_client_id(client_id)
202 response.add_scopes(OAUTH2_SCOPE) 202 response.add_scopes(OAUTH2_SCOPE)
203 203
204 user_service_stub.UserServiceStub._Dynamic_GetOAuthUser = _Dynamic_GetOAuthUse r 204 user_service_stub.UserServiceStub._Dynamic_GetOAuthUser = _Dynamic_GetOAuthUse r
205 205
206 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.
207 """
208 By default, the dispatcher assumes port 80 for target authorities that
209 only contain a hostname but no port part. This hard-coded behavior is
210 altered in function dispatch_tasks_to_user_port() so that the port given
211 as --port option to the appserver-script is used instead. Without this
212 monkey-patch, dispatching tasks from an application run behind a HTTP
213 proxy server on port 80 will fail, because applications will omit the
214 default port when addressing resources.
215 """
216 from google.appengine.tools.devappserver2.dispatcher import Dispatcher
217 resolve_target = Dispatcher._resolve_target
218
219 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.
220 hostname, port = authority.split(":") if ":" in authority else (authority, d ispatcher._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
221 new_authority = "%s:%d" % (hostname, port)
222 result = resolve_target(dispatcher, new_authority, path)
223 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
224
225 Dispatcher._resolve_target = callback
206 226
207 if __name__ == '__main__': 227 if __name__ == '__main__':
208 engine_dir = '/opt/google_appengine' 228 engine_dir = '/opt/google_appengine'
209 storage_path = '/var/lib/rietveld' 229 storage_path = '/var/lib/rietveld'
210 230
211 script_name, script_file = setup_paths(engine_dir) 231 script_name, script_file = setup_paths(engine_dir)
212 adjust_server_id() 232 adjust_server_id()
213 fix_request_scheme() 233 fix_request_scheme()
214 234
215 if script_name == 'dev_appserver.py': 235 if script_name == 'dev_appserver.py':
216 config = read_config(os.path.join(storage_path, 'config.ini')) 236 config = read_config(os.path.join(storage_path, 'config.ini'))
217 237
218 set_storage_path(storage_path) 238 set_storage_path(storage_path)
219 replace_runtime() 239 replace_runtime()
220 protect_cookies(config.get('main', 'cookie_secret')) 240 protect_cookies(config.get('main', 'cookie_secret'))
221 enable_oauth2( 241 enable_oauth2(
222 config.get('oauth2', 'client_id'), 242 config.get('oauth2', 'client_id'),
223 config.get('oauth2', 'client_secret'), 243 config.get('oauth2', 'client_secret'),
224 config.get('main', 'admins').split() 244 config.get('main', 'admins').split()
225 ) 245 )
246 dispatch_tasks_to_user_port()
226 247
227 execfile(script_file) 248 execfile(script_file)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld