Permalink
Browse files

[Http] Fixing issue that caused two Content-Length headers. Adding be…

…tter test coverage for Content-Length and chunked Transfer-Encoding. Removing some duplicate tests.
  • Loading branch information...
1 parent 08931be commit 6bcd8a477e6d1f5b78d5f01c3dd06ebaf7647862 @mtdowling mtdowling committed Jan 25, 2012
Showing with 14 additions and 3 deletions.
  1. +8 −3 Curl/CurlHandle.php
  2. +6 −0 Message/RequestFactory.php
View
@@ -92,6 +92,8 @@ public static function factory(RequestInterface $request)
}
// @codeCoverageIgnoreEnd
+ $headers = $request->getHeaders();
+
// Specify settings according to the HTTP method
switch ($request->getMethod()) {
case 'GET':
@@ -110,14 +112,17 @@ public static function factory(RequestInterface $request)
break;
case 'PUT':
$curlOptions[CURLOPT_UPLOAD] = true;
- if ($request->getBody()) {
- $curlOptions[CURLOPT_INFILESIZE] = $request->getHeader('Content-Length') ?: -1;
+ if (!$request->hasHeader('Content-Length')) {
+ unset($headers['Content-Length']);
+ } else {
+ $curlOptions[CURLOPT_INFILESIZE] = $request->getHeader('Content-Length');
}
+
break;
}
// Add any custom headers to the request
- foreach ($request->getHeaders() as $key => $value) {
+ foreach ($headers as $key => $value) {
if ($key && $value !== '') {
$curlOptions[CURLOPT_HTTPHEADER][] = $key . ': ' . $value;
}
@@ -225,6 +225,12 @@ public static function create($method, $url, $headers = null, $body = null)
$request->setBody((string) $body, $request->getHeader('Content-Type'));
}
}
+
+ // Fix chunked transfers based on the passed headers
+ if (isset($headers['Transfer-Encoding']) && $headers['Transfer-Encoding'] == 'chunked') {
+ $request->removeHeader('Content-Length')
+ ->setHeader('Transfer-Encoding', 'chunked');
+ }
}
return $request;

0 comments on commit 6bcd8a4

Please sign in to comment.