mirror of
https://github.com/v2board/v2board.git
synced 2024-11-10 17:49: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) {
|
||||
$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([
|
||||
'msg' => 'ok',
|
||||
'data' => $data,
|
||||
]);
|
||||
])->header('ETAG', $etag);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user