diff --git a/includes/class-wc-download-handler.php b/includes/class-wc-download-handler.php index fa279c8c6fd..00022f818b0 100644 --- a/includes/class-wc-download-handler.php +++ b/includes/class-wc-download-handler.php @@ -314,7 +314,7 @@ class WC_Download_Handler { /** * Fallback on force download method for remote files. This is because: * 1. xsendfile needs proxy configuration to work for remote files, which cannot be assumed to be available on most hosts. - * 2. Force download method is more secure than redirect method if `allow_url_fopen` is enabled in `php.ini`. We fallback to redirect method in force download method anyway in case `allow_url_fopen` is not enabled. + * 2. Force download method is more secure than redirect method if `allow_url_fopen` is enabled in `php.ini`. */ if ( $parsed_file_path['remote_file'] && ! apply_filters( 'woocommerce_use_xsendfile_for_remote', false ) ) { do_action( 'woocommerce_download_file_force', $file_path, $filename ); @@ -435,11 +435,7 @@ class WC_Download_Handler { $start = isset( $download_range['start'] ) ? $download_range['start'] : 0; $length = isset( $download_range['length'] ) ? $download_range['length'] : 0; if ( ! self::readfile_chunked( $parsed_file_path['file_path'], $start, $length ) ) { - if ( $parsed_file_path['remote_file'] ) { - self::download_file_redirect( $file_path ); - } else { - self::download_error( __( 'File not found', 'woocommerce' ) ); - } + self::download_error( __( 'File not found', 'woocommerce' ) ); } exit; @@ -620,6 +616,15 @@ class WC_Download_Handler { * @param integer $status Error status. */ private static function download_error( $message, $title = '', $status = 404 ) { + /* + * Since we will now render a message instead of serving a download, we should unwind some of the previously set + * headers. + */ + header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) ); + header_remove( 'Content-Description;' ); + header_remove( 'Content-Disposition' ); + header_remove( 'Content-Transfer-Encoding' ); + if ( ! strstr( $message, '' . esc_html__( 'Go to shop', 'woocommerce' ) . ''; }