From 85ed0b20c9dbbb88ffd2e45d59dc19a1c52c3375 Mon Sep 17 00:00:00 2001 From: Tushar Adhatrao <40828350+tusharad@users.noreply.github.com> Date: Sat, 20 Apr 2024 20:45:25 +0530 Subject: [PATCH] Exposed simple cookie functions via Main interface. (#395) * Exposed simple cookie functions via Web.scotty & Trans * Added Explicit export list * Changed cookies example as per new API --- Web/Scotty.hs | 3 +++ Web/Scotty/Trans.hs | 3 +++ changelog.md | 1 + examples/cookies.hs | 8 ++++---- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Web/Scotty.hs b/Web/Scotty.hs index a58f5f8c..414eb3fd 100644 --- a/Web/Scotty.hs +++ b/Web/Scotty.hs @@ -52,6 +52,8 @@ module Web.Scotty -- * Types , ScottyM, ActionM, RoutePattern, File, Content(..), Kilobytes, ErrorHandler, Handler(..) , ScottyState, defaultScottyState + -- ** Functions from Cookie module + , setSimpleCookie,getCookie,getCookies,deleteCookie,makeSimpleCookie ) where import qualified Web.Scotty.Trans as Trans @@ -71,6 +73,7 @@ import qualified Network.Wai.Parse as W import Web.Scotty.Internal.Types (ScottyT, ActionT, ErrorHandler, Param, RoutePattern, Options, defaultOptions, File, Kilobytes, ScottyState, defaultScottyState, ScottyException, StatusError(..), Content(..)) import UnliftIO.Exception (Handler(..), catch) +import Web.Scotty.Cookie (setSimpleCookie,getCookie,getCookies,deleteCookie,makeSimpleCookie) {- $setup >>> :{ diff --git a/Web/Scotty/Trans.hs b/Web/Scotty/Trans.hs index 2320735e..8188c0bc 100644 --- a/Web/Scotty/Trans.hs +++ b/Web/Scotty/Trans.hs @@ -60,6 +60,8 @@ module Web.Scotty.Trans -- * Monad Transformers , ScottyT, ActionT , ScottyState, defaultScottyState + -- ** Functions from Cookie module + , setSimpleCookie,getCookie,getCookies,deleteCookie,makeSimpleCookie ) where import Blaze.ByteString.Builder (fromByteString) @@ -84,6 +86,7 @@ import Web.Scotty.Util (socketDescription) import Web.Scotty.Body (newBodyInfo) import UnliftIO.Exception (Handler(..), catch) +import Web.Scotty.Cookie (setSimpleCookie,getCookie,getCookies,deleteCookie,makeSimpleCookie) -- | Run a scotty application using the warp server. diff --git a/changelog.md b/changelog.md index e9440461..409c788a 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,7 @@ ## next [????.??.??] * Fixed cookie example from `Cookie` module documentation. `getCookie` Function would return strict variant of `Text`. Will convert it into lazy variant using `fromStrict`. +* Exposed simple functions of `Cookie` module via `Web.Scotty` & `Web.Scotty.Trans`. ### Breaking changes * Remove dependency on data-default class (#386). We have been exporting constants for default config values since 0.20, and this dependency was simply unnecessary. diff --git a/examples/cookies.hs b/examples/cookies.hs index 7820c87b..a6d19dfe 100644 --- a/examples/cookies.hs +++ b/examples/cookies.hs @@ -5,10 +5,10 @@ module Main (main) where import Control.Monad (forM_) import qualified Text.Blaze.Html5 as H -import Text.Blaze.Html5.Attributes -import Text.Blaze.Html.Renderer.Text (renderHtml) -import Web.Scotty -import Web.Scotty.Cookie (CookiesText, setSimpleCookie, getCookies) +import Text.Blaze.Html5.Attributes +import Text.Blaze.Html.Renderer.Text (renderHtml) +import Web.Scotty -- Web.Scotty exports setSimpleCookie,getCookies +import Web.Scotty.Cookie (CookiesText) renderCookiesTable :: CookiesText -> H.Html renderCookiesTable cs =