Skip to content

Commit

Permalink
Merge branch '6.4' into 7.1
Browse files Browse the repository at this point in the history
* 6.4:
  [Console] Fix division by 0 error
  [ErrorHandler] Fix error message with PHP 8.5
  Add an experimental CI job for PHP 8.5
  [HttpClient] Always set CURLOPT_CUSTOMREQUEST to the correct HTTP method in CurlHttpClient
  evaluate access flags for properties with asymmetric visibility
  [Mime] Fix wrong PHPDoc in `FormDataPart` constructor
  • Loading branch information
xabbuh committed Dec 7, 2024
2 parents f4459f8 + f4f6d81 commit 6f84e44
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
3 changes: 1 addition & 2 deletions CurlHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,12 @@ public function request(string $method, string $url, array $options = []): Respo
$curlopts[\CURLOPT_RESOLVE] = $resolve;
}

$curlopts[\CURLOPT_CUSTOMREQUEST] = $method;
if ('POST' === $method) {
// Use CURLOPT_POST to have browser-like POST-to-GET redirects for 301, 302 and 303
$curlopts[\CURLOPT_POST] = true;
} elseif ('HEAD' === $method) {
$curlopts[\CURLOPT_NOBODY] = true;
} else {
$curlopts[\CURLOPT_CUSTOMREQUEST] = $method;
}

if ('\\' !== \DIRECTORY_SEPARATOR && $options['timeout'] < 1) {
Expand Down
22 changes: 22 additions & 0 deletions Tests/HttpClientTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -656,4 +656,26 @@ public function testDefaultContentType()

$this->assertSame(['abc' => 'def', 'content-type' => 'application/json', 'REQUEST_METHOD' => 'POST'], $response->toArray());
}

public function testHeadRequestWithClosureBody()
{
$p = TestHttpServer::start(8067);

try {
$client = $this->getHttpClient(__FUNCTION__);

$response = $client->request('HEAD', 'http://localhost:8057/head', [
'body' => fn () => '',
]);
$headers = $response->getHeaders();
} finally {
$p->stop();
}

$this->assertArrayHasKey('x-request-vars', $headers);

$vars = json_decode($headers['x-request-vars'][0], true);
$this->assertIsArray($vars);
$this->assertSame('HEAD', $vars['REQUEST_METHOD']);
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"php": ">=8.2",
"psr/log": "^1|^2|^3",
"symfony/deprecation-contracts": "^2.5|^3",
"symfony/http-client-contracts": "~3.4.3|^3.5.1",
"symfony/http-client-contracts": "~3.4.4|^3.5.2",
"symfony/service-contracts": "^2.5|^3"
},
"require-dev": {
Expand Down

0 comments on commit 6f84e44

Please sign in to comment.