Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change \GuzzleHttp\Psr7\Utils::modifyRequest to keep initial Request object with modifications instead of creating new Request #599

Closed
tifeit opened this issue Mar 27, 2024 · 1 comment

Comments

@tifeit
Copy link

tifeit commented Mar 27, 2024

Description
Imagine you have the guzzle client middleware that logs the requests somewhere to DB
In addition to the request itself, you need some arbitrary data to be logged, like UserID
It will be nice to be able to pass the object of the class, that extends RequestInterface with this additional UserId data and use the middleware that will take this additional data and log the request.

Unfortunately, \GuzzleHttp\Psr7\Utils::modifyRequest instead of modifying the request object, creates a new instance of \GuzzleHttp\Psr7\Request::__construct, so the middleware will receive this new instance, without this arbitrary data, instead of the original, but modified request.

It looks like it is possible to modify the function to operate on the request itself using

$request->withoutHeader
$request->withHeader
$request->withMethod
$request->withUri
$request->withBody
$request->withProtocolVersion

mutators instead of creating new object.

I'm eager to write this change and create the PR, but I'd like to double-check first if this approach is valid or if I'm missing something.

Copy link

stale bot commented Feb 1, 2025

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 2 weeks if no further activity occurs. Thank you for your contributions.

@stale stale bot added the lifecycle/stale label Feb 1, 2025
@stale stale bot closed this as completed Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant