1 |
From: W-Mark Kubacki <wmark@×××××××××.de> |
2 |
|
3 |
The remote server logs will read like this: |
4 |
2001:db8::4 - - [14/Aug/2013:20:58:02 +0200] |
5 |
"GET /Packages HTTP/1.1" 304 0 "-" |
6 |
"Gentoo Portage 2.1.13.7 (default/linux/amd64/13.0, gcc-4.6.2, |
7 |
glibc-2.18, 3.9.0-rc8-mark-signed+ x86_64)" |
8 |
|
9 |
This will enable administrators to… |
10 |
• check if a machine uses the correct binhost |
11 |
• decide when new server-side features can be enabled (Portage ver.) |
12 |
• notify the machine's administrator of malconfigurations |
13 |
(such as wrong GCC libraries, profile, obsolete kernel) |
14 |
|
15 |
Construction of this header happens before "Packages" are fetched |
16 |
from a remote binhost. |
17 |
|
18 |
Signed-off-by: W-Mark Kubacki <wmark@×××××××××.de> |
19 |
--- |
20 |
pym/portage/dbapi/bintree.py | 8 +++++++- |
21 |
pym/portage/util/_urlopen.py | 4 ++-- |
22 |
2 files changed, 9 insertions(+), 3 deletions(-) |
23 |
|
24 |
diff --git a/pym/portage/dbapi/bintree.py b/pym/portage/dbapi/bintree.py |
25 |
index 61ac6b5..44ee8e6 100644 |
26 |
--- a/pym/portage/dbapi/bintree.py |
27 |
+++ b/pym/portage/dbapi/bintree.py |
28 |
@@ -20,6 +20,7 @@ portage.proxy.lazyimport.lazyimport(globals(), |
29 |
'portage.util.listdir:listdir', |
30 |
'portage.util._urlopen:urlopen@_urlopen', |
31 |
'portage.versions:best,catpkgsplit,catsplit,_pkg_str', |
32 |
+ '_emerge.actions:load_emerge_config,getportageversion', |
33 |
) |
34 |
|
35 |
from portage.cache.mappings import slot_dict_class |
36 |
@@ -892,8 +893,13 @@ class binarytree(object): |
37 |
# Don't use urlopen for https, since it doesn't support |
38 |
# certificate/hostname verification (bug #469888). |
39 |
if parsed_url.scheme not in ('https',): |
40 |
+ trees = load_emerge_config().trees |
41 |
+ user_agent = "Gentoo "+getportageversion(self.settings["PORTDIR"], None, |
42 |
+ self.settings.profile_path, self.settings["CHOST"], |
43 |
+ trees[self.settings['EROOT']]["vartree"].dbapi) |
44 |
try: |
45 |
- f = _urlopen(url, if_modified_since=local_timestamp) |
46 |
+ f = _urlopen(url, user_agent=user_agent, |
47 |
+ if_modified_since=local_timestamp) |
48 |
if hasattr(f, 'headers') and f.headers.get('timestamp', ''): |
49 |
remote_timestamp = f.headers.get('timestamp') |
50 |
except IOError as err: |
51 |
diff --git a/pym/portage/util/_urlopen.py b/pym/portage/util/_urlopen.py |
52 |
index 798e7b4..9876f29 100644 |
53 |
--- a/pym/portage/util/_urlopen.py |
54 |
+++ b/pym/portage/util/_urlopen.py |
55 |
@@ -26,7 +26,7 @@ if sys.hexversion >= 0x3000000: |
56 |
# and the file-'mtime' |
57 |
TIMESTAMP_TOLERANCE=5 |
58 |
|
59 |
-def urlopen(url, if_modified_since=None): |
60 |
+def urlopen(url, user_agent=None, if_modified_since=None): |
61 |
parse_result = urllib_parse.urlparse(url) |
62 |
if parse_result.scheme not in ("http", "https"): |
63 |
return _urlopen(url) |
64 |
@@ -35,7 +35,7 @@ def urlopen(url, if_modified_since=None): |
65 |
url = urllib_parse.urlunparse((parse_result.scheme, netloc, parse_result.path, parse_result.params, parse_result.query, parse_result.fragment)) |
66 |
password_manager = urllib_request.HTTPPasswordMgrWithDefaultRealm() |
67 |
request = urllib_request.Request(url) |
68 |
- request.add_header('User-Agent', 'Gentoo Portage '+VERSION) |
69 |
+ request.add_header('User-Agent', user_agent or 'Gentoo Portage '+VERSION) |
70 |
if if_modified_since: |
71 |
request.add_header('If-Modified-Since', _timestamp_to_http(if_modified_since)) |
72 |
if parse_result.username is not None: |
73 |
-- |
74 |
1.8.3.2 |