WordPress\AiClient\Providers\Http\Collections
HeadersCollection::set
Sets a header value, replacing any existing value.
Method of the class: HeadersCollection{}
No Hooks.
Returns
null. Nothing (null).
Usage
// private - for code of main (parent) class only $result = $this->set( $name, $value ): void;
- $name(string) (required)
- The header name.
- $value(string|list
) (required) - The header value(s).
Changelog
| Since 0.1.0 | Introduced. |
HeadersCollection::set() HeadersCollection::set code WP 7.0
private function set(string $name, $value): void
{
if (is_array($value)) {
$normalizedValues = array_values($value);
} else {
// Split comma-separated string into array
$normalizedValues = array_map('trim', explode(',', $value));
}
$lowerName = strtolower($name);
// If header exists with different casing, remove the old casing
if (isset($this->headersMap[$lowerName])) {
$oldName = $this->headersMap[$lowerName];
if ($oldName !== $name) {
unset($this->headers[$oldName]);
}
}
// Always use the new casing
$this->headers[$name] = $normalizedValues;
$this->headersMap[$lowerName] = $name;
}