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

Set server params for headers in global env #28

Description

@jasny

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;
    }

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions