Properties

$ipAddress

$ipAddress : string

IP address of the current user.

Type

string

$proxyIPs

$proxyIPs : string|array

Proxy IPs

Type

string|array

$method

$method : string

Request method.

Type

string

$globals

$globals : array

Stores values we've retrieved from PHP globals.

Type

array

$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

$response

$response : \CodeIgniter\HTTP\Response

The response object associated with this request

Type

\CodeIgniter\HTTP\Response

$baseURI

$baseURI : \CodeIgniter\HTTP\URI

The URI associated with this request

Type

\CodeIgniter\HTTP\URI

$config

$config : array

The setting values

Type

array

$redirectDefaults

$redirectDefaults : array

Default values for when 'allow_redirects' option is true.

Type

array

$delay

$delay : float

The number of milliseconds to delay before sending the request.

Type

float

Methods

__construct()

__construct(\Config\App  $config, \CodeIgniter\HTTP\URI  $uri, \CodeIgniter\HTTP\ResponseInterface  $response = null, array  $options = array()) 

Takes an array of options to set the following possible class properties:

  • baseURI
    • timeout
    • any other request options to use as defaults.

Parameters

\Config\App $config
\CodeIgniter\HTTP\URI $uri
\CodeIgniter\HTTP\ResponseInterface $response
array $options

getIPAddress()

getIPAddress() : string

Gets the user's IP address.

Returns

string —

IP address

isValidIP()

isValidIP(string  $ip = null, string  $which = null) : boolean

Validate an IP address

Parameters

string $ip

IP Address

string $which

IP protocol: 'ipv4' or 'ipv6'

Returns

boolean

getMethod()

getMethod(boolean|false  $upper = false) : string

Get the request method. Overrides the Request class' method since users expect a different answer here.

Parameters

boolean|false $upper

Whether to return in upper or lower case.

Returns

string

setMethod()

setMethod(string  $method) : \CodeIgniter\HTTP\Request

Sets the request method. Used when spoofing the request.

Parameters

string $method

Returns

\CodeIgniter\HTTP\Request

getServer()

getServer(string|array|null  $index = null, integer|null  $filter = null, null  $flags = null) : mixed

Fetch an item from the $_SERVER array.

Parameters

string|array|null $index

Index for item to be fetched from $_SERVER

integer|null $filter

A filter name to be applied

null $flags

Returns

mixed

getEnv()

getEnv(null  $index = null, null  $filter = null, null  $flags = null) : mixed

Fetch an item from the $_ENV array.

Parameters

null $index

Index for item to be fetched from $_ENV

null $filter

A filter name to be applied

null $flags

Returns

mixed

setGlobal()

setGlobal(string  $method,   $value) : $this

Allows manually setting the value of PHP global, like $_GET, $_POST, etc.

Parameters

string $method
$value

Returns

$this

fetchGlobal()

fetchGlobal(string  $method, string|array|null  $index = null, integer|null  $filter = null, mixed  $flags = null) : mixed

Fetches one or more items from a global, like cookies, get, post, etc.

Can optionally filter the input when you retrieve it by passing in a filter.

If $type is an array, it must conform to the input allowed by the filter_input_array method.

http://php.net/manual/en/filter.filters.sanitize.php

Parameters

string $method

Input filter constant

string|array|null $index
integer|null $filter

Filter constant

mixed $flags

Returns

mixed

getBody()

getBody() : mixed

Returns the Message's body.

Returns

mixed

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

request()

request(  $method, string  $url, array  $options = array()) : \CodeIgniter\HTTP\ResponseInterface

Sends an HTTP request to the specified $url. If this is a relative URL, it will be merged with $this->baseURI to form a complete URL.

Parameters

$method
string $url
array $options

Returns

\CodeIgniter\HTTP\ResponseInterface

get()

get(string  $url, array  $options = array()) : \CodeIgniter\HTTP\ResponseInterface

Convenience method for sending a GET request.

Parameters

string $url
array $options

Returns

\CodeIgniter\HTTP\ResponseInterface

delete()

delete(string  $url, array  $options = array()) : \CodeIgniter\HTTP\ResponseInterface

Convenience method for sending a DELETE request.

Parameters

string $url
array $options

Returns

\CodeIgniter\HTTP\ResponseInterface

head()

head(string  $url, array  $options = array()) : \CodeIgniter\HTTP\ResponseInterface

Convenience method for sending a HEAD request.

Parameters

string $url
array $options

Returns

\CodeIgniter\HTTP\ResponseInterface

options()

options(string  $url, array  $options = array()) : \CodeIgniter\HTTP\ResponseInterface

Convenience method for sending an OPTIONS request.

Parameters

string $url
array $options

Returns

\CodeIgniter\HTTP\ResponseInterface

patch()

patch(string  $url, array  $options = array()) : \CodeIgniter\HTTP\ResponseInterface

Convenience method for sending a PATCH request.

Parameters

string $url
array $options

Returns

\CodeIgniter\HTTP\ResponseInterface

post()

post(string  $url, array  $options = array()) : \CodeIgniter\HTTP\ResponseInterface

Convenience method for sending a POST request.

Parameters

string $url
array $options

Returns

\CodeIgniter\HTTP\ResponseInterface

put()

put(string  $url, array  $options = array()) : \CodeIgniter\HTTP\ResponseInterface

Convenience method for sending a PUT request.

Parameters

string $url
array $options

Returns

\CodeIgniter\HTTP\ResponseInterface

setAuth()

setAuth(string  $username, string  $password, string  $type = 'basic') : $this

Set the HTTP Authentication.

Parameters

string $username
string $password
string $type

basic or digest

Returns

$this

setForm()

setForm(array  $params, boolean  $multipart = false) : $this

Set form data to be sent.

Parameters

array $params
boolean $multipart

Set TRUE if you are sending CURLFiles

Returns

$this

setJSON()

setJSON(mixed  $data) : $this

Set JSON data to be sent.

Parameters

mixed $data

Returns

$this

send()

send(string  $method, string  $url) : \CodeIgniter\HTTP\ResponseInterface

Fires the actual cURL request.

Parameters

string $method
string $url

Returns

\CodeIgniter\HTTP\ResponseInterface

populateGlobals()

populateGlobals(string  $method) 

Saves a copy of the current state of one of several PHP globals so we can retrieve them later.

Parameters

string $method

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

parseOptions()

parseOptions(array  $options) 

Sets the correct settings based on the options array passed in.

Parameters

array $options

prepareURL()

prepareURL(string  $url) : string

If the $url is a relative URL, will attempt to create a full URL by prepending $this->baseURI to it.

Parameters

string $url

Returns

string

applyRequestHeaders()

applyRequestHeaders(array  $curl_options = array()) : array

Takes all headers current part of this request and adds them to the cURL request.

Parameters

array $curl_options

Returns

array

applyMethod()

applyMethod(string  $method, array  $curl_options) : array

Apply method

Parameters

string $method
array $curl_options

Returns

array

applyBody()

applyBody(array  $curl_options = array()) : array

Apply body

Parameters

array $curl_options

Returns

array

setResponseHeaders()

setResponseHeaders(array  $headers = array()) 

Parses the header retrieved from the cURL response into our Response object.

Parameters

array $headers

setCURLOptions()

setCURLOptions(array  $curl_options = array(), array  $config = array()) : array

Set CURL options

Parameters

array $curl_options
array $config

Throws

\InvalidArgumentException

Returns

array

sendRequest()

sendRequest(array  $curl_options = array()) : string

Does the actual work of initializing cURL, setting the options, and grabbing the output.

Parameters

array $curl_options

Returns

string