Lumen-framework: Unable to add custom headers through $this->call() in TestCase

Created on 17 Jun 2015  路  5Comments  路  Source: laravel/lumen-framework

I'm trying to preform a test where I need to add a custom header to my request. I've tried it like so:

$headers = ['X-Signature' => md5($customer . env("API_SECRET"))];
$this->call(
            'post',
            '/hooks/customers',
            [],
            [],
            [],
            $headers,
            $customer
        );

but the X-Signature header is never added, internally only these headers are _replaced_:

<?php
//class Symfony\Component\HttpFoundation\Request;
$server = array_replace(array(
            'SERVER_NAME' => 'localhost',
            'SERVER_PORT' => 80,
            'HTTP_HOST' => 'localhost',
            'HTTP_USER_AGENT' => 'Symfony/2.X',
            'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
            'HTTP_ACCEPT_LANGUAGE' => 'en-us,en;q=0.5',
            'HTTP_ACCEPT_CHARSET' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
            'REMOTE_ADDR' => '127.0.0.1',
            'SCRIPT_NAME' => '',
            'SCRIPT_FILENAME' => '',
            'SERVER_PROTOCOL' => 'HTTP/1.1',
            'REQUEST_TIME' => time(),
        ), $server); 

Because of this, I have to manually create the request and add the header.

Most helpful comment

Shouldn't this be documented somewhere? I searched quite a lot until I found this here.

All 5 comments

You need HTTP_ first in the header name.

HTTP_X-Signature

Shouldn't this be documented somewhere? I searched quite a lot until I found this here.

Checking in from 2020 to confirm this is still poorly documented.

Feel free to send prs to the docs.

Was this page helpful?
0 / 5 - 0 ratings