I know in Spray that had a request-timeout setting that could be used to control when to timeout a request that has sent the request but has yet to receive a response within a specified timeframe. I don't see this setting anywhere in Akka Http. For a single request, I can handle this by adding takeWithin to my stream processing like so:
val poolClientFlow = Http().cachedHostConnectionPool[Int]("localhost", 9200)
val responseFuture: Future[(Try[HttpResponse], Int)] =
Source.single(HttpRequest(uri = "/foo/bar/16") -> 42)
.via(poolClientFlow)
.takeWithin(5 seconds)
.runWith(Sink.head)
In this case, the Future would be failed with a NoSuchElementException which I suppose I can interpret to mean the timeout occurred. Is there a better way to do this? What happens to the underlying connection from the pool in this case? If it was really and truly hung (as opposed to just being a little late with the response) I would want it closed. Is this kind of stuff possible?