\Guzzle\Http\MessageResponse

Guzzle HTTP response object

Summary

Methods
Properties
Constants
__construct()
setHeaderFactory()
getParams()
addHeader()
addHeaders()
getHeader()
getHeaders()
getHeaderLines()
setHeader()
setHeaders()
hasHeader()
removeHeader()
getTokenizedHeader()
setTokenizedHeader()
getCacheControlDirective()
hasCacheControlDirective()
addCacheControlDirective()
removeCacheControlDirective()
fromMessage()
__toString()
serialize()
unserialize()
getBody()
setBody()
setProtocol()
getProtocol()
getProtocolVersion()
getInfo()
setInfo()
setStatus()
getStatusCode()
getMessage()
getRawHeaders()
getReasonPhrase()
getAcceptRanges()
calculateAge()
getAge()
getAllow()
isMethodAllowed()
getCacheControl()
getConnection()
getContentEncoding()
getContentLanguage()
getContentLength()
getContentLocation()
getContentDisposition()
getContentMd5()
getContentRange()
getContentType()
isContentType()
getDate()
getEtag()
getExpires()
getLastModified()
getLocation()
getPragma()
getProxyAuthenticate()
getRetryAfter()
getServer()
getSetCookie()
getTrailer()
getTransferEncoding()
getVary()
getVia()
getWarning()
getWwwAuthenticate()
isClientError()
isError()
isInformational()
isRedirect()
isServerError()
isSuccessful()
canCache()
getMaxAge()
isFresh()
canValidate()
getFreshness()
json()
xml()
getRedirectCount()
setEffectiveUrl()
getEffectiveUrl()
getPreviousResponse()
setRequest()
getRequest()
No public properties found
No constants found
No protected methods found
$headers
$headerFactory
$params
$protocol
$protocolVersion
$body
$reasonPhrase
$statusCode
$info
$effectiveUrl
$cacheResponseCodes
N/A
No private methods found
$statusTexts
N/A

Properties

$headers

$headers : array

Type

array — HTTP header collection

$params

$params : \Guzzle\Common\Collection

Type

\Guzzle\Common\Collection — Custom message parameters that are extendable by plugins

$protocol

$protocol : string

Type

string — Message protocol

$protocolVersion

$protocolVersion : string

Type

string — HTTP protocol version of the message

$reasonPhrase

$reasonPhrase : string

Type

string — The reason phrase of the response (human readable code)

$statusCode

$statusCode : string

Type

string — The status code of the response

$info

$info : array

Type

array — Information about the request

$effectiveUrl

$effectiveUrl : string

Type

string — The effective URL that returned this response

$cacheResponseCodes

$cacheResponseCodes : array

Type

array — Cacheable response codes (see RFC 2616:13.4)

$statusTexts

$statusTexts : array

Type

array — Array of reason phrases and their corresponding status codes

Methods

__construct()

__construct(string  $statusCode, \Guzzle\Common\ToArrayInterface|array  $headers = null, string|resource|\Guzzle\Http\EntityBodyInterface  $body = null) 

Construct the response

Parameters

string $statusCode

The response status code (e.g. 200, 404, etc)

\Guzzle\Common\ToArrayInterface|array $headers

The response headers

string|resource|\Guzzle\Http\EntityBodyInterface $body

The body of the response

Throws

\Guzzle\Http\Exception\BadResponseException

if an invalid response code is given

getParams()

getParams() : \Guzzle\Common\Collection

Get application and plugin specific parameters set on the message.

Returns

\Guzzle\Common\Collection

addHeader()

addHeader(string  $header, string  $value) : self

Add a header to an existing collection of headers.

Parameters

string $header

Header name to add

string $value

Value of the header

Returns

self

addHeaders()

addHeaders(array  $headers) : self

Add and merge in an array of HTTP headers.

Parameters

array $headers

Associative array of header data.

Returns

self

getHeader()

getHeader(string  $header) : \Guzzle\Http\Message\Header|null

Retrieve an HTTP header by name. Performs a case-insensitive search of all headers.

Parameters

string $header

Header to retrieve.

Returns

\Guzzle\Http\Message\Header|null

getHeaderLines()

getHeaderLines() : array

Get an array of message header lines (e.g. ["Host: example.com", .

..])

Returns

array

setHeader()

setHeader(string  $header, mixed  $value) : self

Set an HTTP header and overwrite any existing value for the header

Parameters

string $header

Name of the header to set.

mixed $value

Value to set.

Returns

self

setHeaders()

setHeaders(array  $headers) : self

Overwrite all HTTP headers with the supplied array of headers

Parameters

array $headers

Associative array of header data.

Returns

self

hasHeader()

hasHeader(string  $header) : boolean

Check if the specified header is present.

Parameters

string $header

The header to check.

Returns

boolean

removeHeader()

removeHeader(string  $header) : self

Remove a specific HTTP header.

Parameters

string $header

HTTP header to remove.

Returns

self

getTokenizedHeader()

getTokenizedHeader(  $header,   $token = ';') 

Parameters

$header
$token

setTokenizedHeader()

setTokenizedHeader(  $header,   $data,   $token = ';') 

Parameters

$header
$data
$token

getCacheControlDirective()

getCacheControlDirective(  $directive) 

Parameters

$directive

hasCacheControlDirective()

hasCacheControlDirective(  $directive) 

Parameters

$directive

addCacheControlDirective()

addCacheControlDirective(  $directive,   $value = true) 

Parameters

$directive
$value

removeCacheControlDirective()

removeCacheControlDirective(  $directive) 

Parameters

$directive

fromMessage()

fromMessage(string  $message) : self|boolean

Create a new Response based on a raw response message

Parameters

string $message

Response message

Returns

self|boolean —

Returns false on error

__toString()

__toString() : string

Returns

string

serialize()

serialize() 

unserialize()

unserialize(  $serialize) 

Parameters

$serialize

getBody()

getBody(boolean  $asString = false) : \Guzzle\Http\EntityBodyInterface|string

Get the response entity body

Parameters

boolean $asString

Set to TRUE to return a string of the body rather than a full body object

Returns

\Guzzle\Http\EntityBodyInterface|string

setBody()

setBody(\Guzzle\Http\EntityBodyInterface|string  $body) : self

Set the response entity body

Parameters

\Guzzle\Http\EntityBodyInterface|string $body

Body to set

Returns

self

setProtocol()

setProtocol(string  $protocol, string  $version) : self

Set the protocol and protocol version of the response

Parameters

string $protocol

Response protocol

string $version

Protocol version

Returns

self

getProtocol()

getProtocol() : string

Get the protocol used for the response (e.g. HTTP)

Returns

string

getProtocolVersion()

getProtocolVersion() : string

Get the HTTP protocol version

Returns

string

getInfo()

getInfo(string  $key = null) : array|string|null

Get a cURL transfer information

Parameters

string $key

A single statistic to check

Returns

array|string|null —

Returns all stats if no key is set, a single stat if a key is set, or null if a key is set and not found

setInfo()

setInfo(array  $info) : self

Set the transfer information

Parameters

array $info

Array of cURL transfer stats

Returns

self

setStatus()

setStatus(integer  $statusCode, string  $reasonPhrase = '') : self

Set the response status

Parameters

integer $statusCode

Response status code to set

string $reasonPhrase

Response reason phrase

Throws

\Guzzle\Http\Exception\BadResponseException

when an invalid response code is received

Returns

self

getStatusCode()

getStatusCode() : integer

Get the response status code

Returns

integer

getMessage()

getMessage() : string

Get the entire response as a string

Returns

string

getRawHeaders()

getRawHeaders() : string

Get the the raw message headers as a string

Returns

string

getReasonPhrase()

getReasonPhrase() : string

Get the response reason phrase- a human readable version of the numeric status code

Returns

string

getAcceptRanges()

getAcceptRanges() : string

Get the Accept-Ranges HTTP header

Returns

string —

Returns what partial content range types this server supports.

calculateAge()

calculateAge() : integer

Calculate the age of the response

Returns

integer

getAge()

getAge() : integer|null

Get the Age HTTP header

Returns

integer|null —

Returns the age the object has been in a proxy cache in seconds.

getAllow()

getAllow() : string|null

Get the Allow HTTP header

Returns

string|null —

Returns valid actions for a specified resource. To be used for a 405 Method not allowed.

isMethodAllowed()

isMethodAllowed(string  $method) : boolean

Check if an HTTP method is allowed by checking the Allow response header

Parameters

string $method

Method to check

Returns

boolean

getCacheControl()

getCacheControl() : string

Get the Cache-Control HTTP header

Returns

string

getConnection()

getConnection() : string

Get the Connection HTTP header

Returns

string

getContentEncoding()

getContentEncoding() : string|null

Get the Content-Encoding HTTP header

Returns

string|null

getContentLanguage()

getContentLanguage() : string|null

Get the Content-Language HTTP header

Returns

string|null —

Returns the language the content is in.

getContentLength()

getContentLength() : integer

Get the Content-Length HTTP header

Returns

integer —

Returns the length of the response body in bytes

getContentLocation()

getContentLocation() : string|null

Get the Content-Location HTTP header

Returns

string|null —

Returns an alternate location for the returned data (e.g /index.htm)

getContentDisposition()

getContentDisposition() : string|null

Get the Content-Disposition HTTP header

Returns

string|null —

Returns the Content-Disposition header

getContentMd5()

getContentMd5() : string|null

Get the Content-MD5 HTTP header

Returns

string|null —

Returns a Base64-encoded binary MD5 sum of the content of the response.

getContentRange()

getContentRange() : string

Get the Content-Range HTTP header

Returns

string —

Returns where in a full body message this partial message belongs (e.g. bytes 21010-47021/47022).

getContentType()

getContentType() : string

Get the Content-Type HTTP header

Returns

string —

Returns the mime type of this content.

isContentType()

isContentType(string  $type) : boolean

Checks if the Content-Type is of a certain type. This is useful if the Content-Type header contains charset information and you need to know if the Content-Type matches a particular type.

Parameters

string $type

Content type to check against

Returns

boolean

getDate()

getDate() : string|null

Get the Date HTTP header

Returns

string|null —

Returns the date and time that the message was sent.

getEtag()

getEtag() : string|null

Get the ETag HTTP header

Returns

string|null —

Returns an identifier for a specific version of a resource, often a Message digest.

getExpires()

getExpires() : string|null

Get the Expires HTTP header

Returns

string|null —

Returns the date/time after which the response is considered stale.

getLastModified()

getLastModified() : string|null

Get the Last-Modified HTTP header

Returns

string|null —

Returns the last modified date for the requested object, in RFC 2822 format (e.g. Tue, 15 Nov 1994 12:45:26 GMT)

getLocation()

getLocation() : string|null

Get the Location HTTP header

Returns

string|null —

Used in redirection, or when a new resource has been created.

getPragma()

getPragma() : \Guzzle\Http\Message\Header|null

Get the Pragma HTTP header

Returns

\Guzzle\Http\Message\Header|null —

Returns the implementation-specific headers that may have various effects anywhere along the request-response chain.

getProxyAuthenticate()

getProxyAuthenticate() : string|null

Get the Proxy-Authenticate HTTP header

Returns

string|null —

Authentication to access the proxy (e.g. Basic)

getRetryAfter()

getRetryAfter() : integer|null

Get the Retry-After HTTP header

Returns

integer|null —

If an entity is temporarily unavailable, this instructs the client to try again after a specified period of time.

getServer()

getServer() : string|null

Get the Server HTTP header

Returns

string|null —

A name for the server

getSetCookie()

getSetCookie() : string|null

Get the Set-Cookie HTTP header

Returns

string|null —

An HTTP cookie.

getTrailer()

getTrailer() : string|null

Get the Trailer HTTP header

Returns

string|null —

The Trailer general field value indicates that the given set of header fields is present in the trailer of a message encoded with chunked transfer-coding.

getTransferEncoding()

getTransferEncoding() : string|null

Get the Transfer-Encoding HTTP header

Returns

string|null —

The form of encoding used to safely transfer the entity to the user

getVary()

getVary() : string|null

Get the Vary HTTP header

Returns

string|null —

Tells downstream proxies how to match future request headers to decide whether the cached response can be used rather than requesting a fresh one from the origin server.

getVia()

getVia() : string|null

Get the Via HTTP header

Returns

string|null —

Informs the client of proxies through which the response was sent.

getWarning()

getWarning() : string|null

Get the Warning HTTP header

Returns

string|null —

A general warning about possible problems with the entity body

getWwwAuthenticate()

getWwwAuthenticate() : string|null

Get the WWW-Authenticate HTTP header

Returns

string|null —

Indicates the authentication scheme that should be used to access the requested entity

isClientError()

isClientError() : boolean

Checks if HTTP Status code is a Client Error (4xx)

Returns

boolean

isError()

isError() : boolean

Checks if HTTP Status code is Server OR Client Error (4xx or 5xx)

Returns

boolean

isInformational()

isInformational() : boolean

Checks if HTTP Status code is Information (1xx)

Returns

boolean

isRedirect()

isRedirect() : boolean

Checks if HTTP Status code is a Redirect (3xx)

Returns

boolean

isServerError()

isServerError() : boolean

Checks if HTTP Status code is Server Error (5xx)

Returns

boolean

isSuccessful()

isSuccessful() : boolean

Checks if HTTP Status code is Successful (2xx | 304)

Returns

boolean

canCache()

canCache() : boolean

Check if the response can be cached based on the response headers

Returns

boolean —

Returns TRUE if the response can be cached or false if not

getMaxAge()

getMaxAge() : integer|null

Gets the number of seconds from the current time in which this response is still considered fresh

Returns

integer|null —

Returns the number of seconds

isFresh()

isFresh() : boolean|null

Check if the response is considered fresh.

A response is considered fresh when its age is less than or equal to the freshness lifetime (maximum age) of the response.

Returns

boolean|null

canValidate()

canValidate() : boolean

Check if the response can be validated against the origin server using a conditional GET request.

Returns

boolean

getFreshness()

getFreshness() : integer

Get the freshness of the response by returning the difference of the maximum lifetime of the response and the age of the response (max-age - age).

Freshness values less than 0 mean that the response is no longer fresh and is ABS(freshness) seconds expired. Freshness values of greater than zero is the number of seconds until the response is no longer fresh. A NULL result means that no freshness information is available.

Returns

integer

json()

json() : array|string|integer|boolean|float

Parse the JSON response body and return an array

Throws

\Guzzle\Common\Exception\RuntimeException

if the response body is not in JSON format

Returns

array|string|integer|boolean|float

xml()

xml() : \SimpleXMLElement

Parse the XML response body and return a \SimpleXMLElement.

In order to prevent XXE attacks, this method disables loading external entities. If you rely on external entities, then you must parse the XML response manually by accessing the response body directly.

Throws

\Guzzle\Common\Exception\RuntimeException

if the response body is not in XML format

Returns

\SimpleXMLElement

getRedirectCount()

getRedirectCount() : integer

Get the redirect count of this response

Returns

integer

setEffectiveUrl()

setEffectiveUrl(string  $url) : self

Set the effective URL that resulted in this response (e.g. the last redirect URL)

Parameters

string $url

The effective URL

Returns

self

getEffectiveUrl()

getEffectiveUrl() : string

Get the effective URL that resulted in this response (e.g. the last redirect URL)

Returns

string

getPreviousResponse()

getPreviousResponse() 

setRequest()

setRequest(  $request) 

Parameters

$request

getRequest()

getRequest()