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 8ddba18

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 76b7a0a commit 8ddba18
Copy full SHA for 8ddba18

File tree

Expand file treeCollapse file tree

2 files changed

+8
-4
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+8
-4
lines changed

‎HttplugClient.php

Copy file name to clipboardExpand all lines: HttplugClient.php
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,13 @@ private function sendPsr7Request(RequestInterface $request, ?bool $buffer = null
227227
$headers = $request->getHeaders();
228228

229229
$size = $request->getHeader('content-length')[0] ?? -1;
230-
if (0 > $size && 0 <= $size = $body->getSize() ?? -1) {
230+
if (0 > $size && 0 < $size = $body->getSize() ?? -1) {
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);

‎Psr18Client.php

Copy file name to clipboardExpand all lines: 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.