diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f97c14..1d93ae9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 1da8d2b..f04df1d 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,6 @@ use Innmind\Http\{ Request, Method, Content\Multipart, - Header\ContentType, Header\ContentType\Boundary, Headers, ProtocolVersion, @@ -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( diff --git a/src/Header/ContentType/Boundary.php b/src/Header/ContentType/Boundary.php index d12f581..66004c4 100644 --- a/src/Header/ContentType/Boundary.php +++ b/src/Header/ContentType/Boundary.php @@ -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, @@ -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); diff --git a/tests/Content/MultipartTest.php b/tests/Content/MultipartTest.php index 8a1f3cf..56ba74b 100644 --- a/tests/Content/MultipartTest.php +++ b/tests/Content/MultipartTest.php @@ -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);