/** * Checks if a complete URI with all parts is transformed into an object correctly. * * @test */ public function constructorParsesAFullBlownUriStringCorrectly() { $uriString = 'http://*****:*****@subdomain.domain.com:8080/path1/path2/index.php?argument1=value1&argument2=value2&argument3[subargument1]=subvalue1#anchor'; $uri = new Uri($uriString); $check = $uri->getScheme() == 'http' && $uri->getUsername() == 'username' && $uri->getPassword() == 'password' && $uri->getHost() == 'subdomain.domain.com' && $uri->getPort() === 8080 && $uri->getPath() == '/path1/path2/index.php' && $uri->getQuery() == 'argument1=value1&argument2=value2&argument3[subargument1]=subvalue1' && $uri->getArguments() == array('argument1' => 'value1', 'argument2' => 'value2', 'argument3' => array('subargument1' => 'subvalue1')) && $uri->getFragment() == 'anchor'; $this->assertTrue($check, 'The valid and complete URI has not been correctly transformed to an URI object'); }
/** * Renders the HTTP headers - including the status header - of this request * * @return string The HTTP headers, one per line, separated by \r\n as required by RFC 2616 sec 5 * @api */ public function renderHeaders() { $preparedHeaders = array(); $uriPathQueryAndFragment = $this->uri->getPath() . ($this->uri->getQuery() ? '?' . $this->uri->getQuery() : '') . ($this->uri->getFragment() ? '#' . $this->uri->getFragment() : ''); $preparedHeaders[] = sprintf('%s %s HTTP/1.1', $this->method, $uriPathQueryAndFragment); foreach ($this->headers->getAll() as $name => $values) { foreach ($values as $value) { $preparedHeaders[] = $name . ': ' . $value; } } return implode("\r\n", $preparedHeaders) . "\r\n"; }
/** * Return the Request-Line of this Request Message, consisting of the method, the uri and the HTTP version * Would be, for example, "GET /foo?bar=baz HTTP/1.1" * Note that the URI part is, at the moment, only possible in the form "abs_path" since the * actual requestUri of the Request cannot be determined during the creation of the Request. * * @return string * @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5.1 * @api */ public function getRequestLine() { $requestUri = $this->uri->getPath() . ($this->uri->getQuery() ? '?' . $this->uri->getQuery() : '') . ($this->uri->getFragment() ? '#' . $this->uri->getFragment() : ''); return sprintf("%s %s %s\r\n", $this->method, $requestUri, $this->version); }
/** * Creates a new Request object from the given data. * * @param \TYPO3\Flow\Http\Uri $uri The request URI * @param string $method Request method, for example "GET" * @param array $arguments Arguments to send in the request body * @param array $files * @param array $server * @return \TYPO3\Flow\Http\Request * @throws \InvalidArgumentException * @api */ public static function create(Uri $uri, $method = 'GET', array $arguments = array(), array $files = array(), array $server = array()) { $get = $uri->getArguments(); $post = $arguments; $isDefaultPort = $uri->getScheme() === 'https' ? $uri->getPort() === 443 : $uri->getPort() === 80; $defaultServerEnvironment = array('HTTP_USER_AGENT' => 'Flow/' . FLOW_VERSION_BRANCH . '.x', 'HTTP_HOST' => $uri->getHost() . ($isDefaultPort !== TRUE && $uri->getPort() !== NULL ? ':' . $uri->getPort() : ''), 'SERVER_NAME' => $uri->getHost(), 'SERVER_ADDR' => '127.0.0.1', 'SERVER_PORT' => $uri->getPort() ?: 80, 'REMOTE_ADDR' => '127.0.0.1', 'SCRIPT_FILENAME' => FLOW_PATH_WEB . 'index.php', 'SERVER_PROTOCOL' => 'HTTP/1.1', 'SCRIPT_NAME' => '/index.php', 'PHP_SELF' => '/index.php'); if ($uri->getScheme() === 'https') { $defaultServerEnvironment['HTTPS'] = 'on'; $defaultServerEnvironment['SERVER_PORT'] = $uri->getPort() ?: 443; } if (in_array($method, array('POST', 'PUT', 'DELETE'))) { $defaultServerEnvironment['HTTP_CONTENT_TYPE'] = 'application/x-www-form-urlencoded'; } $query = $uri->getQuery(); $fragment = $uri->getFragment(); $overrideValues = array('REQUEST_URI' => $uri->getPath() . ($query !== '' ? '?' . $query : '') . ($fragment !== '' ? '#' . $fragment : ''), 'REQUEST_METHOD' => $method, 'QUERY_STRING' => $query); $server = array_replace($defaultServerEnvironment, $server, $overrideValues); return new static($get, $post, $files, $server); }