/**
  * @test
  */
 public function constructorParsesArgumentsWithSpecialCharactersCorrectly()
 {
     $uriString = 'http://www.typo3.com/path1/?argumentäöü1=' . urlencode('valueåø€œ');
     $uri = new Uri($uriString);
     $check = $uri->getScheme() == 'http' && $uri->getHost() == 'www.typo3.com' && $uri->getPath() == '/path1/' && $uri->getQuery() == 'argumentäöü1=value%C3%A5%C3%B8%E2%82%AC%C5%93' && $uri->getArguments() == array('argumentäöü1' => 'valueåø€œ');
     $this->assertTrue($check, 'The URI with special arguments 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";
 }
示例#3
0
 /**
  * @param string $actionName
  * @param array $additionalParameters
  *
  * @return Uri
  */
 protected function buildRequestUri($actionName, array $additionalParameters = [])
 {
     $requestUri = new Uri($this->apiSettings['apiUrl']);
     $requestUri->setPath($requestUri->getPath() . $this->apiSettings['actions'][$actionName]);
     $requestUri->setQuery(http_build_query(array_merge($this->apiSettings['parameters'], $additionalParameters)));
     return $requestUri;
 }
 /**
  * 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);
 }
示例#5
0
 /**
  * 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);
 }