Skip to content

Commit

Permalink
code review @minwoox
Browse files Browse the repository at this point in the history
  • Loading branch information
mscheong01 committed Aug 25, 2022
1 parent 6195f8f commit a498c67
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
4 changes: 2 additions & 2 deletions core/src/main/java/com/linecorp/armeria/common/MediaType.java
Expand Up @@ -1055,8 +1055,8 @@ public boolean isJson() {
}

/**
* Returns {@code true} when the subtype is one of {@link MediaType#PROTOBUF}, {@link MediaType#X_PROTOBUF} and {@link MediaType#X_GOOGLE_PROTOBUF}.
* Otherwise {@code false}.
* Returns {@code true} when the subtype is one of {@link MediaType#PROTOBUF}, {@link MediaType#X_PROTOBUF}
* and {@link MediaType#X_GOOGLE_PROTOBUF}. Otherwise {@code false}.
*
* <pre>{@code
* PROTOBUF.isProtobuf() // true
Expand Down
Expand Up @@ -145,21 +145,14 @@ public HttpResponse serve(ServiceRequestContext ctx, HttpRequest req) throws Exc
ctx.logBuilder().defer(RequestLogProperty.REQUEST_CONTENT,
RequestLogProperty.RESPONSE_CONTENT);

final MediaType responseContentType;
if (clientHeaders.accept().isEmpty() || clientHeaders.accept().contains(contentType)) {
responseContentType = contentType;
} else {
responseContentType = null;
}

final CompletableFuture<HttpResponse> responseFuture = new CompletableFuture<>();
req.aggregateWithPooledObjects(ctx.eventLoop(), ctx.alloc()).handle((clientRequest, t) -> {
try (SafeCloseable ignore = ctx.push()) {
if (t != null) {
responseFuture.completeExceptionally(t);
} else {
frameAndServe(unwrap(), ctx, grpcHeaders.build(), clientRequest.content(),
responseFuture, null, responseContentType);
responseFuture, null, contentType);
}
}
return null;
Expand Down
Expand Up @@ -75,12 +75,12 @@ void respondWithCorrespondingJsonMediaType() throws Exception {

@ParameterizedTest
@ArgumentsSource(ProtobufMediaTypeProvider.class)
void respondWithCorrespondingProtobufMediaType() throws Exception {
void respondWithCorrespondingProtobufMediaType(MediaType protobufType) throws Exception {
final UnframedGrpcService unframedGrpcService = buildUnframedGrpcService(testService);

final HttpRequest request = HttpRequest.of(HttpMethod.POST,
"/armeria.grpc.testing.TestService/EmptyCall",
MediaType.PROTOBUF,
protobufType,
EmptyProtos.Empty.getDefaultInstance().toByteArray());
final ServiceRequestContext ctx = ServiceRequestContext.builder(request)
.build();
Expand Down

0 comments on commit a498c67

Please sign in to comment.