You are here

function str in Lockr 7.3

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 18

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();
}