diff --git a/akka-http/src/main/scala/akka/http/impl/server/RequestContextImpl.scala b/akka-http/src/main/scala/akka/http/impl/server/RequestContextImpl.scala index f15a7aaf87..294b03cfa8 100644 --- a/akka-http/src/main/scala/akka/http/impl/server/RequestContextImpl.scala +++ b/akka-http/src/main/scala/akka/http/impl/server/RequestContextImpl.scala @@ -4,6 +4,10 @@ package akka.http.impl.server +import akka.http.javadsl.model.ContentType +import akka.http.scaladsl.model.HttpEntity +import akka.stream.Materializer + import scala.concurrent.{ ExecutionContext, Future } import akka.http.javadsl.{ model ⇒ jm } import akka.http.impl.util.JavaMapping.Implicits._ @@ -23,8 +27,11 @@ private[http] final case class RequestContextImpl(underlying: ScalaRequestContex def completeWith(futureResult: Future[RouteResult]): RouteResult = futureResult.flatMap { case r: RouteResultImpl ⇒ r.underlying - }(executionContext) + }(executionContext()) def complete(text: String): RouteResult = underlying.complete(text) + def complete(contentType: ContentType, text: String): RouteResult = + underlying.complete(HttpEntity(contentType.asScala, text)) + def completeWithStatus(statusCode: Int): RouteResult = completeWithStatus(jm.StatusCodes.get(statusCode)) def completeWithStatus(statusCode: jm.StatusCode): RouteResult = @@ -39,5 +46,6 @@ private[http] final case class RequestContextImpl(underlying: ScalaRequestContex def notFound(): RouteResult = underlying.reject() - def executionContext: ExecutionContext = underlying.executionContext + def executionContext(): ExecutionContext = underlying.executionContext + def materializer(): Materializer = underlying.materializer } diff --git a/akka-http/src/main/scala/akka/http/javadsl/server/RequestContext.scala b/akka-http/src/main/scala/akka/http/javadsl/server/RequestContext.scala index 8c3332d511..f2836b72ff 100644 --- a/akka-http/src/main/scala/akka/http/javadsl/server/RequestContext.scala +++ b/akka-http/src/main/scala/akka/http/javadsl/server/RequestContext.scala @@ -5,6 +5,7 @@ package akka.http.javadsl.server import akka.http.javadsl.model._ +import akka.stream.Materializer import akka.util.ByteString import scala.concurrent.{ ExecutionContext, Future } @@ -24,6 +25,12 @@ trait RequestContext { */ def unmatchedPath: String + /** Returns the ExecutionContext of this RequestContext */ + def executionContext(): ExecutionContext + + /** Returns the Materializer of this RequestContext */ + def materializer(): Materializer + /** * Completes the request with a value of type T and marshals it using the given * marshaller. @@ -40,6 +47,11 @@ trait RequestContext { */ def complete(text: String): RouteResult + /** + * Completes the request with the given string as an entity of the given type. + */ + def complete(contentType: ContentType, text: String): RouteResult + /** * Completes the request with the given status code and no entity. */ @@ -61,8 +73,5 @@ trait RequestContext { */ def notFound(): RouteResult - /** Returns the ExecutionContext of this RequestContext */ - def executionContext(): ExecutionContext - // FIXME: provide proper support for rejections, see #16438 } \ No newline at end of file