Skip to content

Commit

Permalink
Merge pull request #85 from Trii/proper-content-length
Browse files Browse the repository at this point in the history
Add proper Content-Length based off of the request body's length
  • Loading branch information
nategood committed Jul 3, 2013
2 parents 2e3386e + d766061 commit fe72af0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@
"psr-0": {
"Httpful": "src/"
}
},
"require-dev": {
"phpunit/phpunit": "*"
}
}
15 changes: 9 additions & 6 deletions src/Httpful/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Expand All @@ -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);
}
Expand Down

0 comments on commit fe72af0

Please sign in to comment.