diff --git a/CHANGELOG.md b/CHANGELOG.md index 30431e2..6bb487d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## 1.4.0 - 2024-09-01 + +- No longer automatically add a `Content-Length` header for each part in MultipartStreamBuilder class to comply with RFC 7578 section 4.8. + ## 1.3.1 - 2024-06-10 - Added missing mimetype for `.webp` images. diff --git a/src/MultipartStreamBuilder.php b/src/MultipartStreamBuilder.php index a3bcd7b..ca54c05 100644 --- a/src/MultipartStreamBuilder.php +++ b/src/MultipartStreamBuilder.php @@ -95,9 +95,9 @@ public function addData($resource, array $headers = []) * @param string|resource|StreamInterface $resource * @param array $options { * - * @var array $headers additional headers ['header-name' => 'header-value'] - * @var string $filename - * } + * @var array $headers additional headers ['header-name' => 'header-value'] + * @var string $filename + * } * * @return MultipartStreamBuilder */ @@ -185,13 +185,6 @@ private function prepareHeaders($name, StreamInterface $stream, $filename, array } } - // Set a default content-length header if one was not provided - if (!$this->hasHeader($headers, 'content-length')) { - if ($length = $stream->getSize()) { - $headers['Content-Length'] = (string) $length; - } - } - // Set a default Content-Type if one was not provided if (!$this->hasHeader($headers, 'content-type') && $hasFilename) { if ($type = $this->getMimetypeHelper()->getMimetypeFromFilename($filename)) { diff --git a/tests/FunctionTest.php b/tests/FunctionTest.php index 64b31a6..52e84ea 100644 --- a/tests/FunctionTest.php +++ b/tests/FunctionTest.php @@ -88,13 +88,16 @@ public function testHeaders() $this->assertTrue(false === strpos($multipartStream, 'Content-Disposition:')); } - public function testContentLength() + /** + * Comply with RFC 7578 section 4.8 + */ + public function testShouldNotContainContentLength() { $builder = new MultipartStreamBuilder(); $builder->addResource('foobar', 'stream contents'); $multipartStream = (string) $builder->build(); - $this->assertTrue(false !== strpos($multipartStream, 'Content-Length: 15')); + $this->assertTrue(false === strpos($multipartStream, 'Content-Length:')); } public function testFormName()