Skip to content

Commit 520d22b

Browse files
committed
fixes #122 - translate empty params in POST
1 parent fff9a8e commit 520d22b

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

lib/WebDriver/Service/CurlService.php

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

5252
case 'POST':
53-
if ($parameters && is_array($parameters)) {
54-
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($parameters));
55-
} else {
56-
$customHeaders[] = 'Content-Length: 0';
57-
58-
// Suppress "Transfer-Encoding: chunked" header automatically added by cURL that
59-
// causes a 400 bad request (bad content-length).
60-
$customHeaders[] = 'Transfer-Encoding:';
53+
if ( ! $parameters || ! is_array($parameters)) {
54+
$parameters = array();
6155
}
6256

57+
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($parameters));
58+
6359
// Suppress "Expect: 100-continue" header automatically added by cURL that
6460
// causes a 1 second delay if the remote server does not support Expect.
6561
$customHeaders[] = 'Expect:';
@@ -72,16 +68,12 @@ public function execute($requestMethod, $url, $parameters = null, $extraOptions
7268
break;
7369

7470
case 'PUT':
75-
if ($parameters && is_array($parameters)) {
76-
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($parameters));
77-
} else {
78-
$customHeaders[] = 'Content-Length: 0';
79-
80-
// Suppress "Transfer-Encoding: chunked" header automatically added by cURL that
81-
// causes a 400 bad request (bad content-length).
82-
$customHeaders[] = 'Transfer-Encoding:';
71+
if ( ! $parameters || ! is_array($parameters)) {
72+
$parameters = array();
8373
}
8474

75+
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($parameters));
76+
8577
// Suppress "Expect: 100-continue" header automatically added by cURL that
8678
// causes a 1 second delay if the remote server does not support Expect.
8779
$customHeaders[] = 'Expect:';

0 commit comments

Comments
 (0)