You are here

function str in Zircon Profile 8

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

Returns the string representation of an HTTP message.

Parameters

MessageInterface $message Message to convert to a string.:

Return value

string

File

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

Namespace

GuzzleHttp\Psr7

Code

function str(MessageInterface $message) {
  if ($message instanceof RequestInterface) {
    $msg = trim($message
      ->getMethod() . ' ' . $message
      ->getRequestTarget()) . ' HTTP/' . $message
      ->getProtocolVersion();
    if (!$message
      ->hasHeader('host')) {
      $msg .= "\r\nHost: " . $message
        ->getUri()
        ->getHost();
    }
  }
  elseif ($message instanceof ResponseInterface) {
    $msg = 'HTTP/' . $message
      ->getProtocolVersion() . ' ' . $message
      ->getStatusCode() . ' ' . $message
      ->getReasonPhrase();
  }
  else {
    throw new \InvalidArgumentException('Unknown message type');
  }
  foreach ($message
    ->getHeaders() as $name => $values) {
    $msg .= "\r\n{$name}: " . implode(', ', $values);
  }
  return "{$msg}\r\n\r\n" . $message
    ->getBody();
}