scotty-0.20.1: Haskell web framework inspired by Ruby's Sinatra, using WAI and Warp

Safe Haskell | Safe-Inferred
Language | Haskell2010

Web.Scotty.Internal.Types

Synopsis

- data Options = Options {
  - verbose :: Int
  - settings :: Settings
  }
- defaultOptions :: Options
- newtype RouteOptions = RouteOptions {
  - maxRequestBodySize :: Maybe Kilobytes
  }
- defaultRouteOptions :: RouteOptions
- type Kilobytes = Int
- type Middleware m = Application m -> Application m
- type Application m = Request -> m Response
- data BodyChunkBuffer = BodyChunkBuffer {
  - hasFinishedReadingChunks :: Bool
  - chunksReadSoFar :: [ByteString]
  }
- data BodyInfo = BodyInfo {
  - bodyInfoReadProgress :: MVar Int
  - bodyInfoChunkBuffer :: MVar BodyChunkBuffer
  - bodyInfoDirectChunkRead :: IO ByteString
  }
- data ScottyState m = ScottyState {
  - middlewares :: [Middleware]
  - routes :: [BodyInfo -> Middleware m]
  - handler :: Maybe (ErrorHandler m)
  - routeOptions :: RouteOptions
  }
- defaultScottyState :: ScottyState m
- addMiddleware :: Middleware -> ScottyState m -> ScottyState m
- addRoute :: (BodyInfo -> Middleware m) -> ScottyState m -> ScottyState m
- setHandler :: Maybe (ErrorHandler m) -> ScottyState m -> ScottyState m
- updateMaxRequestBodySize :: RouteOptions -> ScottyState m -> ScottyState m
- newtype ScottyT m a = ScottyT {
  - runS :: State (ScottyState m) a
  }
- data ActionError
  - = AERedirect Text
  - | AENext
  - | AEFinish
- tryNext :: MonadUnliftIO m => m a -> m Bool
- data StatusError = StatusError Status Text
- type ErrorHandler m = Handler (ActionT m) ()
- data ScottyException = RequestException ByteString Status
- type Param = (Text, Text)
- type File = (Text, FileInfo ByteString)
- data ActionEnv = Env {
  - envReq :: Request
  - envCaptureParams :: [Param]
  - envFormParams :: [Param]
  - envQueryParams :: [Param]
  - envBody :: IO ByteString
  - envBodyChunk :: IO ByteString
  - envFiles :: [File]
  - envResponse :: TVar ScottyResponse
  }
- getResponse :: MonadIO m => ActionEnv -> m ScottyResponse
- modifyResponse :: MonadIO m => (ScottyResponse -> ScottyResponse) -> ActionT m ()
- data BodyPartiallyStreamed = BodyPartiallyStreamed
- data Content
  - = ContentBuilder Builder
  - | ContentFile FilePath
  - | ContentStream StreamingBody
  - | ContentResponse Response
- data ScottyResponse = SR {
  - srStatus :: Status
  - srHeaders :: ResponseHeaders
  - srContent :: Content
  }
- setContent :: Content -> ScottyResponse -> ScottyResponse
- setHeaderWith :: ([(HeaderName, ByteString)] -> [(HeaderName, ByteString)]) -> ScottyResponse -> ScottyResponse
- setStatus :: Status -> ScottyResponse -> ScottyResponse
- defaultScottyResponse :: ScottyResponse
- newtype ActionT m a = ActionT {
  - runAM :: ReaderT ActionEnv m a
  }
- tryAnyStatus :: MonadUnliftIO m => m a -> m Bool
- data RoutePattern
  - = Capture Text
  - | Literal Text
  - | Function (Request -> Maybe [Param])

# Documentation

data Options Source #

Constructors

Options |

Fields

- verbose :: Int

  0 = silent, 1(def) = startup banner

- settings :: Settings

  Warp `Settings` Note: to work around an issue in warp, the default FD cache duration is set to 0 so changes to static files are always picked up. This likely has performance implications, so you may want to modify this for production servers using `setFdCacheDuration`.

#### Instances

Instances details

Default Options Source # |
Instance details Defined in Web.Scotty.Internal.Types Methods def :: Options Source #

defaultOptions :: Options Source #

newtype RouteOptions Source #

Constructors

RouteOptions |

Fields

- maxRequestBodySize :: Maybe Kilobytes

#### Instances

Instances details

Default RouteOptions Source # |
Instance details Defined in Web.Scotty.Internal.Types Methods def :: RouteOptions Source #

defaultRouteOptions :: RouteOptions Source #

type Kilobytes = Int Source #

type Middleware m = Application m -> Application m Source #

type Application m = Request -> m Response Source #

data BodyChunkBuffer Source #

Constructors

BodyChunkBuffer |

Fields

- hasFinishedReadingChunks :: Bool

  whether we've reached the end of the stream yet

- chunksReadSoFar :: [ByteString]

data BodyInfo Source #

The key part of having two MVars is that we can "clone" the BodyInfo to create a copy where the index is reset to 0, but the chunk cache is the same. Passing a cloned BodyInfo into each matched route allows them each to start from the first chunk if they call bodyReader.

Introduced in (#308)

Constructors

BodyInfo |

Fields

- bodyInfoReadProgress :: MVar Int

  index into the stream read so far

- bodyInfoChunkBuffer :: MVar BodyChunkBuffer
- bodyInfoDirectChunkRead :: IO ByteString

  can be called to get more chunks

data ScottyState m Source #

Constructors

ScottyState |

Fields

- middlewares :: [Middleware]
- routes :: [BodyInfo -> Middleware m]
- handler :: Maybe (ErrorHandler m)
- routeOptions :: RouteOptions

#### Instances

Instances details

Default (ScottyState m) Source # |
Instance details Defined in Web.Scotty.Internal.Types Methods def :: ScottyState m Source #

defaultScottyState :: ScottyState m Source #

addMiddleware :: Middleware -> ScottyState m -> ScottyState m Source #

addRoute :: (BodyInfo -> Middleware m) -> ScottyState m -> ScottyState m Source #

setHandler :: Maybe (ErrorHandler m) -> ScottyState m -> ScottyState m Source #

updateMaxRequestBodySize :: RouteOptions -> ScottyState m -> ScottyState m Source #

newtype ScottyT m a Source #

Constructors

ScottyT |

Fields

- runS :: State (ScottyState m) a

#### Instances

Instances details

Applicative (ScottyT m) Source # |
Instance details Defined in Web.Scotty.Internal.Types Methods pure :: a -> ScottyT m a Source # (<*>) :: ScottyT m (a -> b) -> ScottyT m a -> ScottyT m b Source # liftA2 :: (a -> b -> c) -> ScottyT m a -> ScottyT m b -> ScottyT m c Source # (*>) :: ScottyT m a -> ScottyT m b -> ScottyT m b Source # (<*) :: ScottyT m a -> ScottyT m b -> ScottyT m a Source #
Functor (ScottyT m) Source # |
Instance details Defined in Web.Scotty.Internal.Types Methods fmap :: (a -> b) -> ScottyT m a -> ScottyT m b Source # (<$) :: a -> ScottyT m b -> ScottyT m a Source #
Monad (ScottyT m) Source # |
Instance details Defined in Web.Scotty.Internal.Types Methods (>>=) :: ScottyT m a -> (a -> ScottyT m b) -> ScottyT m b Source # (>>) :: ScottyT m a -> ScottyT m b -> ScottyT m b Source # return :: a -> ScottyT m a Source #
Monoid a => Monoid (ScottyT m a) Source # |
Instance details Defined in Web.Scotty.Internal.Types Methods mempty :: ScottyT m a Source # mappend :: ScottyT m a -> ScottyT m a -> ScottyT m a Source # mconcat :: [ScottyT m a] -> ScottyT m a Source #
Semigroup a => Semigroup (ScottyT m a) Source # |
Instance details Defined in Web.Scotty.Internal.Types Methods (<>) :: ScottyT m a -> ScottyT m a -> ScottyT m a Source # sconcat :: NonEmpty (ScottyT m a) -> ScottyT m a Source # stimes :: Integral b => b -> ScottyT m a -> ScottyT m a Source #

data ActionError Source #

Internal exception mechanism used to modify the request processing flow.

The exception constructor is not exposed to the user and all exceptions of this type are caught and processed within the `runAction` function.

Constructors

AERedirect Text | Redirect
AENext | Stop processing this route and skip to the next one
AEFinish | Stop processing the request

#### Instances

Instances details

Exception ActionError Source # |
Instance details Defined in Web.Scotty.Internal.Types Methods toException :: ActionError -> SomeException Source # fromException :: SomeException -> Maybe ActionError Source # displayException :: ActionError -> String Source #
Show ActionError Source # |
Instance details Defined in Web.Scotty.Internal.Types Methods showsPrec :: Int -> ActionError -> ShowS Source # show :: ActionError -> String Source # showList :: [ActionError] -> ShowS Source #

tryNext :: MonadUnliftIO m => m a -> m Bool Source #

data StatusError Source #

E.g. when a parameter is not found in a query string (400 Bad Request) or when parsing a JSON body fails (422 Unprocessable Entity)

Constructors

StatusError Status Text |

#### Instances

Instances details

Exception StatusError Source # |
Instance details Defined in Web.Scotty.Internal.Types Methods toException :: StatusError -> SomeException Source # fromException :: SomeException -> Maybe StatusError Source # displayException :: StatusError -> String Source #
Show StatusError Source # |
Instance details Defined in Web.Scotty.Internal.Types Methods showsPrec :: Int -> StatusError -> ShowS Source # show :: StatusError -> String Source # showList :: [StatusError] -> ShowS Source #
MonadUnliftIO m => MonadError StatusError (ActionT m) Source # | Models the invariant that only `StatusError`s can be thrown and caught.
Instance details Defined in Web.Scotty.Internal.Types Methods throwError :: StatusError -> ActionT m a Source # catchError :: ActionT m a -> (StatusError -> ActionT m a) -> ActionT m a Source #

type ErrorHandler m = Handler (ActionT m) () Source #

Specializes a `Handler` to the `ActionT` monad

data ScottyException Source #

Thrown e.g. when a request is too large

Constructors

RequestException ByteString Status |

#### Instances

Instances details

Exception ScottyException Source # |
Instance details Defined in Web.Scotty.Internal.Types Methods toException :: ScottyException -> SomeException Source # fromException :: SomeException -> Maybe ScottyException Source # displayException :: ScottyException -> String Source #
Show ScottyException Source # |
Instance details Defined in Web.Scotty.Internal.Types Methods showsPrec :: Int -> ScottyException -> ShowS Source # show :: ScottyException -> String Source # showList :: [ScottyException] -> ShowS Source #

type Param = (Text, Text) Source #

type File = (Text, FileInfo ByteString) Source #

data ActionEnv Source #

Constructors

Env |

Fields

- envReq :: Request
- envCaptureParams :: [Param]
- envFormParams :: [Param]
- envQueryParams :: [Param]
- envBody :: IO ByteString
- envBodyChunk :: IO ByteString
- envFiles :: [File]
- envResponse :: TVar ScottyResponse

#### Instances

Instances details

Monad m => MonadReader ActionEnv (ActionT m) Source # |
Instance details Defined in Web.Scotty.Internal.Types Methods ask :: ActionT m ActionEnv Source # local :: (ActionEnv -> ActionEnv) -> ActionT m a -> ActionT m a Source # reader :: (ActionEnv -> a) -> ActionT m a Source #

getResponse :: MonadIO m => ActionEnv -> m ScottyResponse Source #

modifyResponse :: MonadIO m => (ScottyResponse -> ScottyResponse) -> ActionT m () Source #

data BodyPartiallyStreamed Source #

Constructors

BodyPartiallyStreamed |

#### Instances

Instances details

Exception BodyPartiallyStreamed Source # |
Instance details Defined in Web.Scotty.Internal.Types Methods toException :: BodyPartiallyStreamed -> SomeException Source # fromException :: SomeException -> Maybe BodyPartiallyStreamed Source # displayException :: BodyPartiallyStreamed -> String Source #
Show BodyPartiallyStreamed Source # |
Instance details Defined in Web.Scotty.Internal.Types Methods showsPrec :: Int -> BodyPartiallyStreamed -> ShowS Source # show :: BodyPartiallyStreamed -> String Source # showList :: [BodyPartiallyStreamed] -> ShowS Source #

data Content Source #

Constructors

ContentBuilder Builder |
ContentFile FilePath |
ContentStream StreamingBody |
ContentResponse Response |

data ScottyResponse Source #

Constructors

SR |

Fields

- srStatus :: Status
- srHeaders :: ResponseHeaders
- srContent :: Content

#### Instances

Instances details

Default ScottyResponse Source # |
Instance details Defined in Web.Scotty.Internal.Types Methods def :: ScottyResponse Source #

setContent :: Content -> ScottyResponse -> ScottyResponse Source #

setHeaderWith :: ([(HeaderName, ByteString)] -> [(HeaderName, ByteString)]) -> ScottyResponse -> ScottyResponse Source #

setStatus :: Status -> ScottyResponse -> ScottyResponse Source #

defaultScottyResponse :: ScottyResponse Source #

The default response has code 200 OK and empty body

newtype ActionT m a Source #

Constructors

ActionT |

Fields

- runAM :: ReaderT ActionEnv m a

#### Instances

Instances details

MonadTransControl ActionT Source # |
Instance details Defined in Web.Scotty.Internal.Types Associated Types type StT ActionT a Source # Methods liftWith :: Monad m => (Run ActionT -> m a) -> ActionT m a Source # restoreT :: Monad m => m (StT ActionT a) -> ActionT m a Source #
MonadTrans ActionT Source # |
Instance details Defined in Web.Scotty.Internal.Types Methods lift :: Monad m => m a -> ActionT m a Source #
MonadBaseControl b m => MonadBaseControl b (ActionT m) Source # |
Instance details Defined in Web.Scotty.Internal.Types Associated Types type StM (ActionT m) a Source # Methods liftBaseWith :: (RunInBase (ActionT m) b -> b a) -> ActionT m a Source # restoreM :: StM (ActionT m) a -> ActionT m a Source #
MonadUnliftIO m => MonadError StatusError (ActionT m) Source # | Models the invariant that only `StatusError`s can be thrown and caught.
Instance details Defined in Web.Scotty.Internal.Types Methods throwError :: StatusError -> ActionT m a Source # catchError :: ActionT m a -> (StatusError -> ActionT m a) -> ActionT m a Source #
Monad m => MonadReader ActionEnv (ActionT m) Source # |
Instance details Defined in Web.Scotty.Internal.Types Methods ask :: ActionT m ActionEnv Source # local :: (ActionEnv -> ActionEnv) -> ActionT m a -> ActionT m a Source # reader :: (ActionEnv -> a) -> ActionT m a Source #
MonadBase b m => MonadBase b (ActionT m) Source # |
Instance details Defined in Web.Scotty.Internal.Types Methods liftBase :: b α -> ActionT m α Source #
MonadIO m => MonadFail (ActionT m) Source # | Modeled after the behaviour in scotty < 0.20, `fail` throws a `StatusError` with code 500 ("Server Error"), which can be caught with `catch` or `rescue`.
Instance details Defined in Web.Scotty.Internal.Types Methods fail :: String -> ActionT m a Source #
MonadIO m => MonadIO (ActionT m) Source # |
Instance details Defined in Web.Scotty.Internal.Types Methods liftIO :: IO a -> ActionT m a Source #
MonadUnliftIO m => Alternative (ActionT m) Source # | `empty` throws `ActionError` `AENext`, whereas `(<|>)` catches any `ActionError`s or `StatusError`s in the first action and proceeds to the second one.
Instance details Defined in Web.Scotty.Internal.Types Methods empty :: ActionT m a Source # (<|>) :: ActionT m a -> ActionT m a -> ActionT m a Source # some :: ActionT m a -> ActionT m [a] Source # many :: ActionT m a -> ActionT m [a] Source #
Applicative m => Applicative (ActionT m) Source # |
Instance details Defined in Web.Scotty.Internal.Types Methods pure :: a -> ActionT m a Source # (<*>) :: ActionT m (a -> b) -> ActionT m a -> ActionT m b Source # liftA2 :: (a -> b -> c) -> ActionT m a -> ActionT m b -> ActionT m c Source # (*>) :: ActionT m a -> ActionT m b -> ActionT m b Source # (<*) :: ActionT m a -> ActionT m b -> ActionT m a Source #
Functor m => Functor (ActionT m) Source # |
Instance details Defined in Web.Scotty.Internal.Types Methods fmap :: (a -> b) -> ActionT m a -> ActionT m b Source # (<$) :: a -> ActionT m b -> ActionT m a Source #
Monad m => Monad (ActionT m) Source # |
Instance details Defined in Web.Scotty.Internal.Types Methods (>>=) :: ActionT m a -> (a -> ActionT m b) -> ActionT m b Source # (>>) :: ActionT m a -> ActionT m b -> ActionT m b Source # return :: a -> ActionT m a Source #
MonadUnliftIO m => MonadPlus (ActionT m) Source # |
Instance details Defined in Web.Scotty.Internal.Types Methods mzero :: ActionT m a Source # mplus :: ActionT m a -> ActionT m a -> ActionT m a Source #
MonadCatch m => MonadCatch (ActionT m) Source # |
Instance details Defined in Web.Scotty.Internal.Types Methods catch :: (HasCallStack, Exception e) => ActionT m a -> (e -> ActionT m a) -> ActionT m a Source #
MonadThrow m => MonadThrow (ActionT m) Source # |
Instance details Defined in Web.Scotty.Internal.Types Methods throwM :: (HasCallStack, Exception e) => e -> ActionT m a Source #
MonadUnliftIO m => MonadUnliftIO (ActionT m) Source # |
Instance details Defined in Web.Scotty.Internal.Types Methods withRunInIO :: ((forall a. ActionT m a -> IO a) -> IO b) -> ActionT m b
(Monad m, Monoid a) => Monoid (ActionT m a) Source # |
Instance details Defined in Web.Scotty.Internal.Types Methods mempty :: ActionT m a Source # mappend :: ActionT m a -> ActionT m a -> ActionT m a Source # mconcat :: [ActionT m a] -> ActionT m a Source #
(Monad m, Semigroup a) => Semigroup (ActionT m a) Source # |
Instance details Defined in Web.Scotty.Internal.Types Methods (<>) :: ActionT m a -> ActionT m a -> ActionT m a Source # sconcat :: NonEmpty (ActionT m a) -> ActionT m a Source # stimes :: Integral b => b -> ActionT m a -> ActionT m a Source #
type StT ActionT a Source # |
Instance details Defined in Web.Scotty.Internal.Types type StT ActionT a = StT (ReaderT ActionEnv) a
type StM (ActionT m) a Source # |
Instance details Defined in Web.Scotty.Internal.Types type StM (ActionT m) a = StM (ReaderT ActionEnv m) a

tryAnyStatus :: MonadUnliftIO m => m a -> m Bool Source #

catches either ActionError (thrown by `next`) or `StatusError` (thrown if e.g. a query parameter is not found)

data RoutePattern Source #

Constructors

Capture Text |
Literal Text |
Function (Request -> Maybe [Param]) |

#### Instances

Instances details

IsString RoutePattern Source # |
Instance details Defined in Web.Scotty.Internal.Types Methods fromString :: String -> RoutePattern Source #