HeadersCollection::set( string $name, string|WordPressAiClientProvidersHttpCollectionslist $value ): void

In this article

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only by core. It is listed here for completeness.

Sets a header value, replacing any existing value.

Parameters

$namestringrequired
The header name.
$valuestring|<span class="WordPressAiClientProvidersHttpCollectionslist”>WordPressAiClientProvidersHttpCollectionslistrequired
The header value(s).

Return

void

Source

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;
}

Changelog

VersionDescription
0.1.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.