diff options
author | adamw <adam@warski.org> | 2017-09-04 16:27:43 +0200 |
---|---|---|
committer | adamw <adam@warski.org> | 2017-09-04 16:27:43 +0200 |
commit | 2761923dcf1ea49f7671cc2f18df9bd07f0df40b (patch) | |
tree | 1e20c4d823f0ff734d77c54e96ab738f4186c740 /akka-http-handler | |
parent | 41bbe08c125bb3714aee862ec9dc55419c29986d (diff) | |
download | sttp-2761923dcf1ea49f7671cc2f18df9bd07f0df40b.tar.gz sttp-2761923dcf1ea49f7671cc2f18df9bd07f0df40b.tar.bz2 sttp-2761923dcf1ea49f7671cc2f18df9bd07f0df40b.zip |
Extracting FollowRedirectsHandler as a wrapper-handler
Diffstat (limited to 'akka-http-handler')
-rw-r--r-- | akka-http-handler/src/main/scala/com/softwaremill/sttp/akkahttp/AkkaHttpHandler.scala | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/akka-http-handler/src/main/scala/com/softwaremill/sttp/akkahttp/AkkaHttpHandler.scala b/akka-http-handler/src/main/scala/com/softwaremill/sttp/akkahttp/AkkaHttpHandler.scala index a2695e2..2aa4251 100644 --- a/akka-http-handler/src/main/scala/com/softwaremill/sttp/akkahttp/AkkaHttpHandler.scala +++ b/akka-http-handler/src/main/scala/com/softwaremill/sttp/akkahttp/AkkaHttpHandler.scala @@ -30,11 +30,11 @@ class AkkaHttpHandler private (actorSystem: ActorSystem, // the supported stream type private type S = Source[ByteString, Any] - private implicit val as = actorSystem - private implicit val materializer = ActorMaterializer() + private implicit val as: ActorSystem = actorSystem + private implicit val materializer: ActorMaterializer = ActorMaterializer() - override protected def doSend[T](r: Request[T, S]): Future[Response[T]] = { - implicit val ec = this.ec + override def send[T](r: Request[T, S]): Future[Response[T]] = { + implicit val ec: ExecutionContext = this.ec requestToAkka(r) .flatMap(setBodyOnAkka(r, r.body, _)) .toFuture @@ -269,6 +269,13 @@ class AkkaHttpHandler private (actorSystem: ActorSystem, object AkkaHttpHandler { + private def apply(actorSystem: ActorSystem, + ec: ExecutionContext, + terminateActorSystemOnClose: Boolean) + : SttpHandler[Future, Source[ByteString, Any]] = + new FollowRedirectsHandler( + new AkkaHttpHandler(actorSystem, ec, terminateActorSystemOnClose)) + /** * @param ec The execution context for running non-network related operations, * e.g. mapping responses. Defaults to the global execution @@ -276,7 +283,7 @@ object AkkaHttpHandler { */ def apply()(implicit ec: ExecutionContext = ExecutionContext.Implicits.global) : SttpHandler[Future, Source[ByteString, Any]] = - new AkkaHttpHandler(ActorSystem("sttp"), ec, true) + AkkaHttpHandler(ActorSystem("sttp"), ec, terminateActorSystemOnClose = true) /** * @param actorSystem The actor system which will be used for the http-client @@ -288,5 +295,5 @@ object AkkaHttpHandler { def usingActorSystem(actorSystem: ActorSystem)( implicit ec: ExecutionContext = ExecutionContext.Implicits.global) : SttpHandler[Future, Source[ByteString, Any]] = - new AkkaHttpHandler(actorSystem, ec, false) + AkkaHttpHandler(actorSystem, ec, terminateActorSystemOnClose = false) } |