mapSettings

Signature

def mapSettings(f: RoutingSettings 

Description

Transforms the RoutingSettingsRoutingSettings with a RoutingSettings => RoutingSettings functionFunction<RoutingSettings, RoutingSettings>.

See also withSettings or extractSettings.

Example

Scala
sourceval tunedSettings = mapSettings { settings =>
  settings.withFileGetConditional(false)
}

val route =
  tunedSettings {
    extractSettings { (settings: RoutingSettings) =>
      complete(s"RoutingSettings.fileGetConditional = ${settings.fileGetConditional}")
    }
  }

// tests:
Get("/") ~> route ~> check {
  responseAs[String] shouldEqual s"RoutingSettings.fileGetConditional = false"
}
Java
sourceimport static org.apache.pekko.http.javadsl.server.Directives.mapSettings;

final Route route =
    mapSettings(
        settings -> settings.withFileGetConditional(false),
        () ->
            extractSettings(
                settings ->
                    complete(
                        "RoutingSettings.fileGetConditional = "
                            + settings.getFileGetConditional())));

// tests:
testRoute(route)
    .run(HttpRequest.GET("/"))
    .assertEntity("RoutingSettings.fileGetConditional = false");