Properties

$CSP

$CSP : \CodeIgniter\HTTP\ContentSecurityPolicy

Content security policy handler

Type

\CodeIgniter\HTTP\ContentSecurityPolicy

$headers

$headers : array

List of all HTTP request headers.

Type

array

$headerMap

$headerMap : array

Holds a map of lower-case header names and their normal-case key as it is in $headers.

Used for case-insensitive header access.

Type

array

$protocolVersion

$protocolVersion : string

Protocol version

Type

string

$validProtocolVersions

$validProtocolVersions : array

List of valid protocol versions

Type

array

$body

$body : string

Message body

Type

string

$statusCodes

$statusCodes : array

HTTP status codes

Type

array

$reason

$reason : string

The current reason phrase for this response.

If null, will use the default provided for the status code.

Type

string

$statusCode

$statusCode : integer

The current status code for this response.

Type

integer

$CSPEnabled

$CSPEnabled : boolean

Whether Content Security Policy is being enforced.

Type

boolean

$cookiePrefix

$cookiePrefix : string

Set a cookie name prefix if you need to avoid collisions

Type

string

$cookieDomain

$cookieDomain : string

Set to .your-domain.com for site-wide cookies

Type

string

$cookiePath

$cookiePath : string

Typically will be a forward slash

Type

string

$cookieSecure

$cookieSecure : boolean

Cookie will only be set if a secure HTTPS connection exists.

Type

boolean

$cookieHTTPOnly

$cookieHTTPOnly : boolean

Cookie will only be accessible via HTTP(S) (no javascript)

Type

boolean

$cookies

$cookies : array

Stores all cookies that were set in the response.

Type

array

$pretend

$pretend : boolean

If true, will not write output. Useful during testing.

Type

boolean

$bodyFormat

$bodyFormat : string

Type of format the body is in.

Valid: html, json, xml

Type

string

Methods

getBody()

getBody() : mixed|string

Grabs the current body.

Returns

mixed|string

populateHeaders()

populateHeaders() 

Populates the $headers array with any headers the getServer knows about.

getHeaders()

getHeaders() : array

Returns an array containing all headers.

Returns

array —

An array of the request headers

getHeader()

getHeader(string  $name) : array|\CodeIgniter\HTTP\Header

Returns a single header object. If multiple headers with the same name exist, then will return an array of header objects.

Parameters

string $name

Returns

array|\CodeIgniter\HTTP\Header

hasHeader()

hasHeader(string  $name) : boolean

Determines whether a header exists.

Parameters

string $name

Returns

boolean

getHeaderLine()

getHeaderLine(string  $name) : string

Retrieves a comma-separated string of the values for a single header.

This method returns all of the header values of the given case-insensitive header name as a string concatenated together using a comma.

NOTE: Not all header values may be appropriately represented using comma concatenation. For such headers, use getHeader() instead and supply your own delimiter when concatenating.

Parameters

string $name

Returns

string

setHeader()

setHeader(string  $name, array|null|string  $value) : \CodeIgniter\HTTP\Message|\CodeIgniter\HTTP\Response

Sets a header and it's value.

Parameters

string $name
array|null|string $value

Returns

\CodeIgniter\HTTP\Message|\CodeIgniter\HTTP\Response

removeHeader()

removeHeader(string  $name) : \CodeIgniter\HTTP\Message

Removes a header from the list of headers we track.

Parameters

string $name

Returns

\CodeIgniter\HTTP\Message

appendHeader()

appendHeader(string  $name, string  $value) : \CodeIgniter\HTTP\Message

Adds an additional header value to any headers that accept multiple values (i.e. are an array or implement ArrayAccess)

Parameters

string $name
string $value

Returns

\CodeIgniter\HTTP\Message

prependHeader()

prependHeader(string  $name, string  $value) : \CodeIgniter\HTTP\Message

Adds an additional header value to any headers that accept multiple values (i.e. are an array or implement ArrayAccess)

Parameters

string $name
string $value

Returns

\CodeIgniter\HTTP\Message

getProtocolVersion()

getProtocolVersion() : string

Returns the HTTP Protocol Version.

Returns

string

setProtocolVersion()

setProtocolVersion(string  $version) : \CodeIgniter\HTTP\Message

Sets the HTTP protocol version.

Parameters

string $version

Returns

\CodeIgniter\HTTP\Message

__construct()

__construct(\Config\App  $config) 

Constructor

Parameters

\Config\App $config

pretend()

pretend(boolean  $pretend = true) : $this

Turns "pretend" mode on or off to aid in testing.

Parameters

boolean $pretend

Returns

$this

getStatusCode()

getStatusCode() : integer

Gets the response status code.

The status code is a 3-digit integer result code of the getServer's attempt to understand and satisfy the request.

Returns

integer —

Status code.

setStatusCode()

setStatusCode(integer  $code, string  $reason = '') : $this

Return an instance with the specified status code and, optionally, reason phrase.

If no reason phrase is specified, will default recommended reason phrase for the response's status code.

Parameters

integer $code

The 3-digit integer result code to set.

string $reason

The reason phrase to use with the provided status code; if none is provided, will default to the IANA name.

Throws

\CodeIgniter\HTTP\Exceptions\HTTPException

For invalid status code arguments.

Returns

$this

getReason()

getReason() : string

Gets the response response phrase associated with the status code.

Returns

string

setDate()

setDate(\DateTime  $date) : \CodeIgniter\HTTP\Response

Sets the date header

Parameters

\DateTime $date

Returns

\CodeIgniter\HTTP\Response

setContentType()

setContentType(string  $mime, string  $charset = 'UTF-8') : \CodeIgniter\HTTP\Response

Sets the Content Type header for this response with the mime type and, optionally, the charset.

Parameters

string $mime
string $charset

Returns

\CodeIgniter\HTTP\Response

setJSON()

setJSON(array|string  $body) : $this

Converts the $body into JSON and sets the Content Type header.

Parameters

array|string $body

Returns

$this

getJSON()

getJSON() : mixed|string

Returns the current body, converted to JSON is it isn't already.

Throws

\InvalidArgumentException

If the body property is not array.

Returns

mixed|string

setXML()

setXML(array|string  $body) : $this

Converts $body into XML, and sets the correct Content-Type.

Parameters

array|string $body

Returns

$this

getXML()

getXML() : mixed|string

Retrieves the current body into XML and returns it.

Throws

\InvalidArgumentException

If the body property is not array.

Returns

mixed|string

noCache()

noCache() : \CodeIgniter\HTTP\Response

Sets the appropriate headers to ensure this response is not cached by the browsers.

Returns

\CodeIgniter\HTTP\Response

setCache()

setCache(array  $options = array()) : \CodeIgniter\HTTP\Response

A shortcut method that allows the developer to set all of the cache-control headers in one method call.

The options array is used to provide the cache-control directives for the header. It might look something like:

 $options = [
     'max-age'  => 300,
     's-maxage' => 900
     'etag'     => 'abcde',
 ];

Typical options are:

  • etag
  • last-modified
  • max-age
  • s-maxage
  • private
  • public
  • must-revalidate
  • proxy-revalidate
  • no-transform

Parameters

array $options

Returns

\CodeIgniter\HTTP\Response

setLastModified()

setLastModified(\DateTime|string  $date) : \CodeIgniter\HTTP\Response

Sets the Last-Modified date header.

$date can be either a string representation of the date or, preferably, an instance of DateTime.

Parameters

\DateTime|string $date

Returns

\CodeIgniter\HTTP\Response

sendHeaders()

sendHeaders() : \CodeIgniter\HTTP\Response

Sends the headers of this HTTP request to the browser.

Returns

\CodeIgniter\HTTP\Response

sendBody()

sendBody() : \CodeIgniter\HTTP\Response

Sends the Body of the message to the browser.

Returns

\CodeIgniter\HTTP\Response

redirect()

redirect(string  $uri, string  $method = 'auto', integer  $code = null) : $this

Perform a redirect to a new URL, in two flavors: header or location.

Parameters

string $uri

The URI to redirect to

string $method
integer $code

The type of redirection, defaults to 302

Throws

\CodeIgniter\HTTP\Exceptions\HTTPException

For invalid status code.

Returns

$this

setCookie()

setCookie(string|array  $name, string  $value = '', string  $expire = '', string  $domain = '', string  $path = '/', string  $prefix = '', boolean|false  $secure = false, boolean|false  $httponly = false) : $this

Set a cookie

Accepts an arbitrary number of binds (up to 7) or an associative array in the first parameter containing all the values.

Parameters

string|array $name

Cookie name or array containing binds

string $value

Cookie value

string $expire

Cookie expiration time in seconds

string $domain

Cookie domain (e.g.: '.yourdomain.com')

string $path

Cookie path (default: '/')

string $prefix

Cookie name prefix

boolean|false $secure

Whether to only transfer cookies via SSL

boolean|false $httponly

Whether only make the cookie accessible via HTTP (no javascript)

Returns

$this

hasCookie()

hasCookie(string  $name, string|null  $value = null, string  $prefix = '') : boolean

Checks to see if the Response has a specified cookie or not.

Parameters

string $name
string|null $value
string $prefix

Returns

boolean

getCookie()

getCookie(string|null  $name = null, string  $prefix = '') : mixed

Returns the cookie

Parameters

string|null $name
string $prefix

Returns

mixed

deleteCookie()

deleteCookie(string  $name = '', string  $domain = '', string  $path = '/', string  $prefix = '') : $this

Sets a cookie to be deleted when the response is sent.

Parameters

string $name
string $domain
string $path
string $prefix

Returns

$this

download()

download(string  $filename = '', string|null  $data = '', boolean  $setMime = false) : \CodeIgniter\HTTP\DownloadResponse|null

Force a download.

Generates the headers that force a download to happen. And sends the file to the browser.

Parameters

string $filename

The path to the file to send

string|null $data

The data to be downloaded

boolean $setMime

Whether to try and send the actual MIME type

Returns

\CodeIgniter\HTTP\DownloadResponse|null

getHeaderName()

getHeaderName(string  $name) : string

Takes a header name in any case, and returns the normal-case version of the header.

Parameters

string $name

Returns

string

formatBody()

formatBody(string|array  $body, string  $format) : mixed

Handles conversion of the of the data into the appropriate format, and sets the correct Content-Type header for our response.

Parameters

string|array $body
string $format

Valid: json, xml

Throws

\InvalidArgumentException

If the body property is not string or array.

Returns

mixed

sendCookies()

sendCookies() 

Actually sets the cookies.