Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed header cache for unknown values #11808

Merged
merged 3 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really want to cache the no-space-after-column case?
It's bad formatting by the client, so it deserves less efficiency?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added it in because I initially write a test that was just looking up "Content-Type:" (no space) and was surprised by the miss. But I will remove for now to just fix the issue and we can think about other optimizations separately.

}
return map;
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,25 @@ 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"));

assertThat(HttpParser.CACHE.getBest("Content-Type:text/plain\r\n").toString(), is("Content-Type: \u0000"));
assertThat(HttpParser.CACHE.getBest("Content-Type:text/plain\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
Loading