Skip to content

Commit

Permalink
Make copy
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreYang committed Feb 14, 2020
1 parent 7e441e5 commit 166fdf7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions datadog_checks_base/datadog_checks/base/utils/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ def _request(self, method, url, options):

extra_headers = options.pop('extra_headers', None)
if extra_headers is not None:
new_options['headers'] = new_options['headers'].copy()
new_options['headers'].update(extra_headers)

with ExitStack() as stack:
Expand Down
7 changes: 6 additions & 1 deletion datadog_checks_base/tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,9 @@ def test_extra_headers_on_http_method_call(self):
init_config = {}
http = RequestsWrapper(instance, init_config)

extra_headers = {"foo": "bar"}
with mock.patch("requests.get") as get:
http.get("http://example.com/hello", extra_headers={"foo": "bar"})
http.get("http://example.com/hello", extra_headers=extra_headers)

expected_options = {'foo': 'bar', 'User-Agent': 'Datadog Agent/0.0.0', 'answer': '42'}
get.assert_called_with(
Expand All @@ -138,6 +139,10 @@ def test_extra_headers_on_http_method_call(self):
verify=True,
)

# make sure the original headers are not modified
assert http.options['headers'] == {'User-Agent': 'Datadog Agent/0.0.0', 'answer': '42'}
assert extra_headers == {"foo": "bar"}


class TestVerify:
def test_config_default(self):
Expand Down

0 comments on commit 166fdf7

Please sign in to comment.