DownloadResponse extends Response
Prompts the user to download the a file
It handles headers, HTTP status code, last modified and ETag.
Tags
Table of Contents
- $contentSecurityPolicy : ContentSecurityPolicy|null
- $contentType : mixed
- $cookies : array
- Cookies that will be need to be constructed as header
- $ETag : string
- ETag
- $featurePolicy : FeaturePolicy
- $filename : mixed
- $headers : array
- Headers - defaults to ['Cache-Control' => 'no-cache, no-store, must-revalidate']
- $lastModified : DateTime
- Last modified date
- $status : int
- HTTP status code - defaults to STATUS OK
- $throttled : bool
- $throttleMetadata : array
- __construct() : mixed
- Creates a response that prompts the user to download the file
- addCookie() : $this
- Adds a new cookie to the response
- addHeader() : $this
- Adds a new header to the response that will be called before the render function
- cacheFor() : $this
- Caches the response
- getContentSecurityPolicy() : EmptyContentSecurityPolicy|null
- Get the currently used Content-Security-Policy
- getCookies() : array
- Returns the cookies
- getETag() : string
- Get the ETag
- getFeaturePolicy() : EmptyFeaturePolicy
- getHeaders() : array
- Returns the set headers
- getLastModified() : DateTime
- Get "last modified" date
- getStatus() : mixed
- Get response status
- getThrottleMetadata() : array
- Returns the throttle metadata, defaults to empty array
- invalidateCookie() : $this
- Invalidates the specified cookie
- invalidateCookies() : $this
- Invalidates the specified cookies
- isThrottled() : mixed
- Whether the current response is throttled.
- render() : string
- By default renders no output
- setContentSecurityPolicy() : $this
- Set a Content-Security-Policy
- setCookies() : $this
- Set the specified cookies
- setETag() : Response
- Set the ETag
- setFeaturePolicy() : self
- setHeaders() : $this
- Set the headers
- setLastModified() : Response
- Set "last modified" date
- setStatus() : Response
- Set response status
- throttle() : mixed
- Marks the response as to throttle. Will be throttled when the
Properties
$contentSecurityPolicy
private
ContentSecurityPolicy|null
$contentSecurityPolicy
= null
$contentType
private
mixed
$contentType
$cookies
Cookies that will be need to be constructed as header
private
array
$cookies
= []
$ETag
ETag
private
string
$ETag
$featurePolicy
private
FeaturePolicy
$featurePolicy
$filename
private
mixed
$filename
$headers
Headers - defaults to ['Cache-Control' => 'no-cache, no-store, must-revalidate']
private
array
$headers
= ['Cache-Control' => 'no-cache, no-store, must-revalidate']
$lastModified
Last modified date
private
DateTime
$lastModified
$status
HTTP status code - defaults to STATUS OK
private
int
$status
= OCPAppFrameworkHttp::STATUS_OK
$throttled
private
bool
$throttled
= false
$throttleMetadata
private
array
$throttleMetadata
= []
Methods
__construct()
Creates a response that prompts the user to download the file
public
__construct(string $filename, string $contentType) : mixed
Parameters
- $filename : string
-
the name that the downloaded file should have
- $contentType : string
-
the mimetype that the downloaded file should have
Tags
Return values
mixed —addCookie()
Adds a new cookie to the response
public
addCookie(string $name, string $value[, DateTime|null $expireDate = null ][, string $sameSite = 'Lax' ]) : $this
Parameters
- $name : string
-
The name of the cookie
- $value : string
-
The value of the cookie
- $expireDate : DateTime|null = null
-
Date on that the cookie should expire, if set to null cookie will be considered as session cookie.
- $sameSite : string = 'Lax'
-
The samesite value of the cookie. Defaults to Lax. Other possibilities are Strict or None
Tags
Return values
$this —addHeader()
Adds a new header to the response that will be called before the render function
public
addHeader(string $name, string $value) : $this
Parameters
- $name : string
-
The name of the HTTP header
- $value : string
-
The value, null will delete it
Tags
Return values
$this —cacheFor()
Caches the response
public
cacheFor(int $cacheSeconds[, bool $public = false ]) : $this
Parameters
- $cacheSeconds : int
-
the amount of seconds that should be cached if 0 then caching will be disabled
- $public : bool = false
Tags
Return values
$this —getContentSecurityPolicy()
Get the currently used Content-Security-Policy
public
getContentSecurityPolicy() : EmptyContentSecurityPolicy|null
Tags
Return values
EmptyContentSecurityPolicy|null —Used Content-Security-Policy or null if none specified.
getCookies()
Returns the cookies
public
getCookies() : array
Tags
Return values
array —getETag()
Get the ETag
public
getETag() : string
Tags
Return values
string —the etag
getFeaturePolicy()
public
getFeaturePolicy() : EmptyFeaturePolicy
Tags
Return values
EmptyFeaturePolicy —getHeaders()
Returns the set headers
public
getHeaders() : array
Tags
Return values
array —the headers
getLastModified()
Get "last modified" date
public
getLastModified() : DateTime
Tags
Return values
DateTime —RFC2822 formatted last modified date
getStatus()
Get response status
public
getStatus() : mixed
Tags
Return values
mixed —getThrottleMetadata()
Returns the throttle metadata, defaults to empty array
public
getThrottleMetadata() : array
Tags
Return values
array —invalidateCookie()
Invalidates the specified cookie
public
invalidateCookie(string $name) : $this
Parameters
- $name : string
Tags
Return values
$this —invalidateCookies()
Invalidates the specified cookies
public
invalidateCookies(array $cookieNames) : $this
Parameters
- $cookieNames : array
-
array('foo', 'bar')
Tags
Return values
$this —isThrottled()
Whether the current response is throttled.
public
isThrottled() : mixed
Tags
Return values
mixed —render()
By default renders no output
public
render() : string
Tags
Return values
string —setContentSecurityPolicy()
Set a Content-Security-Policy
public
setContentSecurityPolicy(EmptyContentSecurityPolicy $csp) : $this
Parameters
- $csp : EmptyContentSecurityPolicy
-
Policy to set for the response object
Tags
Return values
$this —setCookies()
Set the specified cookies
public
setCookies(array $cookies) : $this
Parameters
- $cookies : array
-
array('foo' => array('value' => 'bar', 'expire' => null))
Tags
Return values
$this —setETag()
Set the ETag
public
setETag(string $ETag) : Response
Parameters
- $ETag : string
Tags
Return values
Response —Reference to this object
setFeaturePolicy()
public
setFeaturePolicy(EmptyFeaturePolicy $featurePolicy) : self
Parameters
- $featurePolicy : EmptyFeaturePolicy
Tags
Return values
self —setHeaders()
Set the headers
public
setHeaders(array $headers) : $this
Parameters
- $headers : array
-
value header pairs
Tags
Return values
$this —setLastModified()
Set "last modified" date
public
setLastModified(DateTime $lastModified) : Response
Parameters
- $lastModified : DateTime
Tags
Return values
Response —Reference to this object
setStatus()
Set response status
public
setStatus(int $status) : Response
Parameters
- $status : int
-
a HTTP status code, see also the STATUS constants
Tags
Return values
Response —Reference to this object
throttle()
Marks the response as to throttle. Will be throttled when the
public
throttle([array $metadata = [] ]) : mixed
Parameters
- $metadata : array = []