Question

Je ne sais pas si je pose la bonne question. J'ai du vernis assis devant un site qui a accès à de nombreux cookies. Les plus importants sont les crédits de cookie. Ce que je fais, c'est en déshabiller tous les cookies dont je n'ai pas besoin, puis vérifier s'il reste du cookie. Si c'est le cas, cela signifie que nous contournons le vernis, sinon renvoie l'objet Cache.

  # Remove all cookies that Drupal doesn't need to know about. We explicitly 
  # list the ones that Drupal does need, the SESS , NO_CACHE and credential cookie namely  auth 
  #. 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) {
    # 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, ";(SESS[a-z0-9]+|SSESS[a-z0-9]+|NO_CACHE+|auth)=", "; \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);
    }
  }
}

Cela fonctionne bien. Je reçois un cache manque quand auth Cookie est là-dedans et un coup autrement. Cependant, même lorsqu'il s'agit d'une miss, il semble que le vernis passe la demande sans le reste des cookies qui sont venus dans la demande. Existe-t-il un moyen de diriger le vernis pour passer le Cooke d'origine?

Peut-être quelque chose comme

else {
  # If there is any cookies left (a session or NO_CACHE cookie), do not
  # cache the page. Pass it on to Apache directly.
  # And set the cookie to its original form ??
  return (pass);
}
Était-ce utile?

La solution

Vous pouvez copier un cookie original avant de l'analyser et de le restaurer sur else déclaration, étanche comme:

  # ....
  # Store original cookie in other headder
  set req.http.X-Cookie = req.http.Cookie;
  if (req.http.Cookie) {
    # ... 
    set req.http.Cookie = ";" + req.http.Cookie;
    set req.http.Cookie = regsuball(req.http.Cookie, "; +", ";");    
    set req.http.Cookie = regsuball(req.http.Cookie, ";(SESS[a-z0-9]+|SSESS[a-z0-9]+|NO_CACHE+|auth)=", "; \1=");
    set req.http.Cookie = regsuball(req.http.Cookie, ";[^ ][^;]*", "");
    set req.http.Cookie = regsuball(req.http.Cookie, "^[; ]+|[; ]+$", "");

    if (req.http.Cookie == "") {
      # ....
      # Delete cookie copy
      unset req.http.X-Cookie;
      unset req.http.Cookie;
    }
    else {
      # ...
      # Restore original cookie and delete the copy
      set req.http.Cookie = req.http.X-Cookie;
      unset req.http.X-Cookie;
      return (pass);
    }
  }
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top