How to add a header to an existing Request object


#1

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?


#2

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


#3

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