diff --git a/py/selenium/webdriver/remote/remote_connection.py b/py/selenium/webdriver/remote/remote_connection.py index 1951d087540de..87d2917f2e0a5 100644 --- a/py/selenium/webdriver/remote/remote_connection.py +++ b/py/selenium/webdriver/remote/remote_connection.py @@ -513,7 +513,8 @@ def _request(self, method, url, body=None): else: request = Request(url, data=body.encode('utf-8'), method=method) - request.headers.update(headers) + for key, val in headers.items(): + request.add_header(key, val) if password_manager: opener = url_request.build_opener(url_request.HTTPRedirectHandler(), diff --git a/py/test/unit/selenium/webdriver/remote/test_remote_connection.py b/py/test/unit/selenium/webdriver/remote/test_remote_connection.py index ddf30da858064..a4ab1d41d93b9 100644 --- a/py/test/unit/selenium/webdriver/remote/test_remote_connection.py +++ b/py/test/unit/selenium/webdriver/remote/test_remote_connection.py @@ -63,7 +63,8 @@ def getheader(self, *args, **kwargs): def test_remote_connection_adds_connection_headers_from_get_remote_connection_headers(mocker): - test_headers = {'FOO': 'bar'} + test_headers = {'FOO': 'bar', 'Content-Type': 'json'} + expected_request_headers = {'Foo': 'bar', 'Content-type': 'json'} # Stub out the get_remote_connection_headers method to return something testable mocker.patch( @@ -77,7 +78,7 @@ def test_remote_connection_adds_connection_headers_from_get_remote_connection_he mock_open = mocker.patch('urllib2.OpenerDirector.open') def assert_header_added(request, timeout): - assert request.headers == test_headers + assert request.headers == expected_request_headers return MockResponse() mock_open.side_effect = assert_header_added