Skip to content

Response::expire() should also modify the Expires header #13341

@choonge

Description

@choonge

I have an action with this cache annotation:

/**
 * @Cache(expires="+5 minutes", smaxage="300")
 */

When I use nocache.php rather than index.php, I don't want any http caching. So I do this:

// web/nocache.php
$response = $kernel->handle($request);
$response->expire();
$response->send();

The relevant HTTP headers which I receive when I hit the action over nocache.php, are as follows:

Age:300
Cache-Control:private, s-maxage=300
Date:Fri, 09 Jan 2015 09:40:31 GMT
Expires:Fri, 09 Jan 2015 09:45:34 GMT

So if you look at s-maxage and Age, the response is now stale. But Expires is still set to 5 minutes in the future. Which is expected, because what $response->expire() does is:

// Symfony\Component\HttpFoundation\Response
    /**
     * Marks the response stale by setting the Age header to be equal to the maximum age of the response.
     *
     * @return Response
     *
     * @api
     */
    public function expire()
    {
        if ($this->isFresh()) {
            $this->headers->set('Age', $this->getMaxAge());
        }
        return $this;
    }

Now the actual question: I read that it's good practice to set both Cache-Control and Expires. Cache-Control has precedence if both are defined, but Expires should be there for proxies which don't support HTTP/1.1. In that light, shouldn't Response::expire() also do $this->setExpires(null) ?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions