commit 0e75d7f68714df972e761171cb3529ef25123132
parent 944d73e933fea964add87a6add5e9fcc7f9c61b4
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date: Sun, 27 Oct 2024 13:34:50 +0100
fix: send according status codes and mime types
Diffstat:
2 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/api/new.php b/api/new.php
@@ -34,9 +34,13 @@
$token = validate_input_string(gather_get("token"));
}
+ /* always output JSON */
+ header('Content-Type: application/json');
+
/* run authentification method. exit immediately if it fails */
$auth = auth_user($user, $token, -1);
if ($auth !== true) {
+ http_response_code(401); // unauthorized
exit(
"{" .
"\"status\": \"error\"," .
@@ -77,6 +81,7 @@
);
if ($written === true) {
+ http_response_code(200); // successful
exit(
"{" .
"\"status\": \"success\"," .
@@ -85,6 +90,7 @@
"}"
);
} else {
+ http_response_code(500); // internal server error
exit(
"{" .
"\"status\": \"error\"," .
diff --git a/api/rss.php b/api/rss.php
@@ -29,6 +29,8 @@
/* run authentification method. exit immediately if it fails */
$auth = auth_user($user, $token, -1);
if ($auth !== true) {
+ http_response_code(401); // unauthorized
+ header('Content-Type: application/json');
exit(
"{" .
"\"status\": \"error\"," .
@@ -49,6 +51,7 @@
);
/* write RSS XML */
+ http_response_code(200); // success
header('Content-Type: text/xml');
?>