From a415c29efee45520ae252d2aa28f1083a521cd7b Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 09:56:49 +0200 Subject: Adding upstream version 6.4.3+dfsg1. Signed-off-by: Daniel Baumann --- wp-includes/class-wp-simplepie-file.php | 108 ++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 wp-includes/class-wp-simplepie-file.php (limited to 'wp-includes/class-wp-simplepie-file.php') diff --git a/wp-includes/class-wp-simplepie-file.php b/wp-includes/class-wp-simplepie-file.php new file mode 100644 index 0000000..0ad48fb --- /dev/null +++ b/wp-includes/class-wp-simplepie-file.php @@ -0,0 +1,108 @@ +url = $url; + $this->timeout = $timeout; + $this->redirects = $redirects; + $this->headers = $headers; + $this->useragent = $useragent; + + $this->method = SIMPLEPIE_FILE_SOURCE_REMOTE; + + if ( preg_match( '/^http(s)?:\/\//i', $url ) ) { + $args = array( + 'timeout' => $this->timeout, + 'redirection' => $this->redirects, + ); + + if ( ! empty( $this->headers ) ) { + $args['headers'] = $this->headers; + } + + if ( SIMPLEPIE_USERAGENT !== $this->useragent ) { // Use default WP user agent unless custom has been specified. + $args['user-agent'] = $this->useragent; + } + + $res = wp_safe_remote_request( $url, $args ); + + 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 ); + + /* + * 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 ); + } + } else { + $this->error = ''; + $this->success = false; + } + } +} -- cgit v1.2.3