extractScheme
Description
Extracts the Uri scheme (i.e. “http
”, “https
”, etc.) for an incoming request.
For rejecting a request if it doesn’t match a specified scheme name, see the scheme directive.
Example
- Scala
-
source
val route = extractScheme { scheme => complete(s"The scheme is '$scheme'") } // tests: Get("https://www.example.com/") ~> route ~> check { responseAs[String] shouldEqual "The scheme is 'https'" }
- Java
-
source
import static org.apache.pekko.http.javadsl.server.Directives.complete; import static org.apache.pekko.http.javadsl.server.Directives.extractScheme; final Route route = extractScheme((scheme) -> complete(String.format("The scheme is '%s'", scheme))); testRoute(route) .run(HttpRequest.GET("https://www.example.com/")) .assertEntity("The scheme is 'https'");
1.0.1