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, 10:12 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 fix_target_resolution():
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 fix_target_resolution() 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 (or HTTPS on 443) will fail, because
214 applications will omit the default port when addressing resources.
215 """
216 from google.appengine.tools.devappserver2.dispatcher import Dispatcher
217 orig_resolve_target = Dispatcher._resolve_target
218
219 def resolve_target(dispatcher, hostname, path):
220 new_hostname = hostname if ":" in hostname else "%s:%d" % (hostname, dispatc her._port)
221 result = orig_resolve_target(dispatcher, new_hostname, path)
222 return result
223
224 Dispatcher._resolve_target = resolve_target
206 225
207 if __name__ == '__main__': 226 if __name__ == '__main__':
208 engine_dir = '/opt/google_appengine' 227 engine_dir = '/opt/google_appengine'
209 storage_path = '/var/lib/rietveld' 228 storage_path = '/var/lib/rietveld'
210 229
211 script_name, script_file = setup_paths(engine_dir) 230 script_name, script_file = setup_paths(engine_dir)
212 adjust_server_id() 231 adjust_server_id()
213 fix_request_scheme() 232 fix_request_scheme()
214 233
215 if script_name == 'dev_appserver.py': 234 if script_name == 'dev_appserver.py':
216 config = read_config(os.path.join(storage_path, 'config.ini')) 235 config = read_config(os.path.join(storage_path, 'config.ini'))
217 236
218 set_storage_path(storage_path) 237 set_storage_path(storage_path)
219 replace_runtime() 238 replace_runtime()
220 protect_cookies(config.get('main', 'cookie_secret')) 239 protect_cookies(config.get('main', 'cookie_secret'))
221 enable_oauth2( 240 enable_oauth2(
222 config.get('oauth2', 'client_id'), 241 config.get('oauth2', 'client_id'),
223 config.get('oauth2', 'client_secret'), 242 config.get('oauth2', 'client_secret'),
224 config.get('main', 'admins').split() 243 config.get('main', 'admins').split()
225 ) 244 )
245 fix_target_resolution()
226 246
227 execfile(script_file) 247 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