@Override
    public HttpResponse serve(ServiceRequestContext ctx, HttpRequest req) throws Exception {
        final RequestHeaders clientHeaders = req.headers();
        final MediaType contentType = clientHeaders.contentType();
        if (contentType == null) {
            // All gRPC requests, whether framed or non-framed, must have content-type. If it's not sent, let
            // the delegate return its usual error message.
            return unwrap().serve(ctx, req);
        }

        for (SerializationFormat format : GrpcSerializationFormats.values()) {
            if (format.isAccepted(contentType)) {
                // Framed request, so just delegate.
                return unwrap().serve(ctx, req);
            }
        }

        final ServerMethodDefinition<?, ?> method = methodDefinition(ctx);
        if (method == null) {
            // Unknown method, let the delegate return a usual error.
            return unwrap().serve(ctx, req);
        }

        if (method.getMethodDescriptor().getType() != MethodType.UNARY) {
            return HttpResponse.of(HttpStatus.BAD_REQUEST,
                                   MediaType.PLAIN_TEXT_UTF_8,
                                   "Only unary methods can be used with non-framed requests.");
        }

        final RequestHeadersBuilder grpcHeaders = clientHeaders.toBuilder();

        final MediaType framedContentType;
        if (contentType.isProtobuf()) {
            framedContentType = GrpcSerializationFormats.PROTO.mediaType();
        } else if (contentType.is(MediaType.JSON)) {
            framedContentType = GrpcSerializationFormats.JSON.mediaType();
        } else {
            return HttpResponse.of(HttpStatus.UNSUPPORTED_MEDIA_TYPE,
                                   MediaType.PLAIN_TEXT_UTF_8,
                                   "Unsupported media type. Only application/protobuf, " +
                                   "application/x-protobuf, application/x-google-protobuf" +
                                   "and application/json are supported.");
        }
        grpcHeaders.contentType(framedContentType);

        if (grpcHeaders.get(GrpcHeaderNames.GRPC_ENCODING) != null) {
            return HttpResponse.of(HttpStatus.UNSUPPORTED_MEDIA_TYPE,
                                   MediaType.PLAIN_TEXT_UTF_8,
                                   "gRPC encoding is not supported for non-framed requests.");
        }

        // All clients support no encoding, and we don't support gRPC encoding for non-framed requests, so just
        // clear the header if it's present.
        grpcHeaders.remove(GrpcHeaderNames.GRPC_ACCEPT_ENCODING);

        ctx.logBuilder().defer(RequestLogProperty.REQUEST_CONTENT,
                               RequestLogProperty.RESPONSE_CONTENT);

        final CompletableFuture<HttpResponse> responseFuture = new CompletableFuture<>();
        req.aggregate(AggregationOptions.usePooledObjects(ctx.alloc(), ctx.eventLoop()))
           .handle((clientRequest, t) -> {
               try (SafeCloseable ignore = ctx.push()) {
                   if (t != null) {
                       responseFuture.completeExceptionally(t);
                   } else {
                       // Add the content type to the response headers.
                       final Function<AggregatedHttpResponse, AggregatedHttpResponse> responseConverter =
                               response -> {
                                   final ResponseHeaders headers = response.headers().withMutations(
                                           builder -> builder.contentType(contentType));
                                   return AggregatedHttpResponse.of(headers, response.content());
                               };
                       frameAndServe(unwrap(), ctx, grpcHeaders.build(), clientRequest.content(),
                                     responseFuture, responseConverter);
                   }
               }
               return null;
           });
        return HttpResponse.of(responseFuture);
    }
Creates a new instance that decorates the specified {@link HttpService}.
grpc/src/main/java/com/linecorp/armeria/server/grpc/UnframedGrpcService.java