vary being ignored

#1
.htaccess
<IfModule LiteSpeed>
RewriteEngine On
CacheLookup public on
RewriteCond %{HTTP:Accept-Language} ^de [NC]
RewriteRule .* - [E=Cache-Control:vary=de]
</IfModule>


test.php
<?php
header('Content-type: image/svg+xml');
header('X-LiteSpeed-Cache-Control: public,max-age=30'); // In the actual application max-age is a calculated value
?>


Testing using curl:
curl -v "https://www.example.com/test.php" -H "Accept-Language: en"

first call:
x-litespeed-cache: miss
later calls:
x-litespeed-cache: hit
That is good!


curl -v "https://www.example.com/test.php" -H "Accept-Language: de"

first call:
x-litespeed-cache: miss
later calls:
x-litespeed-cache: miss
That is bad. How do I fix this?
 

serpent_driver

Well-Known Member
#2
RewriteCond %{HTTP:Accept-Language} ^de [NC]
RewriteRule .* - [E=Cache-Control:vary=%{ENV:LSCACHE_VARY_VALUE}+de]
or
Code:
RewriteCond %{HTTP:Accept-Language} de|it|en|es|fr [NC]
RewriteRule .* - [E=Cache-Control:vary=%{ENV:LSCACHE_VARY_VALUE}+lang]
 

serpent_driver

Well-Known Member
#5
Or try this:
Code:
RewriteCond %{HTTP:Accept-Language} (.+) [NC]
RewriteRule .* - [E=Cache-Control:vary=%{ENV:LSCACHE_VARY_VALUE}+lang:%1]
 
#6
After the first one didn't work, I tried the second, too, of course.
You know what is strange? If I remove the Content-type header, it works (my first attempt does, too). But I need that header. My script creates an image.
 
#13
With this header it works:
header('Content-Type: text/html');

With this header it does not:
header('Content-Type: image/svg+xml');

Nothing else changed. I checked this several times. What is going on here?
 

AndreyPopov

Well-Known Member
#14
it may be because: LSCache store cached page as static HTML file with header('Content-Type: text/html');

you can open saved cached file and see that it's always Content-Type: text/html
 
#15
If I flush the cache and access the "de" version first and then the "en" version, LiteSpeed serves me the "de" version. It seems to ignore the vary during the first access.
The cached file contains a string "content-type: image/svg+xml2".

Could someone please try the minimum code example I posted? Maybe my webspace provider has some kind of misconfiguration?
 

AndreyPopov

Well-Known Member
#16
learn how you lscache save file.

- cached url
- route path
- _lscache_vary cookie (if sets) (for different languanges (de) cookie _lscache_vary must be sets to language=de )
- vary value (if sets by rewrite rules - in this example ismobile)
- other cookies
- lscache tags



that's why try use
X-LiteSpeed-Vary: cookie="language=de" for de
and
X-LiteSpeed-Vary: cookie="" for en
 

Attachments

#17
Luckily, I have access to those cache files.

These are the two examples. I ONLY changed the Content-Type in the .php file. Nothing else.

Both files were created after calling the identical:
curl -v "https://www.example.com/test.php" -H "Accept-Language: de"
 

Attachments

AndreyPopov

Well-Known Member
#18
PHP:
<?php
header('Content-type: image/svg+xml');
header('X-LiteSpeed-Cache-Control: public,max-age=30'); 
if (strpos($_SERVER['HTTP_ACCEPT_LANGUAGE'], 'de') !== FALSE) {
    header('X-LiteSpeed-Vary: cookie="language=de"');
    }
?>
??????
 
Top