-
Notifications
You must be signed in to change notification settings - Fork 17
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
Some cleanup, mostly in the HTTP request representations #211
Conversation
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.
Changes look good.
One reason we might want to keep ByteArray (or switch to okio ByteString) is that it makes requests immutable. By switching to Buffer, it is possible (though unlikely) for someone to mutate it.
val message: Buffer, | ||
// HTTP method to use with the request. | ||
// Almost always POST, but side effect free unary RPCs may be made with GET. | ||
httpMethod: String = HTTPMethod.POST, |
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.
Should we remove httpMethod
from the base HTTPRequest class now since it is only used for unary calls?
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.
Done.
@@ -46,16 +47,10 @@ internal class GRPCInterceptor( | |||
requestHeaders[GRPC_ACCEPT_ENCODING] = clientConfig.compressionPools() | |||
.map { compressionPool -> compressionPool.name() } | |||
} | |||
val requestMessage = Buffer().use { buffer -> | |||
if (request.message != null) { |
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.
This is nice that we don't have to do this any more (since unary requests always have to have messages).
While that is true, there's no cheap way to convert between a So by having a different intermediate representation, we have to copy at every step. There's actually a bit more copying we're doing that we could improve/eliminate (such as in the way So I guess it's a tradeoff -- if we want something immutable, we'll have to pay for it with copies at each step of the protocol transformation. |
…) and UnaryHTTPRequest (only for unary RPCs, includes request message contents)
43a9fa2
to
b32f62a
Compare
This PR contains a few changes that try to improve parts of the code.
HTTPRequest
class might have a request message. This message was really required for unary operations (and, if absent, would be treated as empty request) and ignored for stream operations. So now the type is split into two: a baseHTTPRequest
which has no request message, and aUnaryHTTPRequest
which has a non-optional message type. Also, since everything in the framework works withBuffer
for messages, this changes the type of the message fromByteArray
toBuffer
.Envelope.pack
a little more DRY. Though, looking at it again, it doesn't really reduce the total number of lines of code and is perhaps too Go-like and not very idiomatic for Kotlin... Let me know what you think. I can easily back it out.