Repository: guzzle/psr7 (php)

Issue:
Content-Type assumption not done if the file don't have extension
**PHP version**: x.y.z (hint: `php --version`)

**Description**
There is an issue within psr7 in the MultipartStream class inside createElement method (https://github.com/guzzle/psr7/blob/815698d9f11c908bc59471d11f642264b533346a/src/MultipartStream.php#L141C1-L141C1).
There is an assumption a content-type is returned no matter what...

**How to reproduce**
Try to upload a multipart file without extension

**Possible Solution**
Add a default content-type for files without extensions l'île proposes in PR  #566

**Additional context**
<!-- Optional: any other context about the problem: log messages, screenshots, etc. -->


Pull request description:
Fallback to `application/octet-stream` if we are unable to guess the content type for a multipart file upload
Needs tests. Closes #567. Probably should be considered a feature and target 2.6.

Patch:
diff --git a/src/MultipartStream.php b/src/MultipartStream.php
index 688edb3..41c48ee 100644
--- a/src/MultipartStream.php
+++ b/src/MultipartStream.php
@@ -137,9 +137,7 @@ final class MultipartStream implements StreamInterface
         // Set a default Content-Type if one was not supplied
         $type = $this->getHeader($headers, 'content-type');
         if (!$type && ($filename === '0' || $filename)) {
-            if ($type = MimeType::fromFilename($filename)) {
-                $headers['Content-Type'] = $type;
-            }
+            $headers['Content-Type'] = MimeType::fromFilename($filename) ?? 'application/octet-stream';
         }
 
         return [$stream, $headers];


Test patch:
diff --git a/tests/MultipartStreamTest.php b/tests/MultipartStreamTest.php
index 85ef831..ed778e0 100644
--- a/tests/MultipartStreamTest.php
+++ b/tests/MultipartStreamTest.php
@@ -143,7 +143,7 @@ class MultipartStreamTest extends TestCase
 
         $f3 = Psr7\FnStream::decorate(Psr7\Utils::streamFor('bar'), [
             'getMetadata' => static function (): string {
-                return '/foo/bar.gif';
+                return '/foo/bar.unknown';
             },
         ]);
 
@@ -176,9 +176,9 @@ class MultipartStreamTest extends TestCase
             "\r\n",
             "baz\r\n",
             "--boundary\r\n",
-            "Content-Disposition: form-data; name=\"qux\"; filename=\"bar.gif\"\r\n",
+            "Content-Disposition: form-data; name=\"qux\"; filename=\"bar.unknown\"\r\n",
             "Content-Length: 3\r\n",
-            "Content-Type: image/gif\r\n",
+            "Content-Type: application/octet-stream\r\n",
             "\r\n",
             "bar\r\n",
             "--boundary--\r\n",