Repository navigation
feat: support guzzlehttp/guzzle v8 - #315
Conversation
- guzzle 8 removes getResponse() and hasResponse() from the base RequestException, keeping them only on ResponseException and its subclasses; check via method_exists() since ResponseException does not exist in guzzle 7, which this package still supports - guard logResponse() against a null $this->response so a response-less failure (network or protocol errors) no longer throws from the finally block and masks the original exception refs: https://app.clickup.com/t/PRD-3221
- add guzzlehttp/guzzle as an additional matrix package so tests run against the newly supported major - exclude the guzzle 8 combination for the laravel 12.* matrix entry, since laravel 12 requires guzzle ^7 refs: https://app.clickup.com/t/PRD-3221
- send connect_timeout only when it is set, so guzzle 8 keeps its default instead of treating 0 as disabled - cast scalar header values to strings, guzzle 8 rejects int/float/bool - send cookies only when a cookie session is saved instead of null refs: https://app.clickup.com/t/PRD-3221
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ca28725ced
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| @@ -119,7 +119,8 @@ public function send(string $method, string $url, array $data = [], array $heade | |||
|
|
|||
| return $this; | |||
| } catch (RequestException $exception) { | |||
There was a problem hiding this comment.
Clear the cached response for Guzzle 8 network failures
When the same service instance has completed a request and a later Guzzle 8 request fails at the network layer, the cached response is not cleared because Guzzle 8's NetworkException is a sibling of RequestException, not its subclass (exception hierarchy). The failed request therefore leaves getResponse() returning the previous request's response and, in debug mode, logs that stale response as if it belonged to the failure; catch the broader transfer failure or explicitly handle NetworkException and reset the response.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Resetting $this->response = null in src/Services/HttpRequestService.php:115 addresses this, and the testSendResetsPreviousResponseOnFailure test covers it. The thread can be resolved.
Send cookies and connect_timeout exactly as before guzzle 8 support, so consumer tests asserting mocked client options keep passing. Reset the previous response before each request and let getResponse() return null. refs: https://app.clickup.com/t/PRD-3221
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 80bc471224
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| "ext-bcmath": "*", | ||
| "ext-json": "*", | ||
| "guzzlehttp/guzzle": "^7.9.2", | ||
| "guzzlehttp/guzzle": "^7.15.2 || ^8.0", |
There was a problem hiding this comment.
Omit null cookie options before enabling Guzzle 8
With Guzzle 8 installed and saveCookieSession() not called, every request still sends 'cookies' => null from HttpRequestService::setOptions(). Guzzle 8 validates this option and rejects null rather than treating it as disabled, so the newly allowed major version cannot perform ordinary requests; omit the option unless a cookie jar exists.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Client::prepareDefaults() removes null options before validation, and it has been doing so since v8.0.0.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8b8869958d
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
|
||
| protected function normalizeHeaders(array $headers): array | ||
| { | ||
| array_walk_recursive($headers, function (&$value) { |
There was a problem hiding this comment.
Drop empty header arrays before passing them to Guzzle 8
When a caller supplies an optional header as an empty array, such as ['Authorization' => []], array_walk_recursive() never invokes this callback for that value, so the empty array reaches Guzzle unchanged. Guzzle 7 accepted this representation, but Guzzle 8's PSR-7 implementation requires header arrays to be non-empty and throws before sending the request; remove empty-valued headers or explicitly normalize them to an intended string value.
Useful? React with 👍 / 👎.
| $this->assertEquals('some_value', $this->httpRequestServiceClass->getCookie()[0]['Value']); | ||
| } | ||
|
|
||
| public function testSendWithRequestExceptionInDebugMode() |
There was a problem hiding this comment.
Non-blocking: this test only checks that the exception reaches the caller. The issue also requires that the debug log keeps time without code/body and that getResponse() is null here, so a Log::spy() assertion plus assertNull(getResponse()) would cover it; testSendResetsPreviousResponseOnFailure could also assert that json() throws. The repeated HandlerStack/MockHandler/app->instance(Client) setup could move into a helper in tests/Support/Traits.
| } | ||
| }); | ||
|
|
||
| // Guzzle 7 silently drops headers with an empty array value, Guzzle 8 rejects them |
There was a problem hiding this comment.
Nit: the comment will be outdated once Guzzle 7 support is dropped, and it doesn't say why the callback is strict. Maybe:
| // Guzzle 7 silently drops headers with an empty array value, Guzzle 8 rejects them | |
| // Guzzle rejects headers with an empty array value; empty strings and '0' are valid and kept |
… response - check that debug mode logs time without code/body and getResponse() is null - check that json() throws after a failed request resets the response - reword the empty array header filter comment without referring to Guzzle 7 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d3fe637516
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| "ext-bcmath": "*", | ||
| "ext-json": "*", | ||
| "guzzlehttp/guzzle": "^7.9.2", | ||
| "guzzlehttp/guzzle": "^7.15.2 || ^8.0", |
There was a problem hiding this comment.
Exclude the vulnerable Guzzle 8.0.0 release
When an application resolves exactly Guzzle 8.0.0 and sends requests to attacker-influenced URIs or with attacker-influenced Host headers, this new ^8.0 range permits a release affected by the noncanonical-host validation bypass fixed in 8.0.1; the 7.x side already starts at the corresponding patched 7.15.2. Raise the 8.x lower bound to ^8.0.1 so consumers cannot install the vulnerable release (GHSA-v5mv-p594-2x33).
Useful? React with 👍 / 👎.
- add mockGuzzleResponses() binding a real Client with a queued MockHandler and history middleware - add getSentRequest() to read requests recorded by the history middleware - drop the repeated HandlerStack/MockHandler/Client setup from the tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Refs: #318
What changes
guzzlehttp/guzzleconstraint is now^7.15.2 || ^8.0. The 7.x minimum was raised because composer blocks versions below 7.15.2 due to security advisories.HttpRequestServicekeeps the error response after an exception on both majors (Guzzle 8 movedgetResponse()toResponseException).cookiesandconnect_timeoutare always sent. Guzzle 8 accepts them (null options are removed before validation,0is a valid number).protected normalizeHeaders()method.getResponse()returns?ResponseInterface;json()throwsInvalidJSONFormatExceptionwhen there is no response.codeandbodywhen the request failed without a response (it used to fail on a null response).Guzzle 7 → 8 upgrade guide coverage
The package uses only
Client::get/post/put/patch/delete,CookieJar,RequestExceptionand the response object. The sections of the Guzzle and PSR-7 3.x upgrade guides that touch this surface were checked against the code:normalizeHeaders()casts the values; covered bytestSendWithNonStringHeaderValuesgetResponse()exists only onResponseExceptionmethod_exists()check insend(); covered bytestSendWithClientExceptionKeepsResponseNetworkExceptionis not aRequestExceptiontestSendResetsPreviousResponseOnFailurecookies,connect_timeout,allow_redirects)cookiesoption is removed by Guzzle before validation, the other options have valid types$client->get()and the other verb methods, which send uppercase methodsClient::__callis removedjson()andmultipart()read the body through a string cast, which rewinds itquerytestSendWithBodyViaRealClientand the smoke check belowThe guide sections about auth, proxies, HTTP/2, custom handlers and callbacks do not apply: the package does not use these APIs.
Breaking changes / upgrade notes
composer update ronasit/laravel-helpers guzzlehttp/guzzle -W).getResponse()can returnnull: after a request that failed without a response it used to return the previous response (or throw aTypeError).composer update. To stay on 7, addguzzlehttp/guzzle:^7.15.2to the project.ronasit/laravel-telescope-extensiondepends onmuhammadhuzaifa/telescope-guzzle-watcher, which requires guzzle^7.9.Project tests that assert the options of a mocked
Clientneed no changes: the options array is the same as in the previous release.Guzzle 8 behavior that the package does not hide
These changes come from Guzzle 8 itself and reach projects through
HttpRequestService:connect_timeout => 0. On Guzzle 7 this means the libcurl default of 300s. On Guzzle 8 it disables the connect timeout and overrides Guzzle's own new default of 60s. UsesetConnectTimeout()to limit it.set()are validated. Guzzle 8 throwsInvalidArgumentExceptionfor wrong types, for exampleset('timeout', '5'),set('cookies', true)orset('handler', ...).getResponse()exists only onResponseException,RequestExceptionno longer accepts a response, and network failures areNetworkException.HttpRequestService) must be strings or non-empty arrays of strings.Securecookies received over plain HTTP are ignored, and a host-only cookie gets aHostOnlykey in thegetCookie()array.Content-Lengthheader, which affects tests that compare the raw request body.content-typeheader, Guzzle 8 throwsInvalidArgumentExceptionon thebodyoption whenjson_encode()fails.How it was verified
Four throwaway containers on commit
8b88699(PHP 8.5.4, Laravel 13.43.0), each with its own dependency install:json,form_params,multipartand nocontent-type; PUT, PATCH, DELETE; a cookie session; a 422 response kept ingetResponse(); a refused connection that leavesgetResponse()asnull.Known follow-up
The shared CI matrix takes the latest Guzzle major from Packagist, so a future Guzzle 9 release will add a
9.*axis that the constraint does not allow. This needs a fix inronasit/github-actions(cap the matrix by the constraint).https://claude.ai/code/session_01SSJ49j292crVrzcsfH8m9F