@Test public void testCaseSensitiveNames() { Set<Cookie> cookies = ServerCookieDecoder.STRICT.decode("session_id=a; Session_id=b;"); Iterator<Cookie> it = cookies.iterator(); Cookie c; c = it.next(); assertEquals("Session_id", c.name()); assertEquals("b", c.value()); c = it.next(); assertEquals("session_id", c.name()); assertEquals("a", c.value()); assertFalse(it.hasNext()); }
public Set<Cookie> decode(String header) { final int headerLen = checkNotNull(header, "header").length(); if (headerLen == 0) { return Collections.emptySet(); } Set<Cookie> cookies = new TreeSet<Cookie>(); int i = 0; boolean rfc2965Style = false; if (header.regionMatches(true, 0, RFC2965_VERSION, 0, RFC2965_VERSION.length())) { i = header.indexOf(';') + 1; rfc2965Style = true; } loop: for (;;) { for (;;) { if (i == headerLen) { break loop; } char c = header.charAt(i); if (c == '\t' || c == '\n' || c == 0x0b || c == '\f' || c == '\r' || c == ' ' || c == ',' || c == ';') { i++; continue; } break; } int nameBegin = i; int nameEnd; int valueBegin; int valueEnd; for (;;) { char curChar = header.charAt(i); if (curChar == ';') { nameEnd = i; valueBegin = valueEnd = -1; break; } else if (curChar == '=') { nameEnd = i; i++; if (i == headerLen) { valueBegin = valueEnd = 0; break; } valueBegin = i; int semiPos = header.indexOf(';', i); valueEnd = i = semiPos > 0 ? semiPos : headerLen; break; } else { i++; } if (i == headerLen) { nameEnd = headerLen; valueBegin = valueEnd = -1; break; } } if (rfc2965Style && (header.regionMatches(nameBegin, RFC2965_PATH, 0, RFC2965_PATH.length()) || header.regionMatches(nameBegin, RFC2965_DOMAIN, 0, RFC2965_DOMAIN.length()) || header.regionMatches(nameBegin, RFC2965_PORT, 0, RFC2965_PORT.length()))) { continue; } DefaultCookie cookie = initCookie(header, nameBegin, nameEnd, valueBegin, valueEnd); if (cookie != null) { cookies.add(cookie); } } return cookies; }
ServerCookieDecoder extends CookieDecoder { public Set<Cookie> decode(String header) { final int headerLen = checkNotNull(header, "header").length(); if (headerLen == 0) { return Collections.emptySet(); } Set<Cookie> cookies = new TreeSet<Cookie>(); int i = 0; boolean rfc2965Style = false; if (header.regionMatches(true, 0, RFC2965_VERSION, 0, RFC2965_VERSION.length())) { i = header.indexOf(';') + 1; rfc2965Style = true; } loop: for (;;) { for (;;) { if (i == headerLen) { break loop; } char c = header.charAt(i); if (c == '\t' || c == '\n' || c == 0x0b || c == '\f' || c == '\r' || c == ' ' || c == ',' || c == ';') { i++; continue; } break; } int nameBegin = i; int nameEnd; int valueBegin; int valueEnd; for (;;) { char curChar = header.charAt(i); if (curChar == ';') { nameEnd = i; valueBegin = valueEnd = -1; break; } else if (curChar == '=') { nameEnd = i; i++; if (i == headerLen) { valueBegin = valueEnd = 0; break; } valueBegin = i; int semiPos = header.indexOf(';', i); valueEnd = i = semiPos > 0 ? semiPos : headerLen; break; } else { i++; } if (i == headerLen) { nameEnd = headerLen; valueBegin = valueEnd = -1; break; } } if (rfc2965Style && (header.regionMatches(nameBegin, RFC2965_PATH, 0, RFC2965_PATH.length()) || header.regionMatches(nameBegin, RFC2965_DOMAIN, 0, RFC2965_DOMAIN.length()) || header.regionMatches(nameBegin, RFC2965_PORT, 0, RFC2965_PORT.length()))) { continue; } DefaultCookie cookie = initCookie(header, nameBegin, nameEnd, valueBegin, valueEnd); if (cookie != null) { cookies.add(cookie); } } return cookies; } }
ServerCookieDecoder extends CookieDecoder { public Set<Cookie> decode(String header) { final int headerLen = checkNotNull(header, "header").length(); if (headerLen == 0) { return Collections.emptySet(); } Set<Cookie> cookies = new TreeSet<Cookie>(); int i = 0; boolean rfc2965Style = false; if (header.regionMatches(true, 0, RFC2965_VERSION, 0, RFC2965_VERSION.length())) { i = header.indexOf(';') + 1; rfc2965Style = true; } loop: for (;;) { for (;;) { if (i == headerLen) { break loop; } char c = header.charAt(i); if (c == '\t' || c == '\n' || c == 0x0b || c == '\f' || c == '\r' || c == ' ' || c == ',' || c == ';') { i++; continue; } break; } int nameBegin = i; int nameEnd; int valueBegin; int valueEnd; for (;;) { char curChar = header.charAt(i); if (curChar == ';') { nameEnd = i; valueBegin = valueEnd = -1; break; } else if (curChar == '=') { nameEnd = i; i++; if (i == headerLen) { valueBegin = valueEnd = 0; break; } valueBegin = i; int semiPos = header.indexOf(';', i); valueEnd = i = semiPos > 0 ? semiPos : headerLen; break; } else { i++; } if (i == headerLen) { nameEnd = headerLen; valueBegin = valueEnd = -1; break; } } if (rfc2965Style && (header.regionMatches(nameBegin, RFC2965_PATH, 0, RFC2965_PATH.length()) || header.regionMatches(nameBegin, RFC2965_DOMAIN, 0, RFC2965_DOMAIN.length()) || header.regionMatches(nameBegin, RFC2965_PORT, 0, RFC2965_PORT.length()))) { continue; } DefaultCookie cookie = initCookie(header, nameBegin, nameEnd, valueBegin, valueEnd); if (cookie != null) { cookies.add(cookie); } } return cookies; } private  ServerCookieDecoder(boolean strict); }
ServerCookieDecoder extends CookieDecoder { public Set<Cookie> decode(String header) { final int headerLen = checkNotNull(header, "header").length(); if (headerLen == 0) { return Collections.emptySet(); } Set<Cookie> cookies = new TreeSet<Cookie>(); int i = 0; boolean rfc2965Style = false; if (header.regionMatches(true, 0, RFC2965_VERSION, 0, RFC2965_VERSION.length())) { i = header.indexOf(';') + 1; rfc2965Style = true; } loop: for (;;) { for (;;) { if (i == headerLen) { break loop; } char c = header.charAt(i); if (c == '\t' || c == '\n' || c == 0x0b || c == '\f' || c == '\r' || c == ' ' || c == ',' || c == ';') { i++; continue; } break; } int nameBegin = i; int nameEnd; int valueBegin; int valueEnd; for (;;) { char curChar = header.charAt(i); if (curChar == ';') { nameEnd = i; valueBegin = valueEnd = -1; break; } else if (curChar == '=') { nameEnd = i; i++; if (i == headerLen) { valueBegin = valueEnd = 0; break; } valueBegin = i; int semiPos = header.indexOf(';', i); valueEnd = i = semiPos > 0 ? semiPos : headerLen; break; } else { i++; } if (i == headerLen) { nameEnd = headerLen; valueBegin = valueEnd = -1; break; } } if (rfc2965Style && (header.regionMatches(nameBegin, RFC2965_PATH, 0, RFC2965_PATH.length()) || header.regionMatches(nameBegin, RFC2965_DOMAIN, 0, RFC2965_DOMAIN.length()) || header.regionMatches(nameBegin, RFC2965_PORT, 0, RFC2965_PORT.length()))) { continue; } DefaultCookie cookie = initCookie(header, nameBegin, nameEnd, valueBegin, valueEnd); if (cookie != null) { cookies.add(cookie); } } return cookies; } private  ServerCookieDecoder(boolean strict); Set<Cookie> decode(String header); }
ServerCookieDecoder extends CookieDecoder { public Set<Cookie> decode(String header) { final int headerLen = checkNotNull(header, "header").length(); if (headerLen == 0) { return Collections.emptySet(); } Set<Cookie> cookies = new TreeSet<Cookie>(); int i = 0; boolean rfc2965Style = false; if (header.regionMatches(true, 0, RFC2965_VERSION, 0, RFC2965_VERSION.length())) { i = header.indexOf(';') + 1; rfc2965Style = true; } loop: for (;;) { for (;;) { if (i == headerLen) { break loop; } char c = header.charAt(i); if (c == '\t' || c == '\n' || c == 0x0b || c == '\f' || c == '\r' || c == ' ' || c == ',' || c == ';') { i++; continue; } break; } int nameBegin = i; int nameEnd; int valueBegin; int valueEnd; for (;;) { char curChar = header.charAt(i); if (curChar == ';') { nameEnd = i; valueBegin = valueEnd = -1; break; } else if (curChar == '=') { nameEnd = i; i++; if (i == headerLen) { valueBegin = valueEnd = 0; break; } valueBegin = i; int semiPos = header.indexOf(';', i); valueEnd = i = semiPos > 0 ? semiPos : headerLen; break; } else { i++; } if (i == headerLen) { nameEnd = headerLen; valueBegin = valueEnd = -1; break; } } if (rfc2965Style && (header.regionMatches(nameBegin, RFC2965_PATH, 0, RFC2965_PATH.length()) || header.regionMatches(nameBegin, RFC2965_DOMAIN, 0, RFC2965_DOMAIN.length()) || header.regionMatches(nameBegin, RFC2965_PORT, 0, RFC2965_PORT.length()))) { continue; } DefaultCookie cookie = initCookie(header, nameBegin, nameEnd, valueBegin, valueEnd); if (cookie != null) { cookies.add(cookie); } } return cookies; } private  ServerCookieDecoder(boolean strict); Set<Cookie> decode(String header); static final ServerCookieDecoder STRICT; static final ServerCookieDecoder LAX; }