Repository navigation
Conversation
…ders Add a bridge for Symfony HttpClient that triggers `trigger_deprecation()` when a response contains RFC 9745/8594 deprecation headers (Deprecation, Sunset, Link rel="deprecation"). Registered conditionally when symfony/http-client is installed. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR adds an optional Symfony HttpClient bridge to the bundle that detects RFC deprecation-related response headers and emits E_USER_DEPRECATED via trigger_deprecation(), enabling consumers to notice deprecated remote endpoints at runtime.
Changes:
- Introduces
DeprecationDetectorClient(HttpClient decorator) that checksDeprecation,Sunset, andLink(rel="deprecation") headers on responses. - Registers the decorator automatically when
symfony/http-clientis installed and thehttp_clientservice exists. - Adds unit tests covering expected header combinations and updates dev dependencies/suggestions.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/Bridge/HttpClient/DeprecationDetectorClient.php |
Adds the HttpClient decorator and deprecation-header detection logic. |
src/ApiDeprecationBundle.php |
Conditionally decorates the http_client service with the new detector. |
tests/Bridge/HttpClient/DeprecationDetectorClientTest.php |
Adds unit tests to assert deprecation triggering behavior for header combinations. |
composer.json |
Adds symfony/http-client to require-dev and suggests it for consumers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (str_contains($link, 'rel="deprecation"')) { | ||
| return $link; | ||
| } |
There was a problem hiding this comment.
findDeprecationLink() only matches the exact substring rel="deprecation". Valid Link headers can use an unquoted token (e.g. rel=deprecation), different casing, or multiple relation types (e.g. rel="foo deprecation"). This implementation will miss those legitimate deprecation links and fail to trigger deprecations.
Consider parsing the Link header parameters per RFC 8288 (tokenizing rel values case-insensitively and supporting both token and quoted-string forms), or at least using a regex that matches rel containing the deprecation token among other rel values.
| if (str_contains($link, 'rel="deprecation"')) { | |
| return $link; | |
| } | |
| // Split into URI-reference and parameters | |
| $parts = explode(';', $link); | |
| // No parameters, cannot contain a rel attribute | |
| if (\count($parts) < 2) { | |
| continue; | |
| } | |
| // Inspect parameters after the URI-reference | |
| foreach (\array_slice($parts, 1) as $param) { | |
| $param = \trim($param); | |
| if ($param == '') { | |
| continue; | |
| } | |
| $equalsPos = \strpos($param, '='); | |
| if ($equalsPos === false) { | |
| continue; | |
| } | |
| $name = \substr($param, 0, $equalsPos); | |
| $value = \substr($param, $equalsPos + 1); | |
| if (\strcasecmp(\trim($name), 'rel') !== 0) { | |
| continue; | |
| } | |
| // Normalize value: trim whitespace and optional surrounding quotes | |
| $value = \trim($value); | |
| if ($value !== '' && $value[0] === '"' && \substr($value, -1) === '"') { | |
| $value = \substr($value, 1, -1); | |
| } | |
| // rel can contain multiple space-separated relation types | |
| $tokens = \preg_split('/\s+/', $value) ?: []; | |
| foreach ($tokens as $token) { | |
| if ($token !== '' && \strcasecmp($token, 'deprecation') === 0) { | |
| return $link; | |
| } | |
| } | |
| } |
| $client = new DeprecationDetectorClient(new MockHttpClient(new MockResponse('', [ | ||
| 'response_headers' => ['Deprecation' => '@1718236800'], | ||
| ]))); |
There was a problem hiding this comment.
These tests build MockResponse with response_headers as an associative array (['Deprecation' => '...']). Symfony’s documented MockResponse format is a list of raw header lines (and it’s the only format that consistently supports multiple headers with the same name).
To avoid coupling the tests to MockResponse’s internal normalization quirks across Symfony versions, prefer using the canonical list-of-strings form (e.g. ['HTTP/1.1 200 OK', 'Deprecation: ...']).
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
|
|
||
| trigger_deprecation('', '', implode(' ', $parts)); | ||
| } |
There was a problem hiding this comment.
trigger_deprecation() is called with empty package and version strings. This makes the emitted deprecation harder to attribute/filter and can produce awkward messages in tooling expecting a package/version. Pass the actual package name (e.g., tiime/api-deprecation-bundle) and a meaningful version string (or a constant) instead of empty values.
| $parts = [\sprintf('%s %s is deprecated.', $method, $url)]; | ||
|
|
||
| if ($deprecation !== null) { | ||
| $parts[] = \sprintf('Deprecated since: %s.', $deprecation); | ||
| } |
There was a problem hiding this comment.
The deprecation message includes the full request URL verbatim. Since URLs can contain sensitive data (query params, userinfo), this can leak secrets into logs/error handlers when trigger_deprecation() is captured. Consider sanitizing the URL before including it (e.g., stripping userinfo and query/fragment, or logging only method + host + path).
| public function testTriggersDeprecationOnLinkHeaderWithDeprecationRel(): void | ||
| { | ||
| $client = new DeprecationDetectorClient(new MockHttpClient(new MockResponse('', [ | ||
| 'response_headers' => ['Link' => '</api/v2/users>; rel="deprecation"; type="text/html"'], | ||
| ]))); | ||
|
|
||
| $deprecation = $this->catchDeprecation(fn () => $client->request('GET', 'https://api.example.com/users')->getHeaders()); | ||
|
|
||
| self::assertNotNull($deprecation); | ||
| self::assertStringContainsString('rel="deprecation"', $deprecation); | ||
| } |
There was a problem hiding this comment.
The test fixtures/assertions use escaped quotes in Link headers (rel=\"deprecation\" / rel=\"next\"). In PHP single-quoted strings the backslashes are preserved, so this doesn’t represent a real HTTP header value and will mask the production bug in the matching logic. Update these to use actual header syntax (rel="deprecation", rel="next" without backslashes).
| "symfony/dependency-injection": "^6.4|^7.0|^8.0", | ||
| "symfony/deprecation-contracts": "^3.6", | ||
| "symfony/event-dispatcher-contracts": "^3.0", |
There was a problem hiding this comment.
PR description says Infection thresholds are 80%, but the repository’s infection.json5 config enforces minMsi/minCoveredMsi = 95. Please update the PR description (or the config/claim) so they’re consistent.
Summary
DeprecationDetectorClient, a Symfony HttpClient decorator that detects RFC 9745/8594 deprecation headers (Deprecation,Sunset,Linkrel="deprecation") in HTTP responses and triggerstrigger_deprecation()symfony/http-clientis installed andhttp_clientservice existsAsyncDecoratorTrait— the standard Symfony pattern for HTTP client decorationTest plan
make qagreen🤖 Generated with Claude Code