refac: APIHelper 반환 값 정리
This commit is contained in:
+16
-16
@@ -9,6 +9,18 @@ class APIHelper
|
|||||||
//static only
|
//static only
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static function setCacheHeader(){
|
||||||
|
header('cache-control: private, max-age=60');
|
||||||
|
header("Pragma: cache");
|
||||||
|
header_remove('expires');
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function DieWithNotModified(): never{
|
||||||
|
static::setCacheHeader();
|
||||||
|
header("HTTP/1.1 304 Not Modified");
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
|
||||||
public static function launch(string $rootPath, ?string $actionPath = null)
|
public static function launch(string $rootPath, ?string $actionPath = null)
|
||||||
{
|
{
|
||||||
//TODO: path를 php://input에서 받는게 아니라 api.php?~~~~~ 로 받아오는것이 etag 캐시 측면에서 훨씬 나을 듯!
|
//TODO: path를 php://input에서 받는게 아니라 api.php?~~~~~ 로 받아오는것이 etag 캐시 측면에서 훨씬 나을 듯!
|
||||||
@@ -95,26 +107,16 @@ class APIHelper
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($modifiedSince !== null && $lastModified !== null && TimeUtil::DateIntervalToSeconds($modifiedSince->diff($lastModified)) == 0) {
|
if ($modifiedSince !== null && $lastModified !== null && TimeUtil::DateIntervalToSeconds($modifiedSince->diff($lastModified)) == 0) {
|
||||||
header('cache-control: private, max-age=60');
|
static::DieWithNotModified();
|
||||||
header("Pragma: cache");
|
|
||||||
header("HTTP/1.1 304 Not Modified", true, 304);
|
|
||||||
header_remove('expires');
|
|
||||||
die();
|
|
||||||
}
|
}
|
||||||
if ($reqEtags !== null && $reqEtags === $etag) {
|
if ($reqEtags !== null && $reqEtags === $etag) {
|
||||||
header('cache-control: private, max-age=60');
|
static::DieWithNotModified();
|
||||||
header("Pragma: cache");
|
|
||||||
header("HTTP/1.1 304 Not Modified", true, 304);
|
|
||||||
header_remove('expires');
|
|
||||||
die();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($result === null) {
|
if ($result === null) {
|
||||||
if ($setCache) {
|
if ($setCache) {
|
||||||
header('cache-control: private, max-age=60');
|
static::setCacheHeader();
|
||||||
header("Pragma: cache");
|
|
||||||
header_remove('expires');
|
|
||||||
}
|
}
|
||||||
Json::die([
|
Json::die([
|
||||||
'result' => true,
|
'result' => true,
|
||||||
@@ -122,9 +124,7 @@ class APIHelper
|
|||||||
], $setCache ? 0 : Json::NO_CACHE);
|
], $setCache ? 0 : Json::NO_CACHE);
|
||||||
}
|
}
|
||||||
if ($setCache) {
|
if ($setCache) {
|
||||||
header('cache-control: private, max-age=60');
|
static::setCacheHeader();
|
||||||
header("Pragma: cache");
|
|
||||||
header_remove('expires');
|
|
||||||
}
|
}
|
||||||
Json::die($result, $setCache ? 0 : Json::NO_CACHE);
|
Json::die($result, $setCache ? 0 : Json::NO_CACHE);
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user