Skip to content

Commit ab05ed7

Browse files
authored
Set etag and lastModified if available
1 parent c06979c commit ab05ed7

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/Structures/Page.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use ArrayAccess;
66
use Illuminate\Contracts\Support\Arrayable;
77
use Illuminate\Contracts\Support\Responsable;
8+
use Illuminate\Support\Carbon;
89
use Illuminate\Support\Traits\ForwardsCalls;
910
use JsonSerializable;
1011
use Statamic\Contracts\Auth\Protect\Protectable;
@@ -417,7 +418,14 @@ public function site()
417418
public function toResponse($request)
418419
{
419420
if ($this->reference && $this->referenceExists()) {
420-
return (new \Statamic\Http\Responses\DataResponse($this))->toResponse($request);
421+
$response = (new \Statamic\Http\Responses\DataResponse($this))->toResponse($request);
422+
423+
if ($updatedAt = $this->routeData()['updated_at'] ?? null) {
424+
$response->setLastModified(Carbon::parse($updatedAt));
425+
}
426+
427+
return $response
428+
->setEtag(md5($response->getContent() ?? ''));
421429
}
422430

423431
throw new \LogicException('A page without a reference to an entry cannot be rendered.');

0 commit comments

Comments
 (0)