How to add a header to an existing Request object

I get a request which I want to forward via guzzle, but with an aditional header.

client —[myRequest]—>Service—[myRequest with added Header]—>2ndService

I use

$myRequest->withUri($uri_of_2nd_service)

to change the uri of the request and that works great.

But how can i slip in an additional header?
$r = $r->withHeader(‘myHeader’, ‘bla’) works only for response objects, right?

According to the PSR-7 message interface there is a ServerRequestInterface withHeader() method.

1 Like

Okay, I tried this and it works. Thanks a lot!