문제

내가 올바른 질문을하고 있는지 확실하지 않습니다. 나는 수많은 쿠키에 접근 할 수있는 사이트에 배니가 앉아 있습니다. 가장 중요한 것은 Creds 쿠키입니다. 내가하고있는 일은 필요하지 않은 모든 쿠키를 벗기고 쿠키가 남아 있는지 확인하는 것입니다. 그렇다면 이것은 바니시를 우회하고 그렇지 않으면 캐시 객체를 반환한다는 것을 의미합니다.

  # 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);
    }
  }
}

이것은 잘 작동합니다. 캐시가 누락 될 때 얻을 수 있습니다 auth 쿠키가 거기에 있고 그렇지 않으면 타격을 입었습니다. 그러나 미스 일 때도 바니시는 요청에 나온 나머지 쿠키없이 요청을 통과하는 것 같습니다. 오리지널 쿡을 통과하도록 바니시를 지시하는 방법이 있습니까?

어쩌면

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);
}
도움이 되었습니까?

해결책

구문 분석하기 전에 원본 쿠키를 복사하여 복원 할 수 있습니다. else 진술, 같은 말 :

  # ....
  # 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);
    }
  }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top