Chromium Code Reviews| Index: appengine/findit/common/http_client_appengine.py |
| diff --git a/appengine/findit/common/http_client_appengine.py b/appengine/findit/common/http_client_appengine.py |
| index 171f89773ca132841819695ac99c6f57802b8965..fc6f0e0e3416311a33cd29e2fd9f11c78f8bc3df 100644 |
| --- a/appengine/findit/common/http_client_appengine.py |
| +++ b/appengine/findit/common/http_client_appengine.py |
| @@ -7,11 +7,31 @@ import logging |
| from google.appengine.api import urlfetch |
| +from common import auth_util |
| from common.retry_http_client import RetryHttpClient |
| +_CHROME_INTERNAL_HOST = 'https://chrome-internal.googlesource.com' |
|
stgao
2016/05/06 19:11:24
Is it better for this to be a list?
Sharu Jiang
2016/05/06 20:27:27
Done.
|
| + |
| class HttpClientAppengine(RetryHttpClient): # pragma: no cover |
| """A http client for running on appengine.""" |
| + |
| + def _GetExpandedHeaders(self, url, headers): |
|
stgao
2016/05/06 19:11:24
nit: this function is only for adding Oauth2.0 tok
Sharu Jiang
2016/05/06 20:27:27
Done.
|
| + #TODO(katesonia): Move this to config. |
|
stgao
2016/05/06 19:11:24
nit: The host above needs to be moved to config, n
Sharu Jiang
2016/05/06 20:27:27
Done.
|
| + host_to_expanded_headers = { |
| + _CHROME_INTERNAL_HOST: { |
| + 'Authorization': 'Bearer ' + auth_util.GetAuthToken()} |
|
stgao
2016/05/06 19:11:24
This might involve an api request, and is only use
Sharu Jiang
2016/05/06 20:27:27
Done.
|
| + } |
| + |
| + if not headers: |
| + headers = {} |
| + |
| + for host, expanded_headers in host_to_expanded_headers.iteritems(): |
| + if url.startswith(host): |
| + return headers.update(expanded_headers) |
| + |
| + return headers |
| + |
| def _ShouldLogError(self, status_code): |
| if not self.no_error_logging_statuses: |
| return True |
| @@ -19,8 +39,8 @@ class HttpClientAppengine(RetryHttpClient): # pragma: no cover |
| def _SendRequest(self, url, method, data, timeout, headers=None): |
| # We wanted to validate certificate to avoid the man in the middle. |
| - if not headers: |
| - headers = {} |
| + headers = self._GetExpandedHeaders(url, headers) |
| + |
| if method in (urlfetch.POST, urlfetch.PUT): |
| result = urlfetch.fetch( |
| url, payload=data, method=method, |