dave
09/14/2017, 10:27 AMfun main(args: Array<String>) {
val contexts = RequestContexts()
val key = RequestContextKey.of<String>(contexts)
val key2 = RequestContextKey.of<String>(contexts)
fun AddStringTo(key: RequestContextLens<String>) = Filter { next ->
{
next(it.with(key of "hello", key2 of "bob"))
}
}
val next: HttpHandler = { request ->
Response(Status.OK).body(key.extract(request) + key2.extract(request))
}
val b = ServerFilters.InitialiseRequestContext(contexts)
.then(AddStringTo(key))
.then(next)
val a = b(Request(Method.GET, "/hello"))
println(a.bodyString())
}
. The RequestContexts
is an object which is shared globally across the app. You also need to add the InitialiseRequestContext filter to the chain, which deals with cleaning up the RequestContext at the end.