extractSettings
Description
Extracts the RoutingSettings
RoutingSettings
from the RequestContext
RequestContext
.
By default the settings of the Http()
extension running the route will be returned. It is possible to override the settings for specific sub-routes by using the withSettings directive.
Example
- Scala
-
source
val route = extractSettings { (settings: RoutingSettings) => complete(s"RoutingSettings.renderVanityFooter = ${settings.renderVanityFooter}") } // tests: Get("/") ~> route ~> check { responseAs[String] shouldEqual "RoutingSettings.renderVanityFooter = true" }
- Java
-
source
import static org.apache.pekko.http.javadsl.server.Directives.extractRequestContext; final Route route = extractRequestContext( ctx -> { ctx.getLog().debug("Using access to additional context available, like the logger."); final HttpRequest request = ctx.getRequest(); return complete( "Request method is " + request.method().name() + " and content-type is " + request.entity().getContentType()); }); // tests: testRoute(route) .run(HttpRequest.POST("/").withEntity("text")) .assertEntity("Request method is POST and content-type is text/plain; charset=UTF-8"); testRoute(route) .run(HttpRequest.GET("/")) .assertEntity("Request method is GET and content-type is none/none");
1.1.0