public void validate( final Cookie cookie, final CookieOrigin origin) throws MalformedCookieException { if (cookie == null) { throw new IllegalArgumentException("Cookie may not be null"); } if (origin == null) { throw new IllegalArgumentException("Cookie origin may not be null"); } if (cookie.getVersion() > 0) { if (cookie instanceof SetCookie2) { getStrict().validate(cookie, origin); } else { getObsoleteStrict().validate(cookie, origin); } } else { getCompat().validate(cookie, origin); } }
public boolean match(final Cookie cookie, final CookieOrigin origin) { if (cookie == null) { throw new IllegalArgumentException("Cookie may not be null"); } if (origin == null) { throw new IllegalArgumentException("Cookie origin may not be null"); } if (cookie.getVersion() > 0) { if (cookie instanceof SetCookie2) { return getStrict().match(cookie, origin); } else { return getObsoleteStrict().match(cookie, origin); } } else { return getCompat().match(cookie, origin); } }
public List<Header> formatCookies(final List<Cookie> cookies) { if (cookies == null) { throw new IllegalArgumentException("List of cookies may not be null"); } int version = Integer.MAX_VALUE; boolean isSetCookie2 = true; for (Cookie cookie: cookies) { if (!(cookie instanceof SetCookie2)) { isSetCookie2 = false; } if (cookie.getVersion() < version) { version = cookie.getVersion(); } } if (version > 0) { if (isSetCookie2) { return getStrict().formatCookies(cookies); } else { return getObsoleteStrict().formatCookies(cookies); } } else { return getCompat().formatCookies(cookies); } }
public List<Header> formatCookies(final List<Cookie> cookies) { Args.notNull(cookies, "List of cookies"); int version = Integer.MAX_VALUE; boolean isSetCookie2 = true; for (final Cookie cookie: cookies) { if (!(cookie instanceof SetCookie2)) { isSetCookie2 = false; } if (cookie.getVersion() < version) { version = cookie.getVersion(); } } if (version > 0) { if (isSetCookie2) { return getStrict().formatCookies(cookies); } else { return getObsoleteStrict().formatCookies(cookies); } } else { return getCompat().formatCookies(cookies); } }
@Override public void validate( final Cookie cookie, final CookieOrigin origin) throws MalformedCookieException { Args.notNull(cookie, "Cookie"); Args.notNull(origin, "Cookie origin"); if (cookie.getVersion() > 0) { if (cookie instanceof SetCookie2) { strict.validate(cookie, origin); } else { obsoleteStrict.validate(cookie, origin); } } else { netscapeDraft.validate(cookie, origin); } }
@Override public List<Header> formatCookies(final List<Cookie> cookies) { Args.notNull(cookies, "List of cookies"); int version = Integer.MAX_VALUE; boolean isSetCookie2 = true; for (final Cookie cookie: cookies) { if (!(cookie instanceof SetCookie2)) { isSetCookie2 = false; } if (cookie.getVersion() < version) { version = cookie.getVersion(); } } if (version > 0) { if (isSetCookie2) { return strict.formatCookies(cookies); } else { return obsoleteStrict.formatCookies(cookies); } } else { return netscapeDraft.formatCookies(cookies); } }
public List<Header> formatCookies(final List<Cookie> cookies) { if (cookies == null) { throw new IllegalArgumentException("List of cookie may not be null"); } int version = Integer.MAX_VALUE; boolean isSetCookie2 = true; for (Cookie cookie: cookies) { if (!(cookie instanceof SetCookie2)) { isSetCookie2 = false; } if (cookie.getVersion() < version) { version = cookie.getVersion(); } } if (version > 0) { if (isSetCookie2) { return getStrict().formatCookies(cookies); } else { return getObsoleteStrict().formatCookies(cookies); } } else { return getCompat().formatCookies(cookies); } }
/** * validate cookie version attribute. Version attribute is REQUIRED. */ public void validate(final Cookie cookie, final CookieOrigin origin) throws MalformedCookieException { if (cookie == null) { throw new IllegalArgumentException("Cookie may not be null"); } if (cookie instanceof SetCookie2) { if (cookie instanceof ClientCookie && !((ClientCookie) cookie).containsAttribute(ClientCookie.VERSION_ATTR)) { throw new CookieRestrictionViolationException( "Violates RFC 2965. Version attribute is required."); } } }
/** * Parse cookie port attribute. */ public void parse(final SetCookie cookie, final String portValue) throws MalformedCookieException { if (cookie == null) { throw new IllegalArgumentException("Cookie may not be null"); } if (cookie instanceof SetCookie2) { SetCookie2 cookie2 = (SetCookie2) cookie; if (portValue != null && portValue.trim().length() > 0) { int[] ports = parsePortAttribute(portValue); cookie2.setPorts(ports); } } }
public void parse(final SetCookie cookie, final String commenturl) throws MalformedCookieException { if (cookie instanceof SetCookie2) { SetCookie2 cookie2 = (SetCookie2) cookie; cookie2.setCommentURL(commenturl); } }
public void parse(final SetCookie cookie, final String commenturl) throws MalformedCookieException { if (cookie instanceof SetCookie2) { SetCookie2 cookie2 = (SetCookie2) cookie; cookie2.setDiscard(true); } }
/** * Parse cookie port attribute. */ public void parse(final SetCookie cookie, final String portValue) throws MalformedCookieException { Args.notNull(cookie, "Cookie"); if (cookie instanceof SetCookie2) { final SetCookie2 cookie2 = (SetCookie2) cookie; if (portValue != null && portValue.trim().length() > 0) { final int[] ports = parsePortAttribute(portValue); cookie2.setPorts(ports); } } }
/** * validate cookie version attribute. Version attribute is REQUIRED. */ public void validate(final Cookie cookie, final CookieOrigin origin) throws MalformedCookieException { Args.notNull(cookie, "Cookie"); if (cookie instanceof SetCookie2) { if (cookie instanceof ClientCookie && !((ClientCookie) cookie).containsAttribute(ClientCookie.VERSION_ATTR)) { throw new CookieRestrictionViolationException( "Violates RFC 2965. Version attribute is required."); } } }
public void parse(final SetCookie cookie, final String commenturl) throws MalformedCookieException { if (cookie instanceof SetCookie2) { final SetCookie2 cookie2 = (SetCookie2) cookie; cookie2.setCommentURL(commenturl); } }
public void validate( final Cookie cookie, final CookieOrigin origin) throws MalformedCookieException { Args.notNull(cookie, "Cookie"); Args.notNull(origin, "Cookie origin"); if (cookie.getVersion() > 0) { if (cookie instanceof SetCookie2) { getStrict().validate(cookie, origin); } else { getObsoleteStrict().validate(cookie, origin); } } else { getCompat().validate(cookie, origin); } }
public boolean match(final Cookie cookie, final CookieOrigin origin) { Args.notNull(cookie, "Cookie"); Args.notNull(origin, "Cookie origin"); if (cookie.getVersion() > 0) { if (cookie instanceof SetCookie2) { return getStrict().match(cookie, origin); } else { return getObsoleteStrict().match(cookie, origin); } } else { return getCompat().match(cookie, origin); } }
public void parse(final SetCookie cookie, final String commenturl) throws MalformedCookieException { if (cookie instanceof SetCookie2) { final SetCookie2 cookie2 = (SetCookie2) cookie; cookie2.setDiscard(true); } }
/** * validate cookie version attribute. Version attribute is REQUIRED. */ @Override public void validate(final Cookie cookie, final CookieOrigin origin) throws MalformedCookieException { Args.notNull(cookie, "Cookie"); if (cookie instanceof SetCookie2) { if (cookie instanceof ClientCookie && !((ClientCookie) cookie).containsAttribute(ClientCookie.VERSION_ATTR)) { throw new CookieRestrictionViolationException( "Violates RFC 2965. Version attribute is required."); } } }
/** * Parse cookie port attribute. */ @Override public void parse(final SetCookie cookie, final String portValue) throws MalformedCookieException { Args.notNull(cookie, "Cookie"); if (cookie instanceof SetCookie2) { final SetCookie2 cookie2 = (SetCookie2) cookie; if (portValue != null && !portValue.trim().isEmpty()) { final int[] ports = parsePortAttribute(portValue); cookie2.setPorts(ports); } } }
@Override public boolean match(final Cookie cookie, final CookieOrigin origin) { Args.notNull(cookie, "Cookie"); Args.notNull(origin, "Cookie origin"); if (cookie.getVersion() > 0) { if (cookie instanceof SetCookie2) { return strict.match(cookie, origin); } else { return obsoleteStrict.match(cookie, origin); } } else { return netscapeDraft.match(cookie, origin); } }
@Override public void parse(final SetCookie cookie, final String commenturl) throws MalformedCookieException { if (cookie instanceof SetCookie2) { final SetCookie2 cookie2 = (SetCookie2) cookie; cookie2.setCommentURL(commenturl); } }
@Override public void parse(final SetCookie cookie, final String commenturl) throws MalformedCookieException { if (cookie instanceof SetCookie2) { final SetCookie2 cookie2 = (SetCookie2) cookie; cookie2.setDiscard(true); } }
@Test public void testCookieStandardCompliantParsingLocalHost() throws Exception { final CookieSpec cookiespec = new DefaultCookieSpec(); final CookieOrigin origin = new CookieOrigin("localhost", 80, "/", false); final Header header = new BasicHeader("Set-Cookie", "special=\"abcdigh\"; Version=1"); final List<Cookie> cookies = cookiespec.parse(header, origin); for (int i = 0; i < cookies.size(); i++) { final Cookie cookie = cookies.get(i); cookiespec.validate(cookie, origin); Assert.assertEquals("localhost", cookie.getDomain()); Assert.assertFalse(cookie instanceof SetCookie2); } }
@Test public void testCookieStandardCompliantParsingLocalHost2() throws Exception { final CookieSpec cookiespec = new DefaultCookieSpec(); final CookieOrigin origin = new CookieOrigin("localhost", 80, "/", false); final Header header = new BasicHeader("Set-Cookie2", "special=\"abcdigh\"; Version=1"); final List<Cookie> cookies = cookiespec.parse(header, origin); for (int i = 0; i < cookies.size(); i++) { final Cookie cookie = cookies.get(i); cookiespec.validate(cookie, origin); Assert.assertEquals("localhost.local", cookie.getDomain()); Assert.assertTrue(cookie instanceof SetCookie2); } }
/** * validate cookie version attribute. Version attribute is REQUIRED. */ public void validate(final Cookie cookie, final CookieOrigin origin) throws MalformedCookieException { if (cookie == null) { throw new IllegalArgumentException("Cookie may not be null"); } if (cookie instanceof SetCookie2) { if (cookie instanceof ClientCookie && !((ClientCookie) cookie).containsAttribute(ClientCookie.VERSION_ATTR)) { throw new MalformedCookieException( "Violates RFC 2965. Version attribute is required."); } } }