/**
  * @param HttpRequest $request
  * @param Redirection $redirection
  * @return void
  */
 protected function sendRedirectHeaders(HttpRequest $request, Redirection $redirection)
 {
     if (headers_sent()) {
         return;
     }
     $sourceUriPath = $redirection->getRequestPattern();
     $targetUriPath = $redirection->getTarget();
     if (strpos($sourceUriPath, '%') !== false) {
         $sourceUriPath = preg_quote($sourceUriPath, '/');
         $sourceUriPath = str_replace('%', '(.*)', $sourceUriPath);
         $targetUriPath = preg_replace('/' . $sourceUriPath . '/', $redirection->getTarget(), $request->getRelativePath());
     }
     header($redirection->getStatusLine());
     header('Location: ' . $request->getBaseUri() . $targetUriPath);
 }
 /**
  * Starts the authentication: Redirect to login page
  *
  * @param \TYPO3\Flow\Http\Request $request The current request
  * @param \TYPO3\Flow\Http\Response $response The current response
  * @return void
  * @throws MissingConfigurationException
  */
 public function startAuthentication(Request $request, Response $response)
 {
     if (isset($this->options['routeValues'])) {
         $routeValues = $this->options['routeValues'];
         if (!is_array($routeValues)) {
             throw new MissingConfigurationException(sprintf('The configuration for the WebRedirect authentication entry point is incorrect. "routeValues" must be an array, got "%s".', gettype($routeValues)), 1345040415);
         }
         $actionRequest = new ActionRequest($request);
         $this->uriBuilder->setRequest($actionRequest);
         $actionName = $this->extractRouteValue($routeValues, '@action');
         $controllerName = $this->extractRouteValue($routeValues, '@controller');
         $packageKey = $this->extractRouteValue($routeValues, '@package');
         $subPackageKey = $this->extractRouteValue($routeValues, '@subpackage');
         $uri = $this->uriBuilder->setCreateAbsoluteUri(true)->uriFor($actionName, $routeValues, $controllerName, $packageKey, $subPackageKey);
     } elseif (isset($this->options['uri'])) {
         $uri = strpos($this->options['uri'], '://') !== false ? $this->options['uri'] : $request->getBaseUri() . $this->options['uri'];
     } else {
         throw new MissingConfigurationException('The configuration for the WebRedirect authentication entry point is incorrect or missing. You need to specify either the target "uri" or "routeValues".', 1237282583);
     }
     $response->setContent(sprintf('<html><head><meta http-equiv="refresh" content="0;url=%s"/></head></html>', htmlentities($uri, ENT_QUOTES, 'utf-8')));
     $response->setStatus(303);
     $response->setHeader('Location', $uri);
 }
 /**
  * @test
  */
 public function getBaseUriReturnsThePresetBaseUriIfItHasBeenSet()
 {
     $server = array('HTTP_HOST' => 'dev.blog.rob', 'REQUEST_METHOD' => 'GET', 'REQUEST_URI' => '/foo/bar', 'SCRIPT_NAME' => '/index.php', 'PHP_SELF' => '/index.php');
     $request = new Request(array(), array(), array(), $server);
     $baseUri = new \TYPO3\Flow\Http\Uri('http://prod.blog.rob/');
     $request->setBaseUri($baseUri);
     $this->assertEquals('http://prod.blog.rob/', (string) $request->getBaseUri());
 }
 /**
  * Returns the DOM crawler which can be used to interact with the web page
  * structure, submit forms, click links or fetch specific parts of the
  * website's contents.
  *
  * The returned DOM crawler is bound to the response of the last executed
  * request.
  *
  * @return \Symfony\Component\DomCrawler\Crawler
  * @api
  */
 public function getCrawler()
 {
     $crawler = new Crawler(null, $this->lastRequest->getBaseUri());
     $crawler->addContent($this->lastResponse->getContent(), $this->lastResponse->getHeader('Content-Type'));
     return $crawler;
 }