Skip to content

Commit 9d9974b

Browse files
committed
fix: Remove default content-length header from MultipartStreamBuilder class
1 parent ed56da2 commit 9d9974b

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change Log
22

3+
## 1.3.2 - 2024-08-10
4+
5+
- Remove default `Content-Length` header from MultipartStreamBuilder class.
6+
37
## 1.3.1 - 2024-06-10
48

59
- Added missing mimetype for `.webp` images.

src/MultipartStreamBuilder.php

+3-10
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ public function addData($resource, array $headers = [])
9595
* @param string|resource|StreamInterface $resource
9696
* @param array $options {
9797
*
98-
* @var array $headers additional headers ['header-name' => 'header-value']
99-
* @var string $filename
100-
* }
98+
* @var array $headers additional headers ['header-name' => 'header-value']
99+
* @var string $filename
100+
* }
101101
*
102102
* @return MultipartStreamBuilder
103103
*/
@@ -185,13 +185,6 @@ private function prepareHeaders($name, StreamInterface $stream, $filename, array
185185
}
186186
}
187187

188-
// Set a default content-length header if one was not provided
189-
if (!$this->hasHeader($headers, 'content-length')) {
190-
if ($length = $stream->getSize()) {
191-
$headers['Content-Length'] = (string) $length;
192-
}
193-
}
194-
195188
// Set a default Content-Type if one was not provided
196189
if (!$this->hasHeader($headers, 'content-type') && $hasFilename) {
197190
if ($type = $this->getMimetypeHelper()->getMimetypeFromFilename($filename)) {

tests/FunctionTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ public function testHeaders()
8888
$this->assertTrue(false === strpos($multipartStream, 'Content-Disposition:'));
8989
}
9090

91-
public function testContentLength()
91+
public function testShouldNotContainContentLength()
9292
{
9393
$builder = new MultipartStreamBuilder();
9494
$builder->addResource('foobar', 'stream contents');
9595

9696
$multipartStream = (string) $builder->build();
97-
$this->assertTrue(false !== strpos($multipartStream, 'Content-Length: 15'));
97+
$this->assertTrue(false === strpos($multipartStream, 'Content-Length: 15'));
9898
}
9999

100100
public function testFormName()

0 commit comments

Comments
 (0)