- if (($qpos = strpos($path, '?')) !== false) {
- return substr($path, 0, $qpos);
- }
- return $path;
- }
-
- /**
- * Marshal the host and port from the request header
- *
- * @param stdClass $accumulator
- * @param string|array $host
- * @return void
- */
- private static function marshalHostAndPortFromHeader(stdClass $accumulator, $host)
- {
- if (is_array($host)) {
- $host = implode(', ', $host);
- }
-
- $accumulator->host = $host;
- $accumulator->port = null;
-
- // works for regname, IPv4 & IPv6
- if (preg_match('|\:(\d+)$|', $accumulator->host, $matches)) {
- $accumulator->host = substr($accumulator->host, 0, -1 * (strlen($matches[1]) + 1));
- $accumulator->port = (int) $matches[1];
- }
- }
-
- /**
- * Marshal host/port from misinterpreted IPv6 address
- *
- * @param stdClass $accumulator
- * @param array $server
- */
- private static function marshalIpv6HostAndPort(stdClass $accumulator, array $server)
- {
- $accumulator->host = '[' . $server['SERVER_ADDR'] . ']';
- $accumulator->port = $accumulator->port ?: 80;
- if ($accumulator->port . ']' === substr($accumulator->host, strrpos($accumulator->host, ':') + 1)) {
- // The last digit of the IPv6-Address has been taken as port
- // Unset the port so the default port can be used
- $accumulator->port = null;
- }
- }
-
- /**
- * Create and return an UploadedFile instance from a $_FILES specification.
- *
- * If the specification represents an array of values, this method will
- * delegate to normalizeNestedFileSpec() and return that return value.
- *
- * @param array $value $_FILES struct
- * @return array|UploadedFileInterface
- */
- private static function createUploadedFileFromSpec(array $value)
- {
- if (is_array($value['tmp_name'])) {
- return self::normalizeNestedFileSpec($value);
- }
-
- return new UploadedFile(
- $value['tmp_name'],
- $value['size'],
- $value['error'],
- $value['name'],
- $value['type']
- );
- }
-
- /**
- * Normalize an array of file specifications.
- *
- * Loops through all nested files and returns a normalized array of
- * UploadedFileInterface instances.
- *
- * @param array $files
- * @return UploadedFileInterface[]
- */
- private static function normalizeNestedFileSpec(array $files = [])
- {
- $normalizedFiles = [];
- foreach (array_keys($files['tmp_name']) as $key) {
- $spec = [
- 'tmp_name' => $files['tmp_name'][$key],
- 'size' => $files['size'][$key],
- 'error' => $files['error'][$key],
- 'name' => $files['name'][$key],
- 'type' => $files['type'][$key],
- ];
- $normalizedFiles[$key] = self::createUploadedFileFromSpec($spec);
- }
- return $normalizedFiles;
- }
-
- /**
- * Return HTTP protocol version (X.Y)
- *
- * @param array $server
- * @return string
- */
- private static function marshalProtocolVersion(array $server)
- {
- if (! isset($server['SERVER_PROTOCOL'])) {
- return '1.1';
- }
-
- if (! preg_match('#^(HTTP/)?(?P<version>[1-9]\d*(?:\.\d)?)$#', $server['SERVER_PROTOCOL'], $matches)) {
- throw new UnexpectedValueException(sprintf(
- 'Unrecognized protocol version (%s)',
- $server['SERVER_PROTOCOL']
- ));
- }
-
- return $matches['version'];
- }
-
- /**
- * Parse a cookie header according to RFC 6265.
- *
- * PHP will replace special characters in cookie names, which results in other cookies not being available due to
- * overwriting. Thus, the server request should take the cookies from the request header instead.
- *
- * @param $cookieHeader
- * @return array
- */
- private static function parseCookieHeader($cookieHeader)
- {
- preg_match_all('(
- (?:^\\n?[ \t]*|;[ ])
- (?P<name>[!#$%&\'*+-.0-9A-Z^_`a-z|~]+)
- =
- (?P<DQUOTE>"?)
- (?P<value>[\x21\x23-\x2b\x2d-\x3a\x3c-\x5b\x5d-\x7e]*)
- (?P=DQUOTE)
- (?=\\n?[ \t]*$|;[ ])
- )x', $cookieHeader, $matches, PREG_SET_ORDER);
-
- $cookies = [];
-
- foreach ($matches as $match) {
- $cookies[$match['name']] = urldecode($match['value']);
- }
-
- return $cookies;