Skip to content

[5.x] Set etag and lastModified if available #11441

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: 5.x
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/Structures/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use ArrayAccess;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Contracts\Support\Responsable;
use Illuminate\Support\Carbon;
use Illuminate\Support\Traits\ForwardsCalls;
use JsonSerializable;
use Statamic\Contracts\Auth\Protect\Protectable;
Expand Down Expand Up @@ -417,7 +418,14 @@ public function site()
public function toResponse($request)
{
if ($this->reference && $this->referenceExists()) {
return (new \Statamic\Http\Responses\DataResponse($this))->toResponse($request);
$response = (new \Statamic\Http\Responses\DataResponse($this))->toResponse($request);

if ($updatedAt = $this->routeData()['updated_at'] ?? null) {
$response->setLastModified(Carbon::parse($updatedAt));
}

return $response
->setEtag(md5($response->getContent() ?? ''));
}

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