Skip to content

Commit

Permalink
Fix broken content-type for good
Browse files Browse the repository at this point in the history
  • Loading branch information
veewee committed Nov 9, 2023
1 parent 4ff5a2a commit 0d61ec6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions docs/files.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ $transport = EncodedTransportFactory::create(
);

$jsonData = $transport(
new Request('GET', '/some/file', [], new FormDataPart([
new Request('POST', '/some/file', [], new FormDataPart([
'name' => 'Jos bos',
'profile-pic' => DataPart::fromPath('/my-profile-pic.jpg')
])),
Expand All @@ -83,6 +83,6 @@ $transport = EncodedTransportFactory::create(

$multiPartStream = new MultipartStream($parts)
$jsonData = $transport(
new Request('GET', '/some/file', [], $multiPartStream)),
new Request('POST', '/some/file', [], $multiPartStream)),
);
```
2 changes: 1 addition & 1 deletion src/Encoding/Mime/MultiPartEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __invoke(RequestInterface $request, $data): RequestInterface
return $request
->withAddedHeader(
'Content-Type',
string()->assert($data->getPreparedHeaders()->get('content-type')?->toString())
string()->assert($data->getPreparedHeaders()->get('content-type')?->getBodyAsString())
)
->withBody($this->streamFactory->createStream(
$data->bodyToString()
Expand Down
4 changes: 3 additions & 1 deletion tests/Unit/Encoding/Mime/MultiPartEncoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function it_can_encode_multi_part(): void

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

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

self::assertSame($request->getMethod(), $actual->getMethod());
self::assertSame($request->getUri(), $actual->getUri());
Expand All @@ -37,5 +37,7 @@ public function it_can_encode_multi_part(): void
$actual->getHeader('Content-Type')
);
self::assertStringContainsString('boundary', $expectedContentType);
self::assertStringContainsString('multipart/form-data', $expectedContentType);
self::assertStringNotContainsString('content-type:', mb_strtolower($expectedContentType));
}
}

0 comments on commit 0d61ec6

Please sign in to comment.