Skip to content

Commit

Permalink
Fix #5575 SEARCH method
Browse files Browse the repository at this point in the history
Fix #5575 SEARCH and PATCH methods
  • Loading branch information
gregw committed Nov 5, 2020
1 parent 2fd895a commit 17cee2a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 17 deletions.
43 changes: 32 additions & 11 deletions jetty-http/src/main/java/org/eclipse/jetty/http/HttpMethod.java
Expand Up @@ -40,7 +40,9 @@ public enum HttpMethod
CONNECT,
MOVE,
PROXY,
PRI;
PRI,
PATCH,
SEARCH;

/**
* Optimized lookup to find a method name and trailing space in a byte array.
Expand All @@ -62,15 +64,30 @@ public static HttpMethod lookAheadGet(byte[] bytes, final int position, int limi
return GET;
break;
case 'P':
if (bytes[position + 1] == 'O' && bytes[position + 2] == 'S' && bytes[position + 3] == 'T' && length >= 5 && bytes[position + 4] == ' ')
return POST;
if (bytes[position + 1] == 'R' && bytes[position + 2] == 'O' && bytes[position + 3] == 'X' && length >= 6 && bytes[position + 4] == 'Y' && bytes[position + 5] == ' ')
return PROXY;
if (bytes[position + 1] == 'U' && bytes[position + 2] == 'T' && bytes[position + 3] == ' ')
return PUT;
if (bytes[position + 1] == 'R' && bytes[position + 2] == 'I' && bytes[position + 3] == ' ')
return PRI;
break;
switch (bytes[position + 1])
{
case 'O':
if (bytes[position + 2] == 'S' && bytes[position + 3] == 'T' && length >= 5 && bytes[position + 4] == ' ')
return POST;
return null;
case 'R':
if (bytes[position + 2] == 'I' && bytes[position + 3] == ' ')
return PRI;
if (bytes[position + 2] == 'O' && bytes[position + 3] == 'X' && length >= 6 && bytes[position + 4] == 'Y' && bytes[position + 5] == ' ')
return PROXY;
return null;
case 'U':
if (bytes[position + 2] == 'T' && bytes[position + 3] == ' ')
return PUT;
return null;
case 'A':
if (bytes[position + 2] == 'T' && bytes[position + 3] == 'C' && length >= 6 && bytes[position + 4] == 'H' && bytes[position + 5] == ' ')
return PATCH;
return null;
default:
return null;
}

case 'H':
if (bytes[position + 1] == 'E' && bytes[position + 2] == 'A' && bytes[position + 3] == 'D' && length >= 5 && bytes[position + 4] == ' ')
return HEAD;
Expand Down Expand Up @@ -99,7 +116,11 @@ public static HttpMethod lookAheadGet(byte[] bytes, final int position, int limi
if (bytes[position + 1] == 'O' && bytes[position + 2] == 'V' && bytes[position + 3] == 'E' && length >= 5 && bytes[position + 4] == ' ')
return MOVE;
break;

case 'S':
if (bytes[position + 1] == 'E' && bytes[position + 2] == 'A' && bytes[position + 3] == 'R' && length >= 7 &&
bytes[position + 4] == 'C' && bytes[position + 5] == 'H' && bytes[position + 6] == ' ')
return SEARCH;
break;
default:
break;
}
Expand Down
Expand Up @@ -85,12 +85,14 @@ public static void parseAll(HttpParser parser, ByteBuffer buffer)
@Test
public void httpMethodTest()
{
assertNull(HttpMethod.lookAheadGet(BufferUtil.toBuffer("Wibble ")));
assertNull(HttpMethod.lookAheadGet(BufferUtil.toBuffer("GET")));
assertNull(HttpMethod.lookAheadGet(BufferUtil.toBuffer("MO")));

assertEquals(HttpMethod.GET, HttpMethod.lookAheadGet(BufferUtil.toBuffer("GET ")));
assertEquals(HttpMethod.MOVE, HttpMethod.lookAheadGet(BufferUtil.toBuffer("MOVE ")));
for (HttpMethod m : HttpMethod.values())
{
assertNull(HttpMethod.lookAheadGet(BufferUtil.toBuffer(m.asString().substring(0,2))));
assertNull(HttpMethod.lookAheadGet(BufferUtil.toBuffer(m.asString())));
assertNull(HttpMethod.lookAheadGet(BufferUtil.toBuffer(m.asString() + "FOO")));
assertEquals(m, HttpMethod.lookAheadGet(BufferUtil.toBuffer(m.asString() + " ")));
assertEquals(m, HttpMethod.lookAheadGet(BufferUtil.toBuffer(m.asString() + " /foo/bar")));
}

ByteBuffer b = BufferUtil.allocateDirect(128);
BufferUtil.append(b, BufferUtil.toBuffer("GET"));
Expand Down

0 comments on commit 17cee2a

Please sign in to comment.