Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Response.php

function Response::setExpires

Sets the Expires HTTP header with a DateTime instance.

Passing null as value will remove the header.

@final

Return value

$this

File

vendor/symfony/http-foundation/Response.php, line 734

Class

Response
Response represents an HTTP response.

Namespace

Symfony\Component\HttpFoundation

Code

public function setExpires(?\DateTimeInterface $date) : static {
    if (null === $date) {
        $this->headers
            ->remove('Expires');
        return $this;
    }
    $date = \DateTimeImmutable::createFromInterface($date);
    $date = $date->setTimezone(new \DateTimeZone('UTC'));
    $this->headers
        ->set('Expires', $date->format('D, d M Y H:i:s') . ' GMT');
    return $this;
}
RSS feed
Powered by Drupal