Skip to content

feat: support guzzlehttp/guzzle v8 - #315

Merged
DenTray merged 27 commits into
masterfrom
vitgrams/update-guzzle
Nov 30, 2026
Merged

DenTray merged 27 commits into
masterfrom
vitgrams/update-guzzle

Conversation

@vitgrams

@vitgrams vitgrams commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Refs: #318

What changes

  • guzzlehttp/guzzle constraint 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.
  • HttpRequestService keeps the error response after an exception on both majors (Guzzle 8 moved getResponse() to ResponseException).
  • Request options are the same as before: cookies and connect_timeout are always sent. Guzzle 8 accepts them (null options are removed before validation, 0 is a valid number).
  • Header values (int/float/bool/null, including values inside arrays) are cast to strings, because Guzzle 8 rejects non-string values. This happens in the new protected normalizeHeaders() method.
  • The previous response is reset before each request, so a failed request no longer exposes (or logs) the response of the previous one.
  • getResponse() returns ?ResponseInterface; json() throws InvalidJSONFormatException when there is no response.
  • Debug logging skips code and body when the request failed without a response (it used to fail on a null response).
  • The CI matrix runs guzzle 7.* and 8.* (Laravel 12 x Guzzle 8 is excluded, Laravel 11 is dropped).

Guzzle 7 → 8 upgrade guide coverage

The package uses only Client::get/post/put/patch/delete, CookieJar, RequestException and the response object. The sections of the Guzzle and PSR-7 3.x upgrade guides that touch this surface were checked against the code:

Upgrade guide item How the package handles it
Header values must be strings or non-empty arrays of strings normalizeHeaders() casts the values; covered by testSendWithNonStringHeaderValues
getResponse() exists only on ResponseException method_exists() check in send(); covered by testSendWithClientExceptionKeepsResponse
NetworkException is not a RequestException the response is reset before each request; covered by testSendResetsPreviousResponseOnFailure
Request option validation (cookies, connect_timeout, allow_redirects) a null cookies option is removed by Guzzle before validation, the other options have valid types
Request method casing is preserved the package calls $client->get() and the other verb methods, which send uppercase methods
Client::__call is removed magic verb methods are not used
The body cursor is no longer rewound after an HTTP error exception json() and multipart() read the body through a string cast, which rewinds it
Non-string scalars in multipart parts, nested arrays in query accepted; covered by testSendWithBodyViaRealClient and the smoke check below
PHP version and dependencies (PSR-7 3.x, Promises 3.x) resolved by composer on both the lowest and the latest Guzzle 8

The 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

  1. The minimum Guzzle 7 version is now 7.15.2. A project with an older locked version has to update Guzzle together with the package (composer update ronasit/laravel-helpers guzzlehttp/guzzle -W).
  2. getResponse() can return null: after a request that failed without a response it used to return the previous response (or throw a TypeError).
  3. Laravel 13 projects that have no guzzle constraint of their own may get Guzzle 8 on composer update. To stay on 7, add guzzlehttp/guzzle:^7.15.2 to the project.
  4. Known blocker for Guzzle 8 in consumers: ronasit/laravel-telescope-extension depends on muhammadhuzaifa/telescope-guzzle-watcher, which requires guzzle ^7.9.
  5. Suggested release: 3.9.0 (minor version with a BC note).

Project tests that assert the options of a mocked Client need 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:

  1. No connect timeout by default. The package always sends 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. Use setConnectTimeout() to limit it.
  2. Options passed through set() are validated. Guzzle 8 throws InvalidArgumentException for wrong types, for example set('timeout', '5'), set('cookies', true) or set('handler', ...).
  3. Exceptions. getResponse() exists only on ResponseException, RequestException no longer accepts a response, and network failures are NetworkException.
  4. Header values passed directly to Guzzle (not through HttpRequestService) must be strings or non-empty arrays of strings.
  5. Redirects. Only 301, 302, 303, 307 and 308 are followed; other 3xx responses are returned as is.
  6. Cookies. Secure cookies received over plain HTTP are ignored, and a host-only cookie gets a HostOnly key in the getCookie() array.
  7. TLS and libcurl. HTTPS requests default to TLS 1.2 or newer, and the cURL handler requires libcurl 7.34.0 or higher.
  8. Multipart. Parts no longer carry a generated Content-Length header, which affects tests that compare the raw request body.
  9. Request body that cannot be JSON-encoded. For a request with data and no content-type header, Guzzle 8 throws InvalidArgumentException on the body option when json_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:

Guzzle PSR-7 PHPUnit Real HTTP smoke check
7.15.2 (lowest) 2.13.0 502 tests OK 9/9
7.16.5 (latest) 2.13.6 502 tests OK 9/9
8.0.1 (lowest allowed by composer) 3.0.0 502 tests OK 9/9
8.5.5 (latest) 3.6.0 502 tests OK 9/9
  • The smoke check sends requests through the real cURL handler to a local PHP server: GET with a query and an int header; POST with json, form_params, multipart and no content-type; PUT, PATCH, DELETE; a cookie session; a 422 response kept in getResponse(); a refused connection that leaves getResponse() as null.
  • Guzzle 8.0.0 cannot be installed: composer blocks it due to security advisories, so 8.0.1 is the real minimum.
  • Laravel 12 was not run locally; the Laravel 12 x Guzzle 7 combination is covered by CI.
  • Pint: PASS.

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 in ronasit/github-actions (cap the matrix by the constraint).

https://claude.ai/code/session_01SSJ49j292crVrzcsfH8m9F

vitgrams and others added 11 commits November 12, 2026 14:53
- 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
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-30T10:41:50.569214Z 2ab00f8 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@vitgrams vitgrams self-assigned this Nov 14, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread composer.json
"ext-bcmath": "*",
"ext-json": "*",
"guzzlehttp/guzzle": "^7.9.2",
"guzzlehttp/guzzle": "^7.15.2 || ^8.0",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Client::prepareDefaults() removes null options before validation, and it has been doing so since v8.0.0.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@vitgrams
vitgrams requested a review from artengin November 22, 2026 08:35
@vitgrams vitgrams removed their assignment Nov 22, 2026
$this->assertEquals('some_value', $this->httpRequestServiceClass->getCookie()[0]['Value']);
}

public function testSendWithRequestExceptionInDebugMode()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/Services/HttpRequestService.php Outdated
}
});

// Guzzle 7 silently drops headers with an empty array value, Guzzle 8 rejects them

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the comment will be outdated once Guzzle 7 support is dropped, and it doesn't say why the callback is strict. Maybe:

Suggested change
// 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>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread composer.json
"ext-bcmath": "*",
"ext-json": "*",
"guzzlehttp/guzzle": "^7.9.2",
"guzzlehttp/guzzle": "^7.15.2 || ^8.0",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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>
Comment thread tests/HttpRequestServiceTest.php Resolved
@DenTray
DenTray merged commit 7c96f01 into master Nov 30, 2026
12 checks passed
@DenTray
DenTray deleted the vitgrams/update-guzzle branch November 30, 2026 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants