@UseDataProvider("forParsesCookies") @Test public void parsesCookies(String cookiesHeader, List<Cookie> expectedCookies) { List<Cookie> cookies = HeaderHelper.parseCookies(cookiesHeader); assertEquals(expectedCookies, cookies); }
public static List<Cookie> parseCookies(String cookiesString) { final List<Cookie> cookies = new ArrayList<>(); int p = 0; int n; CookieBuilder cookieBuilder = null; int version = Cookie.DEFAULT_VERSION; while (p < cookiesString.length()) { n = findCookieParameterSeparator(cookiesString, p); String pair = cookiesString.substring(p, n); String name; String value = ""; int eq = scan(pair, '='); if (charAtIs(pair, eq, '=')) { name = pair.substring(0, eq).trim(); value = pair.substring(eq + 1).trim(); if (value.length() > 1 && value.startsWith("\"") && value.endsWith("\"")) { value = value.substring(1, value.length() - 1); } } else { name = pair.trim(); } if (doesNotContain(name, '$')) { if (cookieBuilder != null) { cookies.add(cookieBuilder.build()); } cookieBuilder = aCookie().withName(name).withValue(value); cookieBuilder.withVersion(version); } else if ("$Version".equalsIgnoreCase(name)) { version = Integer.valueOf(value); } else if (cookieBuilder != null && "$Path".equalsIgnoreCase(name)) { cookieBuilder.withPath(value); } else if (cookieBuilder != null && "$Domain".equalsIgnoreCase(name)) { cookieBuilder.withDomain(value); } p = n + 1; } if (cookieBuilder != null) { cookies.add(cookieBuilder.build()); } return cookies; }
HeaderHelper { public static List<Cookie> parseCookies(String cookiesString) { final List<Cookie> cookies = new ArrayList<>(); int p = 0; int n; CookieBuilder cookieBuilder = null; int version = Cookie.DEFAULT_VERSION; while (p < cookiesString.length()) { n = findCookieParameterSeparator(cookiesString, p); String pair = cookiesString.substring(p, n); String name; String value = ""; int eq = scan(pair, '='); if (charAtIs(pair, eq, '=')) { name = pair.substring(0, eq).trim(); value = pair.substring(eq + 1).trim(); if (value.length() > 1 && value.startsWith("\"") && value.endsWith("\"")) { value = value.substring(1, value.length() - 1); } } else { name = pair.trim(); } if (doesNotContain(name, '$')) { if (cookieBuilder != null) { cookies.add(cookieBuilder.build()); } cookieBuilder = aCookie().withName(name).withValue(value); cookieBuilder.withVersion(version); } else if ("$Version".equalsIgnoreCase(name)) { version = Integer.valueOf(value); } else if (cookieBuilder != null && "$Path".equalsIgnoreCase(name)) { cookieBuilder.withPath(value); } else if (cookieBuilder != null && "$Domain".equalsIgnoreCase(name)) { cookieBuilder.withDomain(value); } p = n + 1; } if (cookieBuilder != null) { cookies.add(cookieBuilder.build()); } return cookies; } }
HeaderHelper { public static List<Cookie> parseCookies(String cookiesString) { final List<Cookie> cookies = new ArrayList<>(); int p = 0; int n; CookieBuilder cookieBuilder = null; int version = Cookie.DEFAULT_VERSION; while (p < cookiesString.length()) { n = findCookieParameterSeparator(cookiesString, p); String pair = cookiesString.substring(p, n); String name; String value = ""; int eq = scan(pair, '='); if (charAtIs(pair, eq, '=')) { name = pair.substring(0, eq).trim(); value = pair.substring(eq + 1).trim(); if (value.length() > 1 && value.startsWith("\"") && value.endsWith("\"")) { value = value.substring(1, value.length() - 1); } } else { name = pair.trim(); } if (doesNotContain(name, '$')) { if (cookieBuilder != null) { cookies.add(cookieBuilder.build()); } cookieBuilder = aCookie().withName(name).withValue(value); cookieBuilder.withVersion(version); } else if ("$Version".equalsIgnoreCase(name)) { version = Integer.valueOf(value); } else if (cookieBuilder != null && "$Path".equalsIgnoreCase(name)) { cookieBuilder.withPath(value); } else if (cookieBuilder != null && "$Domain".equalsIgnoreCase(name)) { cookieBuilder.withDomain(value); } p = n + 1; } if (cookieBuilder != null) { cookies.add(cookieBuilder.build()); } return cookies; } private  HeaderHelper(); }
HeaderHelper { public static List<Cookie> parseCookies(String cookiesString) { final List<Cookie> cookies = new ArrayList<>(); int p = 0; int n; CookieBuilder cookieBuilder = null; int version = Cookie.DEFAULT_VERSION; while (p < cookiesString.length()) { n = findCookieParameterSeparator(cookiesString, p); String pair = cookiesString.substring(p, n); String name; String value = ""; int eq = scan(pair, '='); if (charAtIs(pair, eq, '=')) { name = pair.substring(0, eq).trim(); value = pair.substring(eq + 1).trim(); if (value.length() > 1 && value.startsWith("\"") && value.endsWith("\"")) { value = value.substring(1, value.length() - 1); } } else { name = pair.trim(); } if (doesNotContain(name, '$')) { if (cookieBuilder != null) { cookies.add(cookieBuilder.build()); } cookieBuilder = aCookie().withName(name).withValue(value); cookieBuilder.withVersion(version); } else if ("$Version".equalsIgnoreCase(name)) { version = Integer.valueOf(value); } else if (cookieBuilder != null && "$Path".equalsIgnoreCase(name)) { cookieBuilder.withPath(value); } else if (cookieBuilder != null && "$Domain".equalsIgnoreCase(name)) { cookieBuilder.withDomain(value); } p = n + 1; } if (cookieBuilder != null) { cookies.add(cookieBuilder.build()); } return cookies; } private  HeaderHelper(); static List<AcceptMediaType> createAcceptMediaTypeList(String header); static List<AcceptLanguage> createAcceptedLanguageList(String header); static List<AcceptToken> createAcceptedCharsetList(String header); static List<AcceptToken> createAcceptedEncodingList(String header); static List<Cookie> parseCookies(String cookiesString); static NewCookie parseNewCookie(String newCookieString); static Date parseDateHeader(String header); static String formatDate(Date date); static long getContentLengthLong(MultivaluedMap<String, String> httpHeaders); @SuppressWarnings({"unchecked"}) static String getHeaderAsString(Object o); static String convertToString(Collection<String> collection); }
HeaderHelper { public static List<Cookie> parseCookies(String cookiesString) { final List<Cookie> cookies = new ArrayList<>(); int p = 0; int n; CookieBuilder cookieBuilder = null; int version = Cookie.DEFAULT_VERSION; while (p < cookiesString.length()) { n = findCookieParameterSeparator(cookiesString, p); String pair = cookiesString.substring(p, n); String name; String value = ""; int eq = scan(pair, '='); if (charAtIs(pair, eq, '=')) { name = pair.substring(0, eq).trim(); value = pair.substring(eq + 1).trim(); if (value.length() > 1 && value.startsWith("\"") && value.endsWith("\"")) { value = value.substring(1, value.length() - 1); } } else { name = pair.trim(); } if (doesNotContain(name, '$')) { if (cookieBuilder != null) { cookies.add(cookieBuilder.build()); } cookieBuilder = aCookie().withName(name).withValue(value); cookieBuilder.withVersion(version); } else if ("$Version".equalsIgnoreCase(name)) { version = Integer.valueOf(value); } else if (cookieBuilder != null && "$Path".equalsIgnoreCase(name)) { cookieBuilder.withPath(value); } else if (cookieBuilder != null && "$Domain".equalsIgnoreCase(name)) { cookieBuilder.withDomain(value); } p = n + 1; } if (cookieBuilder != null) { cookies.add(cookieBuilder.build()); } return cookies; } private  HeaderHelper(); static List<AcceptMediaType> createAcceptMediaTypeList(String header); static List<AcceptLanguage> createAcceptedLanguageList(String header); static List<AcceptToken> createAcceptedCharsetList(String header); static List<AcceptToken> createAcceptedEncodingList(String header); static List<Cookie> parseCookies(String cookiesString); static NewCookie parseNewCookie(String newCookieString); static Date parseDateHeader(String header); static String formatDate(Date date); static long getContentLengthLong(MultivaluedMap<String, String> httpHeaders); @SuppressWarnings({"unchecked"}) static String getHeaderAsString(Object o); static String convertToString(Collection<String> collection); static final Comparator<QualityValue> QUALITY_VALUE_COMPARATOR; }