Skip to content

Commit

Permalink
Driver: Set content length after processing payload
Browse files Browse the repository at this point in the history
  • Loading branch information
chibimagic committed Mar 26, 2015
1 parent 47ffcc3 commit 130f50e
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions WebDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,17 @@ public static function Curl($http_type, $full_url, $payload = null, $escape_payl
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, WebDriver::$CurlConnectTimeoutSec);
curl_setopt($curl, CURLOPT_TIMEOUT, WebDriver::$CurlTimeoutSec);
$headers = array('Expect:', 'Accept: application/json');
if ($http_type === "POST" || $http_type === "PUT") {
$headers[] = 'Content-Length: ' . strlen($payload);
}
if ($payload !== null && is_string($payload) && json_decode($payload) !== null) {
$headers[] = 'Content-Type: application/json; charset=utf-8';
}
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
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);
}
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
if (!empty($cookies)) {
$cookie_string = http_build_query($cookies, '', '; ');
curl_setopt($curl, CURLOPT_COOKIE, $cookie_string);
Expand Down

0 comments on commit 130f50e

Please sign in to comment.