My controller's methods require a header to be set, e.g. X-Authorization
. After a new object has been created (store
action), I do a forward to show the newly created object (show
action):
$request = Request::create(route('api.v1.b.show', ['booking' => 4]), 'GET');
Request::replace($request->input());
return Route::dispatch($request);
The forwarding works ok if I disable the authorization check, but it fails otherwise. ie. the header has gone. I would like to copy the request header, which I can get with Request::header('X-Authorization')
into the forwarded request. Is it possible?
I have tried without success to do $request->header('X-Authorization', 'xxxxx')
. Also tried PHP's header()
before the dispatch and didn't work.
Any ideas? Cheers
The Forwarded request header contains information that may be added by reverse proxy servers (load balancers, CDNs, and so on) that would otherwise be altered or lost when proxy servers are involved in the path of the request.
To add custom headers to an HTTP request object, use the AddHeader() method. You can use this method multiple times to add multiple headers.
Under Custom response headers, click Add header. Enter the Header name and Header value for the custom response header. Enter any additional custom response headers. Click Save.
Ok, i think you need to set the headers like so:
$request = Request::create(route('api.v1.b.show', ['booking' => 4]), 'GET');
$request->headers->set('X-Authorization', 'xxxxx');
That is the answer to your question.
My question is: Where can we set this headers for every api request(forwarding)? Because i personally have 5 headers to set with the request and i don't want to repeat myself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With