Skip to content

Commit

Permalink
Fixed header cache for unknown values
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 committed May 18, 2024
1 parent c97c995 commit 16995ad
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,22 @@ public class HttpParser
{
HttpField field = new PreEncodedHttpField(HttpHeader.CONTENT_TYPE, type);
map.put(field.toString(), field);
map.put(field.toString().replace(": ", ":"), field);

for (String charset : new String[]{"utf-8", "iso-8859-1"})
{
PreEncodedHttpField field1 = new PreEncodedHttpField(HttpHeader.CONTENT_TYPE, type + ";charset=" + charset);
map.put(field1.toString(), field1);
map.put(field1.toString().replace(": ", ":"), field1);
PreEncodedHttpField field2 = new PreEncodedHttpField(HttpHeader.CONTENT_TYPE, type + "; charset=" + charset);
map.put(field2.toString(), field2);
map.put(field1.toString().replace(": ", ":"), field2);
PreEncodedHttpField field3 = new PreEncodedHttpField(HttpHeader.CONTENT_TYPE, type + ";charset=" + charset.toUpperCase(Locale.ENGLISH));
map.put(field3.toString(), field3);
map.put(field1.toString().replace(": ", ":"), field3);
PreEncodedHttpField field4 = new PreEncodedHttpField(HttpHeader.CONTENT_TYPE, type + "; charset=" + charset.toUpperCase(Locale.ENGLISH));
map.put(field4.toString(), field4);
map.put(field1.toString().replace(": ", ":"), field4);
}
}
return map;
Expand All @@ -167,7 +172,8 @@ public class HttpParser
for (HttpHeader h : HttpHeader.values())
{
HttpField httpField = new HttpField(h, UNMATCHED_VALUE);
map.put(httpField.toString(), httpField);
map.put(h + ": ", httpField);
map.put(h + ":", httpField);
}
return map;
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,24 @@ 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: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"));
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 16995ad

Please sign in to comment.