From 6010d3c8b903d7dae8b0ff11ec45c6f78ea50cc8 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Mon, 31 Aug 2015 12:28:09 -0400 Subject: readurl: if headers are provided still provide base headers we want cloud-init user agent to be present even if the user provided some headers. In the event that they provided User-Agent, this will respect their wishes. --- cloudinit/url_helper.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/cloudinit/url_helper.py b/cloudinit/url_helper.py index ce6b5444..a93847ce 100644 --- a/cloudinit/url_helper.py +++ b/cloudinit/url_helper.py @@ -211,10 +211,14 @@ def readurl(url, data=None, timeout=None, retries=0, sec_between=1, manual_tries = 1 if retries: manual_tries = max(int(retries) + 1, 1) - if not headers: - headers = { - 'User-Agent': 'Cloud-Init/%s' % (version.version_string()), - } + + def_headers = { + 'User-Agent': 'Cloud-Init/%s' % (version.version_string()), + } + if headers: + def_headers.update(headers) + headers = def_headers + if not headers_cb: def _cb(url): return headers -- cgit v1.2.3