diff --git a/src/Symfony/Component/HttpClient/HttplugClient.php b/src/Symfony/Component/HttpClient/HttplugClient.php index 8e1dc1c4cb9e3..1d7632425cfc1 100644 --- a/src/Symfony/Component/HttpClient/HttplugClient.php +++ b/src/Symfony/Component/HttpClient/HttplugClient.php @@ -234,13 +234,13 @@ private function sendPsr7Request(RequestInterface $request, ?bool $buffer = null } $headers = $request->getHeaders(); - if (!$request->hasHeader('content-length') && 0 <= $size = $body->getSize() ?? -1) { + if (!$request->hasHeader('content-length') && 0 < $size = $body->getSize() ?? -1) { $headers['Content-Length'] = [$size]; } $options = [ 'headers' => $headers, - 'body' => static fn (int $size) => $body->read($size), + 'body' => 0 === $size ? '' : static fn (int $size) => $body->read($size), 'buffer' => $buffer, ]; diff --git a/src/Symfony/Component/HttpClient/Psr18Client.php b/src/Symfony/Component/HttpClient/Psr18Client.php index a2a19236e8f67..7b59e8bd0f133 100644 --- a/src/Symfony/Component/HttpClient/Psr18Client.php +++ b/src/Symfony/Component/HttpClient/Psr18Client.php @@ -98,13 +98,13 @@ public function sendRequest(RequestInterface $request): ResponseInterface } $headers = $request->getHeaders(); - if (!$request->hasHeader('content-length') && 0 <= $size = $body->getSize() ?? -1) { + if (!$request->hasHeader('content-length') && 0 < $size = $body->getSize() ?? -1) { $headers['Content-Length'] = [$size]; } $options = [ 'headers' => $headers, - 'body' => static fn (int $size) => $body->read($size), + 'body' => 0 === $size ? '' : static fn (int $size) => $body->read($size), ]; if ('1.0' === $request->getProtocolVersion()) {