From 6d74cd24d8522c8c15cbb0af4ae0e1264f8a27cb Mon Sep 17 00:00:00 2001 From: Vincent Amstoutz Date: Thu, 9 Jan 2025 14:40:49 +0100 Subject: [PATCH] fix(state): stop adding Content-Location header for GET responses Avoids adding a redundant `Content-Location` header in GET responses, which can cause unnecessary complications, such as issues with temporary or preview resources lacking an ID. While this behavior complies with the HTTP specification (RFC 9110), it is unnecessary and potentially problematic. --- features/main/crud.feature | 1 + src/State/Processor/RespondProcessor.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/features/main/crud.feature b/features/main/crud.feature index 8dc25500ad2..a2381d1f9f3 100644 --- a/features/main/crud.feature +++ b/features/main/crud.feature @@ -60,6 +60,7 @@ Feature: Create-Retrieve-Update-Delete Then the response status code should be 200 And the response should be in JSON And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" + And the header "Content-Location" should not exist And the JSON should be equal to: """ { diff --git a/src/State/Processor/RespondProcessor.php b/src/State/Processor/RespondProcessor.php index 64b07308d3f..58941e437c3 100644 --- a/src/State/Processor/RespondProcessor.php +++ b/src/State/Processor/RespondProcessor.php @@ -129,7 +129,7 @@ public function process(mixed $data, Operation $operation, array $uriVariables = $iri = $this->iriConverter->getIriFromResource($operation->getClass(), UrlGeneratorInterface::ABS_PATH, $operation); } - if ($iri) { + if ($iri && 'GET' !== $method) { $location = \sprintf('%s.%s', $iri, $request->getRequestFormat()); if (isset($requestParts['query'])) { $location .= '?'.$requestParts['query'];