diff --git a/lib/src/Okapi/App.hs b/lib/src/Okapi/App.hs index b51d67e..fc10c2d 100644 --- a/lib/src/Okapi/App.hs +++ b/lib/src/Okapi/App.hs @@ -329,6 +329,18 @@ endpoint :: endpoint stdMethod transformation handler = route @a $ method @env @(r :-> a) stdMethod transformation handler +any :: + forall env (r :: [Type]). + (Typeable.Typeable r) => + (env Natural.~> IO) -> + Handler r env -> + Node r +any transformation handler = + choice + [ Method @env @r stdMethod transformation handler + | stdMethod <- [minBound ..] + ] + data HList (l :: [Type]) where HNil :: HList '[] HCons :: e -> HList l -> HList (e ': l) diff --git a/lib/src/Okapi/Response.hs b/lib/src/Okapi/Response.hs index c83b407..291ece1 100644 --- a/lib/src/Okapi/Response.hs +++ b/lib/src/Okapi/Response.hs @@ -167,13 +167,14 @@ makeResponder :: forall (status :: Natural.Natural) (headerKeys :: [Exts.Symbol]) (contentType :: Type) (resultType :: Type). (Nat.KnownNat status, ContentType contentType, ToContentType contentType resultType, Typeable.Typeable headerKeys, Typeable.Typeable resultType) => (Headers headerKeys -> resultType -> Wai.Response) -makeResponder _ result = +makeResponder headerMap result = let status = natToStatus $ Nat.natVal @status Typeable.Proxy contentType = toContentType @contentType @resultType result bodyType = contentTypeBody @contentType contentType name = contentTypeName @contentType + headers = toWaiResponseHeaders headerMap in case bodyType of - BodyBytes bytes -> Wai.responseLBS status [] bytes - BodyBuilder builder -> Wai.responseBuilder status [] builder - BodyStream stream -> Wai.responseStream status [] stream - BodyFile path part -> Wai.responseFile status [] path part + BodyBytes bytes -> Wai.responseLBS status headers bytes + BodyBuilder builder -> Wai.responseBuilder status headers builder + BodyStream stream -> Wai.responseStream status headers stream + BodyFile path part -> Wai.responseFile status headers path part