Skip to content

Commit c1f869d

Browse files
committed
set CURLOPT_INFILESIZE to 0 again with no or empty body
1 parent bb2f326 commit c1f869d

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/Psr18/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ protected function initRequest(RequestInterface $request, ResponseHeaderParser $
103103

104104
$requestBody = $request->getBody();
105105
$requestBodySize = $requestBody->getSize();
106-
if ($requestBodySize !== null && $requestBodySize > 0) {
106+
if ($requestBodySize !== null && $requestBodySize >= 0) {
107107
$ch->setopt(CURLOPT_INFILESIZE, $requestBodySize);
108108
$request = $request->withHeader("Content-Length", $requestBodySize);
109109
}

tests/HttpClientTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,4 +681,21 @@ public function testGetDefaultPort(): void
681681
$this->assertEquals(80, $reflection->getMethod("getDefaultPort")->invoke($this->client, new Uri("http://example.com")));
682682
$this->assertNull($reflection->getMethod("getDefaultPort")->invoke($this->client, new Uri("ftp://example.com")));
683683
}
684+
685+
public function testSetContentLengthToZeroWithNoBody(): void
686+
{
687+
$request = $this->requestFactory->createRequest("GET", "https://example.com");
688+
$this->client->sendRequest($request);
689+
$this->assertEquals("0", $this->curlHandle->getRequestHeader("Content-Length"));
690+
$this->assertEquals(0, $this->curlHandle->getOption(CURLOPT_INFILESIZE));
691+
}
692+
693+
public function testSetContentLengthToZeroWithEmptyBody(): void
694+
{
695+
$request = $this->requestFactory->createRequest("POST", "https://example.com")
696+
->withBody($this->streamFactory->createStream());
697+
$this->client->sendRequest($request);
698+
$this->assertEquals("0", $this->curlHandle->getRequestHeader("Content-Length"));
699+
$this->assertEquals(0, $this->curlHandle->getOption(CURLOPT_INFILESIZE));
700+
}
684701
}

0 commit comments

Comments
 (0)