slimphp / Slim-Psr7

PSR-7 implementation for use with Slim 4

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

request->getHeaders() returns HTTP_ uppercased header names

luispabon opened this issue · comments

Given the following slim route:

    // Echo back the request been sent to us
    $app->any('/check/request', function (Request $request, Response $response, array $args) use ($logger) {
        $request->getBody()->rewind();

        $payload = [
            'method'           => $request->getMethod(),
            'body'             => $request->getBody()->getContents(),
            'headers'          => $request->getHeaders(),
            'uri_path'         => $request->getUri()->getPath(),
            'query_parameters' => $request->getQueryParams(),
        ];

        return $response
            ->withHeader('content-type', 'application/json')
            ->withStatus(200)
            ->withBody(stream_for(json_encode($payload)));
    });

And the following curl request:

curl "localhost:8080/check/request?foo=bar" -XPUT -H"cov: fefe" -d"lalala"

The following comes out as a response:

{
    "method": "PUT",
    "body": "lalala",
    "headers": {
        "HTTP_HOST": [
            "localhost:8080"
        ],
        "HTTP_USER_AGENT": [
            "curl\/7.64.0"
        ],
        "HTTP_ACCEPT": [
            "*\/*"
        ],
        "HTTP_COV": [
            "fefe"
        ]
    },
    "uri_path": "\/check\/request",
    "query_parameters": {
        "foo": "bar"
    }
}

As you can see, the cov header comes out as HTTP_COV.

Slim 3.12.1

Ah, my mistake - I didn't realise slim 3 doesn't use this. Whoops.