You are here

public static function EasyRdf_Http_Response::decodeChunkedBody in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/easyrdf/easyrdf/lib/EasyRdf/Http/Response.php \EasyRdf_Http_Response::decodeChunkedBody()

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

Parameters

string $body:

Return value

string

1 call to EasyRdf_Http_Response::decodeChunkedBody()
EasyRdf_Http_Response::getBody in vendor/easyrdf/easyrdf/lib/EasyRdf/Http/Response.php
Get the response body as string

File

vendor/easyrdf/easyrdf/lib/EasyRdf/Http/Response.php, line 319

Class

EasyRdf_Http_Response
Class that represents an HTTP 1.0 / 1.1 response message.

Code

public static function decodeChunkedBody($body) {
  $decBody = '';
  while (trim($body)) {
    if (preg_match('/^([\\da-fA-F]+)[^\\r\\n]*\\r\\n/sm', $body, $m)) {
      $length = hexdec(trim($m[1]));
      $cut = strlen($m[0]);
      $decBody .= substr($body, $cut, $length);
      $body = substr($body, $cut + $length + 2);
    }
    else {
      throw new EasyRdf_Exception("Failed to decode chunked body in HTTP response.");
    }
  }
  return $decBody;
}