Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## 1.3.2 - 2024-08-10

- Remove default `Content-Length` header from MultipartStreamBuilder class.

## 1.3.1 - 2024-06-10

- Added missing mimetype for `.webp` images.
Expand Down
13 changes: 3 additions & 10 deletions src/MultipartStreamBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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)) {
Expand Down
4 changes: 2 additions & 2 deletions tests/FunctionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ public function testHeaders()
$this->assertTrue(false === strpos($multipartStream, 'Content-Disposition:'));
}

public function testContentLength()
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: 15'));
}

public function testFormName()
Expand Down