Skip to content
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

remove isGrpcRequest check from the java api to align with scala api #1669

Merged
merged 2 commits into from
Aug 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions runtime/src/main/scala/akka/grpc/javadsl/ServiceHandler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import java.util.concurrent.{ CompletableFuture, CompletionStage }

import akka.annotation.ApiMayChange
import akka.annotation.InternalApi
import akka.grpc.scaladsl.{ ServiceHandler => sServiceHandler }
import akka.http.javadsl.model.{ HttpRequest, HttpResponse, StatusCodes }
import akka.japi.function.{ Function => JFunction }

Expand Down Expand Up @@ -42,15 +41,13 @@ object ServiceHandler {
/**
* Creates a `HttpRequest` to `HttpResponse` handler for gRPC services that can be used in
* for example `Http().bindAndHandleAsync` for the generated partial function handlers:
* - The generated handler supports the `application/grpc` media type.
* - If the request is for an invalid media type, then a _415: Unsupported Media Type_ response is produced.
* - Otherwise if the request is not handled by one of the provided handlers, a _404: Not Found_ response is produced.
* - If the request is not handled by one of the provided handlers, a _404: Not Found_ response is produced.
*/
@varargs
def handler(handlers: JFunction[HttpRequest, CompletionStage[HttpResponse]]*)
: JFunction[HttpRequest, CompletionStage[HttpResponse]] = {
val servicesHandler = concat(handlers: _*)
(req: HttpRequest) => if (sServiceHandler.isGrpcRequest(req)) servicesHandler(req) else unsupportedMediaType
(req: HttpRequest) => servicesHandler(req)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says "If the request is for an invalid media type, then a 415: Unsupported Media Type response is produced.". This probably only is true for paths matched by the handler? Might be something to double-check and perhaps make the comment more specific?

Copy link
Contributor Author

@sebastian-alfers sebastian-alfers Aug 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I changed the comment.

}

private[javadsl] def concat(handlers: JFunction[HttpRequest, CompletionStage[HttpResponse]]*)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package akka.grpc.scaladsl

import akka.annotation.ApiMayChange
import akka.grpc.GrpcProtocol
import akka.grpc.internal.{ GrpcProtocolNative, GrpcProtocolWeb, GrpcProtocolWebText }
import akka.grpc.internal.{ GrpcProtocolWeb, GrpcProtocolWebText }
import akka.http.javadsl.{ model => jmodel }
import akka.http.scaladsl.model.{ HttpRequest, HttpResponse, StatusCodes }

Expand All @@ -23,7 +23,6 @@ object ServiceHandler {
private def matchesVariant(variants: Set[GrpcProtocol])(request: jmodel.HttpRequest) =
variants.exists(_.mediaTypes.contains(request.entity.getContentType.mediaType))

private[grpc] val isGrpcRequest: jmodel.HttpRequest => Boolean = matchesVariant(Set(GrpcProtocolNative))
private[grpc] val isGrpcWebRequest: jmodel.HttpRequest => Boolean = matchesVariant(
Set(GrpcProtocolWeb, GrpcProtocolWebText))

Expand Down