Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Side by Side Diff: chrome/common/extensions/docs/server2/appengine_url_fetcher.py

Issue 98183003: Docserver: Fix GitHub authentication issues that have recently cropped up: use (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 urlfetch 8 from appengine_wrappers import GetAppVersion, urlfetch
9 from future import Future 9 from future import Future
10 10
11 11
12 class _AsyncFetchDelegate(object): 12 class _AsyncFetchDelegate(object):
13 def __init__(self, rpc): 13 def __init__(self, rpc):
14 self._rpc = rpc 14 self._rpc = rpc
15 15
16 def Get(self): 16 def Get(self):
17 return self._rpc.get_result() 17 return self._rpc.get_result()
18 18
19 19
20 def _MakeHeaders(username, password): 20 def _MakeHeaders(username, password):
21 headers = { 'Cache-Control': 'max-age=0' } 21 headers = {
22 'User-Agent': 'Chromium docserver %s' % GetAppVersion(),
23 'Cache-Control': 'max-age=0',
24 }
22 if username is not None and password is not None: 25 if username is not None and password is not None:
23 headers['Authorization'] = 'Basic %s' % base64.encodestring( 26 headers['Authorization'] = 'Basic %s' % base64.b64encode(
24 '%s:%s' % (username, password)) 27 '%s:%s' % (username, password))
25 return headers 28 return headers
26 29
27 30
28 class AppEngineUrlFetcher(object): 31 class AppEngineUrlFetcher(object):
29 """A wrapper around the App Engine urlfetch module that allows for easy 32 """A wrapper around the App Engine urlfetch module that allows for easy
30 async fetches. 33 async fetches.
31 """ 34 """
32 def __init__(self, base_path=None): 35 def __init__(self, base_path=None):
33 assert base_path is None or not base_path.endswith('/') 36 assert base_path is None or not base_path.endswith('/')
(...skipping 11 matching lines...) Expand all
45 rpc = urlfetch.create_rpc() 48 rpc = urlfetch.create_rpc()
46 urlfetch.make_fetch_call(rpc, 49 urlfetch.make_fetch_call(rpc,
47 self._FromBasePath(url), 50 self._FromBasePath(url),
48 headers=_MakeHeaders(username, password)) 51 headers=_MakeHeaders(username, password))
49 return Future(delegate=_AsyncFetchDelegate(rpc)) 52 return Future(delegate=_AsyncFetchDelegate(rpc))
50 53
51 def _FromBasePath(self, url): 54 def _FromBasePath(self, url):
52 if self._base_path is not None: 55 if self._base_path is not None:
53 url = posixpath.join(self._base_path, url) if url else self._base_path 56 url = posixpath.join(self._base_path, url) if url else self._base_path
54 return url 57 return url
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/server2/app.yaml ('k') | chrome/common/extensions/docs/server2/cron.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698