Back to StreamTransport class

Method getResponse

protected \Joomla\CMS\Http\Response
getResponse
(array $headers, mixed $body)
Method to get a response object from a server response.
Parameters
  • array $headers The response headers as an array.
  • string $body The response body as a string.
Returns
  • \Joomla\CMS\Http\Response
Since
  • 1.7.3
-
  • \Joomla\Http\Exception\InvalidResponseCodeException

Method getResponse - Source code

/**
 * Method to get a response object from a server response.
 *
 * @param   array   $headers  The response headers as an array.
 * @param   string  $body     The response body as a string.
 *
 * @return  Response
 *
 * @since   1.7.3
 * @throws  InvalidResponseCodeException
 */
protected function getResponse(array $headers, $body)
{
    // Get the response code from the first offset of the response headers.
    preg_match('/[0-9]{3}/', array_shift($headers), $matches);
    $code = $matches[0];
    if (!is_numeric($code)) {
        // No valid response code was detected.
        throw new InvalidResponseCodeException('No HTTP response code found.');
    }
    $statusCode = (int) $code;
    $verifiedHeaders = $this->processHeaders($headers);
    $streamInterface = new StreamResponse('php://memory', 'rw');
    $streamInterface->write($body);
    return new Response($streamInterface, $statusCode, $verifiedHeaders);
}