-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A family of combinators for defining webservices APIs and serving them -- -- A family of combinators for defining webservices APIs and serving them -- -- You can learn about the basics in the tutorial. -- -- Here is a runnable example, with comments, that defines a dummy -- API and implements a webserver that serves this API, using this -- package. -- -- CHANGELOG @package servant-server @version 0.13 module Servant.Server.Internal.Context -- | Contexts are used to pass values to combinators. (They are -- not meant to be used to pass parameters to your handlers, i.e. -- they should not replace any custom ReaderT-monad-stack that -- you're using with Enter.) If you don't use combinators that -- require any context entries, you can just use serve as always. -- -- If you are using combinators that require a non-empty Context -- you have to use serveWithContext and pass it a Context -- that contains all the values your combinators need. A Context -- is essentially a heterogenous list and accessing the elements is being -- done by type (see getContextEntry). The parameter of the type -- Context is a type-level list reflecting the types of the -- contained context entries. To create a Context with entries, -- use the operator (:.): -- --
--   >>> :type True :. () :. EmptyContext
--   True :. () :. EmptyContext :: Context '[Bool, ()]
--   
data Context contextTypes [EmptyContext] :: Context '[] [:.] :: x -> Context xs -> Context (x : xs) -- | This class is used to access context entries in Contexts. -- getContextEntry returns the first value where the type matches: -- --
--   >>> getContextEntry (True :. False :. EmptyContext) :: Bool
--   True
--   
-- -- If the Context does not contain an entry of the requested type, -- you'll get an error: -- --
--   >>> getContextEntry (True :. False :. EmptyContext) :: String
--   ...
--   ...No instance for (HasContextEntry '[] [Char])
--   ...
--   
class HasContextEntry (context :: [*]) (val :: *) getContextEntry :: HasContextEntry context val => Context context -> val -- | Normally context entries are accessed by their types. In case you need -- to have multiple values of the same type in your Context and -- need to access them, we provide NamedContext. You can think of -- it as sub-namespaces for Contexts. data NamedContext (name :: Symbol) (subContext :: [*]) NamedContext :: (Context subContext) -> NamedContext -- | descendIntoNamedContext allows you to access -- NamedContexts. Usually you won't have to use it yourself but -- instead use a combinator like WithNamedContext. -- -- This is how descendIntoNamedContext works: -- --
--   >>> :set -XFlexibleContexts
--   
--   >>> let subContext = True :. EmptyContext
--   
--   >>> :type subContext
--   subContext :: Context '[Bool]
--   
--   >>> let parentContext = False :. (NamedContext subContext :: NamedContext "subContext" '[Bool]) :. EmptyContext
--   
--   >>> :type parentContext
--   parentContext :: Context '[Bool, NamedContext "subContext" '[Bool]]
--   
--   >>> descendIntoNamedContext (Proxy :: Proxy "subContext") parentContext :: Context '[Bool]
--   True :. EmptyContext
--   
descendIntoNamedContext :: forall context name subContext. HasContextEntry context (NamedContext name subContext) => Proxy (name :: Symbol) -> Context context -> Context subContext instance Servant.Server.Internal.Context.HasContextEntry xs val => Servant.Server.Internal.Context.HasContextEntry (notIt : xs) val instance Servant.Server.Internal.Context.HasContextEntry (val : xs) val instance GHC.Show.Show (Servant.Server.Internal.Context.Context '[]) instance (GHC.Show.Show a, GHC.Show.Show (Servant.Server.Internal.Context.Context as)) => GHC.Show.Show (Servant.Server.Internal.Context.Context (a : as)) instance GHC.Classes.Eq (Servant.Server.Internal.Context.Context '[]) instance (GHC.Classes.Eq a, GHC.Classes.Eq (Servant.Server.Internal.Context.Context as)) => GHC.Classes.Eq (Servant.Server.Internal.Context.Context (a : as)) module Servant.Server.Internal.ServantErr data ServantErr ServantErr :: Int -> String -> ByteString -> [Header] -> ServantErr [errHTTPCode] :: ServantErr -> Int [errReasonPhrase] :: ServantErr -> String [errBody] :: ServantErr -> ByteString [errHeaders] :: ServantErr -> [Header] responseServantErr :: ServantErr -> Response -- | err300 Multiple Choices -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err300 { errBody = "I can't choose." }
--   
err300 :: ServantErr -- | err301 Moved Permanently -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError err301
--   
err301 :: ServantErr -- | err302 Found -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError err302
--   
err302 :: ServantErr -- | err303 See Other -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError err303
--   
err303 :: ServantErr -- | err304 Not Modified -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError err304
--   
err304 :: ServantErr -- | err305 Use Proxy -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError err305
--   
err305 :: ServantErr -- | err307 Temporary Redirect -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError err307
--   
err307 :: ServantErr -- | err400 Bad Request -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err400 { errBody = "Your request makes no sense to me." }
--   
err400 :: ServantErr -- | err401 Unauthorized -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err401 { errBody = "Your credentials are invalid." }
--   
err401 :: ServantErr -- | err402 Payment Required -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err402 { errBody = "You have 0 credits. Please give me $$$." }
--   
err402 :: ServantErr -- | err403 Forbidden -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err403 { errBody = "Please login first." }
--   
err403 :: ServantErr -- | err404 Not Found -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err404 { errBody = "(╯°□°)╯︵ ┻━┻)." }
--   
err404 :: ServantErr -- | err405 Method Not Allowed -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err405 { errBody = "Your account privileges does not allow for this.  Please pay $$$." }
--   
err405 :: ServantErr -- | err406 Not Acceptable -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError err406
--   
err406 :: ServantErr -- | err407 Proxy Authentication Required -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError err407
--   
err407 :: ServantErr -- | err409 Conflict -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err409 { errBody = "Transaction conflicts with 59879cb56c7c159231eeacdd503d755f7e835f74" }
--   
err409 :: ServantErr -- | err410 Gone -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err410 { errBody = "I know it was here at some point, but.. I blame bad luck." }
--   
err410 :: ServantErr -- | err411 Length Required -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError err411
--   
err411 :: ServantErr -- | err412 Precondition Failed -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err412 { errBody = "Precondition fail: x < 42 && y > 57" }
--   
err412 :: ServantErr -- | err413 Request Entity Too Large -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err413 { errBody = "Request exceeded 64k." }
--   
err413 :: ServantErr -- | err414 Request-URI Too Large -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err414 { errBody = "Maximum length is 64." }
--   
err414 :: ServantErr -- | err415 Unsupported Media Type -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err415 { errBody = "Supported media types:  gif, png" }
--   
err415 :: ServantErr -- | err416 Request range not satisfiable -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err416 { errBody = "Valid range is [0, 424242]." }
--   
err416 :: ServantErr -- | err417 Expectation Failed -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err417 { errBody = "I found a quux in the request.  This isn't going to work." }
--   
err417 :: ServantErr -- | err418 Expectation Failed -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err418 { errBody = "Apologies, this is not a webserver but a teapot." }
--   
err418 :: ServantErr -- | err422 Unprocessable Entity -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err422 { errBody = "I understood your request, but can't process it." }
--   
err422 :: ServantErr -- | err500 Internal Server Error -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err500 { errBody = "Exception in module A.B.C:55.  Have a great day!" }
--   
err500 :: ServantErr -- | err501 Not Implemented -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err501 { errBody = "/v1/foo is not supported with quux in the request." }
--   
err501 :: ServantErr -- | err502 Bad Gateway -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err502 { errBody = "Tried gateway foo, bar, and baz.  None responded." }
--   
err502 :: ServantErr -- | err503 Service Unavailable -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err503 { errBody = "We're rewriting in PHP." }
--   
err503 :: ServantErr -- | err504 Gateway Time-out -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err504 { errBody = "Backend foobar did not respond in 5 seconds." }
--   
err504 :: ServantErr -- | err505 HTTP Version not supported -- -- Example usage: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err505 { errBody = "I support HTTP/4.0 only." }
--   
err505 :: ServantErr instance GHC.Read.Read Servant.Server.Internal.ServantErr.ServantErr instance GHC.Classes.Eq Servant.Server.Internal.ServantErr.ServantErr instance GHC.Show.Show Servant.Server.Internal.ServantErr.ServantErr instance GHC.Exception.Exception Servant.Server.Internal.ServantErr.ServantErr module Servant.Server.Internal.Handler newtype Handler a Handler :: ExceptT ServantErr IO a -> Handler a [runHandler'] :: Handler a -> ExceptT ServantErr IO a runHandler :: Handler a -> IO (Either ServantErr a) instance Control.Monad.Catch.MonadCatch Servant.Server.Internal.Handler.Handler instance Control.Monad.Catch.MonadThrow Servant.Server.Internal.Handler.Handler instance Control.Monad.Error.Class.MonadError Servant.Server.Internal.ServantErr.ServantErr Servant.Server.Internal.Handler.Handler instance GHC.Generics.Generic (Servant.Server.Internal.Handler.Handler a) instance Control.Monad.IO.Class.MonadIO Servant.Server.Internal.Handler.Handler instance GHC.Base.Monad Servant.Server.Internal.Handler.Handler instance GHC.Base.Applicative Servant.Server.Internal.Handler.Handler instance GHC.Base.Functor Servant.Server.Internal.Handler.Handler instance Control.Monad.Base.MonadBase GHC.Types.IO Servant.Server.Internal.Handler.Handler instance Control.Monad.Trans.Control.MonadBaseControl GHC.Types.IO Servant.Server.Internal.Handler.Handler module Servant.Server.Internal.RoutingApplication type RoutingApplication = Request the request, the field 'pathInfo' may be modified by url routing -> (RouteResult Response -> IO ResponseReceived) -> IO ResponseReceived -- | The result of matching against a path in the route tree. data RouteResult a -- | Keep trying other paths. The ServantErr should only be 404, -- 405 or 406. Fail :: ServantErr -> RouteResult a -- | Don't try other paths. FailFatal :: !ServantErr -> RouteResult a Route :: !a -> RouteResult a newtype RouteResultT m a RouteResultT :: m (RouteResult a) -> RouteResultT m a [runRouteResultT] :: RouteResultT m a -> m (RouteResult a) toApplication :: RoutingApplication -> Application -- | A Delayed is a representation of a handler with scheduled -- delayed checks that can trigger errors. -- -- Why would we want to delay checks? -- -- There are two reasons: -- --
    --
  1. In a straight-forward implementation, the order in which we -- perform checks will determine the error we generate. This is because -- once an error occurs, we would abort and not perform any subsequent -- checks, but rather return the current error.
  2. --
-- -- This is not a necessity: we could continue doing other checks, and -- choose the preferred error. However, that would in general mean more -- checking, which leads us to the other reason. -- --
    --
  1. We really want to avoid doing certain checks too early. For -- example, captures involve parsing, and are much more costly than -- static route matches. In particular, if several paths contain the -- "same" capture, we'd like as much as possible to avoid trying the same -- parse many times. Also tricky is the request body. Again, this -- involves parsing, but also, WAI makes obtaining the request body a -- side-effecting operation. We could/can work around this by manually -- caching the request body, but we'd rather keep the number of times we -- actually try to decode the request body to an absolute minimum.
  2. --
-- -- We prefer to have the following relative priorities of error codes: -- --
--   404
--   405 (bad method)
--   401 (unauthorized)
--   415 (unsupported media type)
--   406 (not acceptable)
--   400 (bad request)
--   
-- -- Therefore, while routing, we delay most checks so that they will -- ultimately occur in the right order. -- -- A Delayed contains many delayed blocks of tests, and the actual -- handler: -- --
    --
  1. Delayed captures. These can actually cause 404, and while they're -- costly, they should be done first among the delayed checks (at least -- as long as we do not decouple the check order from the error -- reporting, see above). Delayed captures can provide inputs to the -- actual handler.
  2. --
  3. Method check(s). This can cause a 405. On success, it does not -- provide an input for the handler. Method checks are comparatively -- cheap.
  4. --
  5. Authentication checks. This can cause 401.
  6. --
  7. Accept and content type header checks. These checks can cause 415 -- and 406 errors.
  8. --
  9. Query parameter checks. They require parsing and can cause 400 if -- the parsing fails. Query parameter checks provide inputs to the -- handler
  10. --
  11. Header Checks. They also require parsing and can cause 400 if -- parsing fails.
  12. --
  13. Body check. The request body check can cause 400.
  14. --
data Delayed env c [Delayed] :: {capturesD :: env -> DelayedIO captures, methodD :: DelayedIO (), authD :: DelayedIO auth, acceptD :: DelayedIO (), contentD :: DelayedIO contentType, paramsD :: DelayedIO params, headersD :: DelayedIO headers, bodyD :: contentType -> DelayedIO body, serverD :: captures -> params -> headers -> auth -> body -> Request -> RouteResult c} -> Delayed env c -- | Computations used in a Delayed can depend on the incoming -- Request, may perform 'IO, and result in a 'RouteResult, meaning -- they can either suceed, fail (with the possibility to recover), or -- fail fatally. newtype DelayedIO a DelayedIO :: ReaderT Request (ResourceT (RouteResultT IO)) a -> DelayedIO a [runDelayedIO'] :: DelayedIO a -> ReaderT Request (ResourceT (RouteResultT IO)) a liftRouteResult :: RouteResult a -> DelayedIO a runDelayedIO :: DelayedIO a -> Request -> ResourceT IO (RouteResult a) -- | A Delayed without any stored checks. emptyDelayed :: RouteResult a -> Delayed env a -- | Fail with the option to recover. delayedFail :: ServantErr -> DelayedIO a -- | Fail fatally, i.e., without any option to recover. delayedFailFatal :: ServantErr -> DelayedIO a -- | Gain access to the incoming request. withRequest :: (Request -> DelayedIO a) -> DelayedIO a -- | Add a capture to the end of the capture block. addCapture :: Delayed env (a -> b) -> (captured -> DelayedIO a) -> Delayed (captured, env) b -- | Add a parameter check to the end of the params block addParameterCheck :: Delayed env (a -> b) -> DelayedIO a -> Delayed env b -- | Add a parameter check to the end of the params block addHeaderCheck :: Delayed env (a -> b) -> DelayedIO a -> Delayed env b -- | Add a method check to the end of the method block. addMethodCheck :: Delayed env a -> DelayedIO () -> Delayed env a -- | Add an auth check to the end of the auth block. addAuthCheck :: Delayed env (a -> b) -> DelayedIO a -> Delayed env b -- | Add a content type and body checks around parameter checks. -- -- We'll report failed content type check (415), before trying to parse -- query parameters (400). Which, in turn, happens before request body -- parsing. addBodyCheck :: Delayed env (a -> b) -> DelayedIO c -> (c -> DelayedIO a) -> Delayed env b -- | Add an accept header check before handling parameters. In principle, -- we'd like to take a bad body (400) response take precedence over a -- failed accept check (406). BUT to allow streaming the body, we cannot -- run the body check and then still backtrack. We therefore do the -- accept check before the body check, when we can still backtrack. There -- are other solutions to this, but they'd be more complicated (such as -- delaying the body check further so that it can still be run in a -- situation where we'd otherwise report 406). addAcceptCheck :: Delayed env a -> DelayedIO () -> Delayed env a -- | Many combinators extract information that is passed to the handler -- without the possibility of failure. In such a case, -- passToServer can be used. passToServer :: Delayed env (a -> b) -> (Request -> a) -> Delayed env b -- | Run a delayed server. Performs all scheduled operations in order, and -- passes the results from the capture and body blocks on to the actual -- handler. -- -- This should only be called once per request; otherwise the guarantees -- about effect and HTTP error ordering break down. runDelayed :: Delayed env a -> env -> Request -> ResourceT IO (RouteResult a) -- | Runs a delayed server and the resulting action. Takes a continuation -- that lets us send a response. Also takes a continuation for how to -- turn the result of the delayed server into a response. runAction :: Delayed env (Handler a) -> env -> Request -> (RouteResult Response -> IO r) -> (a -> RouteResult Response) -> IO r instance Control.Monad.Trans.Resource.Internal.MonadResource Servant.Server.Internal.RoutingApplication.DelayedIO instance Control.Monad.Catch.MonadThrow Servant.Server.Internal.RoutingApplication.DelayedIO instance Control.Monad.Reader.Class.MonadReader Network.Wai.Internal.Request Servant.Server.Internal.RoutingApplication.DelayedIO instance Control.Monad.IO.Class.MonadIO Servant.Server.Internal.RoutingApplication.DelayedIO instance GHC.Base.Monad Servant.Server.Internal.RoutingApplication.DelayedIO instance GHC.Base.Applicative Servant.Server.Internal.RoutingApplication.DelayedIO instance GHC.Base.Functor Servant.Server.Internal.RoutingApplication.DelayedIO instance GHC.Base.Functor m => GHC.Base.Functor (Servant.Server.Internal.RoutingApplication.RouteResultT m) instance GHC.Base.Functor Servant.Server.Internal.RoutingApplication.RouteResult instance GHC.Read.Read a => GHC.Read.Read (Servant.Server.Internal.RoutingApplication.RouteResult a) instance GHC.Show.Show a => GHC.Show.Show (Servant.Server.Internal.RoutingApplication.RouteResult a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Servant.Server.Internal.RoutingApplication.RouteResult a) instance GHC.Base.Functor (Servant.Server.Internal.RoutingApplication.Delayed env) instance Control.Monad.Base.MonadBase GHC.Types.IO Servant.Server.Internal.RoutingApplication.DelayedIO instance Control.Monad.Trans.Control.MonadBaseControl GHC.Types.IO Servant.Server.Internal.RoutingApplication.DelayedIO instance Control.Monad.Trans.Class.MonadTrans Servant.Server.Internal.RoutingApplication.RouteResultT instance (GHC.Base.Functor m, GHC.Base.Monad m) => GHC.Base.Applicative (Servant.Server.Internal.RoutingApplication.RouteResultT m) instance GHC.Base.Monad m => GHC.Base.Monad (Servant.Server.Internal.RoutingApplication.RouteResultT m) instance Control.Monad.IO.Class.MonadIO m => Control.Monad.IO.Class.MonadIO (Servant.Server.Internal.RoutingApplication.RouteResultT m) instance Control.Monad.Base.MonadBase b m => Control.Monad.Base.MonadBase b (Servant.Server.Internal.RoutingApplication.RouteResultT m) instance Control.Monad.Trans.Control.MonadBaseControl b m => Control.Monad.Trans.Control.MonadBaseControl b (Servant.Server.Internal.RoutingApplication.RouteResultT m) instance Control.Monad.Trans.Control.MonadTransControl Servant.Server.Internal.RoutingApplication.RouteResultT instance Control.Monad.Catch.MonadThrow m => Control.Monad.Catch.MonadThrow (Servant.Server.Internal.RoutingApplication.RouteResultT m) instance GHC.Base.Applicative Servant.Server.Internal.RoutingApplication.RouteResult instance GHC.Base.Monad Servant.Server.Internal.RoutingApplication.RouteResult module Servant.Server.Internal.Router type Router env = Router' env RoutingApplication -- | Internal representation of a router. -- -- The first argument describes an environment type that is expected as -- extra input by the routers at the leaves. The environment is filled -- while running the router, with path components that can be used to -- process captures. data Router' env a -- | the map contains routers for subpaths (first path component used for -- lookup and removed afterwards), the list contains handlers for the -- empty path, to be tried in order StaticRouter :: (Map Text (Router' env a)) -> [env -> a] -> Router' env a -- | first path component is passed to the child router in its environment -- and removed afterwards CaptureRouter :: (Router' (Text, env) a) -> Router' env a -- | all path components are passed to the child router in its environment -- and are removed afterwards CaptureAllRouter :: (Router' ([Text], env) a) -> Router' env a -- | to be used for routes we do not know anything about RawRouter :: (env -> a) -> Router' env a -- | left-biased choice between two routers Choice :: (Router' env a) -> (Router' env a) -> Router' env a -- | Smart constructor for a single static path component. pathRouter :: Text -> Router' env a -> Router' env a -- | Smart constructor for a leaf, i.e., a router that expects the empty -- path. leafRouter :: (env -> a) -> Router' env a -- | Smart constructor for the choice between routers. We currently -- optimize the following cases: -- -- choice :: Router' env a -> Router' env a -> Router' env a -- | Datatype used for representing and debugging the structure of a -- router. Abstracts from the handlers at the leaves. -- -- Two Routers can be structurally compared by computing their -- RouterStructure using routerStructure and then testing -- for equality, see sameStructure. data RouterStructure StaticRouterStructure :: (Map Text RouterStructure) -> Int -> RouterStructure CaptureRouterStructure :: RouterStructure -> RouterStructure RawRouterStructure :: RouterStructure ChoiceStructure :: RouterStructure -> RouterStructure -> RouterStructure -- | Compute the structure of a router. -- -- Assumes that the request or text being passed in WithRequest -- or CaptureRouter does not affect the structure of the -- underlying tree. routerStructure :: Router' env a -> RouterStructure -- | Compare the structure of two routers. sameStructure :: Router' env a -> Router' env b -> Bool -- | Provide a textual representation of the structure of a router. routerLayout :: Router' env a -> Text -- | Apply a transformation to the response of a Router. tweakResponse :: (RouteResult Response -> RouteResult Response) -> Router env -> Router env -- | Interpret a router as an application. runRouter :: Router () -> RoutingApplication runRouterEnv :: Router env -> env -> RoutingApplication -- | Try a list of routing applications in order. We stop as soon as one -- fails fatally or succeeds. If all fail normally, we pick the "best" -- error. runChoice :: [env -> RoutingApplication] -> env -> RoutingApplication worseHTTPCode :: Int -> Int -> Bool instance GHC.Show.Show Servant.Server.Internal.Router.RouterStructure instance GHC.Classes.Eq Servant.Server.Internal.Router.RouterStructure instance GHC.Base.Functor (Servant.Server.Internal.Router.Router' env) module Servant.Server.Internal.BasicAuth -- | servant-server's current implementation of basic authentication is not -- immune to certian kinds of timing attacks. Decoding payloads does not -- take a fixed amount of time. -- -- The result of authentication/authorization data BasicAuthResult usr Unauthorized :: BasicAuthResult usr BadPassword :: BasicAuthResult usr NoSuchUser :: BasicAuthResult usr Authorized :: usr -> BasicAuthResult usr -- | Datatype wrapping a function used to check authentication. newtype BasicAuthCheck usr BasicAuthCheck :: (BasicAuthData -> IO (BasicAuthResult usr)) -> BasicAuthCheck usr [unBasicAuthCheck] :: BasicAuthCheck usr -> BasicAuthData -> IO (BasicAuthResult usr) -- | Internal method to make a basic-auth challenge mkBAChallengerHdr :: ByteString -> Header -- | Find and decode an Authorization header from the request as -- Basic Auth decodeBAHdr :: Request -> Maybe BasicAuthData -- | Run and check basic authentication, returning the appropriate http -- error per the spec. runBasicAuth :: Request -> ByteString -> BasicAuthCheck usr -> DelayedIO usr instance GHC.Base.Functor Servant.Server.Internal.BasicAuth.BasicAuthCheck instance GHC.Generics.Generic (Servant.Server.Internal.BasicAuth.BasicAuthCheck usr) instance GHC.Base.Functor Servant.Server.Internal.BasicAuth.BasicAuthResult instance GHC.Generics.Generic (Servant.Server.Internal.BasicAuth.BasicAuthResult usr) instance GHC.Read.Read usr => GHC.Read.Read (Servant.Server.Internal.BasicAuth.BasicAuthResult usr) instance GHC.Show.Show usr => GHC.Show.Show (Servant.Server.Internal.BasicAuth.BasicAuthResult usr) instance GHC.Classes.Eq usr => GHC.Classes.Eq (Servant.Server.Internal.BasicAuth.BasicAuthResult usr) module Servant.Server.Internal class HasServer api context where { type family ServerT api (m :: * -> *) :: *; } route :: HasServer api context => Proxy api -> Context context -> Delayed env (Server api) -> Router env hoistServerWithContext :: HasServer api context => Proxy api -> Proxy context -> (forall x. m x -> n x) -> ServerT api m -> ServerT api n type Server api = ServerT api Handler -- | A server for a :<|> b first tries to match the -- request against the route represented by a and if it fails -- tries b. You must provide a request handler for each route. -- --
--   type MyApi = "books" :> Get '[JSON] [Book] -- GET /books
--           :<|> "books" :> ReqBody Book :> Post '[JSON] Book -- POST /books
--   
--   server :: Server MyApi
--   server = listAllBooks :<|> postBook
--     where listAllBooks = ...
--           postBook book = ...
--   
-- | If you use Capture in one of the endpoints for your API, this -- automatically requires your server-side handler to be a function that -- takes an argument of the type specified by the Capture. This -- lets servant worry about getting it from the URL and turning it into a -- value of the type you specify. -- -- You can control how it'll be converted from Text to your type -- by simply providing an instance of FromHttpApiData for your -- type. -- -- Example: -- --
--   type MyApi = "books" :> Capture "isbn" Text :> Get '[JSON] Book
--   
--   server :: Server MyApi
--   server = getBook
--     where getBook :: Text -> Handler Book
--           getBook isbn = ...
--   
-- | If you use CaptureAll in one of the endpoints for your API, -- this automatically requires your server-side handler to be a function -- that takes an argument of a list of the type specified by the -- CaptureAll. This lets servant worry about getting values from -- the URL and turning them into values of the type you specify. -- -- You can control how they'll be converted from Text to your type -- by simply providing an instance of FromHttpApiData for your -- type. -- -- Example: -- --
--   type MyApi = "src" :> CaptureAll "segments" Text :> Get '[JSON] SourceFile
--   
--   server :: Server MyApi
--   server = getSourceFile
--     where getSourceFile :: [Text] -> Handler Book
--           getSourceFile pathSegments = ...
--   
allowedMethodHead :: Method -> Request -> Bool allowedMethod :: Method -> Request -> Bool methodCheck :: Method -> Request -> DelayedIO () acceptCheck :: (AllMime list) => Proxy list -> ByteString -> DelayedIO () methodRouter :: (AllCTRender ctypes a) => (b -> ([(HeaderName, ByteString)], a)) -> Method -> Proxy ctypes -> Status -> Delayed env (Handler b) -> Router env streamRouter :: (MimeRender ctype a, FramingRender framing ctype, ToStreamGenerator f a) => (b -> ([(HeaderName, ByteString)], f a)) -> Method -> Proxy framing -> Proxy ctype -> Delayed env (Handler b) -> Router env -- | If you use Header in one of the endpoints for your API, this -- automatically requires your server-side handler to be a function that -- takes an argument of the type specified by Header. This lets -- servant worry about extracting it from the request and turning it into -- a value of the type you specify. -- -- All it asks is for a FromHttpApiData instance. -- -- Example: -- --
--   newtype Referer = Referer Text
--     deriving (Eq, Show, FromHttpApiData)
--   
--              -- GET /view-my-referer
--   type MyApi = "view-my-referer" :> Header "Referer" Referer :> Get '[JSON] Referer
--   
--   server :: Server MyApi
--   server = viewReferer
--     where viewReferer :: Referer -> Handler referer
--           viewReferer referer = return referer
--   
-- | If you use QueryParam "author" Text in one of the -- endpoints for your API, this automatically requires your server-side -- handler to be a function that takes an argument of type -- Maybe Text. -- -- This lets servant worry about looking it up in the query string and -- turning it into a value of the type you specify, enclosed in -- Maybe, because it may not be there and servant would then hand -- you Nothing. -- -- You can control how it'll be converted from Text to your type -- by simply providing an instance of FromHttpApiData for your -- type. -- -- Example: -- --
--   type MyApi = "books" :> QueryParam "author" Text :> Get '[JSON] [Book]
--   
--   server :: Server MyApi
--   server = getBooksBy
--     where getBooksBy :: Maybe Text -> Handler [Book]
--           getBooksBy Nothing       = ...return all books...
--           getBooksBy (Just author) = ...return books by the given author...
--   
-- | If you use QueryParams "authors" Text in one of the -- endpoints for your API, this automatically requires your server-side -- handler to be a function that takes an argument of type -- [Text]. -- -- This lets servant worry about looking up 0 or more values in the query -- string associated to authors and turning each of them into a -- value of the type you specify. -- -- You can control how the individual values are converted from -- Text to your type by simply providing an instance of -- FromHttpApiData for your type. -- -- Example: -- --
--   type MyApi = "books" :> QueryParams "authors" Text :> Get '[JSON] [Book]
--   
--   server :: Server MyApi
--   server = getBooksBy
--     where getBooksBy :: [Text] -> Handler [Book]
--           getBooksBy authors = ...return all books by these authors...
--   
-- | If you use QueryFlag "published" in one of the -- endpoints for your API, this automatically requires your server-side -- handler to be a function that takes an argument of type Bool. -- -- Example: -- --
--   type MyApi = "books" :> QueryFlag "published" :> Get '[JSON] [Book]
--   
--   server :: Server MyApi
--   server = getBooks
--     where getBooks :: Bool -> Handler [Book]
--           getBooks onlyPublished = ...return all books, or only the ones that are already published, depending on the argument...
--   
-- | Just pass the request to the underlying application and serve its -- response. -- -- Example: -- --
--   type MyApi = "images" :> Raw
--   
--   server :: Server MyApi
--   server = serveDirectory "/var/www/images"
--   
-- | If you use ReqBody in one of the endpoints for your API, this -- automatically requires your server-side handler to be a function that -- takes an argument of the type specified by ReqBody. The -- Content-Type header is inspected, and the list provided is -- used to attempt deserialization. If the request does not have a -- Content-Type header, it is treated as -- application/octet-stream (as specified in RFC7231. -- This lets servant worry about extracting it from the request and -- turning it into a value of the type you specify. -- -- All it asks is for a FromJSON instance. -- -- Example: -- --
--   type MyApi = "books" :> ReqBody '[JSON] Book :> Post '[JSON] Book
--   
--   server :: Server MyApi
--   server = postBook
--     where postBook :: Book -> Handler Book
--           postBook book = ...insert into your db...
--   
-- | Make sure the incoming request starts with "/path", strip it -- and pass the rest of the request path to api. -- | Ignore Summary in server handlers. -- | Ignore Description in server handlers. -- | Singleton type representing a server that serves an empty API. data EmptyServer EmptyServer :: EmptyServer -- | Server for EmptyAPI emptyServer :: ServerT EmptyAPI m -- | The server for an EmptyAPI is emptyAPIServer. -- --
--   type MyApi = "nothing" :> EmptyApi
--   
--   server :: Server MyApi
--   server = emptyAPIServer
--   
-- | Basic Authentication ct_wildcard :: ByteString -- | This instance catches mistakes when there are non-saturated type -- applications on LHS of :>. -- --
--   >>> serve (Proxy :: Proxy (Capture "foo" :> Get '[JSON] Int)) (error "...")
--   ...
--   ...Expected something of kind Symbol or *, got: k -> l on the LHS of ':>'.
--   ...Maybe you haven't applied enough arguments to
--   ...Capture' '[] "foo"
--   ...
--   
-- --
--   >>> undefined :: Server (Capture "foo" :> Get '[JSON] Int)
--   ...
--   ...Expected something of kind Symbol or *, got: k -> l on the LHS of ':>'.
--   ...Maybe you haven't applied enough arguments to
--   ...Capture' '[] "foo"
--   ...
--   
type HasServerArrowKindError arr = ( 'Text "Expected something of kind Symbol or *, got: k -> l on the LHS of ':>'." :$$: 'Text "Maybe you haven't applied enough arguments to") :$$: 'ShowType arr -- | This instance prevents from accidentally using '->' instead of -- :> -- --
--   >>> serve (Proxy :: Proxy (Capture "foo" Int -> Get '[JSON] Int)) (error "...")
--   ...
--   ...No instance HasServer (a -> b).
--   ...Maybe you have used '->' instead of ':>' between
--   ...Capture' '[] "foo" Int
--   ...and
--   ...Verb 'GET 200 '[JSON] Int
--   ...
--   
-- --
--   >>> undefined :: Server (Capture "foo" Int -> Get '[JSON] Int)
--   ...
--   ...No instance HasServer (a -> b).
--   ...Maybe you have used '->' instead of ':>' between
--   ...Capture' '[] "foo" Int
--   ...and
--   ...Verb 'GET 200 '[JSON] Int
--   ...
--   
type HasServerArrowTypeError a b = ((( 'Text "No instance HasServer (a -> b)." :$$: 'Text "Maybe you have used '->' instead of ':>' between ") :$$: 'ShowType a) :$$: 'Text "and") :$$: 'ShowType b instance GHC.Enum.Enum Servant.Server.Internal.EmptyServer instance GHC.Enum.Bounded Servant.Server.Internal.EmptyServer instance GHC.Show.Show Servant.Server.Internal.EmptyServer instance GHC.Classes.Eq Servant.Server.Internal.EmptyServer instance (TypeError ...) => Servant.Server.Internal.HasServer (a -> b) context instance forall k l (arr :: k -> l) api (context :: [*]). (TypeError ...) => Servant.Server.Internal.HasServer (arr Servant.API.Sub.:> api) context instance Servant.Server.Internal.HasServer Servant.API.Empty.EmptyAPI context instance (Servant.Server.Internal.HasServer a context, Servant.Server.Internal.HasServer b context) => Servant.Server.Internal.HasServer (a Servant.API.Alternative.:<|> b) context instance (GHC.TypeLits.KnownSymbol capture, Web.Internal.HttpApiData.FromHttpApiData a, Servant.Server.Internal.HasServer api context) => Servant.Server.Internal.HasServer (Servant.API.Capture.Capture' mods capture a Servant.API.Sub.:> api) context instance (GHC.TypeLits.KnownSymbol capture, Web.Internal.HttpApiData.FromHttpApiData a, Servant.Server.Internal.HasServer api context) => Servant.Server.Internal.HasServer (Servant.API.Capture.CaptureAll capture a Servant.API.Sub.:> api) context instance forall k1 (ctypes :: [*]) a (method :: k1) (status :: GHC.Types.Nat) (context :: [*]). (Servant.API.ContentTypes.AllCTRender ctypes a, Servant.API.Verbs.ReflectMethod method, GHC.TypeNats.KnownNat status) => Servant.Server.Internal.HasServer (Servant.API.Verbs.Verb method status ctypes a) context instance forall k1 (ctypes :: [*]) a (method :: k1) (status :: GHC.Types.Nat) (h :: [*]) (context :: [*]). (Servant.API.ContentTypes.AllCTRender ctypes a, Servant.API.Verbs.ReflectMethod method, GHC.TypeNats.KnownNat status, Servant.API.ResponseHeaders.GetHeaders (Servant.API.ResponseHeaders.Headers h a)) => Servant.Server.Internal.HasServer (Servant.API.Verbs.Verb method status ctypes (Servant.API.ResponseHeaders.Headers h a)) context instance forall k1 ctype a (method :: k1) framing (f :: * -> *) (context :: [*]). (Servant.API.ContentTypes.MimeRender ctype a, Servant.API.Verbs.ReflectMethod method, Servant.API.Stream.FramingRender framing ctype, Servant.API.Stream.ToStreamGenerator f a) => Servant.Server.Internal.HasServer (Servant.API.Stream.Stream method framing ctype (f a)) context instance forall k1 ctype a (method :: k1) framing (f :: * -> *) (h :: [*]) (context :: [*]). (Servant.API.ContentTypes.MimeRender ctype a, Servant.API.Verbs.ReflectMethod method, Servant.API.Stream.FramingRender framing ctype, Servant.API.Stream.ToStreamGenerator f a, Servant.API.ResponseHeaders.GetHeaders (Servant.API.ResponseHeaders.Headers h (f a))) => Servant.Server.Internal.HasServer (Servant.API.Stream.Stream method framing ctype (Servant.API.ResponseHeaders.Headers h (f a))) context instance (GHC.TypeLits.KnownSymbol sym, Web.Internal.HttpApiData.FromHttpApiData a, Servant.Server.Internal.HasServer api context, Data.Singletons.Bool.SBoolI (Servant.API.Modifiers.FoldRequired mods), Data.Singletons.Bool.SBoolI (Servant.API.Modifiers.FoldLenient mods)) => Servant.Server.Internal.HasServer (Servant.API.Header.Header' mods sym a Servant.API.Sub.:> api) context instance (GHC.TypeLits.KnownSymbol sym, Web.Internal.HttpApiData.FromHttpApiData a, Servant.Server.Internal.HasServer api context, Data.Singletons.Bool.SBoolI (Servant.API.Modifiers.FoldRequired mods), Data.Singletons.Bool.SBoolI (Servant.API.Modifiers.FoldLenient mods)) => Servant.Server.Internal.HasServer (Servant.API.QueryParam.QueryParam' mods sym a Servant.API.Sub.:> api) context instance (GHC.TypeLits.KnownSymbol sym, Web.Internal.HttpApiData.FromHttpApiData a, Servant.Server.Internal.HasServer api context) => Servant.Server.Internal.HasServer (Servant.API.QueryParam.QueryParams sym a Servant.API.Sub.:> api) context instance (GHC.TypeLits.KnownSymbol sym, Servant.Server.Internal.HasServer api context) => Servant.Server.Internal.HasServer (Servant.API.QueryParam.QueryFlag sym Servant.API.Sub.:> api) context instance Servant.Server.Internal.HasServer Servant.API.Raw.Raw context instance (Servant.API.ContentTypes.AllCTUnrender list a, Servant.Server.Internal.HasServer api context, Data.Singletons.Bool.SBoolI (Servant.API.Modifiers.FoldLenient mods)) => Servant.Server.Internal.HasServer (Servant.API.ReqBody.ReqBody' mods list a Servant.API.Sub.:> api) context instance (GHC.TypeLits.KnownSymbol path, Servant.Server.Internal.HasServer api context) => Servant.Server.Internal.HasServer (path Servant.API.Sub.:> api) context instance Servant.Server.Internal.HasServer api context => Servant.Server.Internal.HasServer (Servant.API.RemoteHost.RemoteHost Servant.API.Sub.:> api) context instance Servant.Server.Internal.HasServer api context => Servant.Server.Internal.HasServer (Servant.API.IsSecure.IsSecure Servant.API.Sub.:> api) context instance Servant.Server.Internal.HasServer api context => Servant.Server.Internal.HasServer (Data.Vault.Lazy.Vault Servant.API.Sub.:> api) context instance Servant.Server.Internal.HasServer api context => Servant.Server.Internal.HasServer (Network.HTTP.Types.Version.HttpVersion Servant.API.Sub.:> api) context instance Servant.Server.Internal.HasServer api ctx => Servant.Server.Internal.HasServer (Servant.API.Description.Summary desc Servant.API.Sub.:> api) ctx instance Servant.Server.Internal.HasServer api ctx => Servant.Server.Internal.HasServer (Servant.API.Description.Description desc Servant.API.Sub.:> api) ctx instance (GHC.TypeLits.KnownSymbol realm, Servant.Server.Internal.HasServer api context, Servant.Server.Internal.Context.HasContextEntry context (Servant.Server.Internal.BasicAuth.BasicAuthCheck usr)) => Servant.Server.Internal.HasServer (Servant.API.BasicAuth.BasicAuth realm usr Servant.API.Sub.:> api) context instance (Servant.Server.Internal.Context.HasContextEntry context (Servant.Server.Internal.Context.NamedContext name subContext), Servant.Server.Internal.HasServer subApi subContext) => Servant.Server.Internal.HasServer (Servant.API.WithNamedContext.WithNamedContext name subContext subApi) context -- | This module lets you implement Servers for defined APIs. You'll -- most likely just need serve. module Servant.Server -- | serve allows you to implement an API and produce a wai -- Application. -- -- Example: -- --
--   type MyApi = "books" :> Get '[JSON] [Book] -- GET /books
--           :<|> "books" :> ReqBody Book :> Post '[JSON] Book -- POST /books
--   
--   server :: Server MyApi
--   server = listAllBooks :<|> postBook
--     where listAllBooks = ...
--           postBook book = ...
--   
--   myApi :: Proxy MyApi
--   myApi = Proxy
--   
--   app :: Application
--   app = serve myApi server
--   
--   main :: IO ()
--   main = Network.Wai.Handler.Warp.run 8080 app
--   
serve :: (HasServer api '[]) => Proxy api -> Server api -> Application serveWithContext :: (HasServer api context) => Proxy api -> Context context -> Server api -> Application toApplication :: RoutingApplication -> Application class HasServer api context where { type family ServerT api (m :: * -> *) :: *; } route :: HasServer api context => Proxy api -> Context context -> Delayed env (Server api) -> Router env hoistServerWithContext :: HasServer api context => Proxy api -> Proxy context -> (forall x. m x -> n x) -> ServerT api m -> ServerT api n type Server api = ServerT api Handler -- | Singleton type representing a server that serves an empty API. data EmptyServer -- | Server for EmptyAPI emptyServer :: ServerT EmptyAPI m newtype Handler a Handler :: ExceptT ServantErr IO a -> Handler a [runHandler'] :: Handler a -> ExceptT ServantErr IO a runHandler :: Handler a -> IO (Either ServantErr a) -- | The function layout produces a textual description of the -- internal router layout for debugging purposes. Note that the router -- layout is determined just by the API, not by the handlers. -- -- Example: -- -- For the following API -- --
--   type API =
--          "a" :> "d" :> Get '[JSON] NoContent
--     :<|> "b" :> Capture "x" Int :> Get '[JSON] Bool
--     :<|> "c" :> Put '[JSON] Bool
--     :<|> "a" :> "e" :> Get '[JSON] Int
--     :<|> "b" :> Capture "x" Int :> Put '[JSON] Bool
--     :<|> Raw
--   
-- -- we get the following output: -- --
--   /
--   ├─ a/
--   │  ├─ d/
--   │  │  └─•
--   │  └─ e/
--   │     └─•
--   ├─ b/
--   │  └─ <capture>/
--   │     ├─•
--   │     ┆
--   │     └─•
--   ├─ c/
--   │  └─•
--   ┆
--   └─ <raw>
--   
-- -- Explanation of symbols: -- -- layout :: (HasServer api '[]) => Proxy api -> Text -- | Variant of layout that takes an additional Context. layoutWithContext :: (HasServer api context) => Proxy api -> Context context -> Text -- | Hoist server implementation. -- -- Sometimes our cherished Handler monad isn't quite the type -- you'd like for your handlers. Maybe you want to thread some -- configuration in a Reader monad. Or have your types ensure -- that your handlers don't do any IO. Use hoistServer (a -- successor of now deprecated enter). -- -- With hoistServer, you can provide a function, to convert any -- number of endpoints from one type constructor to another. For example -- -- Note: Server Raw can also be entered. It will -- be retagged. -- --
--   >>> import Control.Monad.Reader
--   
--   >>> type ReaderAPI = "ep1" :> Get '[JSON] Int :<|> "ep2" :> Get '[JSON] String :<|> Raw :<|> EmptyAPI
--   
--   >>> let readerApi = Proxy :: Proxy ReaderAPI
--   
--   >>> let readerServer = return 1797 :<|> ask :<|> Tagged (error "raw server") :<|> emptyServer :: ServerT ReaderAPI (Reader String)
--   
--   >>> let nt x = return (runReader x "hi")
--   
--   >>> let mainServer = hoistServer readerApi nt readerServer :: Server ReaderAPI
--   
hoistServer :: (HasServer api '[]) => Proxy api -> (forall x. m x -> n x) -> ServerT api m -> ServerT api n -- | Apply a transformation to the response of a Router. tweakResponse :: (RouteResult Response -> RouteResult Response) -> Router env -> Router env -- | Contexts are used to pass values to combinators. (They are -- not meant to be used to pass parameters to your handlers, i.e. -- they should not replace any custom ReaderT-monad-stack that -- you're using with Enter.) If you don't use combinators that -- require any context entries, you can just use serve as always. -- -- If you are using combinators that require a non-empty Context -- you have to use serveWithContext and pass it a Context -- that contains all the values your combinators need. A Context -- is essentially a heterogenous list and accessing the elements is being -- done by type (see getContextEntry). The parameter of the type -- Context is a type-level list reflecting the types of the -- contained context entries. To create a Context with entries, -- use the operator (:.): -- --
--   >>> :type True :. () :. EmptyContext
--   True :. () :. EmptyContext :: Context '[Bool, ()]
--   
data Context contextTypes [EmptyContext] :: Context '[] [:.] :: x -> Context xs -> Context (x : xs) -- | This class is used to access context entries in Contexts. -- getContextEntry returns the first value where the type matches: -- --
--   >>> getContextEntry (True :. False :. EmptyContext) :: Bool
--   True
--   
-- -- If the Context does not contain an entry of the requested type, -- you'll get an error: -- --
--   >>> getContextEntry (True :. False :. EmptyContext) :: String
--   ...
--   ...No instance for (HasContextEntry '[] [Char])
--   ...
--   
class HasContextEntry (context :: [*]) (val :: *) getContextEntry :: HasContextEntry context val => Context context -> val -- | Normally context entries are accessed by their types. In case you need -- to have multiple values of the same type in your Context and -- need to access them, we provide NamedContext. You can think of -- it as sub-namespaces for Contexts. data NamedContext (name :: Symbol) (subContext :: [*]) NamedContext :: (Context subContext) -> NamedContext -- | descendIntoNamedContext allows you to access -- NamedContexts. Usually you won't have to use it yourself but -- instead use a combinator like WithNamedContext. -- -- This is how descendIntoNamedContext works: -- --
--   >>> :set -XFlexibleContexts
--   
--   >>> let subContext = True :. EmptyContext
--   
--   >>> :type subContext
--   subContext :: Context '[Bool]
--   
--   >>> let parentContext = False :. (NamedContext subContext :: NamedContext "subContext" '[Bool]) :. EmptyContext
--   
--   >>> :type parentContext
--   parentContext :: Context '[Bool, NamedContext "subContext" '[Bool]]
--   
--   >>> descendIntoNamedContext (Proxy :: Proxy "subContext") parentContext :: Context '[Bool]
--   True :. EmptyContext
--   
descendIntoNamedContext :: forall context name subContext. HasContextEntry context (NamedContext name subContext) => Proxy (name :: Symbol) -> Context context -> Context subContext -- | Datatype wrapping a function used to check authentication. newtype BasicAuthCheck usr BasicAuthCheck :: (BasicAuthData -> IO (BasicAuthResult usr)) -> BasicAuthCheck usr [unBasicAuthCheck] :: BasicAuthCheck usr -> BasicAuthData -> IO (BasicAuthResult usr) -- | servant-server's current implementation of basic authentication is not -- immune to certian kinds of timing attacks. Decoding payloads does not -- take a fixed amount of time. -- -- The result of authentication/authorization data BasicAuthResult usr Unauthorized :: BasicAuthResult usr BadPassword :: BasicAuthResult usr NoSuchUser :: BasicAuthResult usr Authorized :: usr -> BasicAuthResult usr data ServantErr ServantErr :: Int -> String -> ByteString -> [Header] -> ServantErr [errHTTPCode] :: ServantErr -> Int [errReasonPhrase] :: ServantErr -> String [errBody] :: ServantErr -> ByteString [errHeaders] :: ServantErr -> [Header] -- | err300 Multiple Choices -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err300 { errBody = "I can't choose." }
--   
err300 :: ServantErr -- | err301 Moved Permanently -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError err301
--   
err301 :: ServantErr -- | err302 Found -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError err302
--   
err302 :: ServantErr -- | err303 See Other -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError err303
--   
err303 :: ServantErr -- | err304 Not Modified -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError err304
--   
err304 :: ServantErr -- | err305 Use Proxy -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError err305
--   
err305 :: ServantErr -- | err307 Temporary Redirect -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError err307
--   
err307 :: ServantErr -- | err400 Bad Request -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err400 { errBody = "Your request makes no sense to me." }
--   
err400 :: ServantErr -- | err401 Unauthorized -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err401 { errBody = "Your credentials are invalid." }
--   
err401 :: ServantErr -- | err402 Payment Required -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err402 { errBody = "You have 0 credits. Please give me $$$." }
--   
err402 :: ServantErr -- | err403 Forbidden -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err403 { errBody = "Please login first." }
--   
err403 :: ServantErr -- | err404 Not Found -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err404 { errBody = "(╯°□°)╯︵ ┻━┻)." }
--   
err404 :: ServantErr -- | err405 Method Not Allowed -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err405 { errBody = "Your account privileges does not allow for this.  Please pay $$$." }
--   
err405 :: ServantErr -- | err406 Not Acceptable -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError err406
--   
err406 :: ServantErr -- | err407 Proxy Authentication Required -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError err407
--   
err407 :: ServantErr -- | err409 Conflict -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err409 { errBody = "Transaction conflicts with 59879cb56c7c159231eeacdd503d755f7e835f74" }
--   
err409 :: ServantErr -- | err410 Gone -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err410 { errBody = "I know it was here at some point, but.. I blame bad luck." }
--   
err410 :: ServantErr -- | err411 Length Required -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError err411
--   
err411 :: ServantErr -- | err412 Precondition Failed -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err412 { errBody = "Precondition fail: x < 42 && y > 57" }
--   
err412 :: ServantErr -- | err413 Request Entity Too Large -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err413 { errBody = "Request exceeded 64k." }
--   
err413 :: ServantErr -- | err414 Request-URI Too Large -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err414 { errBody = "Maximum length is 64." }
--   
err414 :: ServantErr -- | err415 Unsupported Media Type -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err415 { errBody = "Supported media types:  gif, png" }
--   
err415 :: ServantErr -- | err416 Request range not satisfiable -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err416 { errBody = "Valid range is [0, 424242]." }
--   
err416 :: ServantErr -- | err417 Expectation Failed -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err417 { errBody = "I found a quux in the request.  This isn't going to work." }
--   
err417 :: ServantErr -- | err418 Expectation Failed -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err418 { errBody = "Apologies, this is not a webserver but a teapot." }
--   
err418 :: ServantErr -- | err422 Unprocessable Entity -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err422 { errBody = "I understood your request, but can't process it." }
--   
err422 :: ServantErr -- | err500 Internal Server Error -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err500 { errBody = "Exception in module A.B.C:55.  Have a great day!" }
--   
err500 :: ServantErr -- | err501 Not Implemented -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err501 { errBody = "/v1/foo is not supported with quux in the request." }
--   
err501 :: ServantErr -- | err502 Bad Gateway -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err502 { errBody = "Tried gateway foo, bar, and baz.  None responded." }
--   
err502 :: ServantErr -- | err503 Service Unavailable -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err503 { errBody = "We're rewriting in PHP." }
--   
err503 :: ServantErr -- | err504 Gateway Time-out -- -- Example: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err504 { errBody = "Backend foobar did not respond in 5 seconds." }
--   
err504 :: ServantErr -- | err505 HTTP Version not supported -- -- Example usage: -- --
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err505 { errBody = "I support HTTP/4.0 only." }
--   
err505 :: ServantErr -- | The WAI application. -- -- Note that, since WAI 3.0, this type is structured in continuation -- passing style to allow for proper safe resource handling. This was -- handled in the past via other means (e.g., ResourceT). As a -- demonstration: -- --
--   app :: Application
--   app req respond = bracket_
--       (putStrLn "Allocating scarce resource")
--       (putStrLn "Cleaning up")
--       (respond $ responseLBS status200 [] "Hello World")
--   
type Application = Request -> (Response -> IO ResponseReceived) -> IO ResponseReceived -- | A Tagged s b value is a value b with an -- attached phantom type s. This can be used in place of the -- more traditional but less safe idiom of passing in an undefined value -- with the type, because unlike an (s -> b), a -- Tagged s b can't try to use the argument s as -- a real value. -- -- Moreover, you don't have to rely on the compiler to inline away the -- extra argument, because the newtype is "free" -- -- Tagged has kind k -> * -> * if the compiler -- supports PolyKinds, therefore there is an extra k -- showing in the instance haddocks that may cause confusion. newtype Tagged k (s :: k) b :: forall k. () => k -> * -> * Tagged :: b -> Tagged k b [unTagged] :: Tagged k b -> b -- | This module defines server-side handlers that lets you serve static -- files. -- -- The most common needs for a web application are covered by -- serveDirectoryWebApp, but the other variants allow you to use -- different StaticSettings and serveDirectoryWith even -- allows you to specify arbitrary StaticSettings to be used for -- serving static files. module Servant.Utils.StaticFiles -- | Serve anything under the specified directory as a Raw endpoint. -- --
--   type MyApi = "static" :> Raw
--   
--   server :: Server MyApi
--   server = serveDirectoryWebApp "/var/www"
--   
-- -- would capture any request to /static/<something> and -- look for <something> under /var/www. -- -- It will do its best to guess the MIME type for that file, based on the -- extension, and send an appropriate Content-Type header if -- possible. -- -- If your goal is to serve HTML, CSS and Javascript files that use the -- rest of the API as a webapp backend, you will most likely not want the -- static files to be hidden behind a /static/ prefix. In that -- case, remember to put the serveDirectoryWebApp handler in the -- last position, because servant will try to match the handlers -- in order. -- -- Corresponds to the defaultWebAppSettings StaticSettings -- value. serveDirectoryWebApp :: FilePath -> Server Raw -- | Same as serveDirectoryWebApp, but uses -- webAppSettingsWithLookup. serveDirectoryWebAppLookup :: ETagLookup -> FilePath -> Server Raw -- | Same as serveDirectoryWebApp, but uses -- defaultFileServerSettings. serveDirectoryFileServer :: FilePath -> Server Raw -- | Uses embeddedSettings. serveDirectoryEmbedded :: [(FilePath, ByteString)] -> Server Raw -- | Alias for staticApp. Lets you serve a directory with arbitrary -- StaticSettings. Useful when you want particular settings not -- covered by the four other variants. This is the most flexible method. serveDirectoryWith :: StaticSettings -> Server Raw -- | Same as serveDirectoryFileServer. It used to be the only file -- serving function in servant pre-0.10 and will be kept around for a few -- versions, but is deprecated. -- | Deprecated: Use serveDirectoryFileServer instead serveDirectory :: FilePath -> Server Raw module Servant -- | A concrete, poly-kinded proxy type data Proxy k (t :: k) :: forall k. () => k -> * Proxy :: Proxy k -- | Is used within a monadic computation to begin exception processing. throwError :: MonadError e m => forall a. () => e -> m a module Servant.Server.Experimental.Auth -- | Specify the type of data returned after we've authenticated a request. -- quite often this is some User datatype. -- -- NOTE: THIS API IS EXPERIMENTAL AND SUBJECT TO CHANGE -- | Handlers for AuthProtected resources -- -- NOTE: THIS API IS EXPERIMENTAL AND SUBJECT TO CHANGE newtype AuthHandler r usr AuthHandler :: (r -> Handler usr) -> AuthHandler r usr [unAuthHandler] :: AuthHandler r usr -> r -> Handler usr -- | NOTE: THIS API IS EXPERIMENTAL AND SUBJECT TO CHANGE mkAuthHandler :: (r -> Handler usr) -> AuthHandler r usr -- | Known orphan instance. instance GHC.Generics.Generic (Servant.Server.Experimental.Auth.AuthHandler r usr) instance forall k api (context :: [*]) (tag :: k). (Servant.Server.Internal.HasServer api context, Servant.Server.Internal.Context.HasContextEntry context (Servant.Server.Experimental.Auth.AuthHandler Network.Wai.Internal.Request (Servant.Server.Experimental.Auth.AuthServerData (Servant.API.Experimental.Auth.AuthProtect tag)))) => Servant.Server.Internal.HasServer (Servant.API.Experimental.Auth.AuthProtect tag Servant.API.Sub.:> api) context