Http/Response/Stream.php

Show: PublicProtectedPrivateinherited
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: Stream.php 24593 2012-01-05 20:35:02Z matthew $  

\Zend_Http_Response_Stream

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.

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

Properties

>VPropertyprotectedboolean $_cleanup
Should we clean up the stream file when this response is closed?
Details
Type
boolean
>VPropertyprotectedstring $body
inherited
The HTTP response body
Inherited from: \Zend_Http_Response::$$body
Details
Type
string
Inherited_from
\Zend_Http_Response::$$body  
>VPropertyprotectedint $code
inherited
The HTTP response code
Inherited from: \Zend_Http_Response::$$code
Details
Type
int
Inherited_from
\Zend_Http_Response::$$code  
>VPropertyprotectedarray $headers = array()
inherited
The HTTP response headers array
Inherited from: \Zend_Http_Response::$$headers
Default valuearray()Details
Type
array
Inherited_from
\Zend_Http_Response::$$headers  
>VPropertyprotectedstring $message
inherited
The HTTP response code as string (e.g.
Inherited from: \Zend_Http_Response::$$message

'Not Found' for 404 or 'Internal Server Error' for 500)

Details
Type
string
Inherited_from
\Zend_Http_Response::$$message  
>VPropertyprotectedarray $messages = array(100 => 'Continue', 101 => 'Switching Protocols', 200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content', 300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', 304 => 'Not Modified', 305 => 'Use Proxy', 307 => 'Temporary Redirect', 400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 407 => 'Proxy Authentication Required', 408 => 'Request Timeout', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Long', 415 => 'Unsupported Media Type', 416 => 'Requested Range Not Satisfiable', 417 => 'Expectation Failed', 500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Timeout', 505 => 'HTTP Version Not Supported', 509 => 'Bandwidth Limit Exceeded')
staticinherited
List of all known HTTP response codes - used by responseCodeAsText() to translate numeric codes to messages.
Inherited from: \Zend_Http_Response::$$messages
Default valuearray(100 => 'Continue', 101 => 'Switching Protocols', 200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content', 300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', 304 => 'Not Modified', 305 => 'Use Proxy', 307 => 'Temporary Redirect', 400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 407 => 'Proxy Authentication Required', 408 => 'Request Timeout', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Long', 415 => 'Unsupported Media Type', 416 => 'Requested Range Not Satisfiable', 417 => 'Expectation Failed', 500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Timeout', 505 => 'HTTP Version Not Supported', 509 => 'Bandwidth Limit Exceeded')Details
Type
array
Inherited_from
\Zend_Http_Response::$$messages  
>VPropertyprotectedresource $stream
Response as stream
Details
Type
resource
>VPropertyprotectedstring $stream_name
The name of the file containing the stream

Will be empty if stream is not file-based.

Details
Type
string
>VPropertyprotectedstring $version
inherited
The HTTP version (1.0, 1.1)
Inherited from: \Zend_Http_Response::$$version
Details
Type
string
Inherited_from
\Zend_Http_Response::$$version  

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
NameTypeDescription
$codeint

Response code (200, 404, ...)

$headersarray

Headers array

$bodystring

Response body

$versionstring

HTTP version

$messagestring

Response code as text

Throws
ExceptionDescription
\Zend_Http_Exception
methodpublic__destruct() : void

methodpublic__toString() : string
inherited

Implements magic __toString()

Inherited from: \Zend_Http_Response::__toString()
Returns
TypeDescription
string
methodpublicasString(string $br = "\n") : string
inherited

Get the entire response as string

Inherited from: \Zend_Http_Response::asString()
Parameters
NameTypeDescription
$brstring

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

Returns
TypeDescription
string
methodpublicdecodeChunkedBody(string $body) : string
staticinherited

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

Inherited from: \Zend_Http_Response::decodeChunkedBody()
Parameters
NameTypeDescription
$bodystring
Returns
TypeDescription
string
methodpublicdecodeDeflate(string $body) : string
staticinherited

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

Inherited from: \Zend_Http_Response::decodeDeflate()

Currently requires PHP with zlib support

Parameters
NameTypeDescription
$bodystring
Returns
TypeDescription
string
methodpublicdecodeGzip(string $body) : string
staticinherited

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

Inherited from: \Zend_Http_Response::decodeGzip()

Currently requires PHP with zlib support

Parameters
NameTypeDescription
$bodystring
Returns
TypeDescription
string
methodpublicextractBody(string $response_str) : string
staticinherited

Extract the body from a response string

Inherited from: \Zend_Http_Response::extractBody()
Parameters
NameTypeDescription
$response_strstring
Returns
TypeDescription
string
methodpublicextractCode(string $response_str) : int
staticinherited

Extract the response code from a response string

Inherited from: \Zend_Http_Response::extractCode()
Parameters
NameTypeDescription
$response_strstring
Returns
TypeDescription
int
methodpublicextractHeaders(string $response_str) : array
staticinherited

Extract the headers from a response string

Inherited from: \Zend_Http_Response::extractHeaders()
Parameters
NameTypeDescription
$response_strstring
Returns
TypeDescription
array
methodpublicextractMessage(string $response_str) : string
staticinherited

Extract the HTTP message from a response

Inherited from: \Zend_Http_Response::extractMessage()
Parameters
NameTypeDescription
$response_strstring
Returns
TypeDescription
string
methodpublicextractVersion(string $response_str) : string
staticinherited

Extract the HTTP version from a response

Inherited from: \Zend_Http_Response::extractVersion()
Parameters
NameTypeDescription
$response_strstring
Returns
TypeDescription
string
methodpublicfromStream(string $response_str, resource $stream) : \Zend_Http_Response_Stream
static

Create a new Zend_Http_Response_Stream object from a string

Parameters
NameTypeDescription
$response_strstring
$streamresource
Returns
TypeDescription
\Zend_Http_Response_Stream
methodpublicfromString(string $response_str) : \Zend_Http_Response
staticinherited

Create a new Zend_Http_Response object from a string

Inherited from: \Zend_Http_Response::fromString()
Parameters
NameTypeDescription
$response_strstring
Returns
TypeDescription
\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
TypeDescription
string
methodpublicgetCleanup() : boolean

Get the cleanup trigger

Returns
TypeDescription
boolean
methodpublicgetHeader(\string$header $header) : string | array | null
inherited

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

Inherited from: \Zend_Http_Response::getHeader()
Parameters
NameTypeDescription
$header\string$header
Returns
TypeDescription
string | array | null
methodpublicgetHeaders() : array
inherited

Get the response headers

Inherited from: \Zend_Http_Response::getHeaders()
Returns
TypeDescription
array
methodpublicgetHeadersAsString(boolean $status_line = true, string $br = "\n") : string
inherited

Get all headers as string

Inherited from: \Zend_Http_Response::getHeadersAsString()
Parameters
NameTypeDescription
$status_lineboolean

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

$brstring

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

Returns
TypeDescription
string
methodpublicgetMessage() : string
inherited

Return a message describing the HTTP response code (Eg.

Inherited from: \Zend_Http_Response::getMessage()

"OK", "Not Found", "Moved Permanently")

Returns
TypeDescription
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
TypeDescription
string
methodpublicgetStatus() : int
inherited

Get the HTTP response status code

Inherited from: \Zend_Http_Response::getStatus()
Returns
TypeDescription
int
methodpublicgetStream() : \resourse

Get the response as stream

Returns
TypeDescription
\resourse
methodpublicgetStreamName() : string

Get file name associated with the stream

Returns
TypeDescription
string
methodpublicgetVersion() : string
inherited

Get the HTTP version of the response

Inherited from: \Zend_Http_Response::getVersion()
Returns
TypeDescription
string
methodpublicisError() : boolean
inherited

Check whether the response is an error

Inherited from: \Zend_Http_Response::isError()
Returns
TypeDescription
boolean
methodpublicisRedirect() : boolean
inherited

Check whether the response is a redirection

Inherited from: \Zend_Http_Response::isRedirect()
Returns
TypeDescription
boolean
methodpublicisSuccessful() : boolean
inherited

Check whether the response in successful

Inherited from: \Zend_Http_Response::isSuccessful()
Returns
TypeDescription
boolean
methodprotectedreadStream() : string

Read stream content and return it as string

Function reads the remainder of the body from the stream and closes the stream.

Returns
TypeDescription
string
methodpublicresponseCodeAsText(int $code = null, boolean $http11 = true) : string
staticinherited

A convenience function that returns a text representation of HTTP response codes.

Inherited from: \Zend_Http_Response::responseCodeAsText()

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
NameTypeDescription
$codeint

HTTP response code

$http11boolean

Use HTTP version 1.1

Returns
TypeDescription
string
methodpublicsetCleanup(bool $cleanup = true) : void

Set the cleanup trigger

Parameters
NameTypeDescription
$cleanupbool

Set cleanup trigger

methodpublicsetStream(\resourse $stream) : \Zend_Http_Response_Stream

Set the response stream

Parameters
NameTypeDescription
$stream\resourse
Returns
TypeDescription
\Zend_Http_Response_Stream
methodpublicsetStreamName(string $stream_name) : \Zend_Http_Response_Stream

Set file name associated with the stream

Parameters
NameTypeDescription
$stream_namestring

Name to set

Returns
TypeDescription
\Zend_Http_Response_Stream
Documentation was generated by phpDocumentor 2.0.0a12.