Repository navigation
Conversation
Remove the _api_deprecated request attribute before each exit point in onKernelController (sunset/brownout custom response and exception paths). This prevents onKernelResponse from rebuilding and re-appending the Link header to responses that already carry it.
There was a problem hiding this comment.
Pull request overview
Fixes a bug in the deprecation header listener where the Link header could be appended twice during the sunset/brownout “gone” flows, and adds regression tests intended to cover the controller+response lifecycle for those paths.
Changes:
- Clear
_api_deprecatedfrom the request before returning a custom sunset/brownout response or throwingGoneHttpException. - Add 4 new regression tests simulating the controller + response event lifecycle for sunset/brownout, covering both custom-response and exception paths.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/EventListener/DeprecationHeaderListener.php |
Removes _api_deprecated before sunset/brownout early exits to prevent onKernelResponse() from re-processing headers. |
tests/EventListener/DeprecationHeaderListenerTest.php |
Adds regression tests to ensure Link is not duplicated in sunset/brownout custom response and exception flows. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
69
to
72
| if ($customResponse !== null) { | ||
| $event->getRequest()->attributes->remove('_api_deprecated'); | ||
| $event->setController(static fn () => $customResponse); | ||
|
|
| self::assertSame( | ||
| '</api/v2/users>; rel="deprecation"; type="text/html"', | ||
| $customResponse->headers->get('Link'), | ||
| ); |
Comment on lines
+658
to
+666
| // After the exception, the attribute should have been removed | ||
| // so onKernelResponse won't re-add headers to the error response | ||
| self::assertNull($request->attributes->get('_api_deprecated')); | ||
|
|
||
| // The exception itself should carry the headers | ||
| $headers = $e->getHeaders(); | ||
| self::assertArrayHasKey('Link', $headers); | ||
| self::assertArrayHasKey('Sunset', $headers); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Linkheader value was appended twice when sunset had passed (or during brownout), becauseonKernelResponsere-added headers that were already attached viaGoneHttpExceptionor custom event responses._api_deprecatedrequest attribute before each of the 4 exit points inonKernelController(sunset custom response, sunset exception, brownout custom response, brownout exception) soonKernelResponseno longer re-processes them.Root cause
onKernelControllerstores_api_deprecatedon the request (line 55) before checking sunset/brownout. When the controller phase handles the response (custom response or exception with headers), the attribute remains on the request.onKernelResponsethen finds it, rebuilds headers, and appends theLinkvalue again — producing a duplicated header like:Quality gates