Skip to content

Commit 9439246

Browse files
authored
Merge pull request php-webdriver#530 from antoninrykalsky/fix/strict-http-1.1
Disable sending Expect header in POST requests
2 parents 5c724f1 + 42e7b65 commit 9439246

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ This project versioning adheres to [Semantic Versioning](http://semver.org/).
55
### Added
66
- Connection and request timeouts could be specified also when creating RemoteWebDriver from existing session ID.
77

8+
### Changed
9+
- Disable sending 'Expect: 100-Continue' header with POST requests, as they may more easily fail when sending via eg. squid proxy.
10+
811
## 1.5.0 - 2017-11-15
912
### Changed
1013
- Drop PHP 5.5 support, the minimal required version of PHP is now PHP 5.6.

lib/Remote/HttpCommandExecutor.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,12 @@ public function execute(WebDriverCommand $command)
263263
curl_setopt($this->curl, CURLOPT_CUSTOMREQUEST, $http_method);
264264
}
265265

266+
if (in_array($http_method, ['POST', 'PUT'])) {
267+
// Disable sending 'Expect: 100-Continue' header, as it is causing issues with eg. squid proxy
268+
// https://tools.ietf.org/html/rfc7231#section-5.1.1
269+
curl_setopt($this->curl, CURLOPT_HTTPHEADER, ['Expect:']);
270+
}
271+
266272
$encoded_params = null;
267273

268274
if ($http_method === 'POST' && $params && is_array($params)) {

tests/functional/ReportSauceLabsStatusListener.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ private function submitToSauceLabs($url, array $data)
7777
curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
7878
curl_setopt($curl, CURLOPT_USERPWD, getenv('SAUCE_USERNAME') . ':' . getenv('SAUCE_ACCESS_KEY'));
7979
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
80+
// Disable sending 'Expect: 100-Continue' header, as it is causing issues with eg. squid proxy
81+
curl_setopt($curl, CURLOPT_HTTPHEADER, ['Expect:']);
8082

8183
curl_exec($curl);
8284

tests/unit/Remote/HttpCommandExecutorTest.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,32 @@ public function setUp()
3434
* @dataProvider commandProvider
3535
* @param int $command
3636
* @param array $params
37+
* @param bool $shouldResetExpectHeader
3738
* @param string $expectedUrl
3839
* @param string $expectedPostData
3940
*/
40-
public function testShouldSendRequestToAssembledUrl($command, array $params, $expectedUrl, $expectedPostData)
41-
{
41+
public function testShouldSendRequestToAssembledUrl(
42+
$command,
43+
array $params,
44+
$shouldResetExpectHeader,
45+
$expectedUrl,
46+
$expectedPostData
47+
) {
4248
$command = new WebDriverCommand('foo-123', $command, $params);
4349

4450
$curlSetoptMock = $this->getFunctionMock(__NAMESPACE__, 'curl_setopt');
4551
$curlSetoptMock->expects($this->at(0))
4652
->with($this->anything(), CURLOPT_URL, $expectedUrl);
4753

48-
$curlSetoptMock->expects($this->at(2))
49-
->with($this->anything(), CURLOPT_POSTFIELDS, $expectedPostData);
54+
if ($shouldResetExpectHeader) {
55+
$curlSetoptMock->expects($this->at(2))
56+
->with($this->anything(), CURLOPT_HTTPHEADER, ['Expect:']);
57+
$curlSetoptMock->expects($this->at(3))
58+
->with($this->anything(), CURLOPT_POSTFIELDS, $expectedPostData);
59+
} else {
60+
$curlSetoptMock->expects($this->at(2))
61+
->with($this->anything(), CURLOPT_POSTFIELDS, $expectedPostData);
62+
}
5063

5164
$curlExecMock = $this->getFunctionMock(__NAMESPACE__, 'curl_exec');
5265
$curlExecMock->expects($this->once())
@@ -64,30 +77,35 @@ public function commandProvider()
6477
'POST command having :id placeholder in url' => [
6578
DriverCommand::SEND_KEYS_TO_ELEMENT,
6679
['value' => 'submitted-value', ':id' => '1337'],
80+
true,
6781
'http://localhost:4444/session/foo-123/element/1337/value',
6882
'{"value":"submitted-value"}',
6983
],
7084
'POST command without :id placeholder in url' => [
7185
DriverCommand::TOUCH_UP,
7286
['x' => 3, 'y' => 6],
87+
true,
7388
'http://localhost:4444/session/foo-123/touch/up',
7489
'{"x":3,"y":6}',
7590
],
7691
'Extra useless placeholder parameter should be removed' => [
7792
DriverCommand::TOUCH_UP,
7893
['x' => 3, 'y' => 6, ':useless' => 'foo'],
94+
true,
7995
'http://localhost:4444/session/foo-123/touch/up',
8096
'{"x":3,"y":6}',
8197
],
8298
'DELETE command' => [
8399
DriverCommand::DELETE_COOKIE,
84100
[':name' => 'cookie-name'],
101+
false,
85102
'http://localhost:4444/session/foo-123/cookie/cookie-name',
86103
null,
87104
],
88105
'GET command without session in URL' => [
89106
DriverCommand::GET_ALL_SESSIONS,
90107
[],
108+
false,
91109
'http://localhost:4444/sessions',
92110
null,
93111
],

0 commit comments

Comments
 (0)