hostName

Extracts the hostname part of the Host header value in the request.

Signature

def hostName: 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 =
  hostName { hn =>
    complete(s"Hostname: $hn")
  }

Get() ~> Host("company.com", 9090) ~> route ~> check {
  status === OK
  responseAs[String] === "Hostname: company.com"
}