diff -r 34716fd837a4 -r be944660c56a wp/wp-includes/class-wp-simplepie-file.php --- a/wp/wp-includes/class-wp-simplepie-file.php Tue Dec 15 15:52:01 2020 +0100 +++ b/wp/wp-includes/class-wp-simplepie-file.php Wed Sep 21 18:19:35 2022 +0200 @@ -10,6 +10,9 @@ /** * Core class for fetching remote files and reading local files with SimplePie. * + * This uses Core's HTTP API to make requests, which gives plugins the ability + * to hook into the process. + * * @since 2.8.0 * * @see SimplePie_File @@ -21,15 +24,17 @@ * * @since 2.8.0 * @since 3.2.0 Updated to use a PHP5 constructor. + * @since 5.6.1 Multiple headers are concatenated into a comma-separated string, + * rather than remaining an array. * * @param string $url Remote file URL. - * @param integer $timeout Optional. How long the connection should stay open in seconds. + * @param int $timeout Optional. How long the connection should stay open in seconds. * Default 10. - * @param integer $redirects Optional. The number of allowed redirects. Default 5. + * @param int $redirects Optional. The number of allowed redirects. Default 5. * @param string|array $headers Optional. Array or string of headers to send with the request. * Default null. * @param string $useragent Optional. User-agent value sent. Default null. - * @param boolean $force_fsockopen Optional. Whether to force opening internet or unix domain socket + * @param bool $force_fsockopen Optional. Whether to force opening internet or unix domain socket * connection or not. Default false. */ public function __construct( $url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false ) { @@ -60,8 +65,32 @@ if ( is_wp_error( $res ) ) { $this->error = 'WP HTTP Error: ' . $res->get_error_message(); $this->success = false; + } else { - $this->headers = wp_remote_retrieve_headers( $res ); + $this->headers = wp_remote_retrieve_headers( $res ); + + /* + * SimplePie expects multiple headers to be stored as a comma-separated string, + * but `wp_remote_retrieve_headers()` returns them as an array, so they need + * to be converted. + * + * The only exception to that is the `content-type` header, which should ignore + * any previous values and only use the last one. + * + * @see SimplePie_HTTP_Parser::new_line(). + */ + foreach ( $this->headers as $name => $value ) { + if ( ! is_array( $value ) ) { + continue; + } + + if ( 'content-type' === $name ) { + $this->headers[ $name ] = array_pop( $value ); + } else { + $this->headers[ $name ] = implode( ', ', $value ); + } + } + $this->body = wp_remote_retrieve_body( $res ); $this->status_code = wp_remote_retrieve_response_code( $res ); }