Class Response
Guzzle HTTP response object
- Guzzle\Http\Message\AbstractMessage implements Guzzle\Http\Message\MessageInterface
- Guzzle\Http\Message\Response implements Serializable
Methods summary
-
public static
fromMessage ( string $message )
Create a new Response based on a raw response message
-
public
__construct ( string $statusCode, ToArrayInterface|array $headers = null, string|resource|EntityBodyInterface $body = null )
Construct the response
-
public
__toString ( )
-
public
serialize ( )
-
public
unserialize ( mixed $serialize )
-
public
getBody ( bool $asString = false )
Get the response entity body
-
public
setBody ( EntityBodyInterface|string $body )
Set the response entity body
-
public
setProtocol ( string $protocol, string $version )
Set the protocol and protocol version of the response
-
public
getProtocol ( )
Get the protocol used for the response (e.g. HTTP)
-
public
getProtocolVersion ( )
Get the HTTP protocol version
-
public
getInfo ( string $key = null )
Get a cURL transfer information
-
public
setInfo ( array $info )
Set the transfer information
-
public
setStatus ( int $statusCode, string $reasonPhrase = '' )
Set the response status
-
public
getStatusCode ( )
Get the response status code
-
public
getMessage ( )
Get the entire response as a string
-
public
getRawHeaders ( )
Get the the raw message headers as a string
-
public
getReasonPhrase ( )
Get the response reason phrase- a human readable version of the numeric status code
-
public
getAcceptRanges ( )
Get the Accept-Ranges HTTP header
-
public
calculateAge ( )
Calculate the age of the response
-
public
getAge ( )
Get the Age HTTP header
-
public
getAllow ( )
Get the Allow HTTP header
-
public
isMethodAllowed ( string $method )
Check if an HTTP method is allowed by checking the Allow response header
-
public
getCacheControl ( )
Get the Cache-Control HTTP header
-
public
getConnection ( )
Get the Connection HTTP header
-
public
getContentEncoding ( )
Get the Content-Encoding HTTP header
-
public
getContentLanguage ( )
Get the Content-Language HTTP header
-
public
getContentLength ( )
Get the Content-Length HTTP header
-
public
getContentLocation ( )
Get the Content-Location HTTP header
-
public
getContentDisposition ( )
Get the Content-Disposition HTTP header
-
public
getContentMd5 ( )
Get the Content-MD5 HTTP header
-
public
getContentRange ( )
Get the Content-Range HTTP header
-
public
getContentType ( )
Get the Content-Type HTTP header
-
public
isContentType ( string $type )
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
getDate ( )
Get the Date HTTP header
-
public
getEtag ( )
Get the ETag HTTP header
-
public
getExpires ( )
Get the Expires HTTP header
-
public
getLastModified ( )
Get the Last-Modified HTTP header
-
public
getLocation ( )
Get the Location HTTP header
-
public
getPragma ( )
Get the Pragma HTTP header
-
public
getProxyAuthenticate ( )
Get the Proxy-Authenticate HTTP header
-
public
getRetryAfter ( )
Get the Retry-After HTTP header
-
public
getServer ( )
Get the Server HTTP header
-
public
getSetCookie ( )
Get the Set-Cookie HTTP header
-
public
getTrailer ( )
Get the Trailer HTTP header
-
public
getTransferEncoding ( )
Get the Transfer-Encoding HTTP header
-
public
getVary ( )
Get the Vary HTTP header
-
public
getVia ( )
Get the Via HTTP header
-
public
getWarning ( )
Get the Warning HTTP header
-
public
getWwwAuthenticate ( )
Get the WWW-Authenticate HTTP header
-
public
isClientError ( )
Checks if HTTP Status code is a Client Error (4xx)
-
public
isError ( )
Checks if HTTP Status code is Server OR Client Error (4xx or 5xx)
-
public
isInformational ( )
Checks if HTTP Status code is Information (1xx)
-
public
isRedirect ( )
Checks if HTTP Status code is a Redirect (3xx)
-
public
isServerError ( )
Checks if HTTP Status code is Server Error (5xx)
-
public
isSuccessful ( )
Checks if HTTP Status code is Successful (2xx | 304)
-
public
canCache ( )
Check if the response can be cached based on the response headers
-
public
getMaxAge ( )
Gets the number of seconds from the current time in which this response is still considered fresh
-
public
isFresh ( )
Check if the response is considered fresh.
-
public
canValidate ( )
Check if the response can be validated against the origin server using a conditional GET request.
-
public
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).
-
public
json ( )
Parse the JSON response body and return an array
-
public
xml ( )
Parse the XML response body and return a \SimpleXMLElement.
-
public
getRedirectCount ( )
Get the redirect count of this response
-
public
setEffectiveUrl ( string $url )
Set the effective URL that resulted in this response (e.g. the last redirect URL)
-
public
getEffectiveUrl ( )
Get the effective URL that resulted in this response (e.g. the last redirect URL)
Methods detail
Create a new Response based on a raw response message
Parameters
- $message
string
$message Response message
Returns
public
__construct( string $statusCode, Guzzle\Common\ToArrayInterface
|array $headers = null, string|resource|Guzzle\Http\EntityBodyInterface
$body = null )
Construct the response
Parameters
- $statusCode
string
$statusCode The response status code (e.g. 200, 404, etc)- $headers
Guzzle\Common\ToArrayInterface
|array
$headers The response headers- $body
string|resource|
Guzzle\Http\EntityBodyInterface
$body The body of the response
Throws
Overrides
Returns
string
Implementation of
Implementation of
Get the response entity body
Parameters
- $asString
boolean
$asString Set to TRUE to return a string of the body rather than a full body object
Returns
Set the response entity body
Parameters
- $body
Guzzle\Http\EntityBodyInterface
|string
$body Body to set
Returns
Set the protocol and protocol version of the response
Parameters
- $protocol
string
$protocol Response protocol- $version
string
$version Protocol version
Returns
Get the protocol used for the response (e.g. HTTP)
Returns
string
Get the HTTP protocol version
Returns
string
Get a cURL transfer information
Parameters
- $key
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
Link
Set the transfer information
Parameters
- $info
array
$info Array of cURL transfer stats
Returns
Set the response status
Parameters
- $statusCode
integer
$statusCode Response status code to set- $reasonPhrase
string
$reasonPhrase Response reason phrase
Returns
Throws
Get the response status code
Returns
integer
Get the entire response as a string
Returns
string
Get the the raw message headers as a string
Returns
string
Get the response reason phrase- a human readable version of the numeric status code
Returns
string
Get the Accept-Ranges HTTP header
Returns
string
Returns what partial content range types this server supports.
Calculate the age of the response
Returns
integer
Get the Age HTTP header
Returns
integer|null
Returns the age the object has been in a proxy cache in seconds.
Get the Allow HTTP header
Returns
string|null
Returns valid actions for a specified resource. To be used for a 405 Method not allowed.
Check if an HTTP method is allowed by checking the Allow response header
Parameters
- $method
string
$method Method to check
Returns
boolean
Get the Cache-Control HTTP header
Returns
string
Get the Connection HTTP header
Returns
string
Get the Content-Encoding HTTP header
Returns
string|null
Get the Content-Language HTTP header
Returns
string|null
Returns the language the content is in.
Get the Content-Length HTTP header
Returns
integer
Returns the length of the response body in bytes
Get the Content-Location HTTP header
Returns
string|null
Returns an alternate location for the returned data (e.g /index.htm)
Get the Content-Disposition HTTP header
Returns
string|null
Returns the Content-Disposition header
Get the Content-MD5 HTTP header
Returns
string|null
Returns a Base64-encoded binary MD5 sum of the content of the response.
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).
Get the Content-Type HTTP header
Returns
string
Returns the mime type of this content.
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
- $type
string
$type Content type to check against
Returns
boolean
Get the Date HTTP header
Returns
string|null
Returns the date and time that the message was sent.
Get the ETag HTTP header
Returns
string|null
Returns an identifier for a specific version of a resource, often a Message digest.
Get the Expires HTTP header
Returns
string|null
Returns the date/time after which the response is considered stale.
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)
Get the Location HTTP header
Returns
string|null
Used in redirection, or when a new resource has been created.
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.
Get the Proxy-Authenticate HTTP header
Returns
string|null
Authentication to access the proxy (e.g. Basic)
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.
Get the Server HTTP header
Returns
string|null
A name for the server
Get the Set-Cookie HTTP header
Returns
string|null
An HTTP cookie.
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.
Get the Transfer-Encoding HTTP header
Returns
string|null
The form of encoding used to safely transfer the entity to the user
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.
Get the Via HTTP header
Returns
string|null
Informs the client of proxies through which the response was sent.
Get the Warning HTTP header
Returns
string|null
A general warning about possible problems with the entity body
Get the WWW-Authenticate HTTP header
Returns
string|null
Indicates the authentication scheme that should be used to access the requested entity
Checks if HTTP Status code is a Client Error (4xx)
Returns
boolean
Checks if HTTP Status code is Server OR Client Error (4xx or 5xx)
Returns
boolean
Checks if HTTP Status code is Information (1xx)
Returns
boolean
Checks if HTTP Status code is a Redirect (3xx)
Returns
boolean
Checks if HTTP Status code is Server Error (5xx)
Returns
boolean
Checks if HTTP Status code is Successful (2xx | 304)
Returns
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
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
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
Check if the response can be validated against the origin server using a conditional GET request.
Returns
boolean
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
Parse the JSON response body and return an array
Returns
array|string|integer|boolean|float
Throws
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.
Returns
Throws
Link
Get the redirect count of this response
Returns
integer
Set the effective URL that resulted in this response (e.g. the last redirect URL)
Parameters
- $url
string
$url The effective URL
Returns
Get the effective URL that resulted in this response (e.g. the last redirect URL)
Returns
string
Methods inherited from Guzzle\Http\Message\AbstractMessage
addHeader()
,
addHeaders()
,
getHeader()
,
getHeaderLines()
,
getHeaders()
,
getParams()
,
hasHeader()
,
removeHeader()
,
setHeader()
,
setHeaderFactory()
,
setHeaders()
Magic methods summary
Properties summary
protected
|
$body |
#
The response body |
protected
string
|
$reasonPhrase |
#
The reason phrase of the response (human readable code) |
protected
string
|
$statusCode |
#
The status code of the response |
protected
array
|
$info |
#
Information about the request |
protected
string
|
$effectiveUrl |
#
The effective URL that returned this response |
protected static
array
|
$cacheResponseCodes |
#
Cacheable response codes (see RFC 2616:13.4) |
Properties inherited from Guzzle\Http\Message\AbstractMessage
$headerFactory
,
$headers
,
$params
,
$protocol
,
$protocolVersion