Skip to content

Commit cbcc53c

Browse files
Antonin RykalskyOndraM
authored andcommitted
Fix other http headers being not sent in case of adding Except header
1 parent 42e7b65 commit cbcc53c

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

lib/Remote/HttpCommandExecutor.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
*/
2727
class HttpCommandExecutor implements WebDriverCommandExecutor
2828
{
29+
const DEFAULT_HTTP_HEADERS = [
30+
'Content-Type: application/json;charset=UTF-8',
31+
'Accept: application/json',
32+
];
33+
2934
/**
3035
* @see https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#command-reference
3136
*/
@@ -169,14 +174,7 @@ public function __construct($url, $http_proxy = null, $http_proxy_port = null)
169174

170175
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
171176
curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, true);
172-
curl_setopt(
173-
$this->curl,
174-
CURLOPT_HTTPHEADER,
175-
[
176-
'Content-Type: application/json;charset=UTF-8',
177-
'Accept: application/json',
178-
]
179-
);
177+
curl_setopt($this->curl, CURLOPT_HTTPHEADER, static::DEFAULT_HTTP_HEADERS);
180178
$this->setRequestTimeout(30000);
181179
$this->setConnectionTimeout(30000);
182180
}
@@ -266,7 +264,9 @@ public function execute(WebDriverCommand $command)
266264
if (in_array($http_method, ['POST', 'PUT'])) {
267265
// Disable sending 'Expect: 100-Continue' header, as it is causing issues with eg. squid proxy
268266
// https://tools.ietf.org/html/rfc7231#section-5.1.1
269-
curl_setopt($this->curl, CURLOPT_HTTPHEADER, ['Expect:']);
267+
curl_setopt($this->curl, CURLOPT_HTTPHEADER, array_merge(static::DEFAULT_HTTP_HEADERS, ['Expect:']));
268+
} else {
269+
curl_setopt($this->curl, CURLOPT_HTTPHEADER, static::DEFAULT_HTTP_HEADERS);
270270
}
271271

272272
$encoded_params = null;

tests/unit/Remote/HttpCommandExecutorTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,21 @@ public function testShouldSendRequestToAssembledUrl(
5353

5454
if ($shouldResetExpectHeader) {
5555
$curlSetoptMock->expects($this->at(2))
56-
->with($this->anything(), CURLOPT_HTTPHEADER, ['Expect:']);
56+
->with(
57+
$this->anything(),
58+
CURLOPT_HTTPHEADER,
59+
['Content-Type: application/json;charset=UTF-8', 'Accept: application/json', 'Expect:']
60+
);
5761
$curlSetoptMock->expects($this->at(3))
5862
->with($this->anything(), CURLOPT_POSTFIELDS, $expectedPostData);
5963
} else {
6064
$curlSetoptMock->expects($this->at(2))
65+
->with(
66+
$this->anything(),
67+
CURLOPT_HTTPHEADER,
68+
['Content-Type: application/json;charset=UTF-8', 'Accept: application/json']
69+
);
70+
$curlSetoptMock->expects($this->at(3))
6171
->with($this->anything(), CURLOPT_POSTFIELDS, $expectedPostData);
6272
}
6373

0 commit comments

Comments
 (0)