-
Notifications
You must be signed in to change notification settings - Fork 908
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
Support grpc-web-text #2938
Support grpc-web-text #2938
Conversation
Motivation: Currently, we only support grpc-web, not grpc-web-text. It would be nice if we support both. Modifications: - `ArmeriaMessageFramer` and `ArmeriaMessageDeframer` now takes the additional boolean flag which indicates encoding decoding base64 - Add gRPC-web it test with akka-grpc - The official grpc-java does not support grpc-web so we use akka-grpc for it testing Result: - You can now use grpc-web-text using Armeria client and server.
...protocol/src/main/java/com/linecorp/armeria/common/grpc/protocol/ArmeriaMessageDeframer.java
Outdated
Show resolved
Hide resolved
Codecov Report
@@ Coverage Diff @@
## master #2938 +/- ##
============================================
- Coverage 73.22% 73.21% -0.02%
- Complexity 12198 12209 +11
============================================
Files 1061 1062 +1
Lines 47273 47343 +70
Branches 5967 5979 +12
============================================
+ Hits 34614 34660 +46
- Misses 9643 9656 +13
- Partials 3016 3027 +11 Continue to review full report at Codecov.
|
grpc-protocol/src/main/java/com/linecorp/armeria/common/grpc/protocol/ArmeriaMessageFramer.java
Show resolved
Hide resolved
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.
How about updating the *-grpc.mdx
?
grpc-protocol/src/main/java/com/linecorp/armeria/common/grpc/protocol/ArmeriaMessageFramer.java
Outdated
Show resolved
Hide resolved
grpc-protocol/src/main/java/com/linecorp/armeria/common/grpc/protocol/ArmeriaMessageFramer.java
Outdated
Show resolved
Hide resolved
grpc-protocol/src/main/java/com/linecorp/armeria/common/grpc/protocol/Base64Decoder.java
Outdated
Show resolved
Hide resolved
grpc-protocol/src/test/java/com/linecorp/armeria/common/grpc/protocol/Base64DecoderTest.java
Show resolved
Hide resolved
grpc/src/main/java/com/linecorp/armeria/client/grpc/GrpcClientOptions.java
Outdated
Show resolved
Hide resolved
Thanks!, updated |
grpc-protocol/src/main/java/com/linecorp/armeria/common/grpc/protocol/ArmeriaMessageFramer.java
Outdated
Show resolved
Hide resolved
grpc-protocol/src/test/java/com/linecorp/armeria/common/grpc/protocol/Base64DecoderTest.java
Outdated
Show resolved
Hide resolved
grpc/src/main/java/com/linecorp/armeria/client/grpc/GrpcClientOptions.java
Outdated
Show resolved
Hide resolved
grpc/src/main/java/com/linecorp/armeria/client/grpc/GrpcWebUtil.java
Outdated
Show resolved
Hide resolved
grpc-protocol/src/main/java/com/linecorp/armeria/common/grpc/protocol/Base64Decoder.java
Show resolved
Hide resolved
grpc/src/main/java/com/linecorp/armeria/internal/client/grpc/ArmeriaClientCall.java
Show resolved
Hide resolved
grpc/src/main/java/com/linecorp/armeria/internal/client/grpc/ArmeriaClientCall.java
Outdated
Show resolved
Hide resolved
grpc/src/main/java/com/linecorp/armeria/server/grpc/ArmeriaServerCall.java
Outdated
Show resolved
Hide resolved
@@ -65,7 +65,7 @@ | |||
public final class GrpcServiceBuilder { | |||
|
|||
private static final Set<SerializationFormat> DEFAULT_SUPPORTED_SERIALIZATION_FORMATS = | |||
ImmutableSet.of(GrpcSerializationFormats.PROTO, GrpcSerializationFormats.PROTO_WEB); | |||
GrpcSerializationFormats.values(); |
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.
ImmutableSet.of(GrpcSerializationFormats.PROTO, GrpcSerializationFormats.PROTO_WEB); | ||
ImmutableSet.of(GrpcSerializationFormats.PROTO, | ||
GrpcSerializationFormats.PROTO_WEB, | ||
GrpcSerializationFormats.PROTO_WEB_TEXT); |
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.
Could you enable all gRPC protocols by default?
Most of Armeria users use gRPC-Java and com.google.protobuf.Message
. Armeria can encode and decode the messages by default.
Even though Armeria does not support ScalaPB JSON by default. 😅
Any thoughts? @anuraaga
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.
Oops... Ditto 🤣
grpc/src/main/java/com/linecorp/armeria/unsafe/grpc/GrpcUnsafeBufferUtil.java
Outdated
Show resolved
Hide resolved
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.
Finally! 🎉
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.
Nice work! @minwoox
import io.netty.util.ByteProcessor; | ||
|
||
/** | ||
* A stateful Base64decoder. Unlike {@link Base64#getDecoder()}, this decoder does not end when it meets |
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.
* A stateful Base64decoder. Unlike {@link Base64#getDecoder()}, this decoder does not end when it meets | |
* A stateful Base64decoder. Unlike {@link io.netty.handler.codec.base64.Base64Decoder}, this decoder does not end when it meets |
Important to describe the difference in this fork, not behavior vs JDK.
|
||
// White space, Equals sign or better | ||
if (decodedByte < EQUALS_SIGN_ENC) { | ||
// Ignore the white space. |
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.
Why do we ignore white space, that seems like malformed base64?
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.
Let me raise an exception. 😄
decodedSecond.release(); | ||
} | ||
|
||
private static List<ByteBuf> fragmentRandomly(byte[] bytes) { |
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 don't think we should generate test cases randomly, it's very hard to be convinced this class is actually a complete test for base64, can you write a more concrete, easy to reason about test suite? Of course this is a big reason I didn't want to implement it :)
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'm working on a PR that supports compression and decoding base64 in GrpcWebUtil.
Let me work on this in that PR. 😄
@anuraaga Please keep commenting. We'll send a follow up PR for them. 🙇 |
Address the comments from @anuraaga
Motivation: The [spec](https://tools.ietf.org/html/rfc4648#section-3.1) says that ``` Implementations MUST NOT add line feeds to base-encoded data unless the specification referring to this document explicitly directs base encoders to add line feeds after a specific number of characters. ``` So we should not add line-feed when base64 encoding. Motivations: - Do not add line-feed when base64 encoding. - Address comments from @anuraaga in #2938. Result: - grpc-web-text does not contain line-feed characters.
Motivation: I made a mistake in line#2938 that the `ByteBufInputStream` is not closed. Modification: - Close `ByteBufInputStream` Result: - Less leaks
Motivation: I made a mistake in #2938 that the `ByteBufInputStream` is not closed. Modification: - Close `ByteBufInputStream` Result: - Less leaks
Motivation: Currently, we only support grpc-web, not grpc-web-text. It would be nice if we support both. Modifications: - `GrpcService` now supports all `GrpcSerializationFormats` by default. - `ArmeriaMessageFramer` and `ArmeriaMessageDeframer` now takes the additional boolean flag which indicates encoding decoding base64 - Add gRPC-web it test with akka-grpc - The official grpc-java does not support grpc-web so we use akka-grpc for it testing Result: - You can now use grpc-web-text using Armeria client and server. - Close line#2911
…e#2946) Motivation: The [spec](https://tools.ietf.org/html/rfc4648#section-3.1) says that ``` Implementations MUST NOT add line feeds to base-encoded data unless the specification referring to this document explicitly directs base encoders to add line feeds after a specific number of characters. ``` So we should not add line-feed when base64 encoding. Motivations: - Do not add line-feed when base64 encoding. - Address comments from @anuraaga in line#2938. Result: - grpc-web-text does not contain line-feed characters.
Motivation: I made a mistake in line#2938 that the `ByteBufInputStream` is not closed. Modification: - Close `ByteBufInputStream` Result: - Less leaks
Motivation:
Currently, we only support grpc-web, not grpc-web-text.
It would be nice if we support both.
Modifications:
GrpcService
now supports allGrpcSerializationFormats
by default.ArmeriaMessageFramer
andArmeriaMessageDeframer
now takes the additional boolean flag which indicates encoding decoding base64Result:
TO-do:
GrpcWebUtil
.