diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpField.java b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpField.java index 8b6531f6f45..1b5b39f053f 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpField.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpField.java @@ -21,6 +21,8 @@ package org.eclipse.jetty.http; import java.util.ArrayList; import java.util.Objects; +import org.eclipse.jetty.util.StringUtil; + /** A HTTP Field */ public class HttpField @@ -191,7 +193,7 @@ public class HttpField /* ------------------------------------------------------------ */ /** Look for a value in a possible multi valued field - * @param search Values to search for + * @param search Values to search for (case insensitive) * @return True iff the value is contained in the field value entirely or * as an element of a quoted comma separated list. List element parameters (eg qualities) are ignored, * except if they are q=0, in which case the item itself is ignored. @@ -204,6 +206,8 @@ public class HttpField return false; if (_value==null) return false; + + search = StringUtil.asciiToLowerCase(search); int state=0; int match=0; @@ -236,7 +240,7 @@ public class HttpField break; default: // character - match = c==search.charAt(0)?1:-1; + match = Character.toLowerCase(c)==search.charAt(0)?1:-1; state=1; break; } @@ -261,7 +265,7 @@ public class HttpField if (match>0) { if (match=0) { if (match=0) { if (match=0) { if (param<__zeroquality.length()) - param=c==__zeroquality.charAt(param)?(param+1):-1; + param=Character.toLowerCase(c)==__zeroquality.charAt(param)?(param+1):-1; else if (c!='0'&&c!='.') param=-1; } diff --git a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpFieldTest.java b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpFieldTest.java index d381de39097..b083e766567 100644 --- a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpFieldTest.java +++ b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpFieldTest.java @@ -35,10 +35,13 @@ public class HttpFieldTest @Test public void testContainsSimple() throws Exception { - HttpField field = new HttpField("name","somevalue"); + 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("")); @@ -66,10 +69,16 @@ public class HttpFieldTest @Test public void testContainsList() throws Exception { - HttpField field = new HttpField("name",",aaa,bbb,ccc, ddd , e e, \"\\\"f,f\\\"\", "); + 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\"")); @@ -125,6 +134,10 @@ public class HttpFieldTest 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")); } diff --git a/jetty-http2/http2-server/src/test/java/org/eclipse/jetty/http2/server/HTTP2CServerTest.java b/jetty-http2/http2-server/src/test/java/org/eclipse/jetty/http2/server/HTTP2CServerTest.java index dad6e1e681f..ed2d3a4241a 100644 --- a/jetty-http2/http2-server/src/test/java/org/eclipse/jetty/http2/server/HTTP2CServerTest.java +++ b/jetty-http2/http2-server/src/test/java/org/eclipse/jetty/http2/server/HTTP2CServerTest.java @@ -115,7 +115,7 @@ public class HTTP2CServerTest extends AbstractServerTest output.write(("" + "GET /one HTTP/1.1\r\n" + "Host: localhost\r\n" + - "Connection: Upgrade, HTTP2-Settings\r\n" + + "Connection: something, else, upgrade, HTTP2-Settings\r\n" + "Upgrade: h2c\r\n" + "HTTP2-Settings: \r\n" + "\r\n").getBytes(StandardCharsets.ISO_8859_1)); diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannelOverHttp.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannelOverHttp.java index a9d57759f57..c757ca381f3 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannelOverHttp.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannelOverHttp.java @@ -370,7 +370,7 @@ class HttpChannelOverHttp extends HttpChannel implements HttpParser.RequestHandl if (LOG.isDebugEnabled()) LOG.debug("upgrade {} {}",this,_upgrade); - if (_upgrade!=PREAMBLE_UPGRADE_H2C && (_connection==null || !_connection.getValue().contains("Upgrade"))) + if (_upgrade!=PREAMBLE_UPGRADE_H2C && (_connection==null || !_connection.contains("upgrade"))) throw new BadMessageException(HttpStatus.BAD_REQUEST_400); // Find the upgrade factory