-
Notifications
You must be signed in to change notification settings - Fork 36
Implement gRPC-Web protocol #89
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0fad36d
Unit tests for the gRPC-Web protocol
tsegismont 87ebe50
Implement gRPC Web protocol
tsegismont 685ee0a
Add documentation
tsegismont 35b180f
Run gRPC-Web interop tests as part of the build
tsegismont 608ca70
Updates after review
tsegismont 33c2596
gRPC-Web over HTTP/2 should be allowed
tsegismont 2ae4745
Updates after review
tsegismont File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
vertx-grpc-common/src/main/java/io/vertx/grpc/common/GrpcMediaType.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| /* | ||
| * Copyright (c) 2011-2024 Contributors to the Eclipse Foundation | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * terms of the Eclipse Public License 2.0 which is available at | ||
| * http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
| * which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
| */ | ||
|
|
||
| package io.vertx.grpc.common; | ||
|
|
||
| import io.netty.util.AsciiString; | ||
| import io.vertx.codegen.annotations.Unstable; | ||
| import io.vertx.core.http.HttpHeaders; | ||
|
|
||
| /** | ||
| * The gRPC media types. | ||
| */ | ||
| @Unstable | ||
| public final class GrpcMediaType { | ||
|
|
||
| /** | ||
| * gRPC. | ||
| */ | ||
| public static final CharSequence GRPC = HttpHeaders.createOptimized("application/grpc"); | ||
| /** | ||
| * gRPC with Protobuf message format. | ||
| */ | ||
| public static final CharSequence GRPC_PROTO = HttpHeaders.createOptimized("application/grpc+proto"); | ||
|
|
||
| /** | ||
| * gRPC Web binary. | ||
| */ | ||
| public static final CharSequence GRPC_WEB = HttpHeaders.createOptimized("application/grpc-web"); | ||
| /** | ||
| * gRPC Web binary with Protobuf message format. | ||
| */ | ||
| public static final CharSequence GRPC_WEB_PROTO = HttpHeaders.createOptimized("application/grpc-web+proto"); | ||
|
|
||
| /** | ||
| * Whether the provided {@code mediaType} represents gRPC-Web | ||
| * | ||
| * @param mediaType the value to test | ||
| * @return {@code true} if the value represents gRPC-Web, {@code false} otherwise | ||
| */ | ||
| public static boolean isGrpcWeb(CharSequence mediaType) { | ||
| return AsciiString.regionMatches(GRPC_WEB, true, 0, mediaType, 0, GRPC_WEB.length()); | ||
| } | ||
|
|
||
| /** | ||
| * gRPC Web text (base64). | ||
| */ | ||
| public static final CharSequence GRPC_WEB_TEXT = HttpHeaders.createOptimized("application/grpc-web-text"); | ||
| /** | ||
| * gRPC Web text (base64) with Protobuf message format. | ||
| */ | ||
| public static final CharSequence GRPC_WEB_TEXT_PROTO = HttpHeaders.createOptimized("application/grpc-web-text+proto"); | ||
|
|
||
| /** | ||
| * Whether the provided {@code mediaType} represents gRPC-Web | ||
| * | ||
| * @param mediaType the value to test | ||
| * @return {@code true} if the value represents gRPC-Web, {@code false} otherwise | ||
| */ | ||
| public static boolean isGrpcWebText(CharSequence mediaType) { | ||
| return AsciiString.regionMatches(GRPC_WEB_TEXT, true, 0, mediaType, 0, GRPC_WEB_TEXT.length()); | ||
| } | ||
|
|
||
| private GrpcMediaType() { | ||
| // Constants | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
vertx-grpc-server/src/main/generated/io/vertx/grpc/server/GrpcServerOptionsConverter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package io.vertx.grpc.server; | ||
|
|
||
| import io.vertx.core.json.JsonObject; | ||
| import io.vertx.core.json.JsonArray; | ||
| import io.vertx.core.json.impl.JsonUtil; | ||
| import java.time.Instant; | ||
| import java.time.format.DateTimeFormatter; | ||
| import java.util.Base64; | ||
|
|
||
| /** | ||
| * Converter and mapper for {@link io.vertx.grpc.server.GrpcServerOptions}. | ||
| * NOTE: This class has been automatically generated from the {@link io.vertx.grpc.server.GrpcServerOptions} original class using Vert.x codegen. | ||
| */ | ||
| public class GrpcServerOptionsConverter { | ||
|
|
||
|
|
||
| private static final Base64.Decoder BASE64_DECODER = JsonUtil.BASE64_DECODER; | ||
| private static final Base64.Encoder BASE64_ENCODER = JsonUtil.BASE64_ENCODER; | ||
|
|
||
| static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, GrpcServerOptions obj) { | ||
| for (java.util.Map.Entry<String, Object> member : json) { | ||
| switch (member.getKey()) { | ||
| case "grpcWebEnabled": | ||
| if (member.getValue() instanceof Boolean) { | ||
| obj.setGrpcWebEnabled((Boolean)member.getValue()); | ||
| } | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| static void toJson(GrpcServerOptions obj, JsonObject json) { | ||
| toJson(obj, json.getMap()); | ||
| } | ||
|
|
||
| static void toJson(GrpcServerOptions obj, java.util.Map<String, Object> json) { | ||
| json.put("grpcWebEnabled", obj.isGrpcWebEnabled()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.