Skip to content

Commit

Permalink
Merge pull request #36 from veewee/small-issue
Browse files Browse the repository at this point in the history
Fix small boundary issue
  • Loading branch information
veewee authored Nov 9, 2023
2 parents b8501fb + 85452c2 commit 4ff5a2a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/files.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ This decoder will try to parse some information from the Response headers and st
* `Content-Disposistion`: could result in guessing the filename, extension and/or mime-type.
* `Content-Length`: could be used to guess the size in bytes of the response.

The decoder is highly configurable, meaning you can alter the way it guesses specific properties or opt-out on intenser logic like calculating an md5 hash.
The decoder is highly configurable, meaning you can alter the way it guesses specific properties or opt-out on intenser logic like calculating a md5 hash.


## Upload file(s)
Expand Down
5 changes: 4 additions & 1 deletion src/Encoding/Mime/MultiPartEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Http\Discovery\Psr17FactoryDiscovery;
use Phpro\HttpTools\Dependency\SymfonyMimeDependency;
use Phpro\HttpTools\Encoding\EncoderInterface;

use function Psl\Type\string;

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\StreamFactoryInterface;
use Symfony\Component\Mime\Part\AbstractMultipartPart as MultiPart;
Expand Down Expand Up @@ -40,7 +43,7 @@ public function __invoke(RequestInterface $request, $data): RequestInterface
return $request
->withAddedHeader(
'Content-Type',
(string) ($data->getHeaders()->getHeaderBody('Content-Type') ?? 'multipart/form-data')
string()->assert($data->getPreparedHeaders()->get('content-type')?->toString())
)
->withBody($this->streamFactory->createStream(
$data->bodyToString()
Expand Down
8 changes: 7 additions & 1 deletion tests/Unit/Encoding/Mime/MultiPartEncoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,15 @@ public function it_can_encode_multi_part(): void

$actual = $encoder($request, $data);

$expectedContentType = $data->getPreparedHeaders()->get('Content-Type')->toString();

self::assertSame($request->getMethod(), $actual->getMethod());
self::assertSame($request->getUri(), $actual->getUri());
self::assertSame($data->bodyToString(), (string) $actual->getBody());
self::assertSame(['multipart/form-data'], $actual->getHeader('Content-Type'));
self::assertSame(
[$expectedContentType],
$actual->getHeader('Content-Type')
);
self::assertStringContainsString('boundary', $expectedContentType);
}
}

0 comments on commit 4ff5a2a

Please sign in to comment.