From ca2cf6ec58c956a95d7e2cb9aaea206d1fff7aad Mon Sep 17 00:00:00 2001 From: Benni Mack Date: Tue, 1 Apr 2025 23:19:45 +0200 Subject: [PATCH 1/2] [BUGFIX] Fix upload to TER This commit adapts some changes when uploading a new version of extension. Symfony's HTTP Client did not send the Content-Type header properly, and also did not send the body as string, but as iterable/array which does not work anymore and is adapted to a string. Fixes: 82 --- .../UploadExtensionVersionCommand.php | 8 +++++-- src/Dto/RequestConfiguration.php | 21 +++++++++++++++++-- src/HttpClientFactory.php | 2 ++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/Command/Extension/UploadExtensionVersionCommand.php b/src/Command/Extension/UploadExtensionVersionCommand.php index e0b7c8d..3c06f10 100644 --- a/src/Command/Extension/UploadExtensionVersionCommand.php +++ b/src/Command/Extension/UploadExtensionVersionCommand.php @@ -24,6 +24,7 @@ use TYPO3\Tailor\Filesystem; use TYPO3\Tailor\Formatter\ConsoleFormatter; use TYPO3\Tailor\Helper\CommandHelper; +use TYPO3\Tailor\HttpClientFactory; use TYPO3\Tailor\Service\VersionService; /** @@ -75,8 +76,11 @@ protected function getRequestConfiguration(): RequestConfiguration 'POST', 'extension/' . $this->extensionKey . '/' . $this->version, [], - $formDataPart->bodyToIterable(), - $formDataPart->getPreparedHeaders()->toArray() + [], + [], + false, + HttpClientFactory::ALL_AUTH, + $formDataPart ); } diff --git a/src/Dto/RequestConfiguration.php b/src/Dto/RequestConfiguration.php index 18c976e..4fcfd0a 100644 --- a/src/Dto/RequestConfiguration.php +++ b/src/Dto/RequestConfiguration.php @@ -12,6 +12,7 @@ namespace TYPO3\Tailor\Dto; +use Symfony\Component\Mime\Part\Multipart\FormDataPart; use TYPO3\Tailor\HttpClientFactory; /** @@ -35,6 +36,9 @@ class RequestConfiguration /** @var iterable */ protected $body; + /** @var FormDataPart|null */ + protected $formData; + /** @var iterable */ protected $headers; @@ -54,7 +58,8 @@ public function __construct( iterable $body = [], iterable $headers = [], bool $raw = false, - int $defaultAuthMethod = HttpClientFactory::ALL_AUTH + int $defaultAuthMethod = HttpClientFactory::ALL_AUTH, + FormDataPart $formData = null ) { $this->method = $method; $this->endpoint = $endpoint; @@ -63,6 +68,7 @@ public function __construct( $this->headers = $headers; $this->raw = $raw; $this->defaultAuthMethod = $defaultAuthMethod; + $this->formData = $formData; } public function getMethod(): string @@ -85,9 +91,20 @@ public function getBody(): iterable return $this->body; } + public function getFormData(): ?FormDataPart + { + return $this->formData; + } + public function getHeaders(): iterable { - return $this->headers; + $headers = $this->headers; + if ($this->formData) { + foreach ($this->formData->getPreparedHeaders()->all() as $key => $value) { + $headers[$key] = $value->getBodyAsString(); + } + } + return $headers; } public function setRaw(bool $raw): self diff --git a/src/HttpClientFactory.php b/src/HttpClientFactory.php index cffa215..00334f7 100644 --- a/src/HttpClientFactory.php +++ b/src/HttpClientFactory.php @@ -48,6 +48,8 @@ public static function create(RequestConfiguration $requestConfiguration): HttpC } if ($requestConfiguration->getBody() !== []) { $options['body'] = $requestConfiguration->getBody(); + } elseif ($requestConfiguration->getFormData()) { + $options['body'] = $requestConfiguration->getFormData()->bodyToString(); } if (($defaultAuthMethod === self::BEARER_AUTH || $defaultAuthMethod === self::ALL_AUTH) && Variables::has('TYPO3_API_TOKEN') From 8393cbd7c0816f3ad4f26bfa4c0cad88aad43f89 Mon Sep 17 00:00:00 2001 From: Benni Mack Date: Tue, 1 Apr 2025 23:29:18 +0200 Subject: [PATCH 2/2] chore: adapt CGL --- src/Dto/RequestConfiguration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Dto/RequestConfiguration.php b/src/Dto/RequestConfiguration.php index 4fcfd0a..47cf070 100644 --- a/src/Dto/RequestConfiguration.php +++ b/src/Dto/RequestConfiguration.php @@ -59,7 +59,7 @@ public function __construct( iterable $headers = [], bool $raw = false, int $defaultAuthMethod = HttpClientFactory::ALL_AUTH, - FormDataPart $formData = null + ?FormDataPart $formData = null ) { $this->method = $method; $this->endpoint = $endpoint;