Skip to content

Commit

Permalink
Fix Content-Length for POST when data empty
Browse files Browse the repository at this point in the history
Signed-off-by: Jacques ROUSSEL <[email protected]>
  • Loading branch information
rouja committed Oct 28, 2023
1 parent 76de900 commit 018caa4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -1256,6 +1256,12 @@ protected function prepareHeaders($body, $uri)
$headers['Content-Length'] = strlen($body);
}
}

Check failure on line 1258 in src/Client.php

View workflow job for this annotation

GitHub Actions / QA Checks (PHPCodeSniffer [8.0, locked], ubuntu-latest, laminas/laminas-continuous-integration-ac...

Expected 1 space after closing brace; newline found
else {
if ($this->getMethod() == 'POST') {

Check failure on line 1260 in src/Client.php

View workflow job for this annotation

GitHub Actions / QA Checks (PHPCodeSniffer [8.0, locked], ubuntu-latest, laminas/laminas-continuous-integration-ac...

Operator == is disallowed, use === instead.
$headers['Content-Length'] = 0;
}
}

Check failure on line 1264 in src/Client.php

View workflow job for this annotation

GitHub Actions / QA Checks (PHPCodeSniffer [8.0, locked], ubuntu-latest, laminas/laminas-continuous-integration-ac...

Unexpected blank line found

// Merge the headers of the request (if any)
// here we need right 'http field' and not lowercase letters
Expand Down
20 changes: 20 additions & 0 deletions test/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,26 @@ public function testClientRequestMethod()
$this->assertSame(Client::ENC_URLENCODED, $client->getEncType());
}

public function testClientEmptyPost()
{
$client = new Client();
$prepareHeadersReflection = new ReflectionMethod($client, 'prepareHeaders');
$prepareHeadersReflection->setAccessible(true);

$request = new Request();
$request->setMethod(Request::METHOD_POST);
$client->setRequest($request);

$this->assertSame($client->getRequest(), $request);

$headers = $prepareHeadersReflection->invoke($client, '', new Http('http://localhost:5984'));

$this->assertIsArray($headers);
$this->assertArrayHasKey('Content-Length', $headers);

Check failure on line 523 in test/ClientTest.php

View workflow job for this annotation

GitHub Actions / QA Checks (PHPCodeSniffer [8.0, locked], ubuntu-latest, laminas/laminas-continuous-integration-ac...

Spaces must be used to indent lines; tabs are not allowed

Check failure on line 523 in test/ClientTest.php

View workflow job for this annotation

GitHub Actions / QA Checks (PHPCodeSniffer [8.0, locked], ubuntu-latest, laminas/laminas-continuous-integration-ac...

Line indented incorrectly; expected at least 8 spaces, found 4
$this->assertSame($headers['Content-Length'], 0);

Check failure on line 524 in test/ClientTest.php

View workflow job for this annotation

GitHub Actions / QA Checks (PHPCodeSniffer [8.0, locked], ubuntu-latest, laminas/laminas-continuous-integration-ac...

Spaces must be used to indent lines; tabs are not allowed

Check failure on line 524 in test/ClientTest.php

View workflow job for this annotation

GitHub Actions / QA Checks (PHPCodeSniffer [8.0, locked], ubuntu-latest, laminas/laminas-continuous-integration-ac...

Line indented incorrectly; expected at least 8 spaces, found 4

}

Check failure on line 526 in test/ClientTest.php

View workflow job for this annotation

GitHub Actions / QA Checks (PHPCodeSniffer [8.0, locked], ubuntu-latest, laminas/laminas-continuous-integration-ac...

Function closing brace must go on the next line following the body; found 1 blank lines before brace

Check failure on line 526 in test/ClientTest.php

View workflow job for this annotation

GitHub Actions / QA Checks (PHPCodeSniffer [8.0, locked], ubuntu-latest, laminas/laminas-continuous-integration-ac...

Blank line found before closing brace

/**
* @group 7332
*/
Expand Down

0 comments on commit 018caa4

Please sign in to comment.