Skip to content

Commit 508d605

Browse files
ajgarlagnicolas-grekas
authored andcommitted
Prevent empty request body stream in HttplugClient and Psr18Client
This prevents adding `Content-Length` and `Transfer-Encoding` headers when sending a request with an empty body using CurlHttpClient
1 parent f0239d8 commit 508d605

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/Symfony/Component/HttpClient/HttplugClient.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,9 @@ private function sendPsr7Request(RequestInterface $request, ?bool $buffer = null
231231
$headers['Content-Length'] = [$size];
232232
}
233233

234-
if (0 <= $size && $size < 1 << 21) {
234+
if (0 === $size) {
235+
$body = '';
236+
} elseif (0 < $size && $size < 1 << 21) {
235237
if ($body->isSeekable()) {
236238
try {
237239
$body->seek(0);

src/Symfony/Component/HttpClient/Psr18Client.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,13 @@ public function sendRequest(RequestInterface $request): ResponseInterface
9191
$headers = $request->getHeaders();
9292

9393
$size = $request->getHeader('content-length')[0] ?? -1;
94-
if (0 > $size && 0 <= $size = $body->getSize() ?? -1) {
94+
if (0 > $size && 0 < $size = $body->getSize() ?? -1) {
9595
$headers['Content-Length'] = [$size];
9696
}
9797

98-
if (0 <= $size && $size < 1 << 21) {
98+
if (0 === $size) {
99+
$body = '';
100+
} elseif (0 < $size && $size < 1 << 21) {
99101
if ($body->isSeekable()) {
100102
try {
101103
$body->seek(0);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy