Requests_Response_Headers

Case-insensitive dictionary, suitable for HTTP headers.

Defined (1)

The class is defined in the following location(s).

/wp-includes/Requests/Response/Headers.php  
  1. class Requests_Response_Headers extends Requests_Utility_CaseInsensitiveDictionary { 
  2. /** 
  3. * Get the given header 
  4. * Unlike {@see self::getValues()}, this returns a string. If there are 
  5. * multiple values, it concatenates them with a comma as per RFC2616. 
  6. * Avoid using this where commas may be used unquoted in values, such as 
  7. * Set-Cookie headers. 
  8. * @param string $key 
  9. * @return string Header value 
  10. */ 
  11. public function offsetGet($key) { 
  12. $key = strtolower($key); 
  13. if (!isset($this->data[$key])) { 
  14. return null; 
  15.  
  16. return $this->flatten($this->data[$key]); 
  17.  
  18. /** 
  19. * Set the given item 
  20. * @throws Requests_Exception On attempting to use dictionary as list (`invalidset`) 
  21. * @param string $key Item name 
  22. * @param string $value Item value 
  23. */ 
  24. public function offsetSet($key, $value) { 
  25. if ($key === null) { 
  26. throw new Requests_Exception('Object is a dictionary, not a list', 'invalidset'); 
  27.  
  28. $key = strtolower($key); 
  29.  
  30. if (!isset($this->data[$key])) { 
  31. $this->data[$key] = array(); 
  32.  
  33. $this->data[$key][] = $value; 
  34.  
  35. /** 
  36. * Get all values for a given header 
  37. * @param string $key 
  38. * @return array Header values 
  39. */ 
  40. public function getValues($key) { 
  41. $key = strtolower($key); 
  42. if (!isset($this->data[$key])) { 
  43. return null; 
  44.  
  45. return $this->data[$key]; 
  46.  
  47. /** 
  48. * Flattens a value into a string 
  49. * Converts an array into a string by imploding values with a comma, as per 
  50. * RFC2616's rules for folding headers. 
  51. * @param string|array $value Value to flatten 
  52. * @return string Flattened value 
  53. */ 
  54. public function flatten($value) { 
  55. if (is_array($value)) { 
  56. $value = implode(', ', $value); 
  57.  
  58. return $value; 
  59.  
  60. /** 
  61. * Get an iterator for the data 
  62. * Converts the internal 
  63. * @return ArrayIterator 
  64. */ 
  65. public function getIterator() { 
  66. return new Requests_Utility_FilteredIterator($this->data, array($this, 'flatten'));