2020-11-23 14:31:50 +00:00
|
|
|
<?php
|
|
|
|
/** @license MIT
|
|
|
|
* Copyright 2017 J. King, Dustin Wilson et al.
|
|
|
|
* See LICENSE and AUTHORS files for details */
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2021-04-14 15:17:01 +00:00
|
|
|
|
2020-11-23 14:31:50 +00:00
|
|
|
namespace JKingWeb\Arsse\REST\Miniflux;
|
|
|
|
|
2022-08-05 02:04:39 +00:00
|
|
|
use JKingWeb\Arsse\Misc\HTTP;
|
2020-11-23 14:31:50 +00:00
|
|
|
use Psr\Http\Message\ServerRequestInterface;
|
|
|
|
use Psr\Http\Message\ResponseInterface;
|
|
|
|
|
|
|
|
class Status extends \JKingWeb\Arsse\REST\AbstractHandler {
|
|
|
|
public function __construct() {
|
|
|
|
}
|
|
|
|
|
|
|
|
public function dispatch(ServerRequestInterface $req): ResponseInterface {
|
|
|
|
$target = parse_url($req->getRequestTarget())['path'] ?? "";
|
|
|
|
if (!in_array($target, ["/version", "/healthcheck"])) {
|
2022-08-05 02:04:39 +00:00
|
|
|
return HTTP::respEmpty(404);
|
2020-11-23 14:31:50 +00:00
|
|
|
}
|
|
|
|
$method = $req->getMethod();
|
|
|
|
if ($method === "OPTIONS") {
|
2022-08-05 02:04:39 +00:00
|
|
|
return HTTP::respEmpty(204, ['Allow' => "HEAD, GET"]);
|
2020-11-23 14:31:50 +00:00
|
|
|
} elseif ($method !== "GET") {
|
2022-08-05 02:04:39 +00:00
|
|
|
return HTTP::respEmpty(405, ['Allow' => "HEAD, GET"]);
|
2020-11-23 14:31:50 +00:00
|
|
|
}
|
|
|
|
$out = "";
|
|
|
|
if ($target === "/version") {
|
|
|
|
$out = V1::VERSION;
|
|
|
|
} elseif ($target === "/healthcheck") {
|
|
|
|
$out = "OK";
|
|
|
|
}
|
2022-08-06 17:40:02 +00:00
|
|
|
return HTTP::respText($out);
|
2020-11-23 14:31:50 +00:00
|
|
|
}
|
|
|
|
}
|