04/23/2019, 2:08 AM
I have a header that needs to be passed on every single request. I’m using a
right now to validate it, but I also want to put it on the OpenAPI contract for each route. It looks like the only way for me to require that header on every route is to copy-paste the contract header checks?
✔️ 1
oh nevermind, this is perfect!
package org.http4k.contract

import org.http4k.core.Filter
import org.http4k.core.Method.OPTIONS
import org.http4k.core.Request
import org.http4k.core.Response
import org.http4k.core.Status.Companion.UNAUTHORIZED
import org.http4k.lens.Lens
import org.http4k.lens.LensFailure

 * Endpoint security. Provides filter to be applied to endpoints for all requests.
interface Security {
    val filter: Filter
class AuthSecurity(authFilter: (RequestContexts) -> Filter, contexts: RequestContexts) : Security {
        override val filter = authFilter(contexts)