-
Notifications
You must be signed in to change notification settings - Fork 3
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
feat: add gzip to http responses for query/batch-query #232
Conversation
@@ -118,7 +118,7 @@ func Test_QueryNoTopics(t *testing.T) { | |||
require.Equal(t, codes.InvalidArgument, grpcErr.Code()) | |||
require.EqualError(t, err, `rpc error: code = InvalidArgument desc = content topics required`) | |||
} else { | |||
require.EqualError(t, err, "400 Bad Request: {\"code\":3, \"message\":\"content topics required\", \"details\":[]}") | |||
require.Regexp(t, `400 Bad Request: {"code\":3,\s?"message":"content topics required",\s?"details":\[\]}`, err.Error()) |
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.
somehow the whitespaces get stripped now? I noticed the test above already accounts for this via regexp so did the same here
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.
Oh right I think this is what's happening golang/protobuf#1121
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.
Looks like a good idea. 👍
pkg/api/handler_utils.go
Outdated
@@ -0,0 +1,39 @@ | |||
package api |
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.
Want to just call this file gzip.go
?
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.
good call, will make that change
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 ended up renaming to gzip_handler.go, I balked at gzip.go
since it seemed like a name that could be used a lot elsewhere.
Goal
This PR implements gzip compression for HTTP responses of the JSON interface of our node gRPC API. This happens for responses to
query
andbatch-query
methods. As of now, clients already send:Accept-Encoding: gzip, deflate
but server responses are not currently compressed. Given 1) base64 encoding and 2) redundant structure and fields, our responses are pretty compressible even though the envelope contents are high entropy.(encrypted contents of test accounts, no sweat that I'm pasting here)
Changes
One issue is that our clients currently send
Accept-Encoding: gzip
even for long-lived/subscribe
requests, which our server will happily attempt to gzip before sending a response. To combat this I've implemented our gzip handler with standard libraries and gated it to just/query && /batch-query
responses.Testing