/**
  * Sends the specified HTTP status immediately.
  *
  * NOTE: This method only supports web requests and will throw an exception if used with other request types.
  *
  * @param integer $statusCode The HTTP status code
  * @param string $statusMessage A custom HTTP status message
  * @param string $content Body content which further explains the status
  * @throws \TYPO3\Flow\Mvc\Exception\UnsupportedRequestTypeException If the request is not a web request
  * @throws \TYPO3\Flow\Mvc\Exception\StopActionException
  * @api
  */
 protected function throwStatus($statusCode, $statusMessage = null, $content = null)
 {
     $this->response->setStatus($statusCode, $statusMessage);
     if ($content === null) {
         $content = $this->response->getStatus();
     }
     $this->response->setContent($content);
     throw new \TYPO3\Flow\Mvc\Exception\StopActionException();
 }
 /**
  * Just return the processed value
  *
  * @return mixed
  */
 public function evaluate()
 {
     $httpResponse = new Response();
     $httpResponse->setStatus($this->getStatusCode());
     $httpResponse->setHeaders(new Headers());
     foreach ($this->getHeaders() as $name => $value) {
         $httpResponse->setHeader($name, $value);
     }
     return implode("\r\n", $httpResponse->renderHeaders()) . "\r\n\r\n";
 }
 /**
  * Starts the authentication by redirecting to the SSO endpoint
  *
  * The redirect includes the callback URI (the original URI from the given request)
  * the client identifier and a signature of the arguments with the client private key.
  *
  * @param \TYPO3\Flow\Http\Request $request The current request
  * @param \TYPO3\Flow\Http\Response $response The current response
  * @return void
  */
 public function startAuthentication(Request $request, Response $response)
 {
     $callbackUri = $request->getUri();
     if (!isset($this->options['server'])) {
         throw new Exception('Missing "server" option for SingleSignOnRedirect entry point. Please specifiy one using the entryPointOptions setting.', 1351690358);
     }
     $ssoServer = $this->ssoServerFactory->create($this->options['server']);
     $ssoClient = $this->ssoClientFactory->create();
     $redirectUri = $ssoServer->buildAuthenticationEndpointUri($ssoClient, $callbackUri);
     $response->setStatus(303);
     $response->setHeader('Location', $redirectUri);
 }
 /**
  * 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);
 }
 /**
  * Prepare a response in case an error occurred.
  *
  * @param \Throwable $exception
  * @param Http\Response $response
  * @return void
  */
 protected function prepareErrorResponse($exception, Http\Response $response)
 {
     $pathPosition = strpos($exception->getFile(), 'Packages/');
     $filePathAndName = $pathPosition !== false ? substr($exception->getFile(), $pathPosition) : $exception->getFile();
     $exceptionCodeNumber = $exception->getCode() > 0 ? '#' . $exception->getCode() . ': ' : '';
     $content = PHP_EOL . 'Uncaught Exception in Flow ' . $exceptionCodeNumber . $exception->getMessage() . PHP_EOL;
     $content .= 'thrown in file ' . $filePathAndName . PHP_EOL;
     $content .= 'in line ' . $exception->getLine() . PHP_EOL . PHP_EOL;
     $content .= Debugger::getBacktraceCode($exception->getTrace(), false, true) . PHP_EOL;
     if ($exception instanceof Exception) {
         $statusCode = $exception->getStatusCode();
     } else {
         $statusCode = 500;
     }
     $response->setStatus($statusCode);
     $response->setContent($content);
     $response->setHeader('X-Flow-ExceptionCode', $exception->getCode());
     $response->setHeader('X-Flow-ExceptionMessage', $exception->getMessage());
 }
 /**
  * @test
  * @expectedException \TYPO3\Flow\Http\Client\InfiniteRedirectionException
  */
 public function browserHaltsOnExceedingMaximumRedirections()
 {
     $requestEngine = $this->getMock(\TYPO3\Flow\Http\Client\RequestEngineInterface::class);
     for ($i = 0; $i <= 10; $i++) {
         $response = new Response();
         $response->setHeader('Location', 'http://localhost/this/willLead/you/knowhere/' . $i);
         $response->setStatus(301);
         $requestEngine->expects($this->at($i))->method('sendRequest')->will($this->returnValue($response));
     }
     $this->browser->setRequestEngine($requestEngine);
     $this->browser->request('http://localhost/some/initialRequest');
 }
 /**
  * RFC 2616 / 4.3 (Message Body)
  *
  * 10.1.1 (100 Continue)
  * 10.1.2 (101 Switching Protocols)
  * 10.2.5 (204 No Content)
  * 10.3.5 (304 Not Modified)
  *
  * @test
  */
 public function makeStandardsCompliantRemovesBodyContentIfStatusCodeImpliesIt()
 {
     $request = Request::create(new Uri('http://localhost'));
     $response = new Response();
     foreach (array(100, 101, 204, 304) as $statusCode) {
         $response->setStatus($statusCode);
         $response->setContent('Body Language');
         $response->makeStandardsCompliant($request);
         $this->assertEquals('', $response->getContent());
     }
 }
 /**
  * Starts the authentication: Send HTTP header
  *
  * @param \TYPO3\Flow\Http\Request $request The current request
  * @param \TYPO3\Flow\Http\Response $response The current response
  * @return void
  */
 public function startAuthentication(Request $request, Response $response)
 {
     $response->setStatus(401);
     $response->setHeader('WWW-Authenticate', 'Basic realm="' . (isset($this->options['realm']) ? $this->options['realm'] : sha1(FLOW_PATH_ROOT)) . '"');
     $response->setContent('Authorization required');
 }