WP_REST_Request::canonicalize_header_name() WordPress Method

The WP_REST_Request::canonicalize_header_name() method is used to transform a header name into a canonical form. This is useful for comparing header names, or for creating a case-insensitive header name.

WP_REST_Request::canonicalize_header_name( string $key ) #

Canonicalizes the header name.


Description

Ensures that header names are always treated the same regardless of source. Header names are always case insensitive.

Note that we treat - (dashes) and _ (underscores) as the same character, as per header parsing rules in both Apache and nginx.


Top ↑

Parameters

$key

(string)(Required)Header name.


Top ↑

Return

(string) Canonicalized name.


Top ↑

Source

File: wp-includes/rest-api/class-wp-rest-request.php

	public static function canonicalize_header_name( $key ) {
		$key = strtolower( $key );
		$key = str_replace( '-', '_', $key );

		return $key;
	}


Top ↑

Changelog

Changelog
VersionDescription
4.4.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.