Skip to content

LiteSpeed HTML comment appended to response breaks JSON #212

@westonruter

Description

@westonruter

The WordPress AMP plugin generates JSON responses when performing AMP validation. LiteSpeed Cache is currently appending this HTML comment to all responses, including those which do not have a text/html content type. This is breaking the AMP plugin's ability to obtain validation results. I've had to provide users with a workaround plugin to disable the litespeed_comment filter.

This logic here:

if ( $this->footer_comment ) {
$buffer .= $this->footer_comment ;
}

The condition should be changed as follows:

$content_type = ini_get( 'default_mimetype' );
foreach ( headers_list() as $header ) {
	list( $name, $value ) = explode( ':', $header, 2 );
	if ( 'content-type' === strtolower( $name ) ) {
		$content_type = trim( $value );
		break;
	}
}
if ( $this->footer_comment && 'text/html' === substr( $content_type, 0, 9 ) ) {

Support forum topics:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions