/** * 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; }
private function headers(MessageInterface $message) { $result = ''; foreach ($message->getHeaders() as $name => $values) { $result .= $name . ': ' . implode(', ', $values) . "\r\n"; } return trim($result); }
/** * Gets the headers of a message as a string * * @param MessageInterface $message * * @return string */ public static function getHeadersAsString(MessageInterface $message) { $result = ''; foreach ($message->getHeaders() as $name => $values) { $result .= "\r\n{$name}: " . implode(', ', $values); } return $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; }