function Message::parseResponse
Parses a response message string into a response object.
Parameters
string $message Response message string.:
File
-
vendor/
guzzlehttp/ psr7/ src/ Message.php, line 227
Class
Namespace
GuzzleHttp\Psr7Code
public static function parseResponse(string $message) : ResponseInterface {
$data = self::parseMessage($message);
// According to https://datatracker.ietf.org/doc/html/rfc7230#section-3.1.2
// the space between status-code and reason-phrase is required. But
// browsers accept responses without space and reason as well.
if (!preg_match('/^HTTP\\/.* [0-9]{3}( .*|$)/', $data['start-line'])) {
throw new \InvalidArgumentException('Invalid response string: ' . $data['start-line']);
}
$parts = explode(' ', $data['start-line'], 3);
return new Response((int) $parts[1], $data['headers'], $data['body'], explode('/', $parts[0])[1], $parts[2] ?? null);
}