Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set the Connection close header #1154

Merged
merged 1 commit into from
May 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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