Definition at line 39 of file Response.php.
◆ __construct()
__construct |
( |
|
$code, |
|
|
array |
$headers, |
|
|
|
$body = null , |
|
|
|
$version = '1.1' , |
|
|
|
$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.
- Parameters
-
int | $code | Response code (200, 404, ...) |
array | $headers | Headers array |
string | $body | Response body |
string | $version | HTTP version |
string | $message | Response code as text |
- Exceptions
-
Definition at line 156 of file Response.php.
159 if (self::responseCodeAsText(
$code) ===
null) {
160 #require_once 'Zend/Http/Exception.php'; 168 $header = explode(
":",
$value, 2);
169 if (count($header) != 2) {
170 #require_once 'Zend/Http/Exception.php'; 174 $name = trim($header[0]);
175 $value = trim($header[1]);
178 $this->headers[ucwords(strtolower(
$name))] =
$value;
185 if (! preg_match(
'|^\d\.\d$|',
$version)) {
186 #require_once 'Zend/Http/Exception.php';
static responseCodeAsText($code=null, $http11=true)
if(!isset($_GET['name'])) $name
◆ __toString()
◆ asString()
Get the entire response as string
- Parameters
-
string | $br | Line breaks (eg. "\n", "\r\n", "<br />") |
- Returns
- string
Definition at line 402 of file Response.php.
getHeadersAsString($status_line=true, $br="\n")
◆ decodeChunkedBody()
static decodeChunkedBody |
( |
|
$body | ) |
|
|
static |
Decode a "chunked" transfer-encoded body and return the decoded text
- Parameters
-
- Returns
- string
Definition at line 599 of file Response.php.
606 ((
int)
ini_get(
'mbstring.func_overload')) & 2) {
608 $mbIntEnc = mb_internal_encoding();
609 mb_internal_encoding(
'ASCII');
612 while (trim(
$body)) {
613 if (! preg_match(
"/^([\da-fA-F]+)[^\r\n]*\r\n/sm",
$body, $m)) {
614 #require_once 'Zend/Http/Exception.php'; 615 throw new Zend_Http_Exception(
"Error parsing body - doesn't seem to be a chunked message");
618 $length = hexdec(trim($m[1]));
619 $cut = strlen($m[0]);
620 $decBody .= substr(
$body, $cut, $length);
624 if (isset($mbIntEnc)) {
625 mb_internal_encoding($mbIntEnc);
◆ decodeDeflate()
static decodeDeflate |
( |
|
$body | ) |
|
|
static |
Decode a zlib deflated message (when Content-encoding = deflate)
Currently requires PHP with zlib support
- Parameters
-
- Returns
- string
Some servers (IIS ?) send a broken deflate response, without the RFC-required zlib header.
We try to detect the zlib header, and if it does not exsit we teat the body is plain DEFLATE content.
This method was adapted from PEAR HTTP_Request2 by (c) Alexey Borzov
http://framework.zend.com/issues/browse/ZF-6040
Definition at line 659 of file Response.php.
662 #require_once 'Zend/Http/Exception.php'; 664 'zlib extension is required in order to decode "deflate" encoding' 679 $zlibHeader = unpack(
'n', substr(
$body, 0, 2));
680 if ($zlibHeader[1] % 31 == 0 && ord(
$body[0]) == 0x78 && in_array(ord(
$body[1]), array(0x01, 0x5e, 0x9c, 0xda))) {
681 return gzuncompress(
$body);
683 return gzinflate(
$body);
◆ decodeGzip()
static decodeGzip |
( |
|
$body | ) |
|
|
static |
Decode a gzip encoded message (when Content-encoding = gzip)
Currently requires PHP with zlib support
- Parameters
-
- Returns
- string
Definition at line 639 of file Response.php.
642 #require_once 'Zend/Http/Exception.php'; 644 'zlib extension is required in order to decode "gzip" encoding' 648 return gzinflate(substr(
$body, 10));
◆ extractBody()
static extractBody |
( |
|
$response_str | ) |
|
|
static |
Extract the body from a response string
- Parameters
-
- Returns
- string
Definition at line 584 of file Response.php.
586 $parts = preg_split(
'|(?:\r\n){2}|m', $response_str, 2);
587 if (isset($parts[1])) {
◆ extractCode()
static extractCode |
( |
|
$response_str | ) |
|
|
static |
Extract the response code from a response string
- Parameters
-
- Returns
- int
Definition at line 449 of file Response.php.
451 preg_match(
"|^HTTP/[\d\.x]+ (\d+)|", $response_str, $m);
◆ extractHeaders()
static extractHeaders |
( |
|
$response_str | ) |
|
|
static |
Extract the headers from a response string
- Parameters
-
- Returns
- array
Definition at line 500 of file Response.php.
506 $parts = preg_split(
'|(?:\r\n){2}|m', $response_str, 2);
512 $lines = explode(
"\r\n", $parts[0]);
516 foreach($lines as
$index => $line) {
517 if (
$index === 0 && preg_match(
'#^HTTP/\d+(?:\.\d+) [1-5]\d+#', $line)) {
528 if (preg_match(
"|^([a-zA-Z0-9\'`#$%&*+.^_\|\~!-]+):\s*(.*)|s", $line, $m)) {
530 $h_name = strtolower($m[1]);
535 if (! is_array(
$headers[$h_name])) {
539 $headers[$h_name][] = ltrim($h_value);
540 $last_header = $h_name;
544 $headers[$h_name] = ltrim($h_value);
545 $last_header = $h_name;
550 if (preg_match(
"|^[ \t](.+)$|s", $line, $m) && $last_header !==
null) {
551 $h_value = trim($m[1]);
552 if (is_array(
$headers[$last_header])) {
554 $last_header_key = key(
$headers[$last_header]);
556 $h_value =
$headers[$last_header][$last_header_key] . $h_value;
559 $headers[$last_header][$last_header_key] = $h_value;
563 $h_value =
$headers[$last_header] . $h_value;
571 #require_once 'Zend/Http/Exception.php';
◆ extractMessage()
static extractMessage |
( |
|
$response_str | ) |
|
|
static |
Extract the HTTP message from a response
- Parameters
-
- Returns
- string
Definition at line 466 of file Response.php.
468 preg_match(
"|^HTTP/[\d\.x]+ \d+ ([^\r\n]+)|", $response_str, $m);
◆ extractVersion()
static extractVersion |
( |
|
$response_str | ) |
|
|
static |
Extract the HTTP version from a response
- Parameters
-
- Returns
- string
Definition at line 483 of file Response.php.
485 preg_match(
"|^HTTP/([\d\.x]+) \d+|", $response_str, $m);
◆ fromString()
static fromString |
( |
|
$response_str | ) |
|
|
static |
Create a new Zend_Http_Response object from a string
- Parameters
-
- Returns
- Zend_Http_Response
Definition at line 693 of file Response.php.
static extractHeaders($response_str)
static extractVersion($response_str)
static extractBody($response_str)
static extractMessage($response_str)
static extractCode($response_str)
◆ getBody()
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
- string
Definition at line 258 of file Response.php.
263 switch (strtolower($this->
getHeader(
'transfer-encoding'))) {
278 switch (strtolower($this->
getHeader(
'content-encoding'))) {
static decodeChunkedBody($body)
static decodeDeflate($body)
◆ getHeader()
Get a specific header as string, or null if it is not set
- Parameters
-
- Returns
- string|array|null
Definition at line 357 of file Response.php.
359 $header = ucwords(strtolower($header));
360 if (! is_string($header) || ! isset($this->headers[$header]))
return null;
362 return $this->headers[$header];
◆ getHeaders()
Get the response headers
- Returns
- array
Definition at line 346 of file Response.php.
◆ getHeadersAsString()
getHeadersAsString |
( |
|
$status_line = true , |
|
|
|
$br = "\n" |
|
) |
| |
Get all headers as string
- Parameters
-
boolean | $status_line | Whether to return the first status line (IE "HTTP 200 OK") |
string | $br | Line breaks (eg. "\n", "\r\n", "<br />") |
- Returns
- string
Definition at line 372 of file Response.php.
377 $str =
"HTTP/{$this->version} {$this->code} {$this->message}{$br}";
384 $str .=
"{$name}: {$value}{$br}";
387 foreach (
$value as $subval) {
388 $str .=
"{$name}: {$subval}{$br}";
elseif(isset( $params[ 'redirect_parent']))
if(!isset($_GET['name'])) $name
◆ getMessage()
Return a message describing the HTTP response code (Eg. "OK", "Not Found", "Moved Permanently")
- Returns
- string
Definition at line 336 of file Response.php.
◆ getRawBody()
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
- string
Definition at line 305 of file Response.php.
◆ getStatus()
Get the HTTP response status code
- Returns
- int
Definition at line 325 of file Response.php.
◆ getVersion()
Get the HTTP version of the response
- Returns
- string
Definition at line 315 of file Response.php.
◆ isError()
Check whether the response is an error
- Returns
- boolean
Definition at line 206 of file Response.php.
208 $restype = floor($this->code / 100);
209 if ($restype == 4 || $restype == 5) {
◆ isRedirect()
Check whether the response is a redirection
- Returns
- boolean
Definition at line 236 of file Response.php.
238 $restype = floor($this->code / 100);
◆ isSuccessful()
Check whether the response in successful
- Returns
- boolean
Definition at line 221 of file Response.php.
223 $restype = floor($this->code / 100);
224 if ($restype == 2 || $restype == 1) {
◆ responseCodeAsText()
static responseCodeAsText |
( |
|
$code = null , |
|
|
|
$http11 = true |
|
) |
| |
|
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
-
int | $code | HTTP response code |
boolean | $http11 | Use HTTP version 1.1 |
- Returns
- string
Definition at line 429 of file Response.php.
432 if (! $http11)
$messages[302] =
'Moved Temporarily';
434 if (
$code ===
null) {
elseif(isset( $params[ 'redirect_parent']))
◆ $body
◆ $code
◆ $headers
◆ $message
◆ $messages
◆ $version
The documentation for this class was generated from the following file:
- vendor/magento/zendframework1/library/Zend/Http/Response.php