From 28358ab213ba26894bb9827f87f5530643d609be Mon Sep 17 00:00:00 2001 From: audrasjb Date: Fri, 3 Feb 2023 13:35:20 +0000 Subject: [PATCH] HTTP API: Fix request header inconsistencies. This changeset improves the consistency in capitalization of fetching and outputting of request headers. It also updates occurrences found in some docblocks. Props johnjamesjacoby, costdev, audrasjb, petitphp, mhkuu, SergeyBiryukov. Fixes #54225. Built from https://develop.svn.wordpress.org/trunk@55210 git-svn-id: http://core.svn.wordpress.org/trunk@54743 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/ajax-actions.php | 2 +- wp-admin/includes/file.php | 6 +++--- wp-admin/includes/upgrade.php | 2 +- wp-includes/class-json.php | 2 +- wp-includes/class-simplepie.php | 4 ++-- wp-includes/class-snoopy.php | 12 ++++++------ wp-includes/comment.php | 6 +++--- wp-includes/functions.php | 4 ++-- wp-includes/general-template.php | 2 +- wp-includes/pluggable.php | 2 +- wp-includes/rest-api/class-wp-rest-request.php | 12 ++++++------ wp-includes/sitemaps/class-wp-sitemaps-renderer.php | 4 ++-- .../sitemaps/class-wp-sitemaps-stylesheet.php | 2 +- wp-includes/version.php | 2 +- wp-mail.php | 2 +- 15 files changed, 32 insertions(+), 32 deletions(-) diff --git a/wp-admin/includes/ajax-actions.php b/wp-admin/includes/ajax-actions.php index 35090e2288..a4e4e810df 100644 --- a/wp-admin/includes/ajax-actions.php +++ b/wp-admin/includes/ajax-actions.php @@ -2532,7 +2532,7 @@ function wp_ajax_upload_attachment() { check_ajax_referer( 'media-form' ); /* * This function does not use wp_send_json_success() / wp_send_json_error() - * as the html4 Plupload handler requires a text/html content-type for older IE. + * as the html4 Plupload handler requires a text/html Content-Type for older IE. * See https://core.trac.wordpress.org/ticket/31037 */ diff --git a/wp-admin/includes/file.php b/wp-admin/includes/file.php index 62e9c0cb91..6d22898b9c 100644 --- a/wp-admin/includes/file.php +++ b/wp-admin/includes/file.php @@ -1184,7 +1184,7 @@ function download_url( $url, $timeout = 300, $signature_verification = false ) { return new WP_Error( 'http_404', trim( wp_remote_retrieve_response_message( $response ) ), $data ); } - $content_disposition = wp_remote_retrieve_header( $response, 'content-disposition' ); + $content_disposition = wp_remote_retrieve_header( $response, 'Content-Disposition' ); if ( $content_disposition ) { $content_disposition = strtolower( $content_disposition ); @@ -1211,7 +1211,7 @@ function download_url( $url, $timeout = 300, $signature_verification = false ) { } } - $content_md5 = wp_remote_retrieve_header( $response, 'content-md5' ); + $content_md5 = wp_remote_retrieve_header( $response, 'Content-MD5' ); if ( $content_md5 ) { $md5_check = verify_file_md5( $tmpfname, $content_md5 ); @@ -1238,7 +1238,7 @@ function download_url( $url, $timeout = 300, $signature_verification = false ) { // Perform signature valiation if supported. if ( $signature_verification ) { - $signature = wp_remote_retrieve_header( $response, 'x-content-signature' ); + $signature = wp_remote_retrieve_header( $response, 'X-Content-Signature' ); if ( ! $signature ) { // Retrieve signatures from a file if the header wasn't included. diff --git a/wp-admin/includes/upgrade.php b/wp-admin/includes/upgrade.php index 63580cceb0..9c4cb43580 100644 --- a/wp-admin/includes/upgrade.php +++ b/wp-admin/includes/upgrade.php @@ -512,7 +512,7 @@ function wp_install_maybe_enable_pretty_permalinks() { * can block head requests. */ $response = wp_remote_get( $test_url, array( 'timeout' => 5 ) ); - $x_pingback_header = wp_remote_retrieve_header( $response, 'x-pingback' ); + $x_pingback_header = wp_remote_retrieve_header( $response, 'X-Pingback' ); $pretty_permalinks = $x_pingback_header && get_bloginfo( 'pingback_url' ) === $x_pingback_header; if ( $pretty_permalinks ) { diff --git a/wp-includes/class-json.php b/wp-includes/class-json.php index d651dcdfb8..6091d567f5 100644 --- a/wp-includes/class-json.php +++ b/wp-includes/class-json.php @@ -291,7 +291,7 @@ class Services_JSON { _deprecated_function( __METHOD__, '5.3.0', 'The PHP native JSON extension' ); - header('Content-type: application/json'); + header('Content-Type: application/json'); return $this->encodeUnsafe($var); } /** diff --git a/wp-includes/class-simplepie.php b/wp-includes/class-simplepie.php index a392e54cd9..3d639fc709 100644 --- a/wp-includes/class-simplepie.php +++ b/wp-includes/class-simplepie.php @@ -1864,7 +1864,7 @@ class SimplePie } /** - * Send the content-type header with correct encoding + * Send the Content-Type header with correct encoding * * This method ensures that the SimplePie-enabled page is being served with * the correct {@link http://www.iana.org/assignments/media-types/ mime-type} @@ -1886,7 +1886,7 @@ class SimplePie { if (!headers_sent()) { - $header = "Content-type: $mime;"; + $header = "Content-Type: $mime;"; if ($this->get_encoding()) { $header .= ' charset=' . $this->get_encoding(); diff --git a/wp-includes/class-snoopy.php b/wp-includes/class-snoopy.php index fb6857c525..e82c673989 100644 --- a/wp-includes/class-snoopy.php +++ b/wp-includes/class-snoopy.php @@ -53,7 +53,7 @@ class Snoopy var $cookies = array(); // array of cookies to pass // $cookies["username"]="joe"; var $rawheaders = array(); // array of raw headers to send - // $rawheaders["Content-type"]="text/html"; + // $rawheaders["Content-Type"]="text/html"; var $maxredirs = 5; // http redirection depth maximum. 0 = disallow var $lastredirectaddr = ""; // contains address of last redirected address @@ -825,13 +825,13 @@ class Snoopy $headers .= $headerKey.": ".$headerVal."\r\n"; } if(!empty($content_type)) { - $headers .= "Content-type: $content_type"; + $headers .= "Content-Type: $content_type"; if ($content_type == "multipart/form-data") $headers .= "; boundary=".$this->_mime_boundary; $headers .= "\r\n"; } if(!empty($body)) - $headers .= "Content-length: ".strlen($body)."\r\n"; + $headers .= "Content-Length: ".strlen($body)."\r\n"; if(!empty($this->user) || !empty($this->pass)) $headers .= "Authorization: Basic ".base64_encode($this->user.":".$this->pass)."\r\n"; @@ -990,12 +990,12 @@ class Snoopy } if(!empty($content_type)) { if ($content_type == "multipart/form-data") - $headers[] = "Content-type: $content_type; boundary=".$this->_mime_boundary; + $headers[] = "Content-Type: $content_type; boundary=".$this->_mime_boundary; else - $headers[] = "Content-type: $content_type"; + $headers[] = "Content-Type: $content_type"; } if(!empty($body)) - $headers[] = "Content-length: ".strlen($body); + $headers[] = "Content-Length: ".strlen($body); if(!empty($this->user) || !empty($this->pass)) $headers[] = "Authorization: BASIC ".base64_encode($this->user.":".$this->pass); diff --git a/wp-includes/comment.php b/wp-includes/comment.php index a52edf84f4..50a761f94a 100644 --- a/wp-includes/comment.php +++ b/wp-includes/comment.php @@ -2824,12 +2824,12 @@ function discover_pingback_server_uri( $url, $deprecated = '' ) { return false; } - if ( wp_remote_retrieve_header( $response, 'x-pingback' ) ) { - return wp_remote_retrieve_header( $response, 'x-pingback' ); + if ( wp_remote_retrieve_header( $response, 'X-Pingback' ) ) { + return wp_remote_retrieve_header( $response, 'X-Pingback' ); } // Not an (x)html, sgml, or xml page, no use going further. - if ( preg_match( '#(image|audio|video|model)/#is', wp_remote_retrieve_header( $response, 'content-type' ) ) ) { + if ( preg_match( '#(image|audio|video|model)/#is', wp_remote_retrieve_header( $response, 'Content-Type' ) ) ) { return false; } diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 623a69aba0..1d285b6cf7 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -943,8 +943,8 @@ function do_enclose( $content, $post ) { $headers = wp_get_http_headers( $url ); if ( $headers ) { - $len = isset( $headers['content-length'] ) ? (int) $headers['content-length'] : 0; - $type = isset( $headers['content-type'] ) ? $headers['content-type'] : ''; + $len = isset( $headers['Content-Length'] ) ? (int) $headers['Content-Length'] : 0; + $type = isset( $headers['Content-Type'] ) ? $headers['Content-Type'] : ''; $allowed_types = array( 'video', 'audio' ); // Check to see if we can figure out the mime type from the extension. diff --git a/wp-includes/general-template.php b/wp-includes/general-template.php index ba5e89737c..5f234f47a2 100644 --- a/wp-includes/general-template.php +++ b/wp-includes/general-template.php @@ -755,7 +755,7 @@ function bloginfo( $show = '' ) { * - 'admin_email' - Admin email (set in Settings > General) * - 'charset' - The "Encoding for pages and feeds" (set in Settings > Reading) * - 'version' - The current WordPress version - * - 'html_type' - The content-type (default: "text/html"). Themes and plugins + * - 'html_type' - The Content-Type (default: "text/html"). Themes and plugins * can override the default value using the {@see 'pre_option_html_type'} filter * - 'text_direction' - The text direction determined by the site's language. is_rtl() * should be used instead diff --git a/wp-includes/pluggable.php b/wp-includes/pluggable.php index a3cb0408b4..dded2fee86 100644 --- a/wp-includes/pluggable.php +++ b/wp-includes/pluggable.php @@ -463,7 +463,7 @@ if ( ! function_exists( 'wp_mail' ) ) : // Set Content-Type and charset. - // If we don't have a content-type from the input headers. + // If we don't have a Content-Type from the input headers. if ( ! isset( $content_type ) ) { $content_type = 'text/plain'; } diff --git a/wp-includes/rest-api/class-wp-rest-request.php b/wp-includes/rest-api/class-wp-rest-request.php index 494abd2360..18e867de3a 100644 --- a/wp-includes/rest-api/class-wp-rest-request.php +++ b/wp-includes/rest-api/class-wp-rest-request.php @@ -291,16 +291,16 @@ class WP_REST_Request implements ArrayAccess { } /** - * Retrieves the content-type of the request. + * Retrieves the Content-Type of the request. * * @since 4.4.0 * * @return array|null Map containing 'value' and 'parameters' keys - * or null when no valid content-type header was + * or null when no valid Content-Type header was * available. */ public function get_content_type() { - $value = $this->get_header( 'content-type' ); + $value = $this->get_header( 'Content-Type' ); if ( empty( $value ) ) { return null; } @@ -325,11 +325,11 @@ class WP_REST_Request implements ArrayAccess { } /** - * Checks if the request has specified a JSON content-type. + * Checks if the request has specified a JSON Content-Type. * * @since 5.6.0 * - * @return bool True if the content-type header is JSON. + * @return bool True if the Content-Type header is JSON. */ public function is_json_content_type() { $content_type = $this->get_content_type(); @@ -719,7 +719,7 @@ class WP_REST_Request implements ArrayAccess { $this->parsed_body = true; /* - * Check that we got URL-encoded. Treat a missing content-type as + * Check that we got URL-encoded. Treat a missing Content-Type as * URL-encoded for maximum compatibility. */ $content_type = $this->get_content_type(); diff --git a/wp-includes/sitemaps/class-wp-sitemaps-renderer.php b/wp-includes/sitemaps/class-wp-sitemaps-renderer.php index 11d5c3820a..9f91a10b7c 100644 --- a/wp-includes/sitemaps/class-wp-sitemaps-renderer.php +++ b/wp-includes/sitemaps/class-wp-sitemaps-renderer.php @@ -123,7 +123,7 @@ class WP_Sitemaps_Renderer { * @param array $sitemaps Array of sitemap URLs. */ public function render_index( $sitemaps ) { - header( 'Content-type: application/xml; charset=UTF-8' ); + header( 'Content-Type: application/xml; charset=UTF-8' ); $this->check_for_simple_xml_availability(); @@ -188,7 +188,7 @@ class WP_Sitemaps_Renderer { * @param array $url_list Array of URLs for a sitemap. */ public function render_sitemap( $url_list ) { - header( 'Content-type: application/xml; charset=UTF-8' ); + header( 'Content-Type: application/xml; charset=UTF-8' ); $this->check_for_simple_xml_availability(); diff --git a/wp-includes/sitemaps/class-wp-sitemaps-stylesheet.php b/wp-includes/sitemaps/class-wp-sitemaps-stylesheet.php index 8268fcc924..f752a7f55f 100644 --- a/wp-includes/sitemaps/class-wp-sitemaps-stylesheet.php +++ b/wp-includes/sitemaps/class-wp-sitemaps-stylesheet.php @@ -22,7 +22,7 @@ class WP_Sitemaps_Stylesheet { * @param string $type Stylesheet type. Either 'sitemap' or 'index'. */ public function render_stylesheet( $type ) { - header( 'Content-type: application/xml; charset=UTF-8' ); + header( 'Content-Type: application/xml; charset=UTF-8' ); if ( 'sitemap' === $type ) { // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- All content escaped below. diff --git a/wp-includes/version.php b/wp-includes/version.php index dd72204902..12301dbaea 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.2-alpha-55209'; +$wp_version = '6.2-alpha-55210'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. diff --git a/wp-mail.php b/wp-mail.php index 631645cbed..2600521e38 100644 --- a/wp-mail.php +++ b/wp-mail.php @@ -171,7 +171,7 @@ for ( $i = 1; $i <= $count; $i++ ) { $content = explode( '--' . $boundary, $content ); $content = $content[2]; - // Match case-insensitive content-transfer-encoding. + // Match case-insensitive Content-Transfer-Encoding. if ( preg_match( '/Content-Transfer-Encoding: quoted-printable/i', $content, $delim ) ) { $content = explode( $delim[0], $content ); $content = $content[1];