cachingProhibited • Akka HTTP (original) (raw)

Signature

def cachingProhibited: Directive0

Description

This directive is used to filter out requests that forbid caching. It is used as a building block of the cache directive to prevent caching if the client requests so.

Example

Scala

source`` import akka.http.scaladsl.model.headers.Cache-Control import akka.http.scaladsl.model.headers.CacheDirectives.no-cache

val route = cachingProhibited { complete("abc") }

Get("/") ~> route ~> check { handled shouldEqual false } Get("/") ~> Cache-Control(no-cache) ~> route ~> check { responseAs[String] shouldEqual "abc" } ``

Java

source`final Route route = cachingProhibited(() -> complete("abc") );

// tests: testRoute(route) .run(HttpRequest.GET("/")) .assertStatusCode(StatusCodes.NOT_FOUND);

final CacheControl noCache = CacheControl.create(CacheDirectives.NO_CACHE); testRoute(route) .run(HttpRequest.GET("/").addHeader(noCache)) .assertEntity("abc");`

Found an error in this documentation? The source code for this page can be found here. Please feel free to edit and contribute a pull request.