Browse Source

Better debuggability of content-length mismatch

Jordi Boggiano 8 years ago
parent
commit
1fe5064560
1 changed files with 6 additions and 1 deletions
  1. 6 1
      src/Composer/Util/RemoteFilesystem.php

+ 6 - 1
src/Composer/Util/RemoteFilesystem.php

@@ -286,7 +286,12 @@ class RemoteFilesystem
             $contentLength = !empty($http_response_header[0]) ? $this->findHeaderValue($http_response_header, 'content-length') : null;
             if ($contentLength && Platform::strlen($result) < $contentLength) {
                 // alas, this is not possible via the stream callback because STREAM_NOTIFY_COMPLETED is documented, but not implemented anywhere in PHP
-                throw new TransportException('Content-Length mismatch');
+                $e = new TransportException('Content-Length mismatch, received '.Platform::strlen($result).' bytes out of the expected '.$contentLength);
+                $e->setHeaders($http_response_header);
+                $e->setStatusCode($this->findStatusCode($http_response_header));
+                $e->setResponse($result);
+
+                throw $e;
             }
 
             if (PHP_VERSION_ID < 50600 && !empty($options['ssl']['peer_fingerprint'])) {