Skip to content

Commit

Permalink
Fixed header cache for unknown values (#11808)
Browse files Browse the repository at this point in the history
Avoid adding the unknown marker into the CACHE index. Issue introduced in #11661 fixing #11659
  • Loading branch information
gregw authored May 21, 2024
1 parent 00f322f commit a1b3acb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public class HttpParser
for (HttpHeader h : HttpHeader.values())
{
HttpField httpField = new HttpField(h, UNMATCHED_VALUE);
map.put(httpField.toString(), httpField);
map.put(h + ": ", httpField);
}
return map;
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,20 @@ public void testLowerCaseVersion(String eoln)
assertEquals(1, _headers);
}

@Test
public void testHeaderCache()
{
assertThat(HttpParser.CACHE.getBest("Content-Type: text/plain\r\n").toString(), is("Content-Type: text/plain"));
assertThat(HttpParser.CACHE.getBest("Content-Type: text/plain\n").toString(), is("Content-Type: text/plain"));
assertThat(HttpParser.CACHE.getBest("content-type: text/plain\r\n").toString(), is("Content-Type: text/plain"));
assertThat(HttpParser.CACHE.getBest("content-type: text/plain\n").toString(), is("Content-Type: text/plain"));

assertThat(HttpParser.CACHE.getBest("Content-Type: unknown\r\n").toString(), is("Content-Type: \u0000"));
assertThat(HttpParser.CACHE.getBest("Content-Type: unknown\n").toString(), is("Content-Type: \u0000"));
assertThat(HttpParser.CACHE.getBest("content-type: unknown\r\n").toString(), is("Content-Type: \u0000"));
assertThat(HttpParser.CACHE.getBest("content-type: unknown\n").toString(), is("Content-Type: \u0000"));
}

@ParameterizedTest
@ValueSource(strings = {"\r\n", "\n"})
public void testHeaderCacheNearMiss(String eoln)
Expand Down

0 comments on commit a1b3acb

Please sign in to comment.