From 1908914a669a2ad8c25c67367a5eb65747859d8d Mon Sep 17 00:00:00 2001 From: Fabian Gruber Date: Wed, 5 Mar 2025 15:32:17 +0100 Subject: [PATCH] fix: allow null body --- src/Client.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Client.php b/src/Client.php index cd73edd..e52da87 100644 --- a/src/Client.php +++ b/src/Client.php @@ -204,14 +204,14 @@ private function withRetries(callable $callback): mixed public function fetch( string $url, string $method = self::METHOD_GET, - array $body = [], - array $query = [], + ?array $body = [], + ?array $query = [], ): Response { if (!in_array($method, [self::METHOD_PATCH, self::METHOD_GET, self::METHOD_CONNECT, self::METHOD_DELETE, self::METHOD_POST, self::METHOD_HEAD, self::METHOD_OPTIONS, self::METHOD_PUT, self::METHOD_TRACE])) { throw new FetchException("Unsupported HTTP method"); } - if (isset($this->headers['content-type'])) { + if (isset($this->headers['content-type']) && $body !== null) { $body = match ($this->headers['content-type']) { self::CONTENT_TYPE_APPLICATION_JSON => json_encode($body), self::CONTENT_TYPE_APPLICATION_FORM_URLENCODED, self::CONTENT_TYPE_MULTIPART_FORM_DATA => self::flatten($body),