Try to unify API responses

This commit is contained in:
2024-07-21 16:10:02 +02:00
parent a01515aa9c
commit b76c434216
5 changed files with 59 additions and 38 deletions

View File

@ -5,8 +5,8 @@ function http_401_unauthorized(): void {
header('Status: 401');
header('WWW-Authenticate: Basic realm="Elwig"');
header('Content-Type: text/plain; charset=UTF-8');
header('Content-Length: 20');
exit("401 Unauthorized :(\n");
header('Content-Length: 17');
exit("401 Unauthorized\n");
}
function authenticate(): void {

View File

@ -7,10 +7,12 @@ function get_fmt(): string {
if ($fmt === 'ascii') {
header('Status: 303');
header('Location: ?format=text');
exit();
header('Content-Length: 14');
exit("303 See Other\n");
} else if ($fmt !== 'json' && $fmt !== 'html' && $fmt !== 'text') {
header('Status: 300');
header('Content-Type: text/html; charset=UTF-8');
header('Content-Length: 162');
echo "<!DOCTYPE html><html><head></head><body>\n<a href='?format=html'>HTML</a><br/>\n<a href='?format=json'>JSON</a><br/>\n<a href='?format=text'>Text</a>\n</body></html>\n";
exit();
}