FinishResponseSubscriber
class FinishResponseSubscriber implements EventSubscriberInterface (View source)
Response subscriber to handle finished responses.
Properties
| protected LanguageManagerInterface | $languageManager | The language manager object for retrieving the correct language code. |
|
| protected Config | $config | A config object for the system performance configuration. |
|
| protected RequestPolicyInterface | $requestPolicy | A policy rule determining the cacheability of a request. |
|
| protected ResponsePolicyInterface | $responsePolicy | A policy rule determining the cacheability of the response. |
|
| protected CacheContextsManager | $cacheContexts | The cache contexts manager service. |
|
| protected bool | $debugCacheabilityHeaders | Whether to send cacheability headers for debugging purposes. |
Methods
Constructs a FinishResponseSubscriber object.
Sets extra headers on any responses, also subrequest ones.
Sets extra headers on successful responses.
Determine whether the given response has a custom Cache-Control header.
Add Cache-Control and Expires headers to a response which is not cacheable.
Add Cache-Control and Expires headers to a cacheable response.
Disable caching in the browser and for HTTP/1.1 proxies and clients.
Disable caching in ancient browsers and for HTTP/1.0 proxies and clients.
Registers the methods in this class that should be listeners.
Details
__construct(LanguageManagerInterface $language_manager, ConfigFactoryInterface $config_factory, RequestPolicyInterface $request_policy, ResponsePolicyInterface $response_policy, CacheContextsManager $cache_contexts_manager, bool $http_response_debug_cacheability_headers = FALSE)
Constructs a FinishResponseSubscriber object.
onAllResponds(ResponseEvent $event)
Sets extra headers on any responses, also subrequest ones.
onRespond(ResponseEvent $event)
Sets extra headers on successful responses.
protected bool
isCacheControlCustomized(Response $response)
Determine whether the given response has a custom Cache-Control header.
Upon construction, the ResponseHeaderBag is initialized with an empty Cache-Control header. Consequently it is not possible to check whether the header was set explicitly by simply checking its presence. Instead, it is necessary to examine the computed Cache-Control header and compare with values known to be present only when Cache-Control was never set explicitly.
When neither Cache-Control nor any of the ETag, Last-Modified, Expires headers are set on the response, ::get('Cache-Control') returns the value 'no-cache, private'. If any of ETag, Last-Modified or Expires are set but not Cache-Control, then 'private, must-revalidate' (in exactly this order) is returned.
protected
setResponseNotCacheable(Response $response, Request $request)
Add Cache-Control and Expires headers to a response which is not cacheable.
protected
setResponseCacheable(Response $response, Request $request)
Add Cache-Control and Expires headers to a cacheable response.
protected
setCacheControlNoCache(Response $response)
Disable caching in the browser and for HTTP/1.1 proxies and clients.
protected
setExpiresNoCache(Response $response)
Disable caching in ancient browsers and for HTTP/1.0 proxies and clients.
HTTP/1.0 proxies do not support the Vary header, so prevent any caching by sending an Expires date in the past. HTTP/1.1 clients ignore the Expires header if a Cache-Control: max-age= directive is specified (see RFC 2616, section 14.9.3).
static array
getSubscribedEvents()
Registers the methods in this class that should be listeners.