3
* Case-insensitive dictionary, suitable for HTTP headers
9
* Case-insensitive dictionary, suitable for HTTP headers
13
class Requests_Response_Headers extends Requests_Utility_CaseInsensitiveDictionary {
15
* Get the given header
17
* Unlike {@see self::getValues()}, this returns a string. If there are
18
* multiple values, it concatenates them with a comma as per RFC2616.
20
* Avoid using this where commas may be used unquoted in values, such as
24
* @return string Header value
26
public function offsetGet($key) {
27
$key = strtolower($key);
28
if (!isset($this->data[$key])) {
32
return $this->flatten($this->data[$key]);
38
* @throws Requests_Exception On attempting to use dictionary as list (`invalidset`)
40
* @param string $key Item name
41
* @param string $value Item value
43
public function offsetSet($key, $value) {
45
throw new Requests_Exception('Object is a dictionary, not a list', 'invalidset');
48
$key = strtolower($key);
50
if (!isset($this->data[$key])) {
51
$this->data[$key] = array();
54
$this->data[$key][] = $value;
58
* Get all values for a given header
61
* @return array Header values
63
public function getValues($key) {
64
$key = strtolower($key);
65
if (!isset($this->data[$key])) {
69
return $this->data[$key];
73
* Flattens a value into a string
75
* Converts an array into a string by imploding values with a comma, as per
76
* RFC2616's rules for folding headers.
78
* @param string|array $value Value to flatten
79
* @return string Flattened value
81
public function flatten($value) {
82
if (is_array($value)) {
83
$value = implode(',', $value);
90
* Get an iterator for the data
92
* Converts the internal
93
* @return ArrayIterator
95
public function getIterator() {
96
return new Requests_Utility_FilteredIterator($this->data, array($this, 'flatten'));