Skip to content

Commit

Permalink
Fix output buffering for cross-origin isolation (#65701)
Browse files Browse the repository at this point in the history
  • Loading branch information
swissspidy committed Sep 28, 2024
1 parent 5ac6838 commit 88d60e4
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions lib/experimental/media/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,24 @@ function gutenberg_rest_get_attachment_filesize( array $post ): ?int {
return null;
}

/**
* Filters the list of rewrite rules formatted for output to an .htaccess file.
*
* Adds support for serving wasm-vips locally.
*
* @param string $rules mod_rewrite Rewrite rules formatted for .htaccess.
* @return string Filtered rewrite rules.
*/
function gutenberg_filter_mod_rewrite_rules( string $rules ): string {
$rules .= "\n# BEGIN Gutenberg client-side media processing experiment\n" .
"AddType application/wasm wasm\n" .
"# END Gutenberg client-side media processing experiment\n";

return $rules;
}

add_filter( 'mod_rewrite_rules', 'gutenberg_filter_mod_rewrite_rules' );

/**
* Enables cross-origin isolation in the block editor.
*
Expand Down Expand Up @@ -236,16 +254,11 @@ function gutenberg_start_cross_origin_isolation_output_buffer(): void {
$coep = $is_safari ? 'require-corp' : 'credentialless';

ob_start(
function ( string $output, ?int $phase ) use ( $coep ): string {
// Only send the header when the buffer is not being cleaned.
if ( ( $phase & PHP_OUTPUT_HANDLER_CLEAN ) === 0 ) {
header( 'Cross-Origin-Opener-Policy: same-origin' );
header( "Cross-Origin-Embedder-Policy: $coep" );

$output = gutenberg_add_crossorigin_attributes( $output );
}
function ( string $output ) use ( $coep ): string {
header( 'Cross-Origin-Opener-Policy: same-origin' );
header( "Cross-Origin-Embedder-Policy: $coep" );

return $output;
return gutenberg_add_crossorigin_attributes( $output );
}
);
}
Expand Down

0 comments on commit 88d60e4

Please sign in to comment.