mirror of
https://github.com/v2board/v2board.git
synced 2025-02-11 07:59:11 +08:00
Add ETag for caching
This commit is contained in:
parent
2b5ef08fe0
commit
d2bce02d4e
@ -135,9 +135,23 @@ class PoseidonController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected function success($data) {
|
protected function success($data) {
|
||||||
|
$req = request();
|
||||||
|
// Only for "GET" method
|
||||||
|
if (!$req->isMethod('GET') || !$data) {
|
||||||
|
return response([
|
||||||
|
'msg' => 'ok',
|
||||||
|
'data' => $data,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$etag = sha1(json_encode($data));
|
||||||
|
if ($etag == $req->header("IF-NONE-MATCH")) {
|
||||||
|
return response(null, 304);
|
||||||
|
}
|
||||||
|
|
||||||
return response([
|
return response([
|
||||||
'msg' => 'ok',
|
'msg' => 'ok',
|
||||||
'data' => $data,
|
'data' => $data,
|
||||||
]);
|
])->header('ETAG', $etag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user