Skip to content

Commit eb80a1a

Browse files
authored
fix!(state): precise format on content-location (#6627)
1 parent 4a22716 commit eb80a1a

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

features/hydra/collection.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ Feature: Collections support
7777
When I send a "GET" request to "/dummies?page=7"
7878
Then the response status code should be 200
7979
And the response should be in JSON
80+
And the header "Content-Location" should be equal to "/dummies.jsonld?page=7"
8081
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
8182
And the JSON should be valid according to this schema:
8283
"""

src/State/Processor/RespondProcessor.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function process(mixed $data, Operation $operation, array $uriVariables =
105105
&& ($isAlternateResourceMetadata || $canonicalUriTemplate)
106106
) {
107107
$canonicalOperation = $operation;
108-
if ($this->operationMetadataFactory && null !== ($canonicalUriTemplate)) {
108+
if ($this->operationMetadataFactory && null !== $canonicalUriTemplate) {
109109
$canonicalOperation = $this->operationMetadataFactory->create($canonicalUriTemplate, $context);
110110
}
111111

@@ -119,6 +119,7 @@ public function process(mixed $data, Operation $operation, array $uriVariables =
119119

120120
$status ??= self::METHOD_TO_CODE[$method] ?? 200;
121121

122+
$requestParts = parse_url($request->getRequestUri());
122123
if ($this->iriConverter && !isset($headers['Content-Location'])) {
123124
try {
124125
if ($hasData) {
@@ -127,10 +128,16 @@ public function process(mixed $data, Operation $operation, array $uriVariables =
127128
$iri = $this->iriConverter->getIriFromResource($operation->getClass(), UrlGeneratorInterface::ABS_PATH, $operation);
128129
}
129130

130-
$headers['Content-Location'] = sprintf('%s.%s', $iri, $request->getRequestFormat());
131+
if ($iri) {
132+
$location = \sprintf('%s.%s', $iri, $request->getRequestFormat());
133+
if (isset($requestParts['query'])) {
134+
$location .= '?'.$requestParts['query'];
135+
}
131136

132-
if ((201 === $status || (300 <= $status && $status < 400)) && 'POST' === $method && !isset($headers['Location'])) {
133-
$headers['Location'] = $iri;
137+
$headers['Content-Location'] = $location;
138+
if ((201 === $status || (300 <= $status && $status < 400)) && 'POST' === $method && !isset($headers['Location'])) {
139+
$headers['Location'] = $iri;
140+
}
134141
}
135142
} catch (InvalidArgumentException|ItemNotFoundException|RuntimeException) {
136143
}

0 commit comments

Comments
 (0)