Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure headers are consistent #11

Closed
akrabat opened this issue Oct 30, 2018 · 2 comments · Fixed by #70
Closed

Ensure headers are consistent #11

akrabat opened this issue Oct 30, 2018 · 2 comments · Fixed by #70

Comments

@akrabat
Copy link
Member

akrabat commented Oct 30, 2018

Migrated from slimphp/Slim-Http#61

@schmengler
Copy link

schmengler commented Nov 14, 2018

Glad that the issue is being addressed. This caused me some headache when passing a modified Slim request object from the environment to a Guzzle client and the headers with HTTP_ prefix got lost.

A workaround is to reset the original keys, using reflection:

    private function resetHeaderOriginalKeys(Request $request): void
    {
        $headersProperty = new \ReflectionProperty(Request::class, 'headers');
        $headersProperty->setAccessible(true);
        /** @var Headers $headers */
        $headers = $headersProperty->getValue($request);
        foreach ($headers as $key => $header) {
            $headers->set($key, $header['value']);
        }
        $headersProperty->setAccessible(false);
    }

@sridesmet
Copy link

Glad that the issue is being addressed. This caused me some headache when passing a modified Slim request object from the environment to a Guzzle client and the headers with HTTP_ prefix got lost.

A workaround is to reset the original keys, using reflection:

    private function resetHeaderOriginalKeys(Request $request): void
    {
        $headersProperty = new \ReflectionProperty(Request::class, 'headers');
        $headersProperty->setAccessible(true);
        /** @var Headers $headers */
        $headers = $headersProperty->getValue($request);
        foreach ($headers as $key => $header) {
            $headers->set($key, $header['value']);
        }
        $headersProperty->setAccessible(false);
    }

Here is your code in a middleware: https://gist.github.com/sridesmet/a3e0a6f3a3515aaf5d5b4b42479e8c67

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants