API Documentation

Http/Response.php

Classes 
category
Zend
copyright
Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
license
http://framework.zend.com/license/new-bsd New BSD License
package
Zend_Http
subpackage
Response
version
$Id: Response.php 22811 2010-08-08 10:33:21Z shahar $
Classes
Zend_Http_Response

Description

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.

Zend_Http_Response

copyright
Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
license
http://framework.zend.com/license/new-bsd New BSD License
package
Zend_Http
subpackage
Response
Properties
$messages
$version
$code
$message
$headers
$body
Methods
__construct
isError
isSuccessful
isRedirect
getBody
getRawBody
getVersion
getStatus
getMessage
getHeaders
getHeader
getHeadersAsString
asString
__toString
responseCodeAsText
extractCode
extractMessage
extractVersion
extractHeaders
extractBody
decodeChunkedBody
decodeGzip
decodeDeflate
fromString

Description

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.

Properties

$body

string $body = ''

The HTTP response body

Details

$body
string
visibility
protected
default
final
false
static
false

$code

int $code = ''

The HTTP response code

Details

$code
int
visibility
protected
default
final
false
static
false

$headers

array $headers = 'array'

The HTTP response headers array

Details

$headers
array
visibility
protected
default
array
final
false
static
false

$message

string $message = ''

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

Details

$message
string
visibility
protected
default
final
false
static
false

$messages

array $messages = 'array'

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

Details

$messages
array
visibility
protected
default
array
final
false
static
true

$version

string $version = ''

The HTTP version (1.0, 1.1)

Details

$version
string
visibility
protected
default
final
false
static
false

Methods

__construct

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

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.

Arguments
$code
int
Response code (200, 404, ...)
$headers
array
Headers array
$body
string
Response body
$version
string
HTTP version
$message
string
Response code as text
Details
visibility
public
final
false
static
false
throws

__toString

__toString( ) : string

Implements magic __toString()

Output
string
Details
visibility
public
final
false
static
false

asString

asString( string $br = \n ) : string

Get the entire response as string

Arguments
$br
string
Line breaks (eg. "\n", "\r\n", "<br />")
Output
string
Details
visibility
public
final
false
static
false

decodeChunkedBody

decodeChunkedBody( string $body ) : string

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

Arguments
$body
string
Output
string
Details
visibility
public
final
false
static
true

decodeDeflate

decodeDeflate( string $body ) : string

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

Currently requires PHP with zlib support

Arguments
$body
string
Output
string
Details
visibility
public
final
false
static
true

decodeGzip

decodeGzip( string $body ) : string

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

Currently requires PHP with zlib support

Arguments
$body
string
Output
string
Details
visibility
public
final
false
static
true

extractBody

extractBody( string $response_str ) : string

Extract the body from a response string

Arguments
$response_str
string
Output
string
Details
visibility
public
final
false
static
true

extractCode

extractCode( string $response_str ) : int

Extract the response code from a response string

Arguments
$response_str
string
Output
int
Details
visibility
public
final
false
static
true

extractHeaders

extractHeaders( string $response_str ) : array

Extract the headers from a response string

Arguments
$response_str
string
Output
array
Details
visibility
public
final
false
static
true

extractMessage

extractMessage( string $response_str ) : string

Extract the HTTP message from a response

Arguments
$response_str
string
Output
string
Details
visibility
public
final
false
static
true

extractVersion

extractVersion( string $response_str ) : string

Extract the HTTP version from a response

Arguments
$response_str
string
Output
string
Details
visibility
public
final
false
static
true

fromString

fromString( string $response_str ) : Zend_Http_Response

Create a new Zend_Http_Response object from a string

Arguments
$response_str
string
Details
visibility
public
final
false
static
true

getBody

getBody( ) : 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.

Output
string
Details
visibility
public
final
false
static
false

getHeader

getHeader(  $header ) : string|array|null

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

Arguments
$header
string$header
Output
string|array|null
Details
visibility
public
final
false
static
false

getHeaders

getHeaders( ) : array

Get the response headers

Output
array
Details
visibility
public
final
false
static
false

getHeadersAsString

getHeadersAsString( boolean $status_line = true, string $br = \n ) : string

Get all headers as string

Arguments
$status_line
boolean
Whether to return the first status line (IE "HTTP 200 OK")
$br
string
Line breaks (eg. "\n", "\r\n", "<br />")
Output
string
Details
visibility
public
final
false
static
false

getMessage

getMessage( ) : string

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

Output
string
Details
visibility
public
final
false
static
false

getRawBody

getRawBody( ) : 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.

Output
string
Details
visibility
public
final
false
static
false

getStatus

getStatus( ) : int

Get the HTTP response status code

Output
int
Details
visibility
public
final
false
static
false

getVersion

getVersion( ) : string

Get the HTTP version of the response

Output
string
Details
visibility
public
final
false
static
false

isError

isError( ) : boolean

Check whether the response is an error

Output
boolean
Details
visibility
public
final
false
static
false

isRedirect

isRedirect( ) : boolean

Check whether the response is a redirection

Output
boolean
Details
visibility
public
final
false
static
false

isSuccessful

isSuccessful( ) : boolean

Check whether the response in successful

Output
boolean
Details
visibility
public
final
false
static
false

responseCodeAsText

responseCodeAsText( int $code = null, boolean $http11 = true ) : string

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

Arguments
$code
int
HTTP response code
$http11
boolean
Use HTTP version 1.1
Output
string
Details
visibility
public
final
false
static
true
Documentation was generated by DocBlox.