diff --git a/docs/index.md b/docs/index.md index b274587..a8a990a 100644 --- a/docs/index.md +++ b/docs/index.md @@ -172,7 +172,7 @@ Request. These operations are covered in more detail below. Its type is `StdMethod` from the `http-types` library. - Only the standard methods mentioned in RFC-1234 are allowed. + [HTTP standard method (as defined by RFC 2616, and PATCH which is defined by RFC 5789).](https://hackage.haskell.org/package/http-types-0.12.3/docs/Network-HTTP-Types-Method.html#t:StdMethod) 2. #### Path Script diff --git a/docs/pages/index.html b/docs/pages/index.html index 4f26690..eef4ada 100644 --- a/docs/pages/index.html +++ b/docs/pages/index.html @@ -187,7 +187,10 @@ detail below.

Endpoint accepts.

Its type is StdMethod from the http-types library.

-

Only the standard methods mentioned in RFC-1234 are allowed.

+

HTTP +standard method (as defined by RFC 2616, and PATCH which is defined by +RFC 5789).

  • Path Script

    The path field defines the Request Path that the Endpoint accepts, including Path parameters.

    diff --git a/lib/okapi.cabal b/lib/okapi.cabal index 8bdb721..4472a7d 100644 --- a/lib/okapi.cabal +++ b/lib/okapi.cabal @@ -38,6 +38,7 @@ library Okapi.Script.Body Okapi.Script.Responder Okapi.Script.AddHeader + Okapi.Script.Security other-modules: Paths_okapi hs-source-dirs: diff --git a/lib/src/Okapi/Endpoint.hs b/lib/src/Okapi/Endpoint.hs index b24a51d..fd55463 100644 --- a/lib/src/Okapi/Endpoint.hs +++ b/lib/src/Okapi/Endpoint.hs @@ -47,9 +47,11 @@ import Okapi.Script.Headers qualified as Headers import Okapi.Script.Path qualified as Path import Okapi.Script.Query qualified as Query import Okapi.Script.Responder qualified as Responder +import Okapi.Script.Security qualified as Security -data Endpoint p q h b r = Endpoint - { method :: HTTP.StdMethod, +data Endpoint s p q h b r = Endpoint + { security :: Security.Security s, + method :: HTTP.StdMethod, path :: Path.Script p, query :: Query.Script q, headers :: Headers.Script h, @@ -57,7 +59,7 @@ data Endpoint p q h b r = Endpoint responder :: Responder.Script r } -toPathItem :: Endpoint p q h b r -> (FilePath, OAPI.PathItem) +toPathItem :: Endpoint s p q h b r -> (FilePath, OAPI.PathItem) toPathItem endpoint = (pathName, pathItem) where pathName :: FilePath @@ -188,10 +190,10 @@ toPathItem endpoint = (pathName, pathItem) Path.Static t -> "/" <> Text.unpack t Path.Param @p name -> "/{" <> Text.unpack name <> "}" -data Plan m p q h b r = Plan +data Plan m s p q h b r = Plan { transformer :: m ~> IO, - endpoint :: Endpoint p q h b r, - handler :: Monad m => p -> q -> b -> h -> r -> m Response + endpoint :: Endpoint s p q h b r, + handler :: Monad m => s -> p -> q -> b -> h -> r -> m Response } data Executable = Run (IO WAI.Response) | Null @@ -204,9 +206,9 @@ data Artifact = Artifact } build :: - forall m p q h b r. + forall m s p q h b r. Monad m => - Plan m p q h b r -> + Plan m s p q h b r -> Artifact build plan = Artifact {..} where @@ -214,14 +216,17 @@ build plan = Artifact {..} compiler (method, path, query, body, headers) = if method == plan.endpoint.method then - let pathResult = fst $ Path.eval plan.endpoint.path path + let securityResult = case plan.endpoint.security of + Security.NotSecure -> Ok () + Security.Secure script -> fst $ Security.eval script $ Security.State query headers [] + pathResult = fst $ Path.eval plan.endpoint.path path queryResult = fst $ Query.eval plan.endpoint.query query bodyResult = fst $ Body.eval plan.endpoint.body body headersResult = fst $ Headers.eval plan.endpoint.headers headers responderResult = fst $ Responder.eval plan.endpoint.responder () - in case (pathResult, queryResult, bodyResult, headersResult, responderResult) of - (Ok p, Ok q, Ok b, Ok h, Ok r) -> Run do - response <- transformer plan $ handler plan p q b h r + in case (securityResult, pathResult, queryResult, bodyResult, headersResult, responderResult) of + (Ok s, Ok p, Ok q, Ok b, Ok h, Ok r) -> Run do + response <- transformer plan $ handler plan s p q b h r return $ toWaiResponse response _ -> Null else Null