/** * Gets or sets HTTP headers to the request or response. All headers * are included immediately after the HTTP protocol definition during * transmission. This method provides a simple array or key/value * interface to the headers. * * @param mixed $key Key or array of key/value pairs to set * @param string $value Value to set to the supplied key * * @return Request|HTTP_Header|mixed */ public function headers($key = NULL, $value = NULL) { if ($key instanceof HTTP_Header) { // Act a setter, replace all headers $this->_header = $key; return $this; } if (is_array($key)) { // Act as a setter, replace all headers $this->_header->exchangeArray($key); return $this; } if ($this->_header->count() === 0 and $this->is_initial()) { // Lazy load the request headers $this->_header = HTTP::request_headers(); } if ($key === NULL) { // Act as a getter, return all headers return $this->_header; } elseif ($value === NULL) { // Act as a getter, single header return $this->_header->offsetExists($key) ? $this->_header->offsetGet($key) : NULL; } // Act as a setter for a single header $this->_header[$key] = $value; return $this; }