Skip to content

Commit 9e60018

Browse files
committed
fix empty POST/PUT body in 520d22b
1 parent 4ac0709 commit 9e60018

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

lib/WebDriver/Service/CurlService.php

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,36 +50,25 @@ public function execute($requestMethod, $url, $parameters = null, $extraOptions
5050
break;
5151

5252
case 'POST':
53-
if ( ! $parameters || ! is_array($parameters)) {
54-
$parameters = array();
55-
}
53+
case 'PUT':
54+
$parameters = ! $parameters || ! is_array($parameters)
55+
? '{}'
56+
: json_encode($parameters);
5657

57-
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($parameters));
58+
curl_setopt($curl, CURLOPT_POSTFIELDS, $parameters);
5859

5960
// Suppress "Expect: 100-continue" header automatically added by cURL that
6061
// causes a 1 second delay if the remote server does not support Expect.
6162
$customHeaders[] = 'Expect:';
6263

63-
curl_setopt($curl, CURLOPT_POST, true);
64+
$requestMethod === 'POST'
65+
? curl_setopt($curl, CURLOPT_POST, true)
66+
: curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');
6467
break;
6568

6669
case 'DELETE':
6770
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE');
6871
break;
69-
70-
case 'PUT':
71-
if ( ! $parameters || ! is_array($parameters)) {
72-
$parameters = array();
73-
}
74-
75-
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($parameters));
76-
77-
// Suppress "Expect: 100-continue" header automatically added by cURL that
78-
// causes a 1 second delay if the remote server does not support Expect.
79-
$customHeaders[] = 'Expect:';
80-
81-
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');
82-
break;
8372
}
8473

8574
foreach ($extraOptions as $option => $value) {

0 commit comments

Comments
 (0)