Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[HttpKernel] Ensure HttpCache::getTraceKey() does not throw exception
  • Loading branch information
lyrixx authored and nicolas-grekas committed Nov 20, 2024
commit a2ebbe0596d1126d1e3616c29f3533d87fc6c254
7 changes: 6 additions & 1 deletion src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

namespace Symfony\Component\HttpKernel\HttpCache;

use Symfony\Component\HttpFoundation\Exception\SuspiciousOperationException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelInterface;
Expand Down Expand Up @@ -715,7 +716,11 @@ private function getTraceKey(Request $request): string
$path .= '?'.$qs;
}

return $request->getMethod().' '.$path;
try {
return $request->getMethod().' '.$path;
} catch (SuspiciousOperationException $e) {
return '_BAD_METHOD_ '.$path;
}
}

/**
Expand Down
11 changes: 11 additions & 0 deletions src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ public function testPassesOnNonGetHeadRequests()
$this->assertFalse($this->response->headers->has('Age'));
}

public function testPassesSuspiciousMethodRequests()
{
$this->setNextResponse(200);
$this->request('POST', '/', ['HTTP_X-HTTP-Method-Override' => '__CONSTRUCT']);
$this->assertHttpKernelIsCalled();
$this->assertResponseOk();
$this->assertTraceNotContains('stale');
$this->assertTraceNotContains('invalid');
$this->assertFalse($this->response->headers->has('Age'));
}

public function testInvalidatesOnPostPutDeleteRequests()
{
foreach (['post', 'put', 'delete'] as $method) {
Expand Down
Loading