Skip to content

Commit

Permalink
set the Connection close header
Browse files Browse the repository at this point in the history
  • Loading branch information
boumenot committed May 8, 2018
1 parent 7d81e99 commit d6b6a17
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions azurelinuxagent/common/utils/restutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions tests/utils/test_rest_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit d6b6a17

Please sign in to comment.