8000 test that HTTP clients sent HEAD requests despite a request body clos… · symfony/symfony@727f020 · GitHub
[go: up one dir, main page]

Skip to content

Commit 727f020

Browse files
committed
test that HTTP clients sent HEAD requests despite a request body closure being set
1 parent 552f861 commit 727f020

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/Symfony/Component/HttpClient/Tests/HttpClientTestCase.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,4 +656,26 @@ public function testDefaultContentType()
656656

657657
$this->assertSame(['abc' => 'def', 'content-type' => 'application/json', 'REQUEST_METHOD' => 'POST'], $response->toArray());
658658
}
659+
660+
public function testHeadRequestWithClosureBody()
661+
{
662+
$p = TestHttpServer::start(8067);
663+
664+
try {
665+
$client = $this->getHttpClient(__FUNCTION__);
666+
667+
$response = $client->request('HEAD', "http://localhost:8057/head", [
668+
'body' => fn () => '',
669+
]);
670+
$headers = $response->getHeaders();
671+
} finally {
672+
$p->stop();
673+
}
674+
675+
$this->assertArrayHasKey("x-request-vars", $headers);
676+
677+
$vars = json_decode($headers["x-request-vars"][0], true);
678+
$this->assertIsArray($vars);
679+
$this->assertSame("HEAD", $vars["REQUEST_METHOD"]);
680+
}
659681
}

src/Symfony/Contracts/HttpClient/Test/Fixtures/web/index.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
exit;
4343

4444
case '/head':
45+
header('X-Request-Vars: '.json_encode($vars, \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE));
4546
header('Content-Length: '.strlen($json), true);
4647
break;
4748

0 commit comments

Comments
 (0)
0