Last active
August 29, 2015 14:02
-
-
Save christophknabe/2ca72ce5a5aa2d942d62 to your computer and use it in GitHub Desktop.
Getting the Future of the ProductVersion of the server offering the requested URI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def requestProductVersion(uri: String)(implicit system: ActorSystem): Future[ProductVersion] = { | |
val uriCompleted = if(uri.indexOf('/') < 0) uri+'/' else uri | |
import system.dispatcher // execution context for future transformation below | |
val startTime = Platform.currentTime | |
for { | |
response <- IO(Http).ask(HttpRequest(GET, Uri(s"http://$uri"))).mapTo[HttpResponse] | |
_ <- IO(Http) ? Http.CloseAll | |
} yield { | |
val startAtMillis = startTime - system.startTime | |
val durationInMillis = Platform.currentTime - startTime | |
system.log.info(s"Get URI $uri responded '${response.status}' with ${response.entity.data.length} bytes. Started at $startAtMillis ms, lasted $durationInMillis ms.") | |
response.header[HttpHeaders.Server].get.products.head | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment