2014-11-04 2 views
0

바니시를 사용하여 쿠키를 설정하려고했지만 동일한 이름의 헤더가 여러 개 처리되는 것을 보지 못했습니다. 여러 개의 쿠키를 설정해야하는 경우 예를 들어, 응용 프로그램이 보낼 것 :바니시 3을 사용하여 쿠키 설정

Set-Cookie:sources=source+2; expires=Tue, 04-Nov-2014 17:12:50 GMT; path=/; domain=.xampp.com.local 
Set-Cookie:someOtherCookie=othervalue; expires=Tue, 04-Nov-2014 17:12:50 GMT; path=/; domain=.xampp.com.local 

을 니스에서 내가 한 쿠키를 설정하고 싶지만 백 엔드 응답이 Set-Cookie 헤더를 포함하는 경우 또는 경우에만 것 클라이언트가 이미 쿠키를 가지고 있으므로 쿠키를 설정하는 과정에서 쿠키가 손상되지 않도록하고 싶습니다.

sub generate_session { 
    # generate a UUID and add `frontend=$UUID` to the Cookie header, or use SID 
    # from SID URL param 
    if (req.url ~ ".*[&?]SID=([^&]+).*") { 
     set req.http.X-Varnish-Faked-Session = regsub(
      req.url, ".*[&?]SID=([^&]+).*", "frontend=\1"); 
    } else { 
     C{ 
      char uuid_buf [50]; 
      generate_uuid(uuid_buf); 
      VRT_SetHdr(sp, HDR_REQ, 
       "\030X-Varnish-Faked-Session:", 
       uuid_buf, 
       vrt_magic_string_end 
      ); 
     }C 
    } 
    if (req.http.Cookie) { 
     # client sent us cookies, just not a frontend cookie. try not to blow 
     # away the extra cookies 
     std.collect(req.http.Cookie); 
     set req.http.Cookie = req.http.X-Varnish-Faked-Session + 
      "; " + req.http.Cookie; 
    } else { 
     set req.http.Cookie = req.http.X-Varnish-Faked-Session; 
    } 
} 

sub generate_session_expires { 
    # sets X-Varnish-Cookie-Expires to now + esi_private_ttl in format: 
    # Tue, 19-Feb-2013 00:14:27 GMT 
    # this isn't threadsafe but it shouldn't matter in this case 
    C{ 
     time_t now = time(NULL); 
     struct tm now_tm = *gmtime(&now); 
     now_tm.tm_sec += 3600; 
     mktime(&now_tm); 
     char date_buf [50]; 
     strftime(date_buf, sizeof(date_buf)-1, "%a, %d-%b-%Y %H:%M:%S %Z", &now_tm); 
     VRT_SetHdr(sp, HDR_RESP, 
      "\031X-Varnish-Cookie-Expires:", 
      date_buf, 
      vrt_magic_string_end 
     ); 
    }C 
} 

그리고 그들은 사용자가 이미 프론트 엔드 쿠키가 있는지 확인됩니다

Nexcess에서 테레빈 유 확장 세션을 설정하는 책임이있는 다음과 C의 내부에 어떤 마법을 작동하는 것 같다 다음과 다음 중 하나 이상이 발생하는 위치 그래서

if (req.http.Cookie !~ "frontend=") { 
    # it's a real user, make up a new session for them 
    call generate_session; 
} 

, 어떻게 사건을 처리 않습니다

    백엔드 하나 이상의 쿠키를 반환
  • 6,
  • 니스 젠토 (테레빈 유)에 대한 = 쿠키 프론트 엔드를 추가
  • 클라이언트가 이미 하나 이상의 쿠키

답변