Adding headers to internal requests in Laravel 4
Turns out setting headers is as simple as doing
$request->headers->set('MyHeaderName', 'header value');
before dispatching the request.
The catch (and the reason this did not work when I tried) is that in the API I have to use Route::getCurrentRequest()
to get my custom request (as opposed to just asking the Request facade):
$request = Route::getCurrentRequest();$all_headers = $request->header();$specific_header = $request->header("SomeHeaderName");
You could set the headers using a application event in your filters.php
App::after(function($request, $response){ $response->headers->set('key','value');});
If you find your using a lot of them, moving them into their own service provider may provide for a better structure.