Level 13
Hi, did you ever figure this out? I want to add some data to the body for every request, but facing the same issues
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello,
I'm trying to add headers to outgoing PendingRequests from within beforeSending callback.
I guess it's the right moment to be sure everything I need is set to populate my headers' data.
Here is my callback:
public function buildRequestToHeaders(\Illuminate\Http\Client\Request $currentRequest, array $options, PendingRequest $requestTo): PendingRequest
{
$headers['x-forwarded-for'] = request()->ip();
$headers['x-my-custom-header'] = 'custom data computed from within the app';
$requestTo->withHeaders($headers);
return $requestTo;
}
The problem is that my headers go into $options but not into the embedded Guzzle client.
Do you know if it's possible ? How can I rebuild the Guzzle client so that it takes the new headers ?
Please or to participate in this conversation.