withScheme($scheme); // Set the host list($host, $port) = $marshalHostAndPort($headers, $server); if (! empty($host)) { $uri = $uri->withHost($host); if (! empty($port)) { $uri = $uri->withPort($port); } } // URI path $path = $marshalRequestPath($server); // Strip query string $path = explode('?', $path, 2)[0]; // URI query $query = ''; if (isset($server['QUERY_STRING'])) { $query = ltrim($server['QUERY_STRING'], '?'); } // URI fragment $fragment = ''; if (strpos($path, '#') !== false) { list($path, $fragment) = explode('#', $path, 2); } return $uri ->withPath($path) ->withFragment($fragment) ->withQuery($query); }