/** * 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\FLOW3\Mvc\Exception\UnsupportedRequestTypeException If the request is not a web request * @throws \TYPO3\FLOW3\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\FLOW3\Mvc\Exception\StopActionException(); }
/** * Starts the authentication: Redirect to login page * * @param \TYPO3\FLOW3\Http\Request $request The current request * @param \TYPO3\FLOW3\Http\Response $response The current response * @return void * @throws \TYPO3\FLOW3\Security\Exception\RequestTypeNotSupportedException * @throws \TYPO3\FLOW3\Security\Exception\MissingConfigurationException */ public function startAuthentication(Request $request, Response $response) { if (!isset($this->options['uri'])) { throw new \TYPO3\FLOW3\Security\Exception\MissingConfigurationException('The configuration for the WebRedirect authentication entry point is incorrect or missing.', 1237282583); } $plainUri = strpos('://', $this->options['uri'] !== FALSE) ? $this->options['uri'] : $request->getBaseUri() . $this->options['uri']; $escapedUri = htmlentities($plainUri, ENT_QUOTES, 'utf-8'); $response->setContent('<html><head><meta http-equiv="refresh" content="0;url=' . $escapedUri . '"/></head></html>'); $response->setStatus(303); $response->setHeader('Location', $plainUri); }
/** * Redirects the web request to another uri. * * NOTE: This method only supports web requests and will throw an exception * if used with other request types. * * @param mixed $uri Either a string representation of a URI or a \TYPO3\FLOW3\Http\Uri object * @param integer $delay (optional) The delay in seconds. Default is no delay. * @param integer $statusCode (optional) The HTTP status code for the redirect. Default is "303 See Other" * @return void * @throws \TYPO3\FLOW3\Mvc\Exception\StopActionException * @api */ protected function redirectToUri($uri, $delay = 0, $statusCode = 303) { // the parent method throws the exception, but we need to act afterwards // thus the code in catch - it's the expected state try { parent::redirectToUri($uri, $delay, $statusCode); } catch (\TYPO3\FLOW3\Mvc\Exception\StopActionException $exception) { if ($this->request->getFormat() === 'json') { $this->response->setContent(''); } throw $exception; } }
/** * Starts the authentication: Send HTTP header * * @param \TYPO3\FLOW3\Http\Request $request The current request * @param \TYPO3\FLOW3\Http\Response $response The current response * @return void * @throws \TYPO3\FLOW3\Security\Exception\RequestTypeNotSupportedException */ public function startAuthentication(Request $request, Response $response) { $response->setStatus(401); $response->setHeader('WWW-Authenticate', 'Basic realm="' . (isset($this->options['realm']) ? $this->options['realm'] : sha1(FLOW3_PATH_ROOT)) . '"'); $response->setContent('Authorization required'); }
/** * @test */ public function contentCanBeSetAppendedAndRetrieved() { $response = new Response(); $response->setContent('Two households, both alike in dignity, '); $response->appendContent('In fair Verona, where we lay our scene'); $this->assertEquals('Two households, both alike in dignity, In fair Verona, where we lay our scene', $response->getContent()); $response->setContent('For never was a story of more woe, Than this of Juliet and her Romeo.'); $this->assertEquals('For never was a story of more woe, Than this of Juliet and her Romeo.', $response->getContent()); $this->assertEquals('For never was a story of more woe, Than this of Juliet and her Romeo.', (string) $response); }