/**
  * Creates an array of cacheable and normalized message headers
  *
  * @param MessageInterface $message
  *
  * @return array
  */
 private function persistHeaders(MessageInterface $message)
 {
     // Headers are excluded from the caching (see RFC 2616:13.5.1)
     static $noCache = ['age' => true, 'connection' => true, 'keep-alive' => true, 'proxy-authenticate' => true, 'proxy-authorization' => true, 'te' => true, 'trailers' => true, 'transfer-encoding' => true, 'upgrade' => true, 'set-cookie' => true, 'set-cookie2' => true];
     // Clone the response to not destroy any necessary headers when caching
     $headers = array_diff_key($message->getHeaders(), $noCache);
     // Cast the headers to a string
     foreach ($headers as &$value) {
         $value = implode(', ', $value);
     }
     return $headers;
 }
 /**
  * Gets the start line of a message
  *
  * @param MessageInterface $message
  *
  * @return string
  * @throws \InvalidArgumentException
  */
 public static function getStartLine(MessageInterface $message)
 {
     if ($message instanceof RequestInterface) {
         return trim($message->getMethod() . ' ' . $message->getResource()) . ' HTTP/' . $message->getProtocolVersion();
     } elseif ($message instanceof ResponseInterface) {
         return 'HTTP/' . $message->getProtocolVersion() . ' ' . $message->getStatusCode() . ' ' . $message->getReasonPhrase();
     } else {
         throw new \InvalidArgumentException('Unknown message type');
     }
 }
 /**
  * Converts an array of header values that may contain comma separated
  * headers into an array of headers with no comma separated values.
  *
  * @param MessageInterface $message That contains the header
  * @param string              $header  Header to retrieve from the message
  *
  * @return array Returns the normalized header field values.
  */
 public static function normalizeHeader(MessageInterface $message, $header)
 {
     $h = $message->getHeader($header, true);
     for ($i = 0, $total = count($h); $i < $total; $i++) {
         if (strpos($h[$i], ',') === false) {
             continue;
         }
         foreach (preg_split('/,(?=([^"]*"[^"]*")*[^"]*$)/', $h[$i]) as $v) {
             $h[] = trim($v);
         }
         unset($h[$i]);
     }
     return $h;
 }
Example #4
0
 private function headers(MessageInterface $message)
 {
     $result = '';
     foreach ($message->getHeaders() as $name => $values) {
         $result .= $name . ': ' . implode(', ', $values) . "\r\n";
     }
     return trim($result);
 }
 /**
  * Creates an array of cacheable and normalized message headers.
  *
  * @param MessageInterface $message
  *
  * @return array
  */
 private function persistHeaders(MessageInterface $message)
 {
     // Clone the response to not destroy any necessary headers when caching
     $headers = array_diff_key($message->getHeaders(), self::$noCache);
     // Cast the headers to a string
     foreach ($headers as &$value) {
         $value = implode(', ', $value);
     }
     return $headers;
 }