Code example for HttpCookie

Methods: getDiscard, getMaxAge, hasExpired

0
        // In Set-Cookie header, max-age does not take effect when expires 
        // exists. 
        list = HttpCookie
                .parse("Set-Cookie:name=test;expires=Tue, 27-Jan-1998 19:14:07 GMT;Max-Age=1000");
        cookie = list.get(0);
        assertTrue(cookie.getMaxAge() < 0);
        assertTrue(cookie.hasExpired());
        assertFalse(cookie.getDiscard());
        // Reverse sequence. max-age takes effect and decides the result of 
        // hasExpired() method. 
        list = HttpCookie
                .parse("Set-Cookie:name=value;max-age=1000;expires=Tue, 17-Jan-1998 19:14:07 GMT;version=1");
        cookie = list.get(0);
        assertEquals(0, cookie.getVersion());
        assertEquals(1000, cookie.getMaxAge());
        assertFalse(cookie.hasExpired());
 
        // expires decides the version. Not take Set-cookie header, version into 
        // consideration if expires exists. 
        list = HttpCookie
                .parse("Set-Cookie2:name=value;max-age=1000;version=1;expires=Tue, 17-Jan-1998 19:07:14 GMT;");