Skip to content

Commit

Permalink
Driver: Only set content-length for strings
Browse files Browse the repository at this point in the history
  • Loading branch information
chibimagic committed Mar 26, 2015
1 parent 130f50e commit 3db82a6
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions WebDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,19 @@ public static function Curl($http_type, $full_url, $payload = null, $escape_payl
curl_setopt($curl, CURLOPT_HEADER, TRUE);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, WebDriver::$CurlConnectTimeoutSec);
curl_setopt($curl, CURLOPT_TIMEOUT, WebDriver::$CurlTimeoutSec);
$headers = array('Expect:', 'Accept: application/json');
if ($payload !== null && is_string($payload) && json_decode($payload) !== null) {
$headers[] = 'Content-Type: application/json; charset=utf-8';
}
if (($http_type === "POST" || $http_type === "PUT") && $payload !== null) {
if ($escape_payload && (is_array($payload) || is_object($payload))) {
$payload = http_build_query($payload);
}
$headers[] = 'Content-Length: ' . strlen($payload);
curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);
}
$headers = array('Expect:', 'Accept: application/json');
if ($payload !== null && is_string($payload) && json_decode($payload) !== null) {
$headers[] = 'Content-Type: application/json; charset=utf-8';
}
if (is_string($payload)) {
$headers[] = 'Content-Length: ' . strlen($payload);
}
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
if (!empty($cookies)) {
$cookie_string = http_build_query($cookies, '', '; ');
Expand Down

0 comments on commit 3db82a6

Please sign in to comment.