From 34c7e11d84059136ac8f526a6e179b29e62c6025 Mon Sep 17 00:00:00 2001 From: wn_ Date: Mon, 2 Jun 2025 20:57:31 +0000 Subject: [PATCH] Use the official JSON MIME type of 'application/json'. --- api/index.php | 2 +- backend.php | 16 ++++++++-------- classes/API.php | 2 +- classes/Handler_Public.php | 10 +++++----- public.php | 4 ++-- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/api/index.php b/api/index.php index 6110beb2b..8114e3a66 100644 --- a/api/index.php +++ b/api/index.php @@ -31,7 +31,7 @@ if (!empty($_SESSION["uid"])) { if (!Sessions::validate_session()) { - header("Content-Type: text/json"); + header("Content-Type: application/json"); print json_encode([ "seq" => -1, diff --git a/backend.php b/backend.php index d9a0af7c7..6098333b7 100644 --- a/backend.php +++ b/backend.php @@ -35,7 +35,7 @@ return; } - header("Content-Type: text/json; charset=utf-8"); + header("Content-Type: application/json; charset=utf-8"); if (Config::get(Config::SINGLE_USER_MODE)) { UserHelper::authenticate("admin", null); @@ -43,7 +43,7 @@ if (!empty($_SESSION["uid"])) { if (!Sessions::validate_session()) { - header("Content-Type: text/json"); + header("Content-Type: application/json"); print Errors::to_json(Errors::E_UNAUTHORIZED); return; @@ -113,7 +113,7 @@ if (str_starts_with($method, "_")) { user_error("Refusing to invoke method $method of handler $op which starts with underscore.", E_USER_WARNING); - header("Content-Type: text/json"); + header("Content-Type: application/json"); print Errors::to_json(Errors::E_UNAUTHORIZED); return; @@ -142,7 +142,7 @@ $handler->$method(); } else { user_error("Refusing to invoke method $method of handler $op which has required parameters.", E_USER_WARNING); - header("Content-Type: text/json"); + header("Content-Type: application/json"); print Errors::to_json(Errors::E_UNAUTHORIZED); } @@ -150,7 +150,7 @@ if (method_exists($handler, "catchall")) { $handler->catchall($method); } else { - header("Content-Type: text/json"); + header("Content-Type: application/json"); print Errors::to_json(Errors::E_UNKNOWN_METHOD, ["info" => get_class($handler) . "->$method"]); } @@ -159,14 +159,14 @@ $handler->after(); return; } else { - header("Content-Type: text/json"); + header("Content-Type: application/json"); print Errors::to_json(Errors::E_UNAUTHORIZED); return; } } else { user_error("Refusing to invoke method $method of handler $op with invalid CSRF token.", E_USER_WARNING); - header("Content-Type: text/json"); + header("Content-Type: application/json"); print Errors::to_json(Errors::E_UNAUTHORIZED); return; @@ -174,6 +174,6 @@ } } - header("Content-Type: text/json"); + header("Content-Type: application/json"); print Errors::to_json(Errors::E_UNKNOWN_METHOD, [ "info" => (isset($handler) ? get_class($handler) : "UNKNOWN:".$op) . "->$method"]); diff --git a/classes/API.php b/classes/API.php index e1d4de214..03f5a2502 100644 --- a/classes/API.php +++ b/classes/API.php @@ -30,7 +30,7 @@ class API extends Handler { function before(string $method): bool { if (parent::before($method)) { - header("Content-Type: text/json"); + header("Content-Type: application/json"); if (empty($_SESSION["uid"]) && $method != "login" && $method != "isloggedin") { $this->_wrap(self::STATUS_ERR, array("error" => self::E_NOT_LOGGED_IN)); diff --git a/classes/Handler_Public.php b/classes/Handler_Public.php index 36820ab13..347a38381 100644 --- a/classes/Handler_Public.php +++ b/classes/Handler_Public.php @@ -248,7 +248,7 @@ class Handler_Public extends Handler { array_push($feed['articles'], $article); } - header("Content-Type: text/json; charset=utf-8"); + header("Content-Type: application/json; charset=utf-8"); print json_encode($feed); } else { @@ -320,7 +320,7 @@ class Handler_Public extends Handler { header("Location: " . $redirect_url); } else { - header("Content-Type: text/json"); + header("Content-Type: application/json"); print Errors::to_json(Errors::E_UNAUTHORIZED); } } @@ -806,17 +806,17 @@ class Handler_Public extends Handler { $plugin->$method(); } else { user_error("PluginHandler[PUBLIC]: Requested private method '$method' of plugin '$plugin_name'.", E_USER_WARNING); - header("Content-Type: text/json"); + header("Content-Type: application/json"); print Errors::to_json(Errors::E_UNAUTHORIZED); } } else { user_error("PluginHandler[PUBLIC]: Requested unknown method '$method' of plugin '$plugin_name'.", E_USER_WARNING); - header("Content-Type: text/json"); + header("Content-Type: application/json"); print Errors::to_json(Errors::E_UNKNOWN_METHOD); } } else { user_error("PluginHandler[PUBLIC]: Requested method '$method' of unknown plugin '$plugin_name'.", E_USER_WARNING); - header("Content-Type: text/json"); + header("Content-Type: application/json"); print Errors::to_json(Errors::E_UNKNOWN_PLUGIN, ['plugin' => $plugin_name]); } } diff --git a/public.php b/public.php index 5d99fe519..68327c2d7 100644 --- a/public.php +++ b/public.php @@ -34,7 +34,7 @@ if (str_starts_with($method, "_")) { user_error("Refusing to invoke method $method which starts with underscore.", E_USER_WARNING); - header("Content-Type: text/json"); + header("Content-Type: application/json"); print Errors::to_json(Errors::E_UNAUTHORIZED); return; @@ -49,7 +49,7 @@ $handler->$method(); } else { user_error("Refusing to invoke method $method which has required parameters.", E_USER_WARNING); - header("Content-Type: text/json"); + header("Content-Type: application/json"); print Errors::to_json(Errors::E_UNAUTHORIZED); }