diff --git a/src/MultipartStream.php b/src/MultipartStream.php index 43d718f6..337d7d91 100644 --- a/src/MultipartStream.php +++ b/src/MultipartStream.php @@ -131,14 +131,6 @@ private function createElement(string $name, StreamInterface $stream, ?string $f : "form-data; name=\"{$name}\""; } - // Set a default content-length header if one was no provided - $length = self::getHeader($headers, 'content-length'); - if (!$length) { - if ($length = $stream->getSize()) { - $headers['Content-Length'] = (string) $length; - } - } - // Set a default Content-Type if one was not supplied $type = self::getHeader($headers, 'content-type'); if (!$type && ($filename === '0' || $filename)) { diff --git a/tests/MultipartStreamTest.php b/tests/MultipartStreamTest.php index ed778e0c..bf2652aa 100644 --- a/tests/MultipartStreamTest.php +++ b/tests/MultipartStreamTest.php @@ -64,12 +64,10 @@ public function testSerializesFields(): void $expected = \implode('', [ "--boundary\r\n", "Content-Disposition: form-data; name=\"foo\"\r\n", - "Content-Length: 3\r\n", "\r\n", "bar\r\n", "--boundary\r\n", "Content-Disposition: form-data; name=\"baz\"\r\n", - "Content-Length: 3\r\n", "\r\n", "bam\r\n", "--boundary--\r\n", @@ -102,7 +100,6 @@ public function testSerializesNonStringFields(): void $expected = \implode('', [ "--boundary\r\n", "Content-Disposition: form-data; name=\"int\"\r\n", - "Content-Length: 1\r\n", "\r\n", "1\r\n", "--boundary\r\n", @@ -112,12 +109,10 @@ public function testSerializesNonStringFields(): void '--boundary', "\r\n", "Content-Disposition: form-data; name=\"bool2\"\r\n", - "Content-Length: 1\r\n", "\r\n", "1\r\n", "--boundary\r\n", "Content-Disposition: form-data; name=\"float\"\r\n", - "Content-Length: 3\r\n", "\r\n", "1.1\r\n", "--boundary--\r\n", @@ -165,19 +160,16 @@ public function testSerializesFiles(): void $expected = \implode('', [ "--boundary\r\n", "Content-Disposition: form-data; name=\"foo\"; filename=\"bar.txt\"\r\n", - "Content-Length: 3\r\n", "Content-Type: text/plain\r\n", "\r\n", "foo\r\n", "--boundary\r\n", "Content-Disposition: form-data; name=\"qux\"; filename=\"baz.jpg\"\r\n", - "Content-Length: 3\r\n", "Content-Type: image/jpeg\r\n", "\r\n", "baz\r\n", "--boundary\r\n", "Content-Disposition: form-data; name=\"qux\"; filename=\"bar.unknown\"\r\n", - "Content-Length: 3\r\n", "Content-Type: application/octet-stream\r\n", "\r\n", "bar\r\n", @@ -208,7 +200,6 @@ public function testSerializesFilesWithMixedNewlines(): void $expected = \implode('', [ "--boundary\r\n", "Content-Disposition: form-data; name=\"newlines\"; filename=\"newlines.txt\"\r\n", - "Content-Length: {$contentLength}\r\n", "Content-Type: text/plain\r\n", "\r\n", "{$content}\r\n", @@ -243,7 +234,6 @@ public function testSerializesFilesWithCustomHeaders(): void "--boundary\r\n", "x-foo: bar\r\n", "content-disposition: custom\r\n", - "Content-Length: 3\r\n", "Content-Type: text/plain\r\n", "\r\n", "foo\r\n", @@ -287,14 +277,12 @@ public function testSerializesFilesWithCustomHeadersAndMultipleValues(): void "--boundary\r\n", "x-foo: bar\r\n", "content-disposition: custom\r\n", - "Content-Length: 3\r\n", "Content-Type: text/plain\r\n", "\r\n", "foo\r\n", "--boundary\r\n", "cOntenT-Type: custom\r\n", "Content-Disposition: form-data; name=\"foo\"; filename=\"baz.jpg\"\r\n", - "Content-Length: 3\r\n", "\r\n", "baz\r\n", "--boundary--\r\n",