litespeedtech / litespeedtech/lscache_wp

LiteSpeed HTML comment appended to response breaks JSON

Open
#212 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
257
Forks
123
PR merge metrics
No merged PRs in 30d

Description

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](https://gist.github.com/westonruter/e588bd4ed1778799b19417c838eb5e5e) plugin to disable the `litespeed_comment` filter.

This logic here:

https://github.com/litespeedtech/lscache_wp/blob/6f3e5bd70db78e1900a8ba0c68765c7257534f5c/litespeed-cache/inc/litespeed-cache.class.php#L556-L558

The condition should be changed as follows:

```php
$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:

* https://wordpress.org/support/topic/amp-not-working-with-litespeed/#post-12716407
* https://wordpress.org/support/topic/url-validation-failed-due-to-unexpected-json-in-amp-validation-response-2/

Contributor guide

No contributing guide indexed for this repository

Research direction

Open litespeed-cache/inc/litespeed-cache.class.php around lines 556-558 and inspect how the footer comment is appended. Reproduce the AMP validation response or another non-HTML response, then verify that the comment is only appended for text/html content types while HTML responses retain it.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, wordpress
Domain
backend, web-dev
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.