diff --git a/http-testkit/src/main/scala/org/apache/pekko/http/scaladsl/testkit/RouteTest.scala b/http-testkit/src/main/scala/org/apache/pekko/http/scaladsl/testkit/RouteTest.scala index 2bbde91bd..4ed18506c 100644 --- a/http-testkit/src/main/scala/org/apache/pekko/http/scaladsl/testkit/RouteTest.scala +++ b/http-testkit/src/main/scala/org/apache/pekko/http/scaladsl/testkit/RouteTest.scala @@ -20,7 +20,7 @@ import scala.reflect.ClassTag import scala.util.DynamicVariable import org.apache.pekko -import pekko.actor.ActorSystem +import pekko.actor.{ ActorSystem, ClassicActorSystemProvider } import pekko.http.scaladsl.Http import pekko.http.scaladsl.client.RequestBuilding import pekko.http.scaladsl.model._ @@ -224,8 +224,24 @@ trait RouteTest extends RequestBuilding with WSTestRequestBuilding with RouteTes } } } -private[http] object RouteTest { - def runRouteClientServer(request: HttpRequest, route: Route, serverSettings: ServerSettings)( +object RouteTest { + + /** + * Turn the route into a function for testing, but do not handle exceptions in any way, instead, they are bubbled + * out as is to the caller. + * @since 1.4.0 + */ + def toFunctionPassThroughExceptions(route: Route)( + implicit system: ClassicActorSystemProvider): HttpRequest => Future[HttpResponse] = { + val routingLog = RoutingLog(system.classicSystem.log) + val routingSettings = RoutingSettings(system) + val parserSettings = ParserSettings.forServer + implicit val ec: ExecutionContextExecutor = system.classicSystem.dispatcher + implicit val mat: Materializer = SystemMaterializer(system).materializer + Route.createAsyncHandler(route, routingLog, routingSettings, parserSettings) + } + + private[http] def runRouteClientServer(request: HttpRequest, route: Route, serverSettings: ServerSettings)( implicit system: ActorSystem): Future[HttpResponse] = { import system.dispatcher for { diff --git a/http/src/main/scala/org/apache/pekko/http/scaladsl/server/Route.scala b/http/src/main/scala/org/apache/pekko/http/scaladsl/server/Route.scala index cbacfdea0..bbd20d423 100644 --- a/http/src/main/scala/org/apache/pekko/http/scaladsl/server/Route.scala +++ b/http/src/main/scala/org/apache/pekko/http/scaladsl/server/Route.scala @@ -85,7 +85,7 @@ object Route { SystemMaterializer(system).materializer) } - private def createAsyncHandler(sealedRoute: Route, routingLog: RoutingLog, routingSettings: RoutingSettings, + private[pekko] def createAsyncHandler(sealedRoute: Route, routingLog: RoutingLog, routingSettings: RoutingSettings, parserSettings: ParserSettings)( implicit ec: ExecutionContextExecutor, mat: Materializer): HttpRequest => Future[HttpResponse] = { request =>