/**
* Method to get a response object from a server response.
*
* @param string $content The complete server response, including headers.
*
* @return Response
*
* @since 1.7.3
* @throws InvalidResponseCodeException
*/
protected function getResponse($content)
{
if (empty($content)) {
throw new \UnexpectedValueException('No content in response.');
}
// Split the response into headers and body.
$response = explode("\r\n\r\n", $content, 2);
// Get the response headers as an array.
$headers = explode("\r\n", $response[0]);
// Set the body for the response.
$body = empty($response[1]) ? '' : $response[1];
// 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);
}