scotty 0.8.2 → 0.9.0
raw patch · 6 files changed
+32/−55 lines, 6 filesdep +hspec-waidep +hspec2dep −conduitdep −hspecdep ~textdep ~wai-extra
Dependencies added: hspec-wai, hspec2
Dependencies removed: conduit, hspec
Dependency ranges changed: text, wai-extra
Files
- Web/Scotty.hs +4/−15
- Web/Scotty/Action.hs +7/−20
- Web/Scotty/Internal/Types.hs +1/−1
- Web/Scotty/Trans.hs +6/−15
- changelog.md +10/−0
- scotty.cabal +4/−4
Web/Scotty.hs view
@@ -24,7 +24,7 @@ -- -- | Note: only one of these should be present in any given route -- definition, as they completely replace the current 'Response' body.- , text, html, file, json, stream, source, raw+ , text, html, file, json, stream, raw -- ** Exceptions , raise, rescue, next, defaultHandler -- * Parsing Parameters@@ -35,14 +35,10 @@ -- With the exception of this, everything else better just import types. import qualified Web.Scotty.Trans as Trans-import qualified Web.Scotty.Action as Action -- for 'source', to avoid deprecation warning on Trans.source -import Blaze.ByteString.Builder (Builder)- import Data.Aeson (FromJSON, ToJSON) import Data.ByteString.Lazy.Char8 (ByteString) import Data.Text.Lazy (Text)-import Data.Conduit (Flush, Source) import Network.HTTP.Types (Status, StdMethod) import Network.Wai (Application, Middleware, Request, StreamingBody)@@ -175,12 +171,12 @@ setHeader = Trans.setHeader -- | Set the body of the response to the given 'Text' value. Also sets \"Content-Type\"--- header to \"text/plain\".+-- header to \"text/plain; charset=utf-8\". text :: Text -> ActionM () text = Trans.text -- | Set the body of the response to the given 'Text' value. Also sets \"Content-Type\"--- header to \"text/html\".+-- header to \"text/html; charset=utf-8\". html :: Text -> ActionM () html = Trans.html @@ -190,7 +186,7 @@ file = Trans.file -- | Set the body of the response to the JSON encoding of the given value. Also sets \"Content-Type\"--- header to \"application/json\".+-- header to \"application/json; charset=utf-8\". json :: ToJSON a => a -> ActionM () json = Trans.json @@ -199,13 +195,6 @@ -- own with 'setHeader'. stream :: StreamingBody -> ActionM () stream = Trans.stream---- | Set the body of the response to a Source. Doesn't set the--- \"Content-Type\" header, so you probably want to do that on your--- own with 'setHeader'.-source :: Source IO (Flush Builder) -> ActionM ()-source = Action.source-{-# DEPRECATED source "Use 'stream' instead. This will be removed in the next release." #-} -- | Set the body of the response to the given 'BL.ByteString' value. Doesn't set the -- \"Content-Type\" header, so you probably want to do that on your own with 'setHeader'.
Web/Scotty/Action.hs view
@@ -21,7 +21,6 @@ , setHeader , status , stream- , source -- Deprecated , text , Param , Parsable(..)@@ -29,7 +28,7 @@ , runAction ) where -import Blaze.ByteString.Builder (Builder, fromLazyByteString)+import Blaze.ByteString.Builder (fromLazyByteString) #if MIN_VERSION_mtl(2,2,1) import Control.Monad.Except@@ -43,8 +42,6 @@ import qualified Data.ByteString.Char8 as B import qualified Data.ByteString.Lazy.Char8 as BL import qualified Data.CaseInsensitive as CI-import Data.Conduit-import qualified Data.Conduit.List as CL import Data.Default (def) import Data.Monoid (mconcat) import qualified Data.Text as ST@@ -238,17 +235,17 @@ setHeader k v = ActionT . MS.modify $ setHeaderWith $ replace (CI.mk $ lazyTextToStrictByteString k) (lazyTextToStrictByteString v) -- | Set the body of the response to the given 'T.Text' value. Also sets \"Content-Type\"--- header to \"text/plain\".+-- header to \"text/plain; charset=utf-8\". text :: (ScottyError e, Monad m) => T.Text -> ActionT e m () text t = do- setHeader "Content-Type" "text/plain"+ setHeader "Content-Type" "text/plain; charset=utf-8" raw $ encodeUtf8 t -- | Set the body of the response to the given 'T.Text' value. Also sets \"Content-Type\"--- header to \"text/html\".+-- header to \"text/html; charset=utf-8\". html :: (ScottyError e, Monad m) => T.Text -> ActionT e m () html t = do- setHeader "Content-Type" "text/html"+ setHeader "Content-Type" "text/html; charset=utf-8" raw $ encodeUtf8 t -- | Send a file as the response. Doesn't set the \"Content-Type\" header, so you probably@@ -257,10 +254,10 @@ file = ActionT . MS.modify . setContent . ContentFile -- | Set the body of the response to the JSON encoding of the given value. Also sets \"Content-Type\"--- header to \"application/json\".+-- header to \"application/json; charset=utf-8\". json :: (A.ToJSON a, ScottyError e, Monad m) => a -> ActionT e m () json v = do- setHeader "Content-Type" "application/json"+ setHeader "Content-Type" "application/json; charset=utf-8" raw $ A.encode v -- | Set the body of the response to a Source. Doesn't set the@@ -268,16 +265,6 @@ -- own with 'setHeader'. stream :: (ScottyError e, Monad m) => StreamingBody -> ActionT e m () stream = ActionT . MS.modify . setContent . ContentStream---- | Set the body of the response to a Source. Doesn't set the--- \"Content-Type\" header, so you probably want to do that on your--- own with 'setHeader'.-source :: (ScottyError e, Monad m) => Source IO (Flush Builder) -> ActionT e m ()-source src = stream $ \send flush -> src $$ CL.mapM_ (\mbuilder ->- case mbuilder of- Chunk b -> send b- Flush -> flush)--- Deprecated, but pragma is in Web.Scotty and Web.Scotty.Trans -- | Set the body of the response to the given 'BL.ByteString' value. Doesn't set the -- \"Content-Type\" header, so you probably want to do that on your
Web/Scotty/Internal/Types.hs view
@@ -148,7 +148,7 @@ liftBase = liftBaseDefault -instance (ScottyError e) => MonadTransControl (ActionT e) where+instance ScottyError e => MonadTransControl (ActionT e) where #if MIN_VERSION_mtl(2,2,1) newtype StT (ActionT e) a = StAction {unStAction :: StT (StateT ScottyResponse) (StT (ReaderT ActionEnv) (StT (ExceptT (ActionError e)) a))} #else
Web/Scotty/Trans.hs view
@@ -28,7 +28,7 @@ -- -- | Note: only one of these should be present in any given route -- definition, as they completely replace the current 'Response' body.- , text, html, file, json, stream, source, raw+ , text, html, file, json, stream, raw -- ** Exceptions , raise, rescue, next, defaultHandler, ScottyError(..) -- * Parsing Parameters@@ -39,32 +39,23 @@ , ScottyT, ActionT ) where -import Blaze.ByteString.Builder (Builder, fromByteString)+import Blaze.ByteString.Builder (fromByteString) import Control.Monad (when) import Control.Monad.State (execStateT, modify) import Control.Monad.IO.Class -import Data.Conduit (Flush, Source) import Data.Default (def) -import Network.HTTP.Types (status404)+import Network.HTTP.Types (status404, status500) import Network.Wai import Network.Wai.Handler.Warp (Port, runSettings, setPort, getPort) -import Web.Scotty.Action hiding (source)-import qualified Web.Scotty.Action as Action+import Web.Scotty.Action import Web.Scotty.Route import Web.Scotty.Internal.Types hiding (Application, Middleware) import qualified Web.Scotty.Internal.Types as Scotty --- | Set the body of the response to a Source. Doesn't set the--- \"Content-Type\" header, so you probably want to do that on your--- own with 'setHeader'.-source :: (ScottyError e, Monad m) => Source IO (Flush Builder) -> ActionT e m ()-source = Action.source-{-# DEPRECATED source "Use 'stream' instead. This will be removed in the next release." #-}- -- | Run a scotty application using the warp server. -- NB: scotty p === scottyT p id id scottyT :: (Monad m, MonadIO n)@@ -114,8 +105,8 @@ -- This has security implications, so you probably want to provide your -- own defaultHandler in production which does not send out the error -- strings as 500 responses.-defaultHandler :: Monad m => (e -> ActionT e m ()) -> ScottyT e m ()-defaultHandler f = ScottyT $ modify $ addHandler $ Just f+defaultHandler :: (ScottyError e, Monad m) => (e -> ActionT e m ()) -> ScottyT e m ()+defaultHandler f = ScottyT $ modify $ addHandler $ Just (\e -> status status500 >> f e) -- | Use given middleware. Middleware is nested such that the first declared -- is the outermost middleware (it has first dibs on the request and last action
changelog.md view
@@ -1,3 +1,13 @@+## 0.9.0++* Add `charset=utf-8` to `Content-Type` for `text`, `html` and `json`++* Assume HTTP status 500 for `defaultHandler`++* Remove deprecated `source` method.++* No longer depend on conduit.+ ## 0.8.2 * Bump `aeson` upper bound
scotty.cabal view
@@ -1,5 +1,5 @@ Name: scotty-Version: 0.8.2+Version: 0.9.0 Synopsis: Haskell web framework inspired by Ruby's Sinatra, using WAI and Warp Homepage: https://github.com/scotty-web/scotty Bug-reports: https://github.com/scotty-web/scotty/issues@@ -73,7 +73,6 @@ blaze-builder >= 0.3.3.0 && < 0.4, bytestring >= 0.10.0.2 && < 0.11, case-insensitive >= 1.0.0.1 && < 1.3,- conduit >= 1.1 && < 1.2, data-default >= 0.5.3 && < 0.6, http-types >= 0.8.2 && < 0.9, mtl >= 2.1.2 && < 2.3,@@ -95,11 +94,12 @@ hs-source-dirs: test build-depends: base, bytestring,+ text, http-types, lifted-base, wai,- hspec >= 1.9.2,- wai-extra >= 3.0.0,+ hspec2,+ hspec-wai >= 0.3.0, scotty GHC-options: -Wall -fno-warn-orphans