extractHost

Signature

def extractHost: Directive1[String]

Description

Extract the hostname part of the Host request header and expose it as a String extraction to its inner route.

Example

val route =
  extractHost { hn =>
    complete(s"Hostname: $hn")
  }

// tests:
Get() ~> Host("company.com", 9090) ~> route ~> check {
  status shouldEqual OK
  responseAs[String] shouldEqual "Hostname: company.com"
}
The source code for this page can be found here.