From 167c40f550c8bbb1c82cd5d857605381d8eb3160 Mon Sep 17 00:00:00 2001 From: printempw Date: Sun, 30 Oct 2016 11:56:59 +0800 Subject: [PATCH] add last-modified header for json profiles --- app/Providers/ResponseMacroServiceProvider.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/Providers/ResponseMacroServiceProvider.php b/app/Providers/ResponseMacroServiceProvider.php index c979a21d..ac470a38 100644 --- a/app/Providers/ResponseMacroServiceProvider.php +++ b/app/Providers/ResponseMacroServiceProvider.php @@ -41,6 +41,13 @@ class ResponseMacroServiceProvider extends ServiceProvider }); Response::macro('rawJson', function ($src = "", $status = 200, $header = []) { + $last_modified = Arr::get($header, 'Last-Modified', time()); + + if (strtotime(Arr::get($_SERVER, 'If-Modified-Since')) >= $last_modified) { + $status = 304; + $src = ""; + } + return Response::make($src, $status, array_merge([ 'Content-type' => 'application/json', 'Cache-Control' => 'public, max-age='.option('cache_expire_time') // 365 days