8000 [HttpClient] Stream request body in HttplugClient and Psr18Client · symfony/symfony@e6d1182 · GitHub
[go: up one dir, main page]

Skip to content

Commit e6d1182

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

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/Symfony/Component/HttpClient/HttplugClient.php

Lines 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

Lines 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