Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- `Innmind\Http\Header\SetCookie\Expires`
- `Innmind\Http\Header\SetCookie\MaxAge`
- `Innmind\Http\Header\SetCookie\Path`
- `Innmind\Http\Header\ContentType\Boundary::toHeader()`

### Changed

Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ use Innmind\Http\{
Request,
Method,
Content\Multipart,
Header\ContentType,
Header\ContentType\Boundary,
Headers,
ProtocolVersion,
Expand All @@ -77,7 +76,7 @@ $request = Request::of(
Url::of('http://some-server.com/')
Method::post,
ProtocolVersion::v11,
Headers::of(ContentType::of('multipart', 'form-data', $boundary)),
Headers::of($boundary->toHeader()),
Multipart::boundary($boundary)
->with('some[key]', 'some value')
->withFile('some[file]', File::named(
Expand Down
15 changes: 15 additions & 0 deletions src/Header/ContentType/Boundary.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
namespace Innmind\Http\Header\ContentType;

use Innmind\Http\{
Header\ContentType,
Header\Parameter,
Exception\DomainException,
};
use Innmind\MediaType;
use Innmind\Immutable\{
Str,
Maybe,
Expand Down Expand Up @@ -63,6 +65,19 @@ public function value(): string
return $this->value;
}

public function toHeader(): ContentType
{
return ContentType::of(new MediaType\MediaType(
'multipart',
'form-data',
'',
new MediaType\Parameter(
'boundary',
$this->value,
),
));
}

public function toParameter(): Parameter
{
return Parameter::of('boundary', $this->value);
Expand Down
2 changes: 1 addition & 1 deletion tests/Content/MultipartTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public function testFunctional()
\curl_setopt($handle, \CURLOPT_HEADER, false);
\curl_setopt($handle, \CURLOPT_RETURNTRANSFER, true);
\curl_setopt($handle, \CURLOPT_HTTPHEADER, [
'Content-Type: multipart/form-data; '.$boundary->toParameter()->toString(),
$boundary->toHeader()->normalize()->toString(),
]);
\curl_setopt($handle, \CURLOPT_CUSTOMREQUEST, 'POST');
\curl_setopt($handle, \CURLOPT_UPLOAD, true);
Expand Down