All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.http4k.core.RequestContexts.kt Maven / Gradle / Ivy

package org.http4k.core

import java.util.UUID
import java.util.concurrent.ConcurrentHashMap

/**
 * In-memory RequestContext store. Override the storeId to use multiple stores in one app.
 */
class RequestContexts(storeId: String? = null) : Store {
    private val requests = ConcurrentHashMap()

    private val requestContextLens = RequestContext.lensForStore(storeId)

    override fun invoke(target: Request): RequestContext =
        requests[requestContextLens(target)] ?: throw IllegalStateException("No RequestContext initialised")

    override fun  invoke(value: RequestContext, target: R): R {
        requests[value.id] = value
        return requestContextLens(value.id, target)
    }

    override fun remove(value: RequestContext): RequestContext? = requests.remove(value.id)
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy