-- SPDX-FileCopyrightText: 2026 Alexandra de Wit
--
-- SPDX-License-Identifier: MIT
{-# LANGUAGE ExistentialQuantification #-}

{- | Per-request mount wiring, runtime capabilities, and the serve handler monad.
Dispatch pairs one 'MountBinding' with 'ServeRuntime' and establishes the ambient
@katip@ context. The composition root supplies the runtime capabilities.
-}
module Ecluse.Core.Server.Context (
    -- * Request runtime
    ServeRuntime (..),

    -- * Packument-serve dependencies
    PackumentDeps (..),
    pdPrivateBaseUrl,
    pdPublicBaseUrl,
    pdPrivateBase,
    pdPublicBase,
    pdMirror,
    pdTarballHostGate,
    tarballHostHonoured,

    -- * Publish-serve dependencies
    PublishDeps (..),

    -- * The serve action, and the router an adapter supplies
    RouteAction (..),
    ResponseAction (..),
    MountRouter,

    -- * Mount binding
    MountBinding (..),

    -- * Per-request context
    RequestCtx (..),

    -- * The handler monad
    Handler,
    runHandler,
) where

import Data.IP (IPRange)
import Data.Time (UTCTime)
import Katip (Katip, KatipContext, LogEnv, SimpleLogPayload)
import Katip.Monadic (KatipContextT, runKatipContextT)
import Network.HTTP.Types (Method)
import Network.HTTP.Types.Header (RequestHeaders)
import Network.Wai (ResponseReceived)
import Network.Wai qualified as Wai
import UnliftIO (MonadUnliftIO)

import Ecluse.Core.Credential (ClientCredential, Secret)
import Ecluse.Core.Cve.Types (DbEtag)
import Ecluse.Core.Package (PackageName)
import Ecluse.Core.Package.Integrity (MinIntegrity, MinTrustedIntegrity)
import Ecluse.Core.Queue (MirrorQueue)
import Ecluse.Core.Registry.Adapter.Capability (AdapterArtifact, AdapterMetadata, AdapterPublish, ProjectName)
import Ecluse.Core.Registry.Exchange.Types (ExchangeClient)
import Ecluse.Core.Registry.Public (PublicControl)
import Ecluse.Core.Registry.Request (BaseRequest, CredentialMapping, ServicePresentation)
import Ecluse.Core.Rules (PreparedRule)
import Ecluse.Core.Rules.Outage (AdmissionIdentity)
import Ecluse.Core.Security (HostPort, Limits, Origin, TarballHostGate, tarballHostAllowed, thgAllowlist, thgEcosystemHosts)
import Ecluse.Core.Security.Egress (RegistryUrl)
import Ecluse.Core.Server.Admission (ServeAdmission)
import Ecluse.Core.Server.Admission.Bytes (ByteAdmission)
import Ecluse.Core.Server.Admission.Meter (MemoryMeter)
import Ecluse.Core.Server.Cache (MetadataCache)
import Ecluse.Core.Server.Contract (ResponseContract)
import Ecluse.Core.Server.Encoding (MetadataCompression)
import Ecluse.Core.Server.MirrorView (MirrorView)
import Ecluse.Core.Server.Response (HelpMessage)
import Ecluse.Core.Server.Upstream (
    MirrorServePlan,
    MountUpstreams,
    upstreamMirror,
    upstreamPrivateBase,
    upstreamPrivateBaseUrl,
    upstreamPublicBase,
    upstreamPublicBaseUrl,
    upstreamTarballHostGate,
 )
import Ecluse.Core.Telemetry.Record (MetricsPort)
import Ecluse.Core.Telemetry.Span (TracingPort)

-- | Serve capabilities assembled at boot. Both HTTP managers must validate TLS certificates.
data ServeRuntime = ServeRuntime
    { ServeRuntime -> ServeAdmission
srAdmission :: ServeAdmission
    -- ^ Bounds concurrent metadata work, excluding private artifact reads and artifact relay.
    , ServeRuntime -> MemoryMeter
srMemoryMeter :: MemoryMeter
    -- ^ The memory budget metadata requests pay into as they read and build.
    , ServeRuntime -> ExchangeClient
srPublicClient :: ExchangeClient
    -- ^ The validating-TLS pool for the __untrusted__ public metadata fetch and every artifact stream.
    , ServeRuntime -> PublicControl
srPublicControl :: PublicControl
    -- ^ Public request admission and observation shared by all mounts in the process.
    , ServeRuntime -> ExchangeClient
srPrivateClient :: ExchangeClient
    -- ^ The __trusted__ private upstream's validating-TLS pool, which differs in credential handling only.
    , ServeRuntime -> MetadataCache
srMetadataCache :: MetadataCache
    -- ^ The short-TTL, size-bounded metadata cache the serve paths share ("Ecluse.Core.Server.Cache").
    , ServeRuntime -> MirrorQueue
srQueue :: MirrorQueue
    -- ^ The best-effort hand-off from the serve path to the mirror worker.
    , ServeRuntime -> MetricsPort
srMetrics :: MetricsPort
    -- ^ The metric-recording port the serve path emits the @ecluse.*@ catalogue through.
    , ServeRuntime -> TracingPort
srTracing :: TracingPort
    -- ^ The tracing port the serve path opens its hand-added domain spans through.
    }

-- | Mount inputs shared by packument and tarball handlers, resolved at boot.
data PackumentDeps = PackumentDeps
    { PackumentDeps -> MountUpstreams
pdUpstreams :: MountUpstreams
    -- ^ Upstreams bound to their derived host gate, so their authorities cannot diverge.
    , PackumentDeps -> Maybe MirrorView
pdMirrorState :: Maybe MirrorView
    -- ^ Source-only state, validated after each caller authorises the private read.
    , PackumentDeps -> PackageName -> Bool
pdFirstParty :: PackageName -> Bool
    -- ^ Whether this deployment owns the name, derived once at the composition root and deny by default. Only the private upstream serves it, and a private miss is @404@.
    , PackumentDeps -> Text
pdMountBaseUrl :: Text
    -- ^ The mount's external base URL, under which served artifact URLs route back through the gate.
    , PackumentDeps -> [PreparedRule]
pdRules :: [PreparedRule]
    -- ^ Rules prepared at boot and evaluated against every public version.
    , PackumentDeps -> [IPRange]
pdAdditionalBlockedRanges :: [IPRange]
    -- ^ Extra blocked IP ranges for untrusted artifact locations. Empty by default.
    , PackumentDeps -> Limits
pdLimits :: Limits
    -- ^ Fetch and decode limits. A breach discards the whole upstream contribution.
    , PackumentDeps -> Maybe Secret
pdInboundToken :: Maybe Secret
    -- ^ The inbound token a client must present (@ECLUSE_SERVER__AUTH_TOKEN@). 'Nothing' leaves the edge open.
    , PackumentDeps -> IO UTCTime
pdNow :: IO UTCTime
    -- ^ The rules' clock, injected so the quarantine is deterministic under test.
    , PackumentDeps -> IO (Maybe DbEtag)
pdAdvisoryEtag :: IO (Maybe DbEtag)
    -- ^ Non-pinning read of the active advisory etag. 'Nothing' means no database is loaded.
    , PackumentDeps -> AdmissionIdentity -> IO Bool
pdNoteAdmission :: AdmissionIdentity -> IO Bool
    -- ^ Whether to log an admission's skipped checks, once per identity per outage ('Ecluse.Core.Rules.Outage.noteAdmission').
    , PackumentDeps -> Maybe HelpMessage
pdHelp :: Maybe HelpMessage
    -- ^ The operator help message appended to every denial body, if configured.
    , PackumentDeps -> MinIntegrity
pdMinIntegrity :: MinIntegrity
    -- ^ Public integrity floor, at least SHA-256. Private reads use 'pdMinTrustedIntegrity'.
    , PackumentDeps -> MinTrustedIntegrity
pdMinTrustedIntegrity :: MinTrustedIntegrity
    -- ^ The minimum integrity hash required for a trusted upstream dependency.
    , PackumentDeps -> AdapterMetadata
pdMetadata :: AdapterMetadata
    -- ^ The ecosystem's metadata capability, carried whole, never copied field by field.
    , PackumentDeps -> AdapterArtifact
pdArtifact :: AdapterArtifact
    -- ^ The ecosystem's artifact request formation, carried whole, never copied field by field.
    , PackumentDeps -> Text -> Either Text RegistryUrl
pdEgressUrl :: Text -> Either Text RegistryUrl
    -- ^ Validate an artifact URL before enqueueing it. A 'Left' prevents the mirror job.
    , PackumentDeps -> MetadataCompression
pdMetadataCompression :: MetadataCompression
    -- ^ Whether an admitted listing may be gzipped for a client that accepts it.
    }

-- | The private URL bound to the host gate. 'Nothing' skips the private fetch.
pdPrivateBaseUrl :: PackumentDeps -> Maybe RegistryUrl
pdPrivateBaseUrl :: PackumentDeps -> Maybe RegistryUrl
pdPrivateBaseUrl = MountUpstreams -> Maybe RegistryUrl
upstreamPrivateBaseUrl (MountUpstreams -> Maybe RegistryUrl)
-> (PackumentDeps -> MountUpstreams)
-> PackumentDeps
-> Maybe RegistryUrl
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PackumentDeps -> MountUpstreams
pdUpstreams

-- | The public upstream base URL. Reads are anonymous, with no client credential.
pdPublicBaseUrl :: PackumentDeps -> RegistryUrl
pdPublicBaseUrl :: PackumentDeps -> RegistryUrl
pdPublicBaseUrl = MountUpstreams -> RegistryUrl
upstreamPublicBaseUrl (MountUpstreams -> RegistryUrl)
-> (PackumentDeps -> MountUpstreams)
-> PackumentDeps
-> RegistryUrl
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PackumentDeps -> MountUpstreams
pdUpstreams

-- | 'pdPrivateBaseUrl' parsed once per mount, which the private reads build their requests under.
pdPrivateBase :: PackumentDeps -> Maybe BaseRequest
pdPrivateBase :: PackumentDeps -> Maybe BaseRequest
pdPrivateBase = MountUpstreams -> Maybe BaseRequest
upstreamPrivateBase (MountUpstreams -> Maybe BaseRequest)
-> (PackumentDeps -> MountUpstreams)
-> PackumentDeps
-> Maybe BaseRequest
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PackumentDeps -> MountUpstreams
pdUpstreams

-- | 'pdPublicBaseUrl' parsed once per mount, which the public reads build their requests under.
pdPublicBase :: PackumentDeps -> BaseRequest
pdPublicBase :: PackumentDeps -> BaseRequest
pdPublicBase = MountUpstreams -> BaseRequest
upstreamPublicBase (MountUpstreams -> BaseRequest)
-> (PackumentDeps -> MountUpstreams)
-> PackumentDeps
-> BaseRequest
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PackumentDeps -> MountUpstreams
pdUpstreams

-- | The mirror destination for admitted public artifacts, or no write for a serve-only mount.
pdMirror :: PackumentDeps -> MirrorServePlan
pdMirror :: PackumentDeps -> MirrorServePlan
pdMirror = MountUpstreams -> MirrorServePlan
upstreamMirror (MountUpstreams -> MirrorServePlan)
-> (PackumentDeps -> MountUpstreams)
-> PackumentDeps
-> MirrorServePlan
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PackumentDeps -> MountUpstreams
pdUpstreams

-- | The host gate derived from the mount's upstreams at boot.
pdTarballHostGate :: PackumentDeps -> TarballHostGate
pdTarballHostGate :: PackumentDeps -> TarballHostGate
pdTarballHostGate = MountUpstreams -> TarballHostGate
upstreamTarballHostGate (MountUpstreams -> TarballHostGate)
-> (PackumentDeps -> MountUpstreams)
-> PackumentDeps
-> TarballHostGate
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PackumentDeps -> MountUpstreams
pdUpstreams

-- | 'tarballHostAllowed' over this mount's inputs. A missing authority refuses, and trusted origins skip only the internal-range block.
tarballHostHonoured :: Origin -> PackumentDeps -> Maybe HostPort -> Maybe HostPort -> Bool
tarballHostHonoured :: Origin -> PackumentDeps -> Maybe HostPort -> Maybe HostPort -> Bool
tarballHostHonoured Origin
origin PackumentDeps
deps =
    AllowedHostPorts
-> Origin
-> AllowedHostPorts
-> [IPRange]
-> Maybe HostPort
-> Maybe HostPort
-> Bool
tarballHostAllowed
        (TarballHostGate -> AllowedHostPorts
thgEcosystemHosts (PackumentDeps -> TarballHostGate
pdTarballHostGate PackumentDeps
deps))
        Origin
origin
        (TarballHostGate -> AllowedHostPorts
thgAllowlist (PackumentDeps -> TarballHostGate
pdTarballHostGate PackumentDeps
deps))
        (PackumentDeps -> [IPRange]
pdAdditionalBlockedRanges PackumentDeps
deps)

-- | First-party publish inputs. Their presence enables the mount's publish route.
data PublishDeps = PublishDeps
    { PublishDeps -> RegistryUrl
pubReadUrl :: RegistryUrl
    -- ^ The origin for credential-scoped native publication discovery.
    , PublishDeps -> RegistryUrl
pubTargetUrl :: RegistryUrl
    -- ^ The https-only publication target a publish is relayed to, with the package path appended.
    , PublishDeps -> PackageName -> Bool
pubAllowed :: PackageName -> Bool
    -- ^ Whether this package may publish here, checked before any upstream write. It is 'pdFirstParty'.
    , PublishDeps -> Maybe ClientCredential
pubStaticCredential :: Maybe ClientCredential
    -- ^ Replaces the authenticated edge token on publishes. Requires 'pubInboundToken' at boot.
    , PublishDeps -> ServicePresentation
pubStaticPresentation :: ServicePresentation
    -- ^ How the publication target's store asks for 'pubStaticCredential'. A caller credential keeps its own.
    , PublishDeps -> Maybe Secret
pubInboundToken :: Maybe Secret
    -- ^ The read paths' inbound edge token (@ECLUSE_SERVER__AUTH_TOKEN@). 'Nothing' leaves the edge open.
    , PublishDeps -> Int
pubMaxRequestBytes :: Int
    -- ^ The configured per-mount request cap, covered by the shared aggregate budget.
    , PublishDeps -> Limits
pubLimits :: Limits
    -- ^ Separate client request and registry response bounds for publication.
    , PublishDeps -> ByteAdmission
pubBodyBudget :: ByteAdmission
    -- ^ Shared body-byte budget reserved before reading. Exhaustion sheds a @503@.
    , PublishDeps -> Maybe HelpMessage
pubHelp :: Maybe HelpMessage
    -- ^ The operator help message appended to a publish denial, if configured.
    , PublishDeps -> ProjectName
pubProjectName :: ProjectName
    -- ^ The ecosystem's own name parser, which the anti-shadowing guard reads a declared name through.
    , PublishDeps -> AdapterPublish
pubAdapter :: AdapterPublish
    -- ^ The ecosystem's publish capability, carried whole, never copied field by field.
    }

-- | A matched request's action, constrained to its route's response contract.
data ResponseAction response
    = -- | A pure value admitted by the route's response contract.
      AnswerLocally response
    | -- | A refusal the route decided, rendered where the mount's help message is known.
      AnswerRefusal (Maybe HelpMessage -> response)
    | {- | A data-plane handler and its pre-commit fallback, both constrained to the route's response type.
      The fallback is lazy: only an escape before commit reads it, so a request that commits never builds it.
      -}
      RunPipeline ~response (Wai.Request -> (response -> IO ResponseReceived) -> Handler ResponseReceived)

-- | A route's response contract and an action that answers only through it, so dispatch needs no ecosystem's response sum.
data RouteAction = forall response. RouteAction (ResponseContract response) (ResponseAction response)

-- | An adapter's routing decision over a method, headers, and the stripped, decoded path segments.
type MountRouter = Method -> RequestHeaders -> [Text] -> RouteAction

-- | Ecosystem wiring under a non-empty prefix, so adding an ecosystem never displaces a root mount.
data MountBinding = MountBinding
    { MountBinding -> NonEmpty Text
bindingPrefix :: NonEmpty Text
    -- ^ The leading path segments this mount is served under. Never empty.
    , MountBinding -> MountRouter
bindingRouter :: MountRouter
    -- ^ This mount's routing decision, derived from the adapter's own route table.
    , MountBinding -> CredentialMapping
bindingCredential :: CredentialMapping
    -- ^ How the adapter's clients present a credential, and how the proxy carries one upstream.
    , MountBinding -> PackumentDeps
bindingPackumentDeps :: PackumentDeps
    -- ^ A bound mount always serves listings and artifacts. Only /publish/ is opt-in.
    , MountBinding -> Maybe PublishDeps
bindingPublishDeps :: Maybe PublishDeps
    -- ^ Optional first-party publish dependencies. 'Nothing' makes @PUT \/{pkg}@ answer @405@.
    }

-- | The runtime and the matched 'MountBinding' one request is served through, built once per request.
data RequestCtx = RequestCtx
    { RequestCtx -> ServeRuntime
ctxRuntime :: ServeRuntime
    -- ^ The data-plane managers, the caches and queue, and the recording ports.
    , RequestCtx -> MountBinding
ctxMount :: MountBinding
    -- ^ The mount the request matched, carrying its complete ecosystem wiring.
    }

-- | Request context over @katip@'s reader-based logging context, shared across concurrent fetches.
newtype Handler a = Handler
    { forall a. Handler a -> ReaderT RequestCtx (KatipContextT IO) a
unHandler :: ReaderT RequestCtx (KatipContextT IO) a
    }
    deriving newtype
        ( (forall a b. (a -> b) -> Handler a -> Handler b)
-> (forall a b. a -> Handler b -> Handler a) -> Functor Handler
forall a b. a -> Handler b -> Handler a
forall a b. (a -> b) -> Handler a -> Handler b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> Handler a -> Handler b
fmap :: forall a b. (a -> b) -> Handler a -> Handler b
$c<$ :: forall a b. a -> Handler b -> Handler a
<$ :: forall a b. a -> Handler b -> Handler a
Functor
        , Functor Handler
Functor Handler =>
(forall a. a -> Handler a)
-> (forall a b. Handler (a -> b) -> Handler a -> Handler b)
-> (forall a b c.
    (a -> b -> c) -> Handler a -> Handler b -> Handler c)
-> (forall a b. Handler a -> Handler b -> Handler b)
-> (forall a b. Handler a -> Handler b -> Handler a)
-> Applicative Handler
forall a. a -> Handler a
forall a b. Handler a -> Handler b -> Handler a
forall a b. Handler a -> Handler b -> Handler b
forall a b. Handler (a -> b) -> Handler a -> Handler b
forall a b c. (a -> b -> c) -> Handler a -> Handler b -> Handler c
forall (f :: * -> *).
Functor f =>
(forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
$cpure :: forall a. a -> Handler a
pure :: forall a. a -> Handler a
$c<*> :: forall a b. Handler (a -> b) -> Handler a -> Handler b
<*> :: forall a b. Handler (a -> b) -> Handler a -> Handler b
$cliftA2 :: forall a b c. (a -> b -> c) -> Handler a -> Handler b -> Handler c
liftA2 :: forall a b c. (a -> b -> c) -> Handler a -> Handler b -> Handler c
$c*> :: forall a b. Handler a -> Handler b -> Handler b
*> :: forall a b. Handler a -> Handler b -> Handler b
$c<* :: forall a b. Handler a -> Handler b -> Handler a
<* :: forall a b. Handler a -> Handler b -> Handler a
Applicative
        , Applicative Handler
Applicative Handler =>
(forall a b. Handler a -> (a -> Handler b) -> Handler b)
-> (forall a b. Handler a -> Handler b -> Handler b)
-> (forall a. a -> Handler a)
-> Monad Handler
forall a. a -> Handler a
forall a b. Handler a -> Handler b -> Handler b
forall a b. Handler a -> (a -> Handler b) -> Handler b
forall (m :: * -> *).
Applicative m =>
(forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
$c>>= :: forall a b. Handler a -> (a -> Handler b) -> Handler b
>>= :: forall a b. Handler a -> (a -> Handler b) -> Handler b
$c>> :: forall a b. Handler a -> Handler b -> Handler b
>> :: forall a b. Handler a -> Handler b -> Handler b
$creturn :: forall a. a -> Handler a
return :: forall a. a -> Handler a
Monad
        , Monad Handler
Monad Handler => (forall a. IO a -> Handler a) -> MonadIO Handler
forall a. IO a -> Handler a
forall (m :: * -> *).
Monad m =>
(forall a. IO a -> m a) -> MonadIO m
$cliftIO :: forall a. IO a -> Handler a
liftIO :: forall a. IO a -> Handler a
MonadIO
        , MonadReader RequestCtx
        , MonadIO Handler
MonadIO Handler =>
(forall b. ((forall a. Handler a -> IO a) -> IO b) -> Handler b)
-> MonadUnliftIO Handler
forall b. ((forall a. Handler a -> IO a) -> IO b) -> Handler b
forall (m :: * -> *).
MonadIO m =>
(forall b. ((forall a. m a -> IO a) -> IO b) -> m b)
-> MonadUnliftIO m
$cwithRunInIO :: forall b. ((forall a. Handler a -> IO a) -> IO b) -> Handler b
withRunInIO :: forall b. ((forall a. Handler a -> IO a) -> IO b) -> Handler b
MonadUnliftIO
        , MonadIO Handler
Handler LogEnv
MonadIO Handler =>
Handler LogEnv
-> (forall a. (LogEnv -> LogEnv) -> Handler a -> Handler a)
-> Katip Handler
forall a. (LogEnv -> LogEnv) -> Handler a -> Handler a
forall (m :: * -> *).
MonadIO m =>
m LogEnv -> (forall a. (LogEnv -> LogEnv) -> m a -> m a) -> Katip m
$cgetLogEnv :: Handler LogEnv
getLogEnv :: Handler LogEnv
$clocalLogEnv :: forall a. (LogEnv -> LogEnv) -> Handler a -> Handler a
localLogEnv :: forall a. (LogEnv -> LogEnv) -> Handler a -> Handler a
Katip
        , Katip Handler
Handler Namespace
Handler LogContexts
Katip Handler =>
Handler LogContexts
-> (forall a.
    (LogContexts -> LogContexts) -> Handler a -> Handler a)
-> Handler Namespace
-> (forall a. (Namespace -> Namespace) -> Handler a -> Handler a)
-> KatipContext Handler
forall a. (Namespace -> Namespace) -> Handler a -> Handler a
forall a. (LogContexts -> LogContexts) -> Handler a -> Handler a
forall (m :: * -> *).
Katip m =>
m LogContexts
-> (forall a. (LogContexts -> LogContexts) -> m a -> m a)
-> m Namespace
-> (forall a. (Namespace -> Namespace) -> m a -> m a)
-> KatipContext m
$cgetKatipContext :: Handler LogContexts
getKatipContext :: Handler LogContexts
$clocalKatipContext :: forall a. (LogContexts -> LogContexts) -> Handler a -> Handler a
localKatipContext :: forall a. (LogContexts -> LogContexts) -> Handler a -> Handler a
$cgetKatipNamespace :: Handler Namespace
getKatipNamespace :: Handler Namespace
$clocalKatipNamespace :: forall a. (Namespace -> Namespace) -> Handler a -> Handler a
localKatipNamespace :: forall a. (Namespace -> Namespace) -> Handler a -> Handler a
KatipContext
        )

-- | Run a handler with the application's log stream and initial trace-correlation payload.
runHandler :: LogEnv -> SimpleLogPayload -> RequestCtx -> Handler a -> IO a
runHandler :: forall a.
LogEnv -> SimpleLogPayload -> RequestCtx -> Handler a -> IO a
runHandler LogEnv
logEnv SimpleLogPayload
initialContext RequestCtx
ctx Handler a
action =
    LogEnv
-> SimpleLogPayload -> Namespace -> KatipContextT IO a -> IO a
forall c (m :: * -> *) a.
LogItem c =>
LogEnv -> c -> Namespace -> KatipContextT m a -> m a
runKatipContextT LogEnv
logEnv SimpleLogPayload
initialContext Namespace
forall a. Monoid a => a
mempty (ReaderT RequestCtx (KatipContextT IO) a
-> RequestCtx -> KatipContextT IO a
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT (Handler a -> ReaderT RequestCtx (KatipContextT IO) a
forall a. Handler a -> ReaderT RequestCtx (KatipContextT IO) a
unHandler Handler a
action) RequestCtx
ctx)