Skip to content
Snippets Groups Projects
Unverified Commit edb7699d authored by Tim van Dijen's avatar Tim van Dijen Committed by GitHub
Browse files

Simplify HTTP status code to always be 303 on redirect (#1538)

parent c769bc1a
No related branches found
No related tags found
No related merge requests found
...@@ -225,26 +225,13 @@ class HTTP ...@@ -225,26 +225,13 @@ class HTTP
$url = $this->addURLParameters($url, $parameters); $url = $this->addURLParameters($url, $parameters);
} }
/* Set the HTTP result code. This is either 303 See Other or
* 302 Found. HTTP 303 See Other is sent if the HTTP version
* is HTTP/1.1 and the request type was a POST request.
*/
if (
$_SERVER['SERVER_PROTOCOL'] === 'HTTP/1.1'
&& $_SERVER['REQUEST_METHOD'] === 'POST'
) {
$code = 303;
} else {
$code = 302;
}
if (strlen($url) > 2048) { if (strlen($url) > 2048) {
Logger::warning('Redirecting to a URL longer than 2048 bytes.'); Logger::warning('Redirecting to a URL longer than 2048 bytes.');
} }
if (!headers_sent()) { if (!headers_sent()) {
// set the location header // set the location header
header('Location: ' . $url, true, $code); header('Location: ' . $url, true, 303);
// disable caching of this response // disable caching of this response
header('Pragma: no-cache'); header('Pragma: no-cache');
......
...@@ -74,7 +74,7 @@ class IndexTest extends TestCase ...@@ -74,7 +74,7 @@ class IndexTest extends TestCase
$resp = $this->server->get('/index.php', [], [ $resp = $this->server->get('/index.php', [], [
CURLOPT_FOLLOWLOCATION => 0, CURLOPT_FOLLOWLOCATION => 0,
]); ]);
$this->assertEquals('302', $resp['code']); $this->assertEquals('303', $resp['code']);
$this->assertEquals( $this->assertEquals(
'http://example.org/simplesaml/module.php/core/login', 'http://example.org/simplesaml/module.php/core/login',
$resp['headers']['Location'] $resp['headers']['Location']
...@@ -87,7 +87,7 @@ class IndexTest extends TestCase ...@@ -87,7 +87,7 @@ class IndexTest extends TestCase
$resp = $this->server->get('/index.php', [], [ $resp = $this->server->get('/index.php', [], [
CURLOPT_FOLLOWLOCATION => 0, CURLOPT_FOLLOWLOCATION => 0,
]); ]);
$this->assertEquals('302', $resp['code']); $this->assertEquals('303', $resp['code']);
$this->assertEquals( $this->assertEquals(
'https://example.org/module.php/core/login', 'https://example.org/module.php/core/login',
$resp['headers']['Location'] $resp['headers']['Location']
...@@ -100,7 +100,7 @@ class IndexTest extends TestCase ...@@ -100,7 +100,7 @@ class IndexTest extends TestCase
$resp = $this->server->get('/index.php', [], [ $resp = $this->server->get('/index.php', [], [
CURLOPT_FOLLOWLOCATION => 0, CURLOPT_FOLLOWLOCATION => 0,
]); ]);
$this->assertEquals('302', $resp['code']); $this->assertEquals('303', $resp['code']);
$this->assertEquals( $this->assertEquals(
'http://' . $this->server_addr . '/simplesaml/module.php/core/login', 'http://' . $this->server_addr . '/simplesaml/module.php/core/login',
$resp['headers']['Location'] $resp['headers']['Location']
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment