Class Guzzle\Http\Message\Response

InheritanceGuzzle\Http\Message\Response » Guzzle\Http\Message\AbstractMessage
ImplementsGuzzle\Http\Message\MessageInterface, Serializable

Guzzle HTTP response object

Protected Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$body Guzzle\Http\EntityBodyInterface The response body Guzzle\Http\Message\Response
$cacheResponseCodes array Cacheable response codes (see RFC 2616:13. Guzzle\Http\Message\Response
$effectiveUrl string The effective URL that returned this response Guzzle\Http\Message\Response
$headerFactory Guzzle\Http\Message\Header\HeaderFactoryInterface Guzzle\Http\Message\AbstractMessage
$headers array HTTP header collection Guzzle\Http\Message\AbstractMessage
$info array Information about the request Guzzle\Http\Message\Response
$params Guzzle\Common\Collection Custom message parameters that are extendable by plugins Guzzle\Http\Message\AbstractMessage
$protocol string Message protocol Guzzle\Http\Message\AbstractMessage
$protocolVersion string HTTP protocol version of the message Guzzle\Http\Message\AbstractMessage
$reasonPhrase string The reason phrase of the response (human readable code) Guzzle\Http\Message\Response
$statusCode string The status code of the response Guzzle\Http\Message\Response

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__construct() Construct the response Guzzle\Http\Message\Response
__toString() Guzzle\Http\Message\Response
addCacheControlDirective() Guzzle\Http\Message\AbstractMessage
addHeader() Guzzle\Http\Message\AbstractMessage
addHeaders() Guzzle\Http\Message\AbstractMessage
calculateAge() Calculate the age of the response Guzzle\Http\Message\Response
canCache() Check if the response can be cached based on the response headers Guzzle\Http\Message\Response
canValidate() Check if the response can be validated against the origin server using a conditional GET request. Guzzle\Http\Message\Response
fromMessage() Create a new Response based on a raw response message Guzzle\Http\Message\Response
getAcceptRanges() Get the Accept-Ranges HTTP header Guzzle\Http\Message\Response
getAge() Get the Age HTTP header Guzzle\Http\Message\Response
getAllow() Get the Allow HTTP header Guzzle\Http\Message\Response
getBody() Get the response entity body Guzzle\Http\Message\Response
getCacheControl() Get the Cache-Control HTTP header Guzzle\Http\Message\Response
getCacheControlDirective() Guzzle\Http\Message\AbstractMessage
getConnection() Get the Connection HTTP header Guzzle\Http\Message\Response
getContentDisposition() Get the Content-Disposition HTTP header Guzzle\Http\Message\Response
getContentEncoding() Get the Content-Encoding HTTP header Guzzle\Http\Message\Response
getContentLanguage() Get the Content-Language HTTP header Guzzle\Http\Message\Response
getContentLength() Get the Content-Length HTTP header Guzzle\Http\Message\Response
getContentLocation() Get the Content-Location HTTP header Guzzle\Http\Message\Response
getContentMd5() Get the Content-MD5 HTTP header Guzzle\Http\Message\Response
getContentRange() Get the Content-Range HTTP header Guzzle\Http\Message\Response
getContentType() Get the Content-Type HTTP header Guzzle\Http\Message\Response
getDate() Get the Date HTTP header Guzzle\Http\Message\Response
getEffectiveUrl() Get the effective URL that resulted in this response (e.g. the last redirect URL) Guzzle\Http\Message\Response
getEtag() Get the ETag HTTP header Guzzle\Http\Message\Response
getExpires() Get the Expires HTTP header Guzzle\Http\Message\Response
getFreshness() 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). Guzzle\Http\Message\Response
getHeader() Guzzle\Http\Message\AbstractMessage
getHeaderLines() Guzzle\Http\Message\AbstractMessage
getHeaders() Guzzle\Http\Message\AbstractMessage
getInfo() Get a cURL transfer information Guzzle\Http\Message\Response
getLastModified() Get the Last-Modified HTTP header Guzzle\Http\Message\Response
getLocation() Get the Location HTTP header Guzzle\Http\Message\Response
getMaxAge() Gets the number of seconds from the current time in which this response is still considered fresh Guzzle\Http\Message\Response
getMessage() Get the entire response as a string Guzzle\Http\Message\Response
getParams() Guzzle\Http\Message\AbstractMessage
getPragma() Get the Pragma HTTP header Guzzle\Http\Message\Response
getPreviousResponse() Guzzle\Http\Message\Response
getProtocol() Get the protocol used for the response (e.g. HTTP) Guzzle\Http\Message\Response
getProtocolVersion() Get the HTTP protocol version Guzzle\Http\Message\Response
getProxyAuthenticate() Get the Proxy-Authenticate HTTP header Guzzle\Http\Message\Response
getRawHeaders() Get the the raw message headers as a string Guzzle\Http\Message\Response
getReasonPhrase() Get the response reason phrase- a human readable version of the numeric status code Guzzle\Http\Message\Response
getRedirectCount() Get the redirect count of this response Guzzle\Http\Message\Response
getRequest() Guzzle\Http\Message\Response
getRetryAfter() Get the Retry-After HTTP header Guzzle\Http\Message\Response
getServer() Get the Server HTTP header Guzzle\Http\Message\Response
getSetCookie() Get the Set-Cookie HTTP header Guzzle\Http\Message\Response
getStatusCode() Get the response status code Guzzle\Http\Message\Response
getTokenizedHeader() Guzzle\Http\Message\AbstractMessage
getTrailer() Get the Trailer HTTP header Guzzle\Http\Message\Response
getTransferEncoding() Get the Transfer-Encoding HTTP header Guzzle\Http\Message\Response
getVary() Get the Vary HTTP header Guzzle\Http\Message\Response
getVia() Get the Via HTTP header Guzzle\Http\Message\Response
getWarning() Get the Warning HTTP header Guzzle\Http\Message\Response
getWwwAuthenticate() Get the WWW-Authenticate HTTP header Guzzle\Http\Message\Response
hasCacheControlDirective() Guzzle\Http\Message\AbstractMessage
hasHeader() Guzzle\Http\Message\AbstractMessage
isClientError() Checks if HTTP Status code is a Client Error (4xx) Guzzle\Http\Message\Response
isContentType() 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. Guzzle\Http\Message\Response
isError() Checks if HTTP Status code is Server OR Client Error (4xx or 5xx) Guzzle\Http\Message\Response
isFresh() Check if the response is considered fresh. Guzzle\Http\Message\Response
isInformational() Checks if HTTP Status code is Information (1xx) Guzzle\Http\Message\Response
isMethodAllowed() Check if an HTTP method is allowed by checking the Allow response header Guzzle\Http\Message\Response
isRedirect() Checks if HTTP Status code is a Redirect (3xx) Guzzle\Http\Message\Response
isServerError() Checks if HTTP Status code is Server Error (5xx) Guzzle\Http\Message\Response
isSuccessful() Checks if HTTP Status code is Successful (2xx | 304) Guzzle\Http\Message\Response
json() Parse the JSON response body and return an array Guzzle\Http\Message\Response
removeCacheControlDirective() Guzzle\Http\Message\AbstractMessage
removeHeader() Guzzle\Http\Message\AbstractMessage
serialize() Guzzle\Http\Message\Response
setBody() Set the response entity body Guzzle\Http\Message\Response
setEffectiveUrl() Set the effective URL that resulted in this response (e.g. the last redirect URL) Guzzle\Http\Message\Response
setHeader() Guzzle\Http\Message\AbstractMessage
setHeaderFactory() Set the header factory to use to create headers Guzzle\Http\Message\AbstractMessage
setHeaders() Guzzle\Http\Message\AbstractMessage
setInfo() Set the transfer information Guzzle\Http\Message\Response
setProtocol() Set the protocol and protocol version of the response Guzzle\Http\Message\Response
setRequest() Guzzle\Http\Message\Response
setStatus() Set the response status Guzzle\Http\Message\Response
setTokenizedHeader() Guzzle\Http\Message\AbstractMessage
unserialize() Guzzle\Http\Message\Response
xml() Parse the XML response body and return a \SimpleXMLElement. Guzzle\Http\Message\Response

Property Details

$body protected property

The response body

$cacheResponseCodes protected static property

Cacheable response codes (see RFC 2616:13.4)

protected static array $cacheResponseCodes = [200203206300301410]
$effectiveUrl protected property

The effective URL that returned this response

protected string $effectiveUrl null
$info protected property

Information about the request

protected array $info = []
$reasonPhrase protected property

The reason phrase of the response (human readable code)

protected string $reasonPhrase null
$statusCode protected property

The status code of the response

protected string $statusCode null

Method Details

__construct() public method

Construct the response

public void __construct ( $statusCode, $headers null, $body null )
$statusCode string

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

$headers Guzzle\Common\ToArrayInterface|array

The response headers

$body string|resource|Guzzle\Http\EntityBodyInterface

The body of the response

throws Guzzle\Http\Exception\BadResponseException

if an invalid response code is given

__toString() public method

public string __toString ( )
calculateAge() public method

Calculate the age of the response

public integer calculateAge ( )
canCache() public method

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

public bool canCache ( )
return bool

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

canValidate() public method

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

public bool canValidate ( )
fromMessage() public static method

Create a new Response based on a raw response message

public static self|bool fromMessage ( $message )
$message string

Response message

return self|bool

Returns false on error

getAcceptRanges() public method

Get the Accept-Ranges HTTP header

public string getAcceptRanges ( )
return string

Returns what partial content range types this server supports.

getAge() public method

Get the Age HTTP header

public integer|null getAge ( )
return integer|null

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

getAllow() public method

Get the Allow HTTP header

public string|null getAllow ( )
return string|null

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

getBody() public method

Get the response entity body

public Guzzle\Http\EntityBodyInterface|string getBody ( $asString false )
$asString bool

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

getCacheControl() public method

Get the Cache-Control HTTP header

public string getCacheControl ( )
getConnection() public method

Get the Connection HTTP header

public string getConnection ( )
getContentDisposition() public method

Get the Content-Disposition HTTP header

public string|null getContentDisposition ( )
return string|null

Returns the Content-Disposition header

getContentEncoding() public method

Get the Content-Encoding HTTP header

public string|null getContentEncoding ( )
getContentLanguage() public method

Get the Content-Language HTTP header

public string|null getContentLanguage ( )
return string|null

Returns the language the content is in.

getContentLength() public method

Get the Content-Length HTTP header

public integer getContentLength ( )
return integer

Returns the length of the response body in bytes

getContentLocation() public method

Get the Content-Location HTTP header

public string|null getContentLocation ( )
return string|null

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

getContentMd5() public method

Get the Content-MD5 HTTP header

public string|null getContentMd5 ( )
return string|null

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

getContentRange() public method

Get the Content-Range HTTP header

public string getContentRange ( )
return string

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

getContentType() public method

Get the Content-Type HTTP header

public string getContentType ( )
return string

Returns the mime type of this content.

getDate() public method

Get the Date HTTP header

public string|null getDate ( )
return string|null

Returns the date and time that the message was sent.

getEffectiveUrl() public method

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

public string getEffectiveUrl ( )
getEtag() public method

Get the ETag HTTP header

public string|null getEtag ( )
return string|null

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

getExpires() public method

Get the Expires HTTP header

public string|null getExpires ( )
return string|null

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

getFreshness() public method

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.

public int getFreshness ( )
getInfo() public method

Get a cURL transfer information

public array|string|null getInfo ( $key null )
$key string

A single statistic to check

return 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
getLastModified() public method

Get the Last-Modified HTTP header

public string|null getLastModified ( )
return 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() public method

Get the Location HTTP header

public string|null getLocation ( )
return string|null

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

getMaxAge() public method

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

public int|null getMaxAge ( )
return int|null

Returns the number of seconds

getMessage() public method

Get the entire response as a string

public string getMessage ( )
getPragma() public method

Get the Pragma HTTP header

public Guzzle\Http\Message\Header|null getPragma ( )
return Guzzle\Http\Message\Header|null

Returns the implementation-specific headers that may have various effects anywhere along

                the request-response chain.
getPreviousResponse() public method

public void getPreviousResponse ( )
getProtocol() public method

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

public string getProtocol ( )
getProtocolVersion() public method

Get the HTTP protocol version

public string getProtocolVersion ( )
getProxyAuthenticate() public method

Get the Proxy-Authenticate HTTP header

public string|null getProxyAuthenticate ( )
return string|null

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

getRawHeaders() public method

Get the the raw message headers as a string

public string getRawHeaders ( )
getReasonPhrase() public method

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

public string getReasonPhrase ( )
getRedirectCount() public method

Get the redirect count of this response

public int getRedirectCount ( )
getRequest() public method

public void getRequest ( )
getRetryAfter() public method

Get the Retry-After HTTP header

public int|null getRetryAfter ( )
return int|null

If an entity is temporarily unavailable, this instructs the client to try again after a

             specified period of time.
getServer() public method

Get the Server HTTP header

public string|null getServer ( )
return string|null

A name for the server

getSetCookie() public method

Get the Set-Cookie HTTP header

public string|null getSetCookie ( )
return string|null

An HTTP cookie.

getStatusCode() public method

Get the response status code

public integer getStatusCode ( )
getTrailer() public method

Get the Trailer HTTP header

public string|null getTrailer ( )
return 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() public method

Get the Transfer-Encoding HTTP header

public string|null getTransferEncoding ( )
return string|null

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

getVary() public method

Get the Vary HTTP header

public string|null getVary ( )
return 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() public method

Get the Via HTTP header

public string|null getVia ( )
return string|null

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

getWarning() public method

Get the Warning HTTP header

public string|null getWarning ( )
return string|null

A general warning about possible problems with the entity body

getWwwAuthenticate() public method

Get the WWW-Authenticate HTTP header

public string|null getWwwAuthenticate ( )
return string|null

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

isClientError() public method

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

public bool isClientError ( )
isContentType() public method

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.

public bool isContentType ( $type )
$type string

Content type to check against

isError() public method

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

public boolean isError ( )
isFresh() public method

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.

public bool|null isFresh ( )
isInformational() public method

Checks if HTTP Status code is Information (1xx)

public bool isInformational ( )
isMethodAllowed() public method

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

public bool isMethodAllowed ( $method )
$method string

Method to check

isRedirect() public method

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

public bool isRedirect ( )
isServerError() public method

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

public bool isServerError ( )
isSuccessful() public method

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

public bool isSuccessful ( )
json() public method

Parse the JSON response body and return an array

public array|string|int|bool|float json ( )
throws Guzzle\Common\Exception\RuntimeException

if the response body is not in JSON format

serialize() public method

public void serialize ( )
setBody() public method

Set the response entity body

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

Body to set

setEffectiveUrl() public method

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

public self setEffectiveUrl ( $url )
$url string

The effective URL

setInfo() public method

Set the transfer information

public self setInfo ( array $info )
$info array

Array of cURL transfer stats

setProtocol() public method

Set the protocol and protocol version of the response

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

Response protocol

$version string

Protocol version

setRequest() public method

public void setRequest ( $request )
$request
setStatus() public method

Set the response status

public self setStatus ( $statusCode, $reasonPhrase '' )
$statusCode int

Response status code to set

$reasonPhrase string

Response reason phrase

throws Guzzle\Http\Exception\BadResponseException

when an invalid response code is received

unserialize() public method

public void unserialize ( $serialize )
$serialize
xml() public method

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.

public SimpleXMLElement xml ( )
throws Guzzle\Common\Exception\RuntimeException

if the response body is not in XML format