diff options
| author | 2025-11-20 22:16:02 +0100 | |
|---|---|---|
| committer | 2025-11-20 22:16:02 +0100 | |
| commit | d3cb23118c06336e94e07d9c3cc937ef9c5f34c0 (patch) | |
| tree | d28d0751e9f3bba271d1f891a17c147f1aa1cb4c /p/api/misc.php | |
| parent | 9522e8f95018550122276fae746d136f125397db (diff) | |
Misc API: better REST semantics (#8232)
To allow minimal diagnostic from client side
Diffstat (limited to 'p/api/misc.php')
| -rw-r--r-- | p/api/misc.php | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/p/api/misc.php b/p/api/misc.php index 928c0b6e6..39a9c5946 100644 --- a/p/api/misc.php +++ b/p/api/misc.php @@ -8,18 +8,6 @@ declare(strict_types=1); require dirname(__DIR__, 2) . '/constants.php'; require LIB_PATH . '/lib_rss.php'; //Includes class autoloader -function badRequest(): never { - header('HTTP/1.1 400 Bad Request'); - header('Content-Type: text/plain; charset=UTF-8'); - die('Bad Request!'); -} - -function serviceUnavailable(): never { - header('HTTP/1.1 503 Service Unavailable'); - header('Content-Type: text/plain; charset=UTF-8'); - die('Service Unavailable!'); -} - $extensionName = is_string($_GET['ext'] ?? null) ? $_GET['ext'] : ''; if ($extensionName === '') { @@ -43,18 +31,30 @@ if ($extensionName === '') { } if ($extensionName === '') { - badRequest(); + header('HTTP/1.1 400 Bad Request'); + header('Content-Type: text/plain; charset=UTF-8'); + die('Bad Request!'); } Minz_Session::init('FreshRSS', volatile: true); FreshRSS_Context::initSystem(); -if ( - !FreshRSS_Context::hasSystemConf() || - !FreshRSS_Context::systemConf()->api_enabled || - empty(FreshRSS_Context::systemConf()->extensions_enabled[$extensionName]) -) { - serviceUnavailable(); +if (!FreshRSS_Context::hasSystemConf()) { + header('HTTP/1.1 500 Internal Server Error'); + header('Content-Type: text/plain; charset=UTF-8'); + die('Internal Server Error!'); +} + +if (!FreshRSS_Context::systemConf()->api_enabled) { + header('HTTP/1.1 503 Service Unavailable'); + header('Content-Type: text/plain; charset=UTF-8'); + die('Service Unavailable!'); +} + +if (empty(FreshRSS_Context::systemConf()->extensions_enabled[$extensionName])) { + header('HTTP/1.1 404 Not Found'); + header('Content-Type: text/plain; charset=UTF-8'); + die('Not Found!'); } // Only enable the extension that is being called @@ -64,5 +64,7 @@ Minz_ExtensionManager::init(); Minz_Translate::init(); if (!Minz_ExtensionManager::callHookUnique(Minz_HookType::ApiMisc)) { - serviceUnavailable(); + header('HTTP/1.1 501 Not Implemented'); + header('Content-Type: text/plain; charset=UTF-8'); + die('Not Implemented!'); } |
