You are here

function parse_request in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/guzzlehttp/psr7/src/functions.php \GuzzleHttp\Psr7\parse_request()

Parses a request message string into a request object.

Parameters

string $message Request message string.:

Return value

Request

File

vendor/guzzlehttp/psr7/src/functions.php, line 440

Namespace

GuzzleHttp\Psr7

Code

function parse_request($message) {
  $data = _parse_message($message);
  $matches = [];
  if (!preg_match('/^[a-zA-Z]+\\s+([a-zA-Z]+:\\/\\/|\\/).*/', $data['start-line'], $matches)) {
    throw new \InvalidArgumentException('Invalid request string');
  }
  $parts = explode(' ', $data['start-line'], 3);
  $version = isset($parts[2]) ? explode('/', $parts[2])[1] : '1.1';
  $request = new Request($parts[0], $matches[1] === '/' ? _parse_request_uri($parts[1], $data['headers']) : $parts[1], $data['headers'], $data['body'], $version);
  return $matches[1] === '/' ? $request : $request
    ->withRequestTarget($parts[1]);
}