dave
09/12/2018, 9:01 AMval contexts = RequestContexts()
val key = RequestContextKey.required<Credentials>(contexts)
fun lookupCredentials(token: String): Credentials? = if (token == "Bearer: 42") Credentials("user", "pass") else null
val app = ServerFilters.InitialiseRequestContext(contexts)
.then(Filter { next ->
{ req ->
req.header("Authorization")
?.let(::lookupCredentials)
?.let { next(req.with(key of it)) }
?: Response(UNAUTHORIZED)
}
}).then { Response(OK).body(key(it).toString()) }