Code Monkey home page Code Monkey logo

Comments (7)

csandanov avatar csandanov commented on August 27, 2024 1

Our README for WordPress preset states clearly:

VARNISH_WP_PRESERVED_COOKIES:
Not affected by $VARNISH_KEEP_ALL_COOKIES

and

Cookies ($VARNISH_STRIP_COOKIES) stripped unless $VARNISH_KEEP_ALL_COOKIES is set

and

VARNISH_STRIP_COOKIES
Ignored if $VARNISH_KEEP_ALL_COOKIES is set

Also, the search by $VARNISH_KEEP_ALL_COOKIES in the repository will show you that it clearly has nothing to do with WordPress preset:

{{ if not (getenv "VARNISH_KEEP_ALL_COOKIES") }}
set req.http.vckey = ";" + req.http.Cookie;
set req.http.vckey = regsuball(req.http.vckey, "; +", ";");
set req.http.vckey = regsuball(req.http.vckey, ";(VCKEY-[a-zA-Z0-9-_]+)=", "; \1=");
set req.http.vckey = regsuball(req.http.vckey, ";[^ ][^;]*", "");
set req.http.vckey = regsuball(req.http.vckey, "^[; ]+|[; ]+$", "");
{{ $cookies := (getenv "VARNISH_STRIP_COOKIES" "__[a-z]+|wooTracker|VCKEY-[a-zA-Z0-9-_]+") }}
set req.http.Cookie = regsuball(req.http.Cookie, "(^|;\s*)({{ $cookies }})=[^;]*", "");
set req.http.Cookie = regsub(req.http.Cookie, "^;\s*", "");
if (req.http.Cookie ~ "^\s*$") {
unset req.http.Cookie;
}
{{ end }}

from varnish.

urbangrz avatar urbangrz commented on August 27, 2024

Some more info
varnish implementation: varnish:4.1-4.1.2.
Wodby infrastructure version: 5.5.3
Wordpress stack version: wordpress-php:7.2-4.11.0

from varnish.

kuveljicdev avatar kuveljicdev commented on August 27, 2024

Chingis we saw this stuff and it appears that you guys decided to remove from PHP all cookies except the ones that are preserved in Varnish.

Even dough we set the varnish keep all cookies the cookies are not in PHP except the varnish preserved ones but than the page is not cached which is not an ideal approach. What if like in our case u need a cookie to be reached in PHP but not to affect on the cache, we were unable to configure that with the available configs.

Is it possible at all to achive that now with the provided params and avoid huge costs?

from varnish.

kuveljicdev avatar kuveljicdev commented on August 27, 2024

@csandanov what about this part here

# Remove all cookies that WordPress doesn't need to know about. We explicitly
# list the ones that WordPress does need. If, after
# running this code we find that either of these two cookies remains, we
# will pass as the page cannot be cached.
if (req.http.Cookie) {
{{ $preserved_cookies := (getenv "VARNISH_WP_PRESERVED_COOKIES" "PHPSESSID|wp-postpass_[a-z0-9]+|wordpress_[_a-z0-9]+|wordpress_logged_in_[a-z0-9]+|woocommerce_cart_hash|woocommerce_items_in_cart|wp_woocommerce_session_[a-z0-9]+|akm_mobile") }}
# 1. Append a semi-colon to the front of the cookie string.
# 2. Remove all spaces that appear after semi-colons.
# 3. Match the cookies we want to keep, adding the space we removed
# previously back. (\1) is first matching group in the regsuball.
# 4. Remove all other cookies, identifying them by the fact that they have
# no space after the preceding semi-colon.
# 5. Remove all spaces and semi-colons from the beginning and end of the
# cookie string.
set req.http.Cookie = ";" + req.http.Cookie;
set req.http.Cookie = regsuball(req.http.Cookie, "; +", ";");
set req.http.Cookie = regsuball(req.http.Cookie, ";({{ $preserved_cookies }})=", "; \1=");
set req.http.Cookie = regsuball(req.http.Cookie, ";[^ ][^;]*", "");
set req.http.Cookie = regsuball(req.http.Cookie, "^[; ]+|[; ]+$", "");
if (req.http.Cookie == "") {
# If there are no remaining cookies, remove the cookie header. If there
# aren't any cookie headers, Varnish's default behavior will be to cache
# the page.
unset req.http.Cookie;
}
else {
# If there is any cookies left (a session or NO_CACHE cookie), do not
# cache the page. Pass it on to Apache directly.
return (pass);
}
}

If there is a cookie here and it's not in the preserved ones it would be stripped and then missing in PHP. Here the VARNISH_KEEP_ALL_COOKIES is not even mentioned....

from varnish.

csandanov avatar csandanov commented on August 27, 2024

If it does not find the cookies from the preserved it would unset them and they would not be in PHP, sounds like a bug to me.

What makes you think it's a bug? WordPress preset description states:

If a cookie from $VARNISH_WP_PRESERVED_COOKIES is set a page will not be cached. All other cookies stripped

VARNISH_WP_PRESERVED_COOKIES:

Not affected by $VARNISH_KEEP_ALL_COOKIES

Also see https://varnish-cache.org/docs/3.0/tutorial/cookies.html:

Also, if the client sends a Cookie header, Varnish will bypass the cache and go directly to the backend.

from varnish.

kuveljicdev avatar kuveljicdev commented on August 27, 2024

@csandanov obviously you don’t have a full coverage of cases and that’s why you are asking why do we consider this a bug, if you change something that has a negative impact without a backwards compatibility than it must be a buggy approach (clean coding principle) -the way it was before it worked for us perfectly. If a cookie in VARNISH_WP_PRESERVED_COOKIES is set the page would not be cache and all others would be stripped, what is the purpose of VARNISH_KEEP_ALL_COOKIES than? Beside that how do we affect now on the negative rule changes since you don’t have a roll back to the previous stack. It would be much easier if this config would be working VARNISHD_VCL_SCRIPT but it’s not, why not (you told us to use the configs but this one does not work on the prod server)?

from varnish.

csandanov avatar csandanov commented on August 27, 2024

if you change something that has a negative impact without a backwards compatibility than it must be a buggy approach -the way it was before it worked for us perfectly.

it's not an argument, we've made many changes without backward compatibility in our images and reflected in our changelog. It may be worked for you perfectly but it did not for others. Which is the main reason why we changed the caching logic in the first place, we now use the same approach for WP as we've been using in Drupal preset for years.

If you need to preserve additional WP cookies you can always override $VARNISH_WP_PRESERVED_COOKIES.

what is the purpose of VARNISH_KEEP_ALL_COOKIES than?

I've already replied here above, also simple search in README will help you.

It would be much easier if this config would be working VARNISHD_VCL_SCRIPT but it’s not

Why not? We do not limit usage of any environment variables. Or do you refer to the managed stack on Wodby platform? Please note it's a public repository of the docker image that people use outside of Wodby.

you told us to use the configs but this one does not work on the prod server

This is not the support channel for your application.

--

I'm going to lock this issue since I couldn't recognize any valid bug reports for this image.

from varnish.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.