HttpField { public boolean contains(String search) { if (search == null) return value == null; if (search.length() == 0) return false; if (value == null) return false; if (search.equals(value)) return true; search = StringUtils.asciiToLowerCase(search); int state = 0; int match = 0; int param = 0; for (int i = 0; i < value.length(); i++) { char c = value.charAt(i); switch (state) { case 0: switch (c) { case '"': match = 0; state = 2; break; case ',': break; case ';': param = -1; match = -1; state = 5; break; case ' ': case '\t': break; default: match = Character.toLowerCase(c) == search.charAt(0) ? 1 : -1; state = 1; break; } break; case 1: switch (c) { case ',': if (match == search.length()) return true; state = 0; break; case ';': param = match >= 0 ? 0 : -1; state = 5; break; default: if (match > 0) { if (match < search.length()) match = Character.toLowerCase(c) == search.charAt(match) ? (match + 1) : -1; else if (c != ' ' && c != '\t') match = -1; } break; } break; case 2: switch (c) { case '\\': state = 3; break; case '"': state = 4; break; default: if (match >= 0) { if (match < search.length()) match = Character.toLowerCase(c) == search.charAt(match) ? (match + 1) : -1; else match = -1; } } break; case 3: if (match >= 0) { if (match < search.length()) match = Character.toLowerCase(c) == search.charAt(match) ? (match + 1) : -1; else match = -1; } state = 2; break; case 4: switch (c) { case ' ': case '\t': break; case ';': state = 5; break; case ',': if (match == search.length()) return true; state = 0; break; default: match = -1; } break; case 5: switch (c) { case ',': if (param != ZERO_QUALITY.length() && match == search.length()) return true; param = 0; state = 0; break; case ' ': case '\t': break; default: if (param >= 0) { if (param < ZERO_QUALITY.length()) param = Character.toLowerCase(c) == ZERO_QUALITY.charAt(param) ? (param + 1) : -1; else if (c != '0' && c != '.') param = -1; } } break; default: throw new IllegalStateException(); } } return param != ZERO_QUALITY.length() && match == search.length(); } HttpField(HttpHeader header, String name, String value);  HttpField(HttpHeader header, String value);  HttpField(HttpHeader header, HttpHeaderValue value);  HttpField(String name, String value); HttpHeader getHeader(); String getName(); String getLowerCaseName(); String getValue(); int getIntValue(); long getLongValue(); String[] getValues(); boolean contains(String search); @Override String toString(); boolean isSameName(HttpField field); @Override int hashCode(); @Override boolean equals(Object o);  }
@Test void testContainsSimple() { HttpField field = new HttpField("name", "SomeValue"); assertTrue(field.contains("somevalue")); assertTrue(field.contains("sOmEvAlUe")); assertTrue(field.contains("SomeValue")); assertFalse(field.contains("other")); assertFalse(field.contains("some")); assertFalse(field.contains("Some")); assertFalse(field.contains("value")); assertFalse(field.contains("v")); assertFalse(field.contains("")); assertFalse(field.contains(null)); field = new HttpField(HttpHeader.CONNECTION, "Upgrade, HTTP2-Settings"); assertTrue(field.contains("Upgrade")); assertTrue(field.contains("HTTP2-Settings")); }
@Test void testContainsList() { HttpField field = new HttpField("name", ",aaa,Bbb,CCC, ddd , e e, \"\\\"f,f\\\"\", "); assertTrue(field.contains("aaa")); assertTrue(field.contains("bbb")); assertTrue(field.contains("ccc")); assertTrue(field.contains("Aaa")); assertTrue(field.contains("Bbb")); assertTrue(field.contains("Ccc")); assertTrue(field.contains("AAA")); assertTrue(field.contains("BBB")); assertTrue(field.contains("CCC")); assertTrue(field.contains("ddd")); assertTrue(field.contains("e e")); assertTrue(field.contains("\"f,f\"")); assertFalse(field.contains("")); assertFalse(field.contains("aa")); assertFalse(field.contains("bb")); assertFalse(field.contains("cc")); assertFalse(field.contains(null)); }
@Test void testQualityContainsList() { HttpField field; field = new HttpField("name", "yes"); assertTrue(field.contains("yes")); assertFalse(field.contains("no")); field = new HttpField("name", ",yes,"); assertTrue(field.contains("yes")); assertFalse(field.contains("no")); field = new HttpField("name", "other,yes,other"); assertTrue(field.contains("yes")); assertFalse(field.contains("no")); field = new HttpField("name", "other, yes ,other"); assertTrue(field.contains("yes")); assertFalse(field.contains("no")); field = new HttpField("name", "other, y s ,other"); assertTrue(field.contains("y s")); assertFalse(field.contains("no")); field = new HttpField("name", "other, \"yes\" ,other"); assertTrue(field.contains("yes")); assertFalse(field.contains("no")); field = new HttpField("name", "other, \"\\\"yes\\\"\" ,other"); assertTrue(field.contains("\"yes\"")); assertFalse(field.contains("no")); field = new HttpField("name", ";no,yes,;no"); assertTrue(field.contains("yes")); assertFalse(field.contains("no")); field = new HttpField("name", "no;q=0,yes;q=1,no; q = 0"); assertTrue(field.contains("yes")); assertFalse(field.contains("no")); field = new HttpField("name", "no;q=0.0000,yes;q=0.0001,no; q = 0.00000"); assertTrue(field.contains("yes")); assertFalse(field.contains("no")); field = new HttpField("name", "no;q=0.0000,Yes;Q=0.0001,no; Q = 0.00000"); assertTrue(field.contains("yes")); assertFalse(field.contains("no")); }