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

Complete directives take ResponseEntity as a parameter instead of RequestEntity #982

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -17,6 +17,7 @@ import akka.http.impl.model.JavaUri
import akka.http.javadsl.model.HttpHeader
import akka.http.javadsl.model.HttpResponse
import akka.http.javadsl.model.RequestEntity
import akka.http.javadsl.model.ResponseEntity
import akka.http.javadsl.model.StatusCode
import akka.http.javadsl.model.Uri
import akka.http.javadsl.server.{ RoutingJavaMapping, Rejection, Route }
Expand Down Expand Up @@ -112,10 +113,17 @@ abstract class RouteDirectives extends RespondWithDirectives {
/**
* Completes the request using the given status code, headers, and response entity.
*/
def complete(status: StatusCode, headers: java.lang.Iterable[HttpHeader], entity: RequestEntity) = RouteAdapter {
def complete(status: StatusCode, headers: java.lang.Iterable[HttpHeader], entity: ResponseEntity) = RouteAdapter {
D.complete(scaladsl.model.HttpResponse(status = status.asScala, entity = entity.asScala, headers = Util.immutableSeq(headers).map(_.asScala))) // TODO avoid the map()
}

/**
* Completes the request using the given status code, headers, and response entity.
*/
def complete(status: StatusCode, headers: java.lang.Iterable[HttpHeader], entity: RequestEntity): RouteAdapter = {
complete(status, headers, entity: ResponseEntity)
}

/**
* Completes the request using the given status code, marshalling the given value as response entity.
*/
Expand All @@ -126,10 +134,15 @@ abstract class RouteDirectives extends RespondWithDirectives {
/**
* Completes the request using the given status code and response entity.
*/
def complete(status: StatusCode, entity: RequestEntity) = RouteAdapter {
def complete(status: StatusCode, entity: ResponseEntity) = RouteAdapter {
D.complete(scaladsl.model.HttpResponse(status = status.asScala, entity = entity.asScala))
}

/**
* Completes the request using the given status code and response entity.
*/
def complete(status: StatusCode, entity: RequestEntity): RouteAdapter = complete(status, entity: ResponseEntity)

/**
* Completes the request using the given status code and the given body as UTF-8.
*/
Expand All @@ -147,10 +160,16 @@ abstract class RouteDirectives extends RespondWithDirectives {
/**
* Completes the request as HTTP 200 OK, adding the given headers and response entity.
*/
def complete(headers: java.lang.Iterable[HttpHeader], entity: RequestEntity) = RouteAdapter {
def complete(headers: java.lang.Iterable[HttpHeader], entity: ResponseEntity) = RouteAdapter {
D.complete(scaladsl.model.HttpResponse(headers = headers.asScala.toVector.map(_.asScala), entity = entity.asScala)) // TODO can we avoid the map() ?
}

/**
* Completes the request as HTTP 200 OK, adding the given headers and response entity.
*/
def complete(headers: java.lang.Iterable[HttpHeader], entity: RequestEntity): RouteAdapter =
complete(headers, entity: ResponseEntity)

/**
* Completes the request as HTTP 200 OK, marshalling the given value as response entity.
*/
Expand All @@ -162,10 +181,15 @@ abstract class RouteDirectives extends RespondWithDirectives {
/**
* Completes the request as HTTP 200 OK with the given value as response entity.
*/
def complete(entity: RequestEntity) = RouteAdapter {
def complete(entity: ResponseEntity) = RouteAdapter {
D.complete(scaladsl.model.HttpResponse(entity = entity.asScala))
}

/**
* Completes the request as HTTP 200 OK with the given value as response entity.
*/
def complete(entity: RequestEntity): RouteAdapter = complete(entity: ResponseEntity)

// --- manual "magnet" for Scala Future ---

/**
Expand Down