| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import base64 | 5 import base64 |
| 6 import posixpath | 6 import posixpath |
| 7 | 7 |
| 8 from appengine_wrappers import GetAppVersion, urlfetch | 8 from appengine_wrappers import urlfetch |
| 9 from environment import GetAppVersion |
| 9 from future import Future | 10 from future import Future |
| 10 | 11 |
| 11 | 12 |
| 12 def _MakeHeaders(username, password): | 13 def _MakeHeaders(username, password): |
| 13 headers = { | 14 headers = { |
| 14 'User-Agent': 'Chromium docserver %s' % GetAppVersion(), | 15 'User-Agent': 'Chromium docserver %s' % GetAppVersion(), |
| 15 'Cache-Control': 'max-age=0', | 16 'Cache-Control': 'max-age=0', |
| 16 } | 17 } |
| 17 if username is not None and password is not None: | 18 if username is not None and password is not None: |
| 18 headers['Authorization'] = 'Basic %s' % base64.b64encode( | 19 headers['Authorization'] = 'Basic %s' % base64.b64encode( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 41 urlfetch.make_fetch_call(rpc, | 42 urlfetch.make_fetch_call(rpc, |
| 42 self._FromBasePath(url), | 43 self._FromBasePath(url), |
| 43 headers=_MakeHeaders(username, password)) | 44 headers=_MakeHeaders(username, password)) |
| 44 return Future(callback=lambda: rpc.get_result()) | 45 return Future(callback=lambda: rpc.get_result()) |
| 45 | 46 |
| 46 def _FromBasePath(self, url): | 47 def _FromBasePath(self, url): |
| 47 assert not url.startswith('/'), url | 48 assert not url.startswith('/'), url |
| 48 if self._base_path is not None: | 49 if self._base_path is not None: |
| 49 url = posixpath.join(self._base_path, url) if url else self._base_path | 50 url = posixpath.join(self._base_path, url) if url else self._base_path |
| 50 return url | 51 return url |
| OLD | NEW |