Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.0] Remove default content-length header from MultipartStream class #581

Open
wants to merge 3 commits into
base: 2.6
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 0 additions & 8 deletions src/MultipartStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
12 changes: 0 additions & 12 deletions tests/MultipartStreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down