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

Add support for space in get request #5495

Merged
merged 1 commit into from
Nov 9, 2017

Conversation

ph
Copy link
Contributor

@ph ph commented Nov 1, 2017

This fix an issue when the http request contains a space instead of
breaking the line with bytes.fields we are finding the start and the end
of the URI using the METHOD verb and the HTTP/{VERSION}. This will
allow packet beat to record theses request instead of ignoring them.

Fixes: #4974

@ph ph force-pushed the fix/packetbeat-support-space-get-request branch from 16fd62d to a72b29a Compare November 1, 2017 14:28
@ph ph added the Packetbeat label Nov 1, 2017
@ph
Copy link
Contributor Author

ph commented Nov 1, 2017

@urso This is the PR I want to discuss with you, this change for accuracy and supporting badly form URI, add some slowness to that part of the code. It add bit more allocation, but It should be faster if the URI has more space in it than using bytes.Fields(fline). WDYT?

This PR

BenchmarkHTTPSimpleRequest-4       	 1000000	      1790 ns/op

master

BenchmarkHTTPSimpleRequest-4       	 1000000	      2136 ns/op

Copy link

@urso urso left a comment

Choose a reason for hiding this comment

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

Great improvement to the parser.

@ph ph added the v6.1.0 label Nov 2, 2017
Copy link
Contributor

@adriansr adriansr left a comment

Choose a reason for hiding this comment

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

A couple of minor comments

m.method = common.NetString(slices[0])
m.requestURI = common.NetString(slices[1])
m.method = common.NetString(fline[:afterMethodIdx])
m.requestURI = common.NetString(fline[afterMethodIdx+1 : afterRequestURIIdx])
Copy link
Contributor

Choose a reason for hiding this comment

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

if there is more than one space between URI and HTTP_VERSION it will be stored into requestURI. I think you should check for that (bytes.Fields did skip consecutive separators)

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 gave some thoughts about it, I don't think we should check for that, if we do it it would mean that we could potentially normalize the query string parameters.

If we look at the following case:

GET /e/b?movie=a brand new world HTTP/1.1 => '/e/b?movie=a brand new world'
GET /e/b?movie=a brand new world  HTTP/1.1 =>  
/elastic/beats?movie=a brand new world '

When we extract the parameters that should gives us 2 distinct values for the movie field: a brand new world and a brand new world (not the space at the end of world)

WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

I ran a quick check and the server did skip those extra spaces.

Now I was testing again and see that it's more common for servers to return a 400 Bad Request.

So I guess you can just ignore the comment. It's not common at all and spaces are escaped to %20 or + anyway


if bytes.Equal(slices[2][:5], []byte("HTTP/")) {
if bytes.Equal(fline[afterRequestURIIdx+1:afterRequestURIIdx+6], constHTTPVersion) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion
+len(constHTTPVersion)+1 instead of +6
and :len(constHTTPVersion) in the line above

@ph
Copy link
Contributor Author

ph commented Nov 2, 2017

@adriansr thanks, I will do another check.

@ph ph force-pushed the fix/packetbeat-support-space-get-request branch from a72b29a to 68b6066 Compare November 3, 2017 14:15
@ph
Copy link
Contributor Author

ph commented Nov 3, 2017

@adriansr I have updated the code with the change with len()

@ph ph force-pushed the fix/packetbeat-support-space-get-request branch from 68b6066 to 4a2fa7f Compare November 7, 2017 19:00
@ruflin ruflin added the review label Nov 7, 2017
@ph ph added v6.0.1 and removed v6.1.0 labels Nov 8, 2017
@ph
Copy link
Contributor Author

ph commented Nov 8, 2017

This can safely go into 6.0.1, I have created the label for it.

This fix an issue when the http request contains a space instead of
breaking the line with `bytes.fields` we are finding the start and the end
of the URI using the `METHOD` verb and the `HTTP/{VERSION}`. This will
allow packet beat to record theses request instead of ignoring them.

Fixes: elastic#4974
@ph ph force-pushed the fix/packetbeat-support-space-get-request branch from 4a2fa7f to af9f703 Compare November 9, 2017 14:07
@urso urso merged commit 16dffd3 into elastic:master Nov 9, 2017
adriansr pushed a commit to adriansr/beats that referenced this pull request Apr 6, 2018
This fix an issue when the http request contains a space instead of
breaking the line with `bytes.fields` we are finding the start and the end
of the URI using the `METHOD` verb and the `HTTP/{VERSION}`. This will
allow packet beat to record theses request instead of ignoring them.

Fixes: elastic#4974
andrewkroh pushed a commit that referenced this pull request Apr 6, 2018
This fix an issue when the http request contains a space instead of
breaking the line with `bytes.fields` we are finding the start and the end
of the URI using the `METHOD` verb and the `HTTP/{VERSION}`. This will
allow packet beat to record theses request instead of ignoring them.

Fixes: #4974
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.

bug when space in url
4 participants