2014-11-04 38 views
0

我試圖使用光油設置一個cookie,但沒有看到如何處理多個相同名稱的標題。舉例來說,如果多個Cookie需要設置,應用程序將發送:使用光油3來設置Cookie

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 

清漆,我會永遠只需要設置一個cookie的,但如果後端響應包括一個Set-Cookie頭,或者客戶端已經有Cookie,我想確定我沒有在設置我的Cookie的過程中銷燬它們。

從Nexcess松節油擴展似乎工作的一些神奇的C內部與負責建立會話如下:

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 
} 

他們正在檢查,看看是否用戶已經有一個前端的cookie有以下幾點:

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

那麼,我該如何處理的情況下,其中一個或多個以下的正在發生:

  • 光油是增加前端的Magento的(松節油)=餅乾
  • 後臺返回一個或多個Cookie
  • 的客戶端已經有一個或多個Cookie

回答