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: Created June 23, 2015, 8:04 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():
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 from google.appengine.api import request_info
218
219 resolve_target = Dispatcher._resolve_target
220
221 def callback(dispatcher, authority, 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
226
227 Dispatcher._resolve_target = callback
206 228
207 if __name__ == '__main__': 229 if __name__ == '__main__':
208 engine_dir = '/opt/google_appengine' 230 engine_dir = '/opt/google_appengine'
209 storage_path = '/var/lib/rietveld' 231 storage_path = '/var/lib/rietveld'
210 232
211 script_name, script_file = setup_paths(engine_dir) 233 script_name, script_file = setup_paths(engine_dir)
212 adjust_server_id() 234 adjust_server_id()
213 fix_request_scheme() 235 fix_request_scheme()
214 236
215 if script_name == 'dev_appserver.py': 237 if script_name == 'dev_appserver.py':
216 config = read_config(os.path.join(storage_path, 'config.ini')) 238 config = read_config(os.path.join(storage_path, 'config.ini'))
217 239
218 set_storage_path(storage_path) 240 set_storage_path(storage_path)
219 replace_runtime() 241 replace_runtime()
220 protect_cookies(config.get('main', 'cookie_secret')) 242 protect_cookies(config.get('main', 'cookie_secret'))
221 enable_oauth2( 243 enable_oauth2(
222 config.get('oauth2', 'client_id'), 244 config.get('oauth2', 'client_id'),
223 config.get('oauth2', 'client_secret'), 245 config.get('oauth2', 'client_secret'),
224 config.get('main', 'admins').split() 246 config.get('main', 'admins').split()
225 ) 247 )
248 dispatch_tasks_to_user_port()
226 249
227 execfile(script_file) 250 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