Permalink
Browse files

Fixing Content-Length fixing in Response factory. Closes #155

  • Loading branch information...
1 parent 55aadfc commit 4ee3fb71a2021a1c7909dbe7e993d2192b1436bb @mtdowling mtdowling committed Oct 30, 2012
Showing with 7 additions and 5 deletions.
  1. +7 −5 Message/Response.php
View
@@ -131,15 +131,17 @@ public static function fromMessage($message)
return false;
}
- // Always set the appropriate Content-Length
- unset($data['headers']['Content-Length']);
- unset($data['headers']['content-length']);
- $data['headers']['Content-Length'] = strlen($data['body']);
-
$response = new static($data['code'], $data['headers'], $data['body']);
$response->setProtocol($data['protocol'], $data['version'])
->setStatus($data['code'], $data['reason_phrase']);
+ // Set the appropriate Content-Length if the one set is inaccurate (e.g. setting to X)
+ $contentLength = (string) $response->getHeader('Content-Length');
+ $actualLength = strlen($data['body']);
+ if (strlen($data['body']) > 0 && $contentLength != $actualLength) {
+ $response->setHeader('Content-Length', $actualLength);
+ }
+
return $response;
}

0 comments on commit 4ee3fb7

Please sign in to comment.