Fixed overwriting redirection HTTP status codes

This commit is contained in:
rr- 2015-06-27 18:35:21 +02:00
parent 8407a3f70e
commit c74edbee51
3 changed files with 29 additions and 7 deletions

View file

@ -65,9 +65,12 @@ final class Dispatcher
$json['__statements'] = $this->databaseConnection->getPDO()->getStatements();
}
if (!$this->httpHelper->isRedirecting())
{
$this->httpHelper->setResponseCode($code);
$this->httpHelper->setHeader('Content-Type', 'application/json');
$this->httpHelper->outputJSON($json);
}
return $json;
}

View file

@ -3,6 +3,8 @@ namespace Szurubooru\Helpers;
class HttpHelper
{
private $redirected = false;
public function setResponseCode($code)
{
http_response_code($code);
@ -67,4 +69,23 @@ class HttpHelper
$requestUri = preg_replace('/\?.*$/', '', $requestUri);
return $requestUri;
}
public function redirect($destination)
{
$this->setResponseCode(307);
$this->setHeader('Location', $destination);
$this->redirected = true;
}
public function nonCachedRedirect($destination)
{
$this->setResponseCode(303);
$this->setHeader('Location', $destination);
$this->redirected = true;
}
public function isRedirecting()
{
return $this->redirected;
}
}

View file

@ -92,13 +92,11 @@ class NetworkingService
public function redirect($destination)
{
$this->httpHelper->setResponseCode(307);
$this->httpHelper->setHeader('Location', $destination);
$this->httpHelper->redirect($destination);
}
public function nonCachedRedirect($destination)
{
$this->httpHelper->setResponseCode(303);
$this->httpHelper->setHeader('Location', $destination);
$this->httpHelper->nonCachedRedirect($destination);
}
}