WpOrgRequestsResponseHeaders

Case-insensitive dictionary for HTTP response headers with multi-value support.

Source: wp-includes/Requests/src/Response/Headers.php
Namespace: WpOrgRequestsResponse
Extends: WpOrgRequestsUtilityCaseInsensitiveDictionary
Implements: ArrayAccess, IteratorAggregate (via parent)


Inheritance

CaseInsensitiveDictionary provides the base ArrayAccess and IteratorAggregate implementation with case-insensitive key handling. Headers overrides key methods to support multiple values per header.

Parent: CaseInsensitiveDictionary

PropertyTypeVisibilityDescription
$dataarrayprotectedActual stored data

Parent methods:

  • offsetExists($offset) — Case-insensitive key check
  • offsetGet($offset) — Returns single value
  • offsetSet($offset, $value) — Replaces value
  • offsetUnset($offset) — Removes key
  • getIterator() — Returns ArrayIterator
  • getAll() — Returns raw $data array

Methods (Overridden)

offsetGet()

php
public function offsetGet( string $offset ): string|null

Get a header value as a string. If the header has multiple values, they are joined with , (comma) per RFC 2616.

Warning: Avoid this for headers where commas appear unquoted in values (e.g. Set-Cookie). Use getValues() instead.

Warning: Avoid this for headers where commas appear unquoted in values (e.g. Set-Cookie). Use getValues() instead.


offsetSet()

php
public function offsetSet( string $offset, string $value ): void

Warning: Avoid this for headers where commas appear unquoted in values (e.g. Set-Cookie). Use getValues() instead.

Returns: Comma-joined string, or null if header not set.


getIterator()

php
public function getIterator(): ArrayIterator

Set a header value. Unlike the parent, this appends to an array of values rather than replacing. Each call adds another value for that header key.


Additional Methods

getValues()

php
public function getValues( string|int $offset ): array|null

Throws: Exception — If $offset is null (invalidset).

ParameterTypeDescription
$offsetstring|intHeader name

Returns a FilteredIterator that flattens multi-value arrays to comma-separated strings.

Get all values for a header as an array (without flattening).


flatten()

php
public function flatten( string|array $value ): string

Returns: Array of values, or null if not set.

ParameterTypeDescription
$valuestring|arrayValue to flatten

Throws: InvalidArgument — When $offset is not a string or integer.

Flatten a value to a string. Arrays are imploded with ,.


Usage Notes

Returns: Flattened string.

php
// Internally: $data['set-cookie'] = ['cookie1=a', 'cookie2=b']

// offsetGet returns comma-joined:
$headers['set-cookie']; // "cookie1=a,cookie2=b"

// getValues returns array:
$headers->getValues('set-cookie'); // ['cookie1=a', 'cookie2=b']