extractScheme

Signature

def extractScheme: Directive1[String] 

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
sourceval 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
sourceimport 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'");