StreamedResponse
extends Response
in package
StreamedResponse represents a streamed HTTP response.
A StreamedResponse uses a callback for its content.
The callback should use the standard PHP functions like echo to stream the response back to the client. The flush() function can also be used if needed.
Tags
Table of Contents
- HTTP_ACCEPTED = 202
- HTTP_ALREADY_REPORTED = 208
- HTTP_BAD_GATEWAY = 502
- HTTP_BAD_REQUEST = 400
- HTTP_CONFLICT = 409
- HTTP_CONTINUE = 100
- HTTP_CREATED = 201
- HTTP_EARLY_HINTS = 103
- HTTP_EXPECTATION_FAILED = 417
- HTTP_FAILED_DEPENDENCY = 424
- HTTP_FORBIDDEN = 403
- HTTP_FOUND = 302
- HTTP_GATEWAY_TIMEOUT = 504
- HTTP_GONE = 410
- HTTP_I_AM_A_TEAPOT = 418
- HTTP_IM_USED = 226
- HTTP_INSUFFICIENT_STORAGE = 507
- HTTP_INTERNAL_SERVER_ERROR = 500
- HTTP_LENGTH_REQUIRED = 411
- HTTP_LOCKED = 423
- HTTP_LOOP_DETECTED = 508
- HTTP_METHOD_NOT_ALLOWED = 405
- HTTP_MISDIRECTED_REQUEST = 421
- HTTP_MOVED_PERMANENTLY = 301
- HTTP_MULTI_STATUS = 207
- HTTP_MULTIPLE_CHOICES = 300
- HTTP_NETWORK_AUTHENTICATION_REQUIRED = 511
- HTTP_NO_CONTENT = 204
- HTTP_NON_AUTHORITATIVE_INFORMATION = 203
- HTTP_NOT_ACCEPTABLE = 406
- HTTP_NOT_EXTENDED = 510
- HTTP_NOT_FOUND = 404
- HTTP_NOT_IMPLEMENTED = 501
- HTTP_NOT_MODIFIED = 304
- HTTP_OK = 200
- HTTP_PARTIAL_CONTENT = 206
- HTTP_PAYMENT_REQUIRED = 402
- HTTP_PERMANENTLY_REDIRECT = 308
- HTTP_PRECONDITION_FAILED = 412
- HTTP_PRECONDITION_REQUIRED = 428
- HTTP_PROCESSING = 102
- HTTP_PROXY_AUTHENTICATION_REQUIRED = 407
- HTTP_REQUEST_ENTITY_TOO_LARGE = 413
- HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE = 431
- HTTP_REQUEST_TIMEOUT = 408
- HTTP_REQUEST_URI_TOO_LONG = 414
- HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416
- HTTP_RESERVED = 306
- HTTP_RESET_CONTENT = 205
- HTTP_SEE_OTHER = 303
- HTTP_SERVICE_UNAVAILABLE = 503
- HTTP_SWITCHING_PROTOCOLS = 101
- HTTP_TEMPORARY_REDIRECT = 307
- HTTP_TOO_EARLY = 425
- HTTP_TOO_MANY_REQUESTS = 429
- HTTP_UNAUTHORIZED = 401
- HTTP_UNAVAILABLE_FOR_LEGAL_REASONS = 451
- HTTP_UNPROCESSABLE_ENTITY = 422
- HTTP_UNSUPPORTED_MEDIA_TYPE = 415
- HTTP_UPGRADE_REQUIRED = 426
- HTTP_USE_PROXY = 305
- HTTP_VARIANT_ALSO_NEGOTIATES_EXPERIMENTAL = 506
- HTTP_VERSION_NOT_SUPPORTED = 505
- HTTP_RESPONSE_CACHE_CONTROL_DIRECTIVES = ['must_revalidate' => false, 'no_cache' => false, 'no_store' => false, 'no_transform' => false, 'public' => false, 'private' => false, 'proxy_revalidate' => false, 'max_age' => true, 's_maxage' => true, 'immutable' => false, 'last_modified' => true, 'etag' => true]
- $headers : ResponseHeaderBag
- $statusTexts : array<string|int, mixed>
- Status codes translation table.
- $callback : mixed
- $charset : string
- $content : string
- $statusCode : int
- $statusText : string
- $streamed : mixed
- $version : string
- $headersSent : mixed
- __clone() : mixed
- Clones the current Response instance.
- __construct() : mixed
- __toString() : string
- Returns the Response as an HTTP string.
- closeOutputBuffers() : void
- Cleans or flushes output buffers up to target level.
- create() : static
- Factory method for chainability.
- expire() : $this
- Marks the response stale by setting the Age header to be equal to the maximum age of the response.
- getAge() : int
- Returns the age of the response in seconds.
- getCharset() : string|null
- Retrieves the response charset.
- getContent() : string|false
- Gets the current response content.
- getDate() : DateTimeInterface|null
- Returns the Date header as a DateTime instance.
- getEtag() : string|null
- Returns the literal value of the ETag HTTP header.
- getExpires() : DateTimeInterface|null
- Returns the value of the Expires header as a DateTime instance.
- getLastModified() : DateTimeInterface|null
- Returns the Last-Modified HTTP header as a DateTime instance.
- getMaxAge() : int|null
- Returns the number of seconds after the time specified in the response's Date header when the response should no longer be considered fresh.
- getProtocolVersion() : string
- Gets the HTTP protocol version.
- getStatusCode() : int
- Retrieves the status code for the current web response.
- getTtl() : int|null
- Returns the response's time-to-live in seconds.
- getVary() : array<string|int, mixed>
- Returns an array of header names given in the Vary header.
- hasVary() : bool
- Returns true if the response includes a Vary header.
- isCacheable() : bool
- Returns true if the response may safely be kept in a shared (surrogate) cache.
- isClientError() : bool
- Is there a client error?
- isEmpty() : bool
- Is the response empty?
- isForbidden() : bool
- Is the response forbidden?
- isFresh() : bool
- Returns true if the response is "fresh".
- isImmutable() : bool
- Returns true if the response is marked as "immutable".
- isInformational() : bool
- Is response informative?
- isInvalid() : bool
- Is response invalid?
- isNotFound() : bool
- Is the response a not found error?
- isNotModified() : bool
- Determines if the Response validators (ETag, Last-Modified) match a conditional value specified in the Request.
- isOk() : bool
- Is the response OK?
- isRedirect() : bool
- Is the response a redirect of some form?
- isRedirection() : bool
- Is the response a redirect?
- isServerError() : bool
- Was there a server side error?
- isSuccessful() : bool
- Is response successful?
- isValidateable() : bool
- Returns true if the response includes headers that can be used to validate the response with the origin server using a conditional GET request.
- mustRevalidate() : bool
- Returns true if the response must be revalidated by shared caches once it has become stale.
- prepare() : $this
- Prepares the Response before it is sent to the client.
- send() : $this
- Sends HTTP headers and content.
- sendContent() : $this
- Sends content for the current web response.
- sendHeaders() : $this
- Sends HTTP headers.
- setCache() : $this
- Sets the response's cache headers (validation and/or expiration).
- setCallback() : $this
- Sets the PHP callback associated with this Response.
- setCharset() : $this
- Sets the response charset.
- setClientTtl() : $this
- Sets the response's time-to-live for private/client caches in seconds.
- setContent() : $this
- Sets the response content.
- setContentSafe() : void
- Marks a response as safe according to RFC8674.
- setDate() : $this
- Sets the Date header.
- setEtag() : $this
- Sets the ETag value.
- setExpires() : $this
- Sets the Expires HTTP header with a DateTime instance.
- setImmutable() : $this
- Marks the response as "immutable".
- setLastModified() : $this
- Sets the Last-Modified HTTP header with a DateTime instance.
- setMaxAge() : $this
- Sets the number of seconds after which the response should no longer be considered fresh.
- setNotModified() : $this
- Modifies the response so that it conforms to the rules defined for a 304 status code.
- setPrivate() : $this
- Marks the response as "private".
- setProtocolVersion() : $this
- Sets the HTTP protocol version (1.0 or 1.1).
- setPublic() : $this
- Marks the response as "public".
- setSharedMaxAge() : $this
- Sets the number of seconds after which the response should no longer be considered fresh by shared caches.
- setStatusCode() : $this
- Sets the response status code.
- setTtl() : $this
- Sets the response's time-to-live for shared caches in seconds.
- setVary() : $this
- Sets the Vary header.
- ensureIEOverSSLCompatibility() : void
- Checks if we need to remove Cache-Control for SSL encrypted downloads when using IE < 9.
Constants
HTTP_ACCEPTED
public
mixed
HTTP_ACCEPTED
= 202
HTTP_ALREADY_REPORTED
public
mixed
HTTP_ALREADY_REPORTED
= 208
HTTP_BAD_GATEWAY
public
mixed
HTTP_BAD_GATEWAY
= 502
HTTP_BAD_REQUEST
public
mixed
HTTP_BAD_REQUEST
= 400
HTTP_CONFLICT
public
mixed
HTTP_CONFLICT
= 409
HTTP_CONTINUE
public
mixed
HTTP_CONTINUE
= 100
HTTP_CREATED
public
mixed
HTTP_CREATED
= 201
HTTP_EARLY_HINTS
public
mixed
HTTP_EARLY_HINTS
= 103
HTTP_EXPECTATION_FAILED
public
mixed
HTTP_EXPECTATION_FAILED
= 417
HTTP_FAILED_DEPENDENCY
public
mixed
HTTP_FAILED_DEPENDENCY
= 424
HTTP_FORBIDDEN
public
mixed
HTTP_FORBIDDEN
= 403
HTTP_FOUND
public
mixed
HTTP_FOUND
= 302
HTTP_GATEWAY_TIMEOUT
public
mixed
HTTP_GATEWAY_TIMEOUT
= 504
HTTP_GONE
public
mixed
HTTP_GONE
= 410
HTTP_I_AM_A_TEAPOT
public
mixed
HTTP_I_AM_A_TEAPOT
= 418
HTTP_IM_USED
public
mixed
HTTP_IM_USED
= 226
HTTP_INSUFFICIENT_STORAGE
public
mixed
HTTP_INSUFFICIENT_STORAGE
= 507
HTTP_INTERNAL_SERVER_ERROR
public
mixed
HTTP_INTERNAL_SERVER_ERROR
= 500
HTTP_LENGTH_REQUIRED
public
mixed
HTTP_LENGTH_REQUIRED
= 411
HTTP_LOCKED
public
mixed
HTTP_LOCKED
= 423
HTTP_LOOP_DETECTED
public
mixed
HTTP_LOOP_DETECTED
= 508
HTTP_METHOD_NOT_ALLOWED
public
mixed
HTTP_METHOD_NOT_ALLOWED
= 405
HTTP_MISDIRECTED_REQUEST
public
mixed
HTTP_MISDIRECTED_REQUEST
= 421
HTTP_MOVED_PERMANENTLY
public
mixed
HTTP_MOVED_PERMANENTLY
= 301
HTTP_MULTI_STATUS
public
mixed
HTTP_MULTI_STATUS
= 207
HTTP_MULTIPLE_CHOICES
public
mixed
HTTP_MULTIPLE_CHOICES
= 300
HTTP_NETWORK_AUTHENTICATION_REQUIRED
public
mixed
HTTP_NETWORK_AUTHENTICATION_REQUIRED
= 511
HTTP_NO_CONTENT
public
mixed
HTTP_NO_CONTENT
= 204
HTTP_NON_AUTHORITATIVE_INFORMATION
public
mixed
HTTP_NON_AUTHORITATIVE_INFORMATION
= 203
HTTP_NOT_ACCEPTABLE
public
mixed
HTTP_NOT_ACCEPTABLE
= 406
HTTP_NOT_EXTENDED
public
mixed
HTTP_NOT_EXTENDED
= 510
HTTP_NOT_FOUND
public
mixed
HTTP_NOT_FOUND
= 404
HTTP_NOT_IMPLEMENTED
public
mixed
HTTP_NOT_IMPLEMENTED
= 501
HTTP_NOT_MODIFIED
public
mixed
HTTP_NOT_MODIFIED
= 304
HTTP_OK
public
mixed
HTTP_OK
= 200
HTTP_PARTIAL_CONTENT
public
mixed
HTTP_PARTIAL_CONTENT
= 206
HTTP_PAYMENT_REQUIRED
public
mixed
HTTP_PAYMENT_REQUIRED
= 402
HTTP_PERMANENTLY_REDIRECT
public
mixed
HTTP_PERMANENTLY_REDIRECT
= 308
HTTP_PRECONDITION_FAILED
public
mixed
HTTP_PRECONDITION_FAILED
= 412
HTTP_PRECONDITION_REQUIRED
public
mixed
HTTP_PRECONDITION_REQUIRED
= 428
HTTP_PROCESSING
public
mixed
HTTP_PROCESSING
= 102
HTTP_PROXY_AUTHENTICATION_REQUIRED
public
mixed
HTTP_PROXY_AUTHENTICATION_REQUIRED
= 407
HTTP_REQUEST_ENTITY_TOO_LARGE
public
mixed
HTTP_REQUEST_ENTITY_TOO_LARGE
= 413
HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE
public
mixed
HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE
= 431
HTTP_REQUEST_TIMEOUT
public
mixed
HTTP_REQUEST_TIMEOUT
= 408
HTTP_REQUEST_URI_TOO_LONG
public
mixed
HTTP_REQUEST_URI_TOO_LONG
= 414
HTTP_REQUESTED_RANGE_NOT_SATISFIABLE
public
mixed
HTTP_REQUESTED_RANGE_NOT_SATISFIABLE
= 416
HTTP_RESERVED
public
mixed
HTTP_RESERVED
= 306
HTTP_RESET_CONTENT
public
mixed
HTTP_RESET_CONTENT
= 205
HTTP_SEE_OTHER
public
mixed
HTTP_SEE_OTHER
= 303
HTTP_SERVICE_UNAVAILABLE
public
mixed
HTTP_SERVICE_UNAVAILABLE
= 503
HTTP_SWITCHING_PROTOCOLS
public
mixed
HTTP_SWITCHING_PROTOCOLS
= 101
HTTP_TEMPORARY_REDIRECT
public
mixed
HTTP_TEMPORARY_REDIRECT
= 307
HTTP_TOO_EARLY
public
mixed
HTTP_TOO_EARLY
= 425
HTTP_TOO_MANY_REQUESTS
public
mixed
HTTP_TOO_MANY_REQUESTS
= 429
HTTP_UNAUTHORIZED
public
mixed
HTTP_UNAUTHORIZED
= 401
HTTP_UNAVAILABLE_FOR_LEGAL_REASONS
public
mixed
HTTP_UNAVAILABLE_FOR_LEGAL_REASONS
= 451
HTTP_UNPROCESSABLE_ENTITY
public
mixed
HTTP_UNPROCESSABLE_ENTITY
= 422
HTTP_UNSUPPORTED_MEDIA_TYPE
public
mixed
HTTP_UNSUPPORTED_MEDIA_TYPE
= 415
HTTP_UPGRADE_REQUIRED
public
mixed
HTTP_UPGRADE_REQUIRED
= 426
HTTP_USE_PROXY
public
mixed
HTTP_USE_PROXY
= 305
HTTP_VARIANT_ALSO_NEGOTIATES_EXPERIMENTAL
public
mixed
HTTP_VARIANT_ALSO_NEGOTIATES_EXPERIMENTAL
= 506
HTTP_VERSION_NOT_SUPPORTED
public
mixed
HTTP_VERSION_NOT_SUPPORTED
= 505
HTTP_RESPONSE_CACHE_CONTROL_DIRECTIVES
private
mixed
HTTP_RESPONSE_CACHE_CONTROL_DIRECTIVES
= ['must_revalidate' => false, 'no_cache' => false, 'no_store' => false, 'no_transform' => false, 'public' => false, 'private' => false, 'proxy_revalidate' => false, 'max_age' => true, 's_maxage' => true, 'immutable' => false, 'last_modified' => true, 'etag' => true]
Tags
Properties
$headers
public
ResponseHeaderBag
$headers
$statusTexts
Status codes translation table.
public
static array<string|int, mixed>
$statusTexts
= [
100 => 'Continue',
101 => 'Switching Protocols',
102 => 'Processing',
// RFC2518
103 => 'Early Hints',
200 => 'OK',
201 => 'Created',
202 => 'Accepted',
203 => 'Non-Authoritative Information',
204 => 'No Content',
205 => 'Reset Content',
206 => 'Partial Content',
207 => 'Multi-Status',
// RFC4918
208 => 'Already Reported',
// RFC5842
226 => 'IM Used',
// RFC3229
300 => 'Multiple Choices',
301 => 'Moved Permanently',
302 => 'Found',
303 => 'See Other',
304 => 'Not Modified',
305 => 'Use Proxy',
307 => 'Temporary Redirect',
308 => 'Permanent Redirect',
// RFC7238
400 => 'Bad Request',
401 => 'Unauthorized',
402 => 'Payment Required',
403 => 'Forbidden',
404 => 'Not Found',
405 => 'Method Not Allowed',
406 => 'Not Acceptable',
407 => 'Proxy Authentication Required',
408 => 'Request Timeout',
409 => 'Conflict',
410 => 'Gone',
411 => 'Length Required',
412 => 'Precondition Failed',
413 => 'Content Too Large',
// RFC-ietf-httpbis-semantics
414 => 'URI Too Long',
415 => 'Unsupported Media Type',
416 => 'Range Not Satisfiable',
417 => 'Expectation Failed',
418 => 'I'm a teapot',
// RFC2324
421 => 'Misdirected Request',
// RFC7540
422 => 'Unprocessable Content',
// RFC-ietf-httpbis-semantics
423 => 'Locked',
// RFC4918
424 => 'Failed Dependency',
// RFC4918
425 => 'Too Early',
// RFC-ietf-httpbis-replay-04
426 => 'Upgrade Required',
// RFC2817
428 => 'Precondition Required',
// RFC6585
429 => 'Too Many Requests',
// RFC6585
431 => 'Request Header Fields Too Large',
// RFC6585
451 => 'Unavailable For Legal Reasons',
// RFC7725
500 => 'Internal Server Error',
501 => 'Not Implemented',
502 => 'Bad Gateway',
503 => 'Service Unavailable',
504 => 'Gateway Timeout',
505 => 'HTTP Version Not Supported',
506 => 'Variant Also Negotiates',
// RFC2295
507 => 'Insufficient Storage',
// RFC4918
508 => 'Loop Detected',
// RFC5842
510 => 'Not Extended',
// RFC2774
511 => 'Network Authentication Required',
]
The list of codes is complete according to the Hypertext Transfer Protocol (HTTP) Status Code Registry (last updated 2021-10-01).
Unless otherwise noted, the status code is defined in RFC2616.
$callback
protected
mixed
$callback
$charset
protected
string
$charset
$content
protected
string
$content
$statusCode
protected
int
$statusCode
$statusText
protected
string
$statusText
$streamed
protected
mixed
$streamed
$version
protected
string
$version
$headersSent
private
mixed
$headersSent
Methods
__clone()
Clones the current Response instance.
public
__clone() : mixed
Return values
mixed —__construct()
public
__construct([callable|null $callback = null ][, int $status = 200 ][, array<string|int, mixed> $headers = [] ]) : mixed
Parameters
- $callback : callable|null = null
- $status : int = 200
- $headers : array<string|int, mixed> = []
Return values
mixed —__toString()
Returns the Response as an HTTP string.
public
__toString() : string
The string representation of the Response is the same as the one that will be sent to the client only if the prepare() method has been called before.
Tags
Return values
string —closeOutputBuffers()
Cleans or flushes output buffers up to target level.
public
static closeOutputBuffers(int $targetLevel, bool $flush) : void
Resulting level can be greater than target level if a non-removable buffer has been encountered.
Parameters
- $targetLevel : int
- $flush : bool
Tags
Return values
void —create()
Factory method for chainability.
public
static create([callable|null $callback = null ][, int $status = 200 ][, array<string|int, mixed> $headers = [] ]) : static
Parameters
- $callback : callable|null = null
-
A valid PHP callback or null to set it later
- $status : int = 200
- $headers : array<string|int, mixed> = []
Tags
Return values
static —expire()
Marks the response stale by setting the Age header to be equal to the maximum age of the response.
public
expire() : $this
Return values
$this —getAge()
Returns the age of the response in seconds.
public
getAge() : int
Tags
Return values
int —getCharset()
Retrieves the response charset.
public
getCharset() : string|null
Tags
Return values
string|null —getContent()
Gets the current response content.
public
getContent() : string|false
Return values
string|false —getDate()
Returns the Date header as a DateTime instance.
public
getDate() : DateTimeInterface|null
Tags
Return values
DateTimeInterface|null —getEtag()
Returns the literal value of the ETag HTTP header.
public
getEtag() : string|null
Tags
Return values
string|null —getExpires()
Returns the value of the Expires header as a DateTime instance.
public
getExpires() : DateTimeInterface|null
Tags
Return values
DateTimeInterface|null —getLastModified()
Returns the Last-Modified HTTP header as a DateTime instance.
public
getLastModified() : DateTimeInterface|null
Tags
Return values
DateTimeInterface|null —getMaxAge()
Returns the number of seconds after the time specified in the response's Date header when the response should no longer be considered fresh.
public
getMaxAge() : int|null
First, it checks for a s-maxage directive, then a max-age directive, and then it falls back on an expires header. It returns null when no maximum age can be established.
Tags
Return values
int|null —getProtocolVersion()
Gets the HTTP protocol version.
public
getProtocolVersion() : string
Tags
Return values
string —getStatusCode()
Retrieves the status code for the current web response.
public
getStatusCode() : int
Tags
Return values
int —getTtl()
Returns the response's time-to-live in seconds.
public
getTtl() : int|null
It returns null when no freshness information is present in the response.
When the response's TTL is 0, the response may not be served from cache without first revalidating with the origin.
Tags
Return values
int|null —getVary()
Returns an array of header names given in the Vary header.
public
getVary() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —hasVary()
Returns true if the response includes a Vary header.
public
hasVary() : bool
Tags
Return values
bool —isCacheable()
Returns true if the response may safely be kept in a shared (surrogate) cache.
public
isCacheable() : bool
Responses marked "private" with an explicit Cache-Control directive are considered uncacheable.
Responses with neither a freshness lifetime (Expires, max-age) nor cache validator (Last-Modified, ETag) are considered uncacheable because there is no way to tell when or how to remove them from the cache.
Note that RFC 7231 and RFC 7234 possibly allow for a more permissive implementation, for example "status codes that are defined as cacheable by default [...] can be reused by a cache with heuristic expiration unless otherwise indicated" (https://tools.ietf.org/html/rfc7231#section-6.1)
Tags
Return values
bool —isClientError()
Is there a client error?
public
isClientError() : bool
Tags
Return values
bool —isEmpty()
Is the response empty?
public
isEmpty() : bool
Tags
Return values
bool —isForbidden()
Is the response forbidden?
public
isForbidden() : bool
Tags
Return values
bool —isFresh()
Returns true if the response is "fresh".
public
isFresh() : bool
Fresh responses may be served from cache without any interaction with the origin. A response is considered fresh when it includes a Cache-Control/max-age indicator or Expires header and the calculated age is less than the freshness lifetime.
Tags
Return values
bool —isImmutable()
Returns true if the response is marked as "immutable".
public
isImmutable() : bool
Tags
Return values
bool —isInformational()
Is response informative?
public
isInformational() : bool
Tags
Return values
bool —isInvalid()
Is response invalid?
public
isInvalid() : bool
Tags
Return values
bool —isNotFound()
Is the response a not found error?
public
isNotFound() : bool
Tags
Return values
bool —isNotModified()
Determines if the Response validators (ETag, Last-Modified) match a conditional value specified in the Request.
public
isNotModified(Request $request) : bool
If the Response is not modified, it sets the status code to 304 and removes the actual content by calling the setNotModified() method.
Parameters
- $request : Request
Tags
Return values
bool —isOk()
Is the response OK?
public
isOk() : bool
Tags
Return values
bool —isRedirect()
Is the response a redirect of some form?
public
isRedirect([string|null $location = null ]) : bool
Parameters
- $location : string|null = null
Tags
Return values
bool —isRedirection()
Is the response a redirect?
public
isRedirection() : bool
Tags
Return values
bool —isServerError()
Was there a server side error?
public
isServerError() : bool
Tags
Return values
bool —isSuccessful()
Is response successful?
public
isSuccessful() : bool
Tags
Return values
bool —isValidateable()
Returns true if the response includes headers that can be used to validate the response with the origin server using a conditional GET request.
public
isValidateable() : bool
Tags
Return values
bool —mustRevalidate()
Returns true if the response must be revalidated by shared caches once it has become stale.
public
mustRevalidate() : bool
This method indicates that the response must not be served stale by a cache in any circumstance without first revalidating with the origin. When present, the TTL of the response should not be overridden to be greater than the value provided by the origin.
Tags
Return values
bool —prepare()
Prepares the Response before it is sent to the client.
public
prepare(Request $request) : $this
This method tweaks the Response to ensure that it is compliant with RFC 2616. Most of the changes are based on the Request that is "associated" with this Response.
Parameters
- $request : Request
Return values
$this —send()
Sends HTTP headers and content.
public
send() : $this
Return values
$this —sendContent()
Sends content for the current web response.
public
sendContent() : $this
This method only sends the content once.
Return values
$this —sendHeaders()
Sends HTTP headers.
public
sendHeaders() : $this
This method only sends the headers once.
Return values
$this —setCache()
Sets the response's cache headers (validation and/or expiration).
public
setCache(array<string|int, mixed> $options) : $this
Available options are: must_revalidate, no_cache, no_store, no_transform, public, private, proxy_revalidate, max_age, s_maxage, immutable, last_modified and etag.
Parameters
- $options : array<string|int, mixed>
Tags
Return values
$this —setCallback()
Sets the PHP callback associated with this Response.
public
setCallback(callable $callback) : $this
Parameters
- $callback : callable
Return values
$this —setCharset()
Sets the response charset.
public
setCharset(string $charset) : $this
Parameters
- $charset : string
Tags
Return values
$this —setClientTtl()
Sets the response's time-to-live for private/client caches in seconds.
public
setClientTtl(int $seconds) : $this
This method adjusts the Cache-Control/max-age directive.
Parameters
- $seconds : int
Tags
Return values
$this —setContent()
Sets the response content.
public
setContent(string|null $content) : $this
Parameters
- $content : string|null
Tags
Return values
$this —setContentSafe()
Marks a response as safe according to RFC8674.
public
setContentSafe([bool $safe = true ]) : void
Parameters
- $safe : bool = true
Tags
Return values
void —setDate()
Sets the Date header.
public
setDate(DateTimeInterface $date) : $this
Parameters
- $date : DateTimeInterface
Tags
Return values
$this —setEtag()
Sets the ETag value.
public
setEtag([string|null $etag = null ][, bool $weak = false ]) : $this
Parameters
- $etag : string|null = null
-
The ETag unique identifier or null to remove the header
- $weak : bool = false
-
Whether you want a weak ETag or not
Tags
Return values
$this —setExpires()
Sets the Expires HTTP header with a DateTime instance.
public
setExpires([DateTimeInterface|null $date = null ]) : $this
Passing null as value will remove the header.
Parameters
- $date : DateTimeInterface|null = null
Tags
Return values
$this —setImmutable()
Marks the response as "immutable".
public
setImmutable([bool $immutable = true ]) : $this
Parameters
- $immutable : bool = true
Tags
Return values
$this —setLastModified()
Sets the Last-Modified HTTP header with a DateTime instance.
public
setLastModified([DateTimeInterface|null $date = null ]) : $this
Passing null as value will remove the header.
Parameters
- $date : DateTimeInterface|null = null
Tags
Return values
$this —setMaxAge()
Sets the number of seconds after which the response should no longer be considered fresh.
public
setMaxAge(int $value) : $this
This methods sets the Cache-Control max-age directive.
Parameters
- $value : int
Tags
Return values
$this —setNotModified()
Modifies the response so that it conforms to the rules defined for a 304 status code.
public
setNotModified() : $this
This sets the status, removes the body, and discards any headers that MUST NOT be included in 304 responses.
Tags
Return values
$this —setPrivate()
Marks the response as "private".
public
setPrivate() : $this
It makes the response ineligible for serving other clients.
Tags
Return values
$this —setProtocolVersion()
Sets the HTTP protocol version (1.0 or 1.1).
public
setProtocolVersion(string $version) : $this
Parameters
- $version : string
Tags
Return values
$this —setPublic()
Marks the response as "public".
public
setPublic() : $this
It makes the response eligible for serving other clients.
Tags
Return values
$this —setSharedMaxAge()
Sets the number of seconds after which the response should no longer be considered fresh by shared caches.
public
setSharedMaxAge(int $value) : $this
This methods sets the Cache-Control s-maxage directive.
Parameters
- $value : int
Tags
Return values
$this —setStatusCode()
Sets the response status code.
public
setStatusCode(int $code[, string|null $text = null ]) : $this
If the status text is null it will be automatically populated for the known status codes and left empty otherwise.
Parameters
- $code : int
- $text : string|null = null
Tags
Return values
$this —setTtl()
Sets the response's time-to-live for shared caches in seconds.
public
setTtl(int $seconds) : $this
This method adjusts the Cache-Control/s-maxage directive.
Parameters
- $seconds : int
Tags
Return values
$this —setVary()
Sets the Vary header.
public
setVary(string|array<string|int, mixed> $headers[, bool $replace = true ]) : $this
Parameters
- $headers : string|array<string|int, mixed>
- $replace : bool = true
-
Whether to replace the actual value or not (true by default)
Tags
Return values
$this —ensureIEOverSSLCompatibility()
Checks if we need to remove Cache-Control for SSL encrypted downloads when using IE < 9.
protected
ensureIEOverSSLCompatibility(Request $request) : void
Parameters
- $request : Request