Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

Set server params for headers in global env #28

Open
jasny opened this issue Jan 20, 2017 · 0 comments
Open

Set server params for headers in global env #28

jasny opened this issue Jan 20, 2017 · 0 comments

Comments

@jasny
Copy link
Owner

jasny commented Jan 20, 2017

When a ServerRequest is bound to the global environment, we modify $_SERVER when the request method, target and headers are set.

The codeception module now does this itself, but it's not actually his task to do so

    /**
     * Get additional server params from request.
     * @internal It would be nicer if this was solved by Jasny Http Message
     * 
     * @param ServerRequestInterface $psrRequest
     * @return array
     */
    protected function determineServerParams(ServerRequestInterface $psrRequest)
    {
        $server = [
            'REQUEST_METHOD' => $psrRequest->getMethod(),
            'QUERY_STRING' => http_build_query($psrRequest->getQueryParams()),
            'REQUEST_URI' => $psrRequest->getRequestTarget()
        ];
        
        foreach ($psrRequest->getHeaders() as $name => $values) {
            $value = end($values);
            $key = strtoupper(str_replace('-', '_', $name));
            
            if ($key !== 'CONTENT_TYPE' && $key !== 'CONTENT_LENGTH') {
                $key = "HTTP_" . $key;
            }
            
            $server[$key] = $value;
        }
        
        return $server;
    }
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant