Skip to content

Navigation Menu

Sign in
Appearance settings

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 e6d1182

Browse filesBrowse files
KurtThiemannnicolas-grekas
authored andcommitted
[HttpClient] Stream request body in HttplugClient and Psr18Client
1 parent dbacea3 commit e6d1182
Copy full SHA for e6d1182

File tree

2 files changed

+14
-4
lines changed
Filter options

2 files changed

+14
-4
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/HttplugClient.php
+7-2Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,14 @@ private function sendPsr7Request(RequestInterface $request, ?bool $buffer = null
229229
$body->seek(0);
230230
}
231231

232+
$headers = $request->getHeaders();
233+
if (!$request->hasHeader('content-length') && 0 <= $size = $body->getSize() ?? -1) {
234+
$headers['Content-Length'] = [$size];
235+
}
236+
232237
$options = [
233-
'headers' => $request->getHeaders(),
234-
'body' => $body->getContents(),
238+
'headers' => $headers,
239+
'body' => static fn (int $size) => $body->read($size),
235240
'buffer' => $buffer,
236241
];
237242

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/Psr18Client.php
+7-2Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,14 @@ public function sendRequest(RequestInterface $request): ResponseInterface
9393
$body->seek(0);
9494
}
9595

96+
$headers = $request->getHeaders();
97+
if (!$request->hasHeader('content-length') && 0 <= $size = $body->getSize() ?? -1) {
98+
$headers['Content-Length'] = [$size];
99+
}
100+
96101
$options = [
97-
'headers' => $request->getHeaders(),
98-
'body' => $body->getContents(),
102+
'headers' => $headers,
103+
'body' => static fn (int $size) => $body->read($size),
99104
];
100105

101106
if ('1.0' === $request->getProtocolVersion()) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.