From d766061e9975329c6b4d1f024318a34a7409b7d7 Mon Sep 17 00:00:00 2001 From: Joshua Johnston Date: Wed, 3 Jul 2013 11:46:36 -0400 Subject: [PATCH] Add phpunit to require-dev Make sure to use serialized_payload length as Content-Length if the request has a body --- composer.json | 3 +++ src/Httpful/Request.php | 15 +++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 510121d..7c3de84 100644 --- a/composer.json +++ b/composer.json @@ -20,5 +20,8 @@ "psr-0": { "Httpful": "src/" } + }, + "require-dev": { + "phpunit/phpunit": "*" } } diff --git a/src/Httpful/Request.php b/src/Httpful/Request.php index d5b7db3..63b92ec 100644 --- a/src/Httpful/Request.php +++ b/src/Httpful/Request.php @@ -784,6 +784,14 @@ public function _curlPrep() curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->strict_ssl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + // https://github.com/nategood/httpful/issues/84 + // set Content-Length to the size of the payload if present + if (isset($this->payload)) { + $this->serialized_payload = $this->_serializePayload($this->payload); + curl_setopt($ch, CURLOPT_POSTFIELDS, $this->serialized_payload); + $this->headers['Content-Length'] = strlen($this->serialized_payload); + } + $headers = array(); // https://github.com/nategood/httpful/issues/37 // Except header removes any HTTP 1.1 Continue from response headers @@ -807,7 +815,7 @@ public function _curlPrep() $headers[] = $accept; } - //Solve a bug on squid proxy, NONE/411 when miss content length + // Solve a bug on squid proxy, NONE/411 when miss content length if (!isset($this->headers['Content-Length'])) { $this->headers['Content-Length'] = 0; } @@ -826,11 +834,6 @@ public function _curlPrep() curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); - if (isset($this->payload)) { - $this->serialized_payload = $this->_serializePayload($this->payload); - curl_setopt($ch, CURLOPT_POSTFIELDS, $this->serialized_payload); - } - if ($this->_debug) { curl_setopt($ch, CURLOPT_VERBOSE, true); }