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

Delta Between Two Patch Sets: modules/rietveld/files/wrapper.py

Issue 29321013: Issue 2682 - Fix GAE dispatcher default port handling (Closed)
Left Patch Set: Created June 23, 2015, 8:04 a.m.
Right Patch Set: Issue 2682 - Fix GAE dispatcher default port handling Created June 23, 2015, 10:12 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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(): 206 def fix_target_resolution():
207 """ 207 """
208 By default, the dispatcher assumes port 80 for target authorities that 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 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 210 altered in function fix_target_resolution() so that the port given
211 as --port option to the appserver-script is used instead. Without this 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 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 213 proxy server on port 80 (or HTTPS on 443) will fail, because
214 default port when addressing resources. 214 applications will omit the default port when addressing resources.
215 """ 215 """
216 from google.appengine.tools.devappserver2.dispatcher import Dispatcher 216 from google.appengine.tools.devappserver2.dispatcher import Dispatcher
217 from google.appengine.api import request_info 217 orig_resolve_target = Dispatcher._resolve_target
218 218
219 resolve_target = Dispatcher._resolve_target 219 def resolve_target(dispatcher, hostname, path):
220 220 new_hostname = hostname if ":" in hostname else "%s:%d" % (hostname, dispatc her._port)
221 def callback(dispatcher, authority, path): 221 result = orig_resolve_target(dispatcher, new_hostname, path)
222 hostname, port = authority.split(":") if ":" in authority else (authority, d ispatcher._port)
223 new_authority = "%s:%d" % (hostname, port)
224 result = resolve_target(dispatcher, new_authority, path)
225 return result 222 return result
226 223
227 Dispatcher._resolve_target = callback 224 Dispatcher._resolve_target = resolve_target
228 225
229 if __name__ == '__main__': 226 if __name__ == '__main__':
230 engine_dir = '/opt/google_appengine' 227 engine_dir = '/opt/google_appengine'
231 storage_path = '/var/lib/rietveld' 228 storage_path = '/var/lib/rietveld'
232 229
233 script_name, script_file = setup_paths(engine_dir) 230 script_name, script_file = setup_paths(engine_dir)
234 adjust_server_id() 231 adjust_server_id()
235 fix_request_scheme() 232 fix_request_scheme()
236 233
237 if script_name == 'dev_appserver.py': 234 if script_name == 'dev_appserver.py':
238 config = read_config(os.path.join(storage_path, 'config.ini')) 235 config = read_config(os.path.join(storage_path, 'config.ini'))
239 236
240 set_storage_path(storage_path) 237 set_storage_path(storage_path)
241 replace_runtime() 238 replace_runtime()
242 protect_cookies(config.get('main', 'cookie_secret')) 239 protect_cookies(config.get('main', 'cookie_secret'))
243 enable_oauth2( 240 enable_oauth2(
244 config.get('oauth2', 'client_id'), 241 config.get('oauth2', 'client_id'),
245 config.get('oauth2', 'client_secret'), 242 config.get('oauth2', 'client_secret'),
246 config.get('main', 'admins').split() 243 config.get('main', 'admins').split()
247 ) 244 )
248 dispatch_tasks_to_user_port() 245 fix_target_resolution()
249 246
250 execfile(script_file) 247 execfile(script_file)
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld