From d6b6a17cd1e5c8b227de30b5718e8e926e3d4637 Mon Sep 17 00:00:00 2001 From: Christopher Boumenot Date: Tue, 8 May 2018 16:10:34 +0000 Subject: [PATCH] set the Connection close header --- azurelinuxagent/common/utils/restutil.py | 2 ++ tests/utils/test_rest_util.py | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/azurelinuxagent/common/utils/restutil.py b/azurelinuxagent/common/utils/restutil.py index fc9aac93b9..5ceb4c949d 100644 --- a/azurelinuxagent/common/utils/restutil.py +++ b/azurelinuxagent/common/utils/restutil.py @@ -170,6 +170,8 @@ def _http_request(method, host, rel_uri, port=None, data=None, secure=False, headers=None, proxy_host=None, proxy_port=None): headers = {} if headers is None else headers + headers['Connection'] = 'close' + use_proxy = proxy_host is not None and proxy_port is not None if port is None: diff --git a/tests/utils/test_rest_util.py b/tests/utils/test_rest_util.py index a864884a84..adeb814185 100644 --- a/tests/utils/test_rest_util.py +++ b/tests/utils/test_rest_util.py @@ -195,7 +195,7 @@ def test_http_request_direct(self, HTTPConnection, HTTPSConnection): ]) HTTPSConnection.assert_not_called() mock_conn.request.assert_has_calls([ - call(method="GET", url="/bar", body=None, headers={'User-Agent': HTTP_USER_AGENT}) + call(method="GET", url="/bar", body=None, headers={'User-Agent': HTTP_USER_AGENT, 'Connection': 'close'}) ]) self.assertEqual(1, mock_conn.getresponse.call_count) self.assertNotEquals(None, resp) @@ -218,7 +218,7 @@ def test_http_request_direct_secure(self, HTTPConnection, HTTPSConnection): call("foo", 443, timeout=10) ]) mock_conn.request.assert_has_calls([ - call(method="GET", url="/bar", body=None, headers={'User-Agent': HTTP_USER_AGENT}) + call(method="GET", url="/bar", body=None, headers={'User-Agent': HTTP_USER_AGENT, 'Connection': 'close'}) ]) self.assertEqual(1, mock_conn.getresponse.call_count) self.assertNotEquals(None, resp) @@ -242,7 +242,7 @@ def test_http_request_proxy(self, HTTPConnection, HTTPSConnection): ]) HTTPSConnection.assert_not_called() mock_conn.request.assert_has_calls([ - call(method="GET", url="http://foo:80/bar", body=None, headers={'User-Agent': HTTP_USER_AGENT}) + call(method="GET", url="http://foo:80/bar", body=None, headers={'User-Agent': HTTP_USER_AGENT, 'Connection': 'close'}) ]) self.assertEqual(1, mock_conn.getresponse.call_count) self.assertNotEquals(None, resp) @@ -267,7 +267,7 @@ def test_http_request_proxy_secure(self, HTTPConnection, HTTPSConnection): call("foo.bar", 23333, timeout=10) ]) mock_conn.request.assert_has_calls([ - call(method="GET", url="https://foo:443/bar", body=None, headers={'User-Agent': HTTP_USER_AGENT}) + call(method="GET", url="https://foo:443/bar", body=None, headers={'User-Agent': HTTP_USER_AGENT, 'Connection': 'close'}) ]) self.assertEqual(1, mock_conn.getresponse.call_count) self.assertNotEquals(None, resp)