Skip to content

Instantly share code, notes, and snippets.

@christophknabe
Last active August 29, 2015 14:02
Show Gist options
  • Save christophknabe/2ca72ce5a5aa2d942d62 to your computer and use it in GitHub Desktop.
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
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