Sending HTTP Headers to Controllers when Testing in Laravel
When testing a controller in Laravel, you can supply server parameters as part of the controller invocation. But if you're trying to send HTTP Headers, you have to make sure they're formatted properly or they'll be ignored.
Internally Laravel uses alot of Symfony components, and in this particular case the Symfony\Component\HttpFoundation\ServerBag wraps the $_SERVER variable, and it filters out any headers that don't start with "HTTP_".
//#call($method, $uri, $parameters, $files, $server, $content, $changeHistory)
//Custom-Header will be ignored, and \Request::header() will not contain it
$this->call('GET', 'my/url', [], [], ['Custom-Header' => 'content']);
//Custom-Header will now be available. The "HTTP_" is stripped off of the name
$this->call('GET', 'my/url', [], [], ['HTTP_Custom-Header' => 'content']);
Written by JP Camara
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#