Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 508d605

Browse filesBrowse 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
Copy full SHA for 508d605

File tree

2 files changed

+7
-3
lines changed
Filter options

2 files changed

+7
-3
lines changed

‎src/Symfony/Component/HttpClient/HttplugClient.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/HttplugClient.php
+3-1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/Psr18Client.php
+4-2Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.