-
Notifications
You must be signed in to change notification settings - Fork 436
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
Set Content-Length header in NodeHTTPTransport to disable chunked encoding #427
Set Content-Length header in NodeHTTPTransport to disable chunked encoding #427
Conversation
836c600
to
1860f23
Compare
Hey @MichaelAquilina, thank you for contributing 🙌 If I understand this change correctly then the It would also be great if you could look to add a unit test for this option; however I appreciate that this package has not test framework - however I would be happy to help guide you on how to contribute such a test if you have the time and interest. |
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.
Only set content-length for unary requests.
Potentially superceded by #446. |
@MichaelAquilina are you still planning on working on this issue? |
Hi @jonny-improbable sorry the delay! Working on it right now however I am struggling to understand how you would identify a unary request from the |
Hey @MichaelAquilina, that's great news :)
The |
@@ -18,6 +18,10 @@ class NodeHttp implements grpc.Transport { | |||
} | |||
|
|||
sendMessage(msgBytes: Uint8Array) { | |||
if (!this.options.methodDefinition.requestStream) { |
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.
From what I understand we only care about checking if the requestStream
is false but you mentioned responseStream
in your comment too. Perhaps I am missing something?
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.
If you only want to set the content-length header for unary methods you will need to check that both requestStream
and responseStream
are false.
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.
Updated :)
edc76b2
to
21e1965
Compare
Fantastic; 3 things
Thanks. |
21e1965
to
f4e4ca6
Compare
1 is done. I can attempt 2 but I suspect I might be slow to actually implement this as I have very little experience with jest. Happy to attempt it if you are patient enough for it though :) |
@MichaelAquilina I'm going to merge this PR in-place so as to unblock others in your position. I've cut #519 to remind us to backfill the missing test. |
Changes
Disable Chunked http encoding for unary requests in NodeHttpTransport.
Chunked encoding is only useful when we do not know what the size of our message will be. Using Raw http encoding means less overall data sent which should be more efficient.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Transfer-Encoding#Chunked_encoding
Setting the Content-Length will disable node's http library default chunked encoding:
https://nodejs.org/api/http.html#http_http_request_url_options_callback
Verification
Tested it locally with my own project.