/** * Redirects to another URI * * @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" * @throws \TYPO3\FLOW3\Mvc\Exception\UnsupportedRequestTypeException If the request is not a web request * @throws \TYPO3\FLOW3\Mvc\Exception\StopActionException * @api */ protected function redirectToUri($uri, $delay = 0, $statusCode = 303) { $escapedUri = htmlentities($uri, ENT_QUOTES, 'utf-8'); $this->response->setContent('<html><head><meta http-equiv="refresh" content="' . intval($delay) . ';url=' . $escapedUri . '"/></head></html>'); $this->response->setStatus($statusCode); if ($delay === 0) { $this->response->setHeader('Location', (string) $uri); } 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); }
/** * 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'); }
/** * RFC 2616 / 14.28 (If-Unmodified-Since) * * @test */ public function makeStandardsCompliantReturns412StatusIfUnmodifiedSinceDoesNotMatch() { $request = Request::create(new Uri('http://localhost')); $response = new Response(); $unmodifiedSince = \DateTime::createFromFormat(DATE_RFC2822, 'Tue, 15 May 2012 09:00:00 GMT'); $lastModified = \DateTime::createFromFormat(DATE_RFC2822, 'Sun, 20 May 2012 08:00:00 UTC'); $request->setHeader('If-Unmodified-Since', $unmodifiedSince); $response->setHeader('Last-Modified', $lastModified); $response->makeStandardsCompliant($request); $this->assertSame(412, $response->getStatusCode()); $response = new Response(); $unmodifiedSince = \DateTime::createFromFormat(DATE_RFC2822, 'Tue, 15 May 2012 09:00:00 GMT'); $lastModified = \DateTime::createFromFormat(DATE_RFC2822, 'Tue, 15 May 2012 08:00:00 UTC'); $request->setHeader('If-Unmodified-Since', $unmodifiedSince); $response->setHeader('Last-Modified', $lastModified); $response->makeStandardsCompliant($request); $this->assertSame(200, $response->getStatusCode()); }