API Documentation

Zend/Http/Response.php

Show: inherited
Table of Contents

Zend Framework

LICENSE

This source file is subject to the new BSD license that is bundled with this package in the file LICENSE.txt. It is also available through the world-wide-web at this URL: http://framework.zend.com/license/new-bsd If you did not receive a copy of the license and are unable to obtain it through the world-wide-web, please send an email to license@zend.com so we can send you a copy immediately.

Category
Zend  
Copyright
Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)  
License
New BSD License  
Package
Zend_Http  
Subpackage
Response  
Version
$Id: Response.php 24593 2012-01-05 20:35:02Z matthew $  

\Zend_Http_Response

Package: Zend\Http\Response

Zend_Http_Response represents an HTTP 1.0 / 1.1 response message. It includes easy access to all the response's different elemts, as well as some convenience methods for parsing and validating HTTP responses.

Children
\Zend_Http_Response_Stream
Copyright
Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)  
License
New BSD License  

Properties

Propertyprotectedstring  $body= ''

The HTTP response body

Details
Type
string
Propertyprotectedint  $code= ''

The HTTP response code

Details
Type
int
Propertyprotectedarray  $headers= 'array()'

The HTTP response headers array

Default valuearray()Details
Type
array
Propertyprotectedstring  $message= ''

The HTTP response code as string (e.g. 'Not Found' for 404 or 'Internal Server Error' for 500)

Details
Type
string
Propertyprotectedarray  $messages= 'array( // Informational 1xx 100 => 'Continue''
static

List of all known HTTP response codes - used by responseCodeAsText() to translate numeric codes to messages.

Default valuearray( // Informational 1xx 100 => 'Continue'Details
Type
array
Propertyprotectedstring  $version= ''

The HTTP version (1.0, 1.1)

Details
Type
string

Methods

methodpublic__construct( int $code, array $headers, string $body = null, string $version = '1.1', string $message = null ) : void

HTTP response constructor

In most cases, you would use Zend_Http_Response::fromString to parse an HTTP response string and create a new Zend_Http_Response object.

NOTE: The constructor no longer accepts nulls or empty values for the code and headers and will throw an exception if the passed values do not form a valid HTTP responses.

If no message is passed, the message will be guessed according to the response code.

Parameters
Name Type Description
$code int

Response code (200, 404, ...)

$headers array

Headers array

$body string

Response body

$version string

HTTP version

$message string

Response code as text

Throws
Exception Description
\Zend_Http_Exception
methodpublic__toString( ) : string

Implements magic __toString()

Returns
Type Description
string
methodpublicasString( string $br = "\n" ) : string

Get the entire response as string

Parameters
Name Type Description
$br string

Line breaks (eg. "\n", "\r\n", "
")

Returns
Type Description
string
methodpublicdecodeChunkedBody( string $body ) : string
static

Decode a "chunked" transfer-encoded body and return the decoded text

Parameters
Name Type Description
$body string
Returns
Type Description
string
methodpublicdecodeDeflate( string $body ) : string
static

Decode a zlib deflated message (when Content-encoding = deflate)

Currently requires PHP with zlib support

Parameters
Name Type Description
$body string
Returns
Type Description
string
methodpublicdecodeGzip( string $body ) : string
static

Decode a gzip encoded message (when Content-encoding = gzip)

Currently requires PHP with zlib support

Parameters
Name Type Description
$body string
Returns
Type Description
string
methodpublicextractBody( string $response_str ) : string
static

Extract the body from a response string

Parameters
Name Type Description
$response_str string
Returns
Type Description
string
methodpublicextractCode( string $response_str ) : int
static

Extract the response code from a response string

Parameters
Name Type Description
$response_str string
Returns
Type Description
int
methodpublicextractHeaders( string $response_str ) : array
static

Extract the headers from a response string

Parameters
Name Type Description
$response_str string
Returns
Type Description
array
methodpublicextractMessage( string $response_str ) : string
static

Extract the HTTP message from a response

Parameters
Name Type Description
$response_str string
Returns
Type Description
string
methodpublicextractVersion( string $response_str ) : string
static

Extract the HTTP version from a response

Parameters
Name Type Description
$response_str string
Returns
Type Description
string
methodpublicfromString( string $response_str ) : \Zend_Http_Response
static

Create a new Zend_Http_Response object from a string

Parameters
Name Type Description
$response_str string
Returns
Type Description
\Zend_Http_Response
methodpublicgetBody( ) : string

Get the response body as string

This method returns the body of the HTTP response (the content), as it should be in it's readable version - that is, after decoding it (if it was decoded), deflating it (if it was gzip compressed), etc.

If you want to get the raw body (as transfered on wire) use $this->getRawBody() instead.

Returns
Type Description
string
methodpublicgetHeader(  $header ) : string|array|null

Get a specific header as string, or null if it is not set

Parameters
Name Type Description
$header

string$header

Returns
Type Description
string|array|null
methodpublicgetHeaders( ) : array

Get the response headers

Returns
Type Description
array
methodpublicgetHeadersAsString( boolean $status_line = true, string $br = "\n" ) : string

Get all headers as string

Parameters
Name Type Description
$status_line boolean

Whether to return the first status line (IE "HTTP 200 OK")

$br string

Line breaks (eg. "\n", "\r\n", "
")

Returns
Type Description
string
methodpublicgetMessage( ) : string

Return a message describing the HTTP response code (Eg. "OK", "Not Found", "Moved Permanently")

Returns
Type Description
string
methodpublicgetRawBody( ) : string

Get the raw response body (as transfered "on wire") as string

If the body is encoded (with Transfer-Encoding, not content-encoding - IE "chunked" body), gzip compressed, etc. it will not be decoded.

Returns
Type Description
string
methodpublicgetStatus( ) : int

Get the HTTP response status code

Returns
Type Description
int
methodpublicgetVersion( ) : string

Get the HTTP version of the response

Returns
Type Description
string
methodpublicisError( ) : boolean

Check whether the response is an error

Returns
Type Description
boolean
methodpublicisRedirect( ) : boolean

Check whether the response is a redirection

Returns
Type Description
boolean
methodpublicisSuccessful( ) : boolean

Check whether the response in successful

Returns
Type Description
boolean
methodpublicresponseCodeAsText( int $code = null, boolean $http11 = true ) : string
static

A convenience function that returns a text representation of HTTP response codes. Returns 'Unknown' for unknown codes.

Returns array of all codes, if $code is not specified.

Conforms to HTTP/1.1 as defined in RFC 2616 (except for 'Unknown') See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10 for reference

Parameters
Name Type Description
$code int

HTTP response code

$http11 boolean

Use HTTP version 1.1

Returns
Type Description
string
Documentation was generated by DocBlox 0.15.1.