Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
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.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.
Expand Down
9 changes: 1 addition & 8 deletions src/MultipartStreamBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function addData($resource, array $headers = [])
* @param string|resource|StreamInterface $resource
* @param array $options {
*
* @var array $headers additional headers ['header-name' => 'header-value']
* @var array $headers additional headers ['header-name' => 'header-value']
* @var string $filename
* }
*
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
7 changes: 5 additions & 2 deletions tests/FunctionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading