From fdd70a75d8c415e088dd12e4e1776c50b7c76041 Mon Sep 17 00:00:00 2001 From: Marco Zocca Date: Mon, 2 Oct 2023 11:05:36 +0200 Subject: [PATCH] keep data-default-class --- Web/Scotty/Internal/Types.hs | 14 +++++++++++++- changelog.md | 1 - scotty.cabal | 1 + 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Web/Scotty/Internal/Types.hs b/Web/Scotty/Internal/Types.hs index 49fd52f6..2e4b9c5d 100644 --- a/Web/Scotty/Internal/Types.hs +++ b/Web/Scotty/Internal/Types.hs @@ -37,7 +37,7 @@ import Control.Monad.Trans.Except import qualified Data.ByteString as BS import qualified Data.ByteString.Lazy.Char8 as LBS8 (ByteString) --- import Data.Default.Class (Default, def) +import Data.Default.Class (Default, def) import Data.String (IsString(..)) import Data.Text.Lazy (Text, pack) import Data.Typeable (Typeable) @@ -65,12 +65,18 @@ data Options = Options { verbose :: Int -- ^ 0 = silent, 1(def) = startup banner -- servers using `setFdCacheDuration`. } +instance Default Options where + def = defaultOptions + defaultOptions :: Options defaultOptions = Options 1 defaultSettings newtype RouteOptions = RouteOptions { maxRequestBodySize :: Maybe Kilobytes -- max allowed request size in KB } +instance Default RouteOptions where + def = defaultRouteOptions + defaultRouteOptions :: RouteOptions defaultRouteOptions = RouteOptions Nothing @@ -101,6 +107,9 @@ data ScottyState m = , routeOptions :: RouteOptions } +instance Default (ScottyState m) where + def = defaultScottyState + defaultScottyState :: ScottyState m defaultScottyState = ScottyState [] [] Nothing defaultRouteOptions @@ -197,6 +206,9 @@ setHeaderWith f sr = sr { srHeaders = f (srHeaders sr) } setStatus :: Status -> ScottyResponse -> ScottyResponse setStatus s sr = sr { srStatus = s } +instance Default ScottyResponse where + def = defaultScottyResponse + -- | The default response has code 200 OK and empty body defaultScottyResponse :: ScottyResponse defaultScottyResponse = SR status200 [] (ContentBuilder mempty) diff --git a/changelog.md b/changelog.md index f9ae752f..f5c9e79c 100644 --- a/changelog.md +++ b/changelog.md @@ -14,7 +14,6 @@ Breaking: * (#310) Introduce `unliftio-core` as a dependency, and base exception handling on methods copied from `unliftio` e.g. `catch`. * (#310) Clarify the exception handling mechanism of ActionT, ScottyT. `raise` and `rescue` change signature to use proper `Exception` types rather than strings. * (#310) All ActionT methods (`text`, `html` etc.) have now a MonadIO constraint on the base monad rather than Monad because the response is in a TVar inside ActionEnv. `rescue` has a MonadUnliftIO constraint. The Alternative instance of ActionT also is based on MonadUnliftIO because `<|>` is implemented in terms of `catch`. -* Get rid of data-default-class (#316) ## 0.12.1 [2022.11.17] * Fix CPP bug that prevented tests from building on Windows. diff --git a/scotty.cabal b/scotty.cabal index f90e2d36..79751fd1 100644 --- a/scotty.cabal +++ b/scotty.cabal @@ -77,6 +77,7 @@ Library bytestring >= 0.10.0.2 && < 0.12, case-insensitive >= 1.0.0.1 && < 1.3, cookie >= 0.4, + data-default-class >= 0.1, exceptions >= 0.7 && < 0.11, http-types >= 0.9.1 && < 0.13, monad-control >= 1.0.0.3 && < 1.1,