Skip to content

Commit 998179d

Browse files
committed
Merge branch '6.x' of github.com:laravel/framework into 6.x
2 parents e7ce561 + 737427f commit 998179d

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/Illuminate/Http/Middleware/SetCacheHeaders.php

+9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Illuminate\Http\Middleware;
44

55
use Closure;
6+
use Illuminate\Support\Carbon;
67

78
class SetCacheHeaders
89
{
@@ -32,6 +33,14 @@ public function handle($request, Closure $next, $options = [])
3233
$options['etag'] = md5($response->getContent());
3334
}
3435

36+
if (isset($options['last_modified'])) {
37+
if (is_numeric($options['last_modified'])) {
38+
$options['last_modified'] = Carbon::createFromTimestamp($options['last_modified']);
39+
} else {
40+
$options['last_modified'] = Carbon::parse($options['last_modified']);
41+
}
42+
}
43+
3544
$response->setCache($options);
3645
$response->isNotModified($request);
3746

tests/Http/Middleware/CacheTest.php

+22
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Http\Middleware\SetCacheHeaders as Cache;
66
use Illuminate\Http\Request;
77
use Illuminate\Http\Response;
8+
use Illuminate\Support\Carbon;
89
use InvalidArgumentException;
910
use PHPUnit\Framework\TestCase;
1011

@@ -82,4 +83,25 @@ public function testInvalidOption()
8283
return new Response('some content');
8384
}, 'invalid');
8485
}
86+
87+
public function testLastModifiedUnixTime()
88+
{
89+
$time = time();
90+
91+
$response = (new Cache)->handle(new Request, function () {
92+
return new Response('some content');
93+
}, "last_modified=$time");
94+
95+
$this->assertSame($time, $response->getLastModified()->getTimestamp());
96+
}
97+
98+
public function testLastModifiedStringDate()
99+
{
100+
$birthdate = '1973-04-09 10:10:10';
101+
$response = (new Cache)->handle(new Request, function () {
102+
return new Response('some content');
103+
}, "last_modified=$birthdate");
104+
105+
$this->assertSame(Carbon::parse($birthdate)->timestamp, $response->getLastModified()->getTimestamp());
106+
}
85107
}

0 commit comments

Comments
 (0)