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

Jetty 12 - Fix for HttpParser quick HTTP Version lookahead #9171

Merged

Conversation

joakime
Copy link
Contributor

@joakime joakime commented Jan 13, 2023

Fixes #9170

+ 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
@gregw
Copy link
Contributor

gregw commented Jan 16, 2023

@joakime I further improved this fix and pushed 593cfdb to your branch:

  • 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

gregw added 4 commits January 16, 2023 13:04
+ 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
@gregw
Copy link
Contributor

gregw commented Jan 16, 2023

Added another optimization to check for HTTP as a single get of an int.

gregw added 2 commits January 16, 2023 16:11
+ 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
@gregw
Copy link
Contributor

gregw commented Jan 16, 2023

@joakime I found a few more issues with the field cache, plus I went a simpler route for the version lookahead using getInt

Copy link
Contributor Author

@joakime joakime left a 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

@joakime
Copy link
Contributor Author

joakime commented Jan 16, 2023

You introduced a parameterized eoln, but it's not used in all test cases.

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) == ' ')
Copy link
Contributor

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);
        ...
    }

Copy link
Contributor

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?

Comment on lines 1280 to 1289
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;
}
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

@gregw gregw requested a review from sbordet January 16, 2023 23:34
@gregw gregw requested a review from sbordet January 17, 2023 21:47
@gregw gregw merged commit a06d1a2 into jetty-12.0.x Jan 17, 2023
@gregw gregw deleted the fix/jetty-12.0.x/httpparser-version-getbest-optimization branch January 17, 2023 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Jetty 12 - HttpParser Version optimization never works
3 participants