I have a question.
I have Akka HTTP Server and using Akka HTTP Client. The Client does a lot of external calls basically with Http.singleRequest(). This takes a lot of time and sometimes User closes the connection to my Server.
So the question is - how can I detect that User has closed the connection ?
server.scala:
val requestHandler: HttpRequest => HttpResponse = {
case HttpRequest(HttpMethods.GET, Uri.Path("/"), _, _, _) =>
Thread.sleep(5000)
println("reply")
HttpResponse(entity = HttpEntity(
ContentTypes.`text/html(UTF-8)`,
"Ok"))
}
val serverBinding: Future[Http.ServerBinding] = Http().bind(host, port)
.via(reactToTopLevelFailures)
.to(Sink.foreach { connection: IncomingConnection =>
println("Accepted new connection from " + connection.remoteAddress)
connection.handleWith(Flow[HttpRequest] map requestHandler)
})
.run()
You can simply do a request via cURL and cancel it immediately you will still see "reply" in the console.
Thanks