-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Jetty 12 - Fix for HttpParser quick HTTP Version lookahead #9171
Jetty 12 - Fix for HttpParser quick HTTP Version lookahead #9171
Conversation
+ Removed the array optimized look ahead + Added caches for version follow by eoln and space + version cache hits now include following character and skip state transition. + improved test harness to check lf and crlf endings
+ Removed the array optimized look ahead + Added caches for version follow by eoln and space + version cache hits now include following character and skip state transition. + improved test harness to check lf and crlf endings
+ Removed the array optimized look ahead + Added caches for version follow by eoln and space + version cache hits now include following character and skip state transition. + improved test harness to check lf and crlf endings
+ Removed the array optimized look ahead + Added caches for version follow by eoln and space + version cache hits now include following character and skip state transition. + improved test harness to check lf and crlf endings
+ Removed the array optimized look ahead + Added caches for version follow by eoln and space + version cache hits now include following character and skip state transition. + improved test harness to check lf and crlf endings + added HTTP as int optimization
Added another optimization to check for HTTP as a single get of an int. |
+ Removed the array optimized look ahead + Added caches for version follow by eoln and space + version cache hits now include following character and skip state transition. + improved test harness to check lf and crlf endings + added HTTP as int optimization
+ Removed the array optimized look ahead + version lookahead now done with getInt + improved test harness to check lf and crlf endings + added HTTP as int optimization + fixed bug in near miss of field cache
@joakime I found a few more issues with the field cache, plus I went a simpler route for the version lookahead using getInt |
jetty-core/jetty-http/src/test/java/org/eclipse/jetty/http/HttpParserTest.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-http/src/test/java/org/eclipse/jetty/http/HttpParserTest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not every place uses eoln
jetty-core/jetty-http/src/test/java/org/eclipse/jetty/http/HttpParserTest.java
Show resolved
Hide resolved
jetty-core/jetty-http/src/test/java/org/eclipse/jetty/http/HttpParserTest.java
Show resolved
Hide resolved
jetty-core/jetty-http/src/test/java/org/eclipse/jetty/http/HttpParserTest.java
Show resolved
Hide resolved
jetty-core/jetty-http/src/test/java/org/eclipse/jetty/http/HttpParserTest.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-http/src/test/java/org/eclipse/jetty/http/HttpParserTest.java
Outdated
Show resolved
Hide resolved
You introduced a parameterized |
jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/HttpParser.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/HttpParser.java
Show resolved
Hide resolved
if (_version != null) | ||
int v = buffer.getInt(position + 4); | ||
_version = v == HTTP_1_1_AS_INT ? HttpVersion.HTTP_1_1 : v == HTTP_1_0_AS_INT ? HttpVersion.HTTP_1_0 : null; | ||
if (_version != null && buffer.get(position + 8) == ' ') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find it quite hard to read and reason about the buffer with these "magic" numbers, like 9
, 4
, 8
, etc.
Can it be rewritten using a int current
to indicate where in the buffer we are looking at?
Something like:
else if (_responseHandler != null && buffer.remaining() >= 9)
{
int current = position;
int h = buffer.getInt(current);
if (h == HTTP_AS_INT)
{
current += 4;
int v = buffer.getInt(current);
...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added some constants. Is that clearer?
jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/HttpParser.java
Show resolved
Hide resolved
jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/HttpParser.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/HttpParser.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/HttpParser.java
Show resolved
Hide resolved
jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/HttpTokens.java
Outdated
Show resolved
Hide resolved
int pos = buffer.position() + n.length() + (v == null ? 0 : v.length()) + 1; | ||
if (v == null || pos >= buffer.limit()) | ||
{ | ||
// Header only | ||
setState(FieldState.VALUE); | ||
_string.setLength(0); | ||
_length = 0; | ||
buffer.position(buffer.position() + n.length() + 1); | ||
buffer.position(v == null ? pos : pos - v.length()); | ||
break; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does not feel right.
pos
may be set past the cached value, and we may still enter the if
block due to pos >= buffer.limit()
, but then we set the state to be VALUE
?
Even if it is correct it's just way more difficult to read, so perhaps needs comments and/or examples.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
restructured to posAfterName
and posAfterValue
... but doing some more checks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
more cleanup and testing done. OK now.
Signed-off-by: Greg Wilkins <[email protected]>
Fixes #9170