Http/Response/Stream.php
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
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

array $headers = array()array()Details- Type
- array
- Inherited_from
- \Zend_Http_Response::$$headers

string $message'Not Found' for 404 or 'Internal Server Error' for 500)
- Type
- string
- Inherited_from
- \Zend_Http_Response::$$message

array $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')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')Details- Type
- array
- Inherited_from
- \Zend_Http_Response::$$messages

string $stream_nameWill be empty if stream is not file-based.
- Type
- string
Methods

__construct(int $code, array $headers, string $body = null, string $version = '1.1', string $message = null) : voidHTTP 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.
| 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 |
| Exception | Description |
|---|---|
| \Zend_Http_Exception |

asString(string $br = "\n") : string| Name | Type | Description |
|---|---|---|
| $br | string | Line breaks (eg. "\n", "\r\n", " |
| Type | Description |
|---|---|
| string |

decodeChunkedBody(string $body) : stringDecode a "chunked" transfer-encoded body and return the decoded text
Inherited from: \Zend_Http_Response::decodeChunkedBody()| Name | Type | Description |
|---|---|---|
| $body | string |
| Type | Description |
|---|---|
| string |

decodeDeflate(string $body) : stringDecode a zlib deflated message (when Content-encoding = deflate)
Inherited from: \Zend_Http_Response::decodeDeflate()Currently requires PHP with zlib support
| Name | Type | Description |
|---|---|---|
| $body | string |
| Type | Description |
|---|---|
| string |

decodeGzip(string $body) : stringDecode a gzip encoded message (when Content-encoding = gzip)
Inherited from: \Zend_Http_Response::decodeGzip()Currently requires PHP with zlib support
| Name | Type | Description |
|---|---|---|
| $body | string |
| Type | Description |
|---|---|
| string |

extractBody(string $response_str) : stringExtract the body from a response string
Inherited from: \Zend_Http_Response::extractBody()| Name | Type | Description |
|---|---|---|
| $response_str | string |
| Type | Description |
|---|---|
| string |

extractCode(string $response_str) : intExtract the response code from a response string
Inherited from: \Zend_Http_Response::extractCode()| Name | Type | Description |
|---|---|---|
| $response_str | string |
| Type | Description |
|---|---|
| int |

extractHeaders(string $response_str) : arrayExtract the headers from a response string
Inherited from: \Zend_Http_Response::extractHeaders()| Name | Type | Description |
|---|---|---|
| $response_str | string |
| Type | Description |
|---|---|
| array |

extractMessage(string $response_str) : stringExtract the HTTP message from a response
Inherited from: \Zend_Http_Response::extractMessage()| Name | Type | Description |
|---|---|---|
| $response_str | string |
| Type | Description |
|---|---|
| string |

extractVersion(string $response_str) : stringExtract the HTTP version from a response
Inherited from: \Zend_Http_Response::extractVersion()| Name | Type | Description |
|---|---|---|
| $response_str | string |
| Type | Description |
|---|---|
| string |

fromStream(string $response_str, resource $stream) : \Zend_Http_Response_StreamCreate a new Zend_Http_Response_Stream object from a string
| Name | Type | Description |
|---|---|---|
| $response_str | string | |
| $stream | resource |
| Type | Description |
|---|---|
| \Zend_Http_Response_Stream |

fromString(string $response_str) : \Zend_Http_ResponseCreate a new Zend_Http_Response object from a string
Inherited from: \Zend_Http_Response::fromString()| Name | Type | Description |
|---|---|---|
| $response_str | string |
| Type | Description |
|---|---|
| \Zend_Http_Response |

getBody() : stringGet 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.
| Type | Description |
|---|---|
| string |

getHeader(\string$header $header) : string | array | nullGet a specific header as string, or null if it is not set
Inherited from: \Zend_Http_Response::getHeader()| Name | Type | Description |
|---|---|---|
| $header | \string$header |
| Type | Description |
|---|---|
| string | array | null |

getHeadersAsString(boolean $status_line = true, string $br = "\n") : string| 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", " |
| Type | Description |
|---|---|
| string |

getMessage() : stringReturn a message describing the HTTP response code (Eg.
Inherited from: \Zend_Http_Response::getMessage()"OK", "Not Found", "Moved Permanently")
| Type | Description |
|---|---|
| string |

getRawBody() : stringGet 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.
| Type | Description |
|---|---|
| string |

isRedirect() : booleanCheck whether the response is a redirection
Inherited from: \Zend_Http_Response::isRedirect()| Type | Description |
|---|---|
| boolean |

isSuccessful() : booleanCheck whether the response in successful
Inherited from: \Zend_Http_Response::isSuccessful()| Type | Description |
|---|---|
| boolean |

readStream() : stringRead stream content and return it as string
Function reads the remainder of the body from the stream and closes the stream.
| Type | Description |
|---|---|
| string |

responseCodeAsText(int $code = null, boolean $http11 = true) : stringA 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
| Name | Type | Description |
|---|---|---|
| $code | int | HTTP response code |
| $http11 | boolean | Use HTTP version 1.1 |
| Type | Description |
|---|---|
| string |

setCleanup(bool $cleanup = true) : voidSet the cleanup trigger
| Name | Type | Description |
|---|---|---|
| $cleanup | bool | Set cleanup trigger |

setStream(\resourse $stream) : \Zend_Http_Response_StreamSet the response stream
| Name | Type | Description |
|---|---|---|
| $stream | \resourse |
| Type | Description |
|---|---|
| \Zend_Http_Response_Stream |

setStreamName(string $stream_name) : \Zend_Http_Response_StreamSet file name associated with the stream
| Name | Type | Description |
|---|---|---|
| $stream_name | string | Name to set |
| Type | Description |
|---|---|
| \Zend_Http_Response_Stream |