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

Open
tifeit opened this issue Mar 27, 2024 · 0 comments

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.

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

No branches or pull requests

1 participant