2012-07-11 67 views
0

我想确保我的方法不会修改某些cookie,如PLAY_FLASH和PLAY_SESSION(为什么?因为bug 785)。如何阻止某个操作修改Cookie?

我尝试这样做:

// This method should never modify any PLAY cookie. 
public static void doNothingPost() throws InterruptedException { 
    logger.info("Done nothing"); 

    response.cookies.remove("PLAY_FLASH"); 
    response.cookies.remove("PLAY_ERRORS"); 
    response.cookies.remove("PLAY_SESSION"); 

    ok(); 
} 

嗯,事实证明,respone.cookies.remove()将积极删除Cookie(setCookie方法与过去的到期日)。我该如何告诉play不要为特定的cookie发送任何SetCookie头? (或全部?)

+0

另外在论坛上:https://groups.google.com/forum/?fromgroups#!topic/play-framework/kP5wb79OcIw – ripper234 2012-07-11 14:06:20

回答

0
  • T0 - >呼叫setSession
  • T5 - >调用doNothing
  • T10 - > setSession返回
  • T15 - > doNothing返回

    public static void setSession(String uuid){ 
        Cache.add(uuid, "guven"); 
        response.setCookie("username", "guven"); 
        await(1000); 
        ok(); 
    } 
    
    public static void doNothing(String sameUUIDWithSetSessionParameter){ 
        String username = Cache.get(sameUUIDWithSetSessionParameter, String.class); 
        Cache.delete(sameUUIDWithSetSessionParameter); 
        Logger.info("dn: " + username); 
        await(1000); 
        ok(); 
    } 
    

如果这些连续的ajax调用没有不同的会话ID,那么忘记uuid参数,只需使用session.getId()Cache得到价值