function RequestSanitizerTest::testRequestSanitizer
Tests X-Http-Method-Override header handling.
Attributes
#[IgnoreDeprecations]
File
-
core/
tests/ Drupal/ FunctionalTests/ HttpKernel/ RequestSanitizerTest.php, line 35
Class
- RequestSanitizerTest
- Tests RequestSanitizerMiddleware.
Namespace
Drupal\FunctionalTests\HttpKernelCode
public function testRequestSanitizer() : void {
$url = new Url('<front>');
$response = $this->makeApiRequest('GET', $url, []);
$this->assertSame(200, $response->getStatusCode());
$response = $this->makeApiRequest('POST', $url, []);
$this->assertSame(200, $response->getStatusCode());
$request_options = [];
$request_options[RequestOptions::HEADERS] = [
'X-Http-Method-Override' => 'GET',
];
$this->expectDeprecation('Since symfony/http-foundation 7.4: HTTP method override is deprecated for methods GET, HEAD, CONNECT and TRACE; it will be ignored in Symfony 8.0.');
$response = $this->makeApiRequest('POST', $url, $request_options);
$this->assertSame(200, $response->getStatusCode());
$this->assertSame('HIT', $response->getHeader('X-Drupal-Cache')[0]);
// Clear the page cache.
$this->rebuildAll();
$response = $this->makeApiRequest('POST', $url, $request_options);
$this->assertSame(400, $response->getStatusCode());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.