Remove all conditional compilation for Yesod 1.4 release
Left in for GHC-bundled libraries (ghc, base, bytestring, binary)
This commit is contained in:
parent
598e570913
commit
ccab062f2d
@ -1,4 +1,3 @@
|
|||||||
./yesod-routes
|
|
||||||
./yesod-core
|
./yesod-core
|
||||||
./yesod-static
|
./yesod-static
|
||||||
./yesod-persistent
|
./yesod-persistent
|
||||||
|
|||||||
@ -161,7 +161,6 @@ class (Yesod master, PathPiece (AuthId master), RenderMessage master FormMessage
|
|||||||
-- Since 1.2.0
|
-- Since 1.2.0
|
||||||
maybeAuthId :: HandlerT master IO (Maybe (AuthId master))
|
maybeAuthId :: HandlerT master IO (Maybe (AuthId master))
|
||||||
|
|
||||||
#if MIN_VERSION_persistent(2, 0, 0)
|
|
||||||
default maybeAuthId
|
default maybeAuthId
|
||||||
:: ( YesodAuth master
|
:: ( YesodAuth master
|
||||||
, PersistEntityBackend val ~ YesodPersistBackend master
|
, PersistEntityBackend val ~ YesodPersistBackend master
|
||||||
@ -172,19 +171,6 @@ class (Yesod master, PathPiece (AuthId master), RenderMessage master FormMessage
|
|||||||
, Typeable val
|
, Typeable val
|
||||||
)
|
)
|
||||||
=> HandlerT master IO (Maybe (AuthId master))
|
=> HandlerT master IO (Maybe (AuthId master))
|
||||||
#else
|
|
||||||
default maybeAuthId
|
|
||||||
:: ( YesodAuth master
|
|
||||||
, PersistMonadBackend (b (HandlerT master IO)) ~ PersistEntityBackend val
|
|
||||||
, b ~ YesodPersistBackend master
|
|
||||||
, Key val ~ AuthId master
|
|
||||||
, PersistStore (b (HandlerT master IO))
|
|
||||||
, PersistEntity val
|
|
||||||
, YesodPersist master
|
|
||||||
, Typeable val
|
|
||||||
)
|
|
||||||
=> HandlerT master IO (Maybe (AuthId master))
|
|
||||||
#endif
|
|
||||||
maybeAuthId = defaultMaybeAuthId
|
maybeAuthId = defaultMaybeAuthId
|
||||||
|
|
||||||
-- | Called on login error for HTTP requests. By default, calls
|
-- | Called on login error for HTTP requests. By default, calls
|
||||||
@ -206,7 +192,6 @@ credsKey = "_ID"
|
|||||||
-- 'maybeAuthIdRaw' for more information.
|
-- 'maybeAuthIdRaw' for more information.
|
||||||
--
|
--
|
||||||
-- Since 1.1.2
|
-- Since 1.1.2
|
||||||
#if MIN_VERSION_persistent(2, 0, 0)
|
|
||||||
defaultMaybeAuthId
|
defaultMaybeAuthId
|
||||||
:: ( YesodAuth master
|
:: ( YesodAuth master
|
||||||
, b ~ YesodPersistBackend master
|
, b ~ YesodPersistBackend master
|
||||||
@ -217,18 +202,6 @@ defaultMaybeAuthId
|
|||||||
, YesodPersist master
|
, YesodPersist master
|
||||||
, Typeable val
|
, Typeable val
|
||||||
) => HandlerT master IO (Maybe (AuthId master))
|
) => HandlerT master IO (Maybe (AuthId master))
|
||||||
#else
|
|
||||||
defaultMaybeAuthId
|
|
||||||
:: ( YesodAuth master
|
|
||||||
, PersistMonadBackend (b (HandlerT master IO)) ~ PersistEntityBackend val
|
|
||||||
, b ~ YesodPersistBackend master
|
|
||||||
, Key val ~ AuthId master
|
|
||||||
, PersistStore (b (HandlerT master IO))
|
|
||||||
, PersistEntity val
|
|
||||||
, YesodPersist master
|
|
||||||
, Typeable val
|
|
||||||
) => HandlerT master IO (Maybe (AuthId master))
|
|
||||||
#endif
|
|
||||||
defaultMaybeAuthId = do
|
defaultMaybeAuthId = do
|
||||||
ms <- lookupSession credsKey
|
ms <- lookupSession credsKey
|
||||||
case ms of
|
case ms of
|
||||||
@ -238,7 +211,6 @@ defaultMaybeAuthId = do
|
|||||||
Nothing -> return Nothing
|
Nothing -> return Nothing
|
||||||
Just aid -> fmap (fmap entityKey) $ cachedAuth aid
|
Just aid -> fmap (fmap entityKey) $ cachedAuth aid
|
||||||
|
|
||||||
#if MIN_VERSION_persistent(2, 0, 0)
|
|
||||||
cachedAuth :: ( YesodAuth master
|
cachedAuth :: ( YesodAuth master
|
||||||
, b ~ YesodPersistBackend master
|
, b ~ YesodPersistBackend master
|
||||||
, b ~ PersistEntityBackend val
|
, b ~ PersistEntityBackend val
|
||||||
@ -248,17 +220,6 @@ cachedAuth :: ( YesodAuth master
|
|||||||
, YesodPersist master
|
, YesodPersist master
|
||||||
, Typeable val
|
, Typeable val
|
||||||
) => AuthId master -> HandlerT master IO (Maybe (Entity val))
|
) => AuthId master -> HandlerT master IO (Maybe (Entity val))
|
||||||
#else
|
|
||||||
cachedAuth :: ( YesodAuth master
|
|
||||||
, PersistMonadBackend (b (HandlerT master IO)) ~ PersistEntityBackend val
|
|
||||||
, b ~ YesodPersistBackend master
|
|
||||||
, Key val ~ AuthId master
|
|
||||||
, PersistStore (b (HandlerT master IO))
|
|
||||||
, PersistEntity val
|
|
||||||
, YesodPersist master
|
|
||||||
, Typeable val
|
|
||||||
) => AuthId master -> HandlerT master IO (Maybe (Entity val))
|
|
||||||
#endif
|
|
||||||
cachedAuth aid = runMaybeT $ do
|
cachedAuth aid = runMaybeT $ do
|
||||||
a <- MaybeT $ fmap unCachedMaybeAuth
|
a <- MaybeT $ fmap unCachedMaybeAuth
|
||||||
$ cached
|
$ cached
|
||||||
@ -411,7 +372,6 @@ handlePluginR plugin pieces = do
|
|||||||
-- assumes that you are using a Persistent database.
|
-- assumes that you are using a Persistent database.
|
||||||
--
|
--
|
||||||
-- Since 1.1.0
|
-- Since 1.1.0
|
||||||
#if MIN_VERSION_persistent(2, 0, 0)
|
|
||||||
maybeAuth :: ( YesodAuth master
|
maybeAuth :: ( YesodAuth master
|
||||||
, b ~ YesodPersistBackend master
|
, b ~ YesodPersistBackend master
|
||||||
, b ~ PersistEntityBackend val
|
, b ~ PersistEntityBackend val
|
||||||
@ -421,17 +381,6 @@ maybeAuth :: ( YesodAuth master
|
|||||||
, YesodPersist master
|
, YesodPersist master
|
||||||
, Typeable val
|
, Typeable val
|
||||||
) => HandlerT master IO (Maybe (Entity val))
|
) => HandlerT master IO (Maybe (Entity val))
|
||||||
#else
|
|
||||||
maybeAuth :: ( YesodAuth master
|
|
||||||
, PersistMonadBackend (b (HandlerT master IO)) ~ PersistEntityBackend val
|
|
||||||
, b ~ YesodPersistBackend master
|
|
||||||
, Key val ~ AuthId master
|
|
||||||
, PersistStore (b (HandlerT master IO))
|
|
||||||
, PersistEntity val
|
|
||||||
, YesodPersist master
|
|
||||||
, Typeable val
|
|
||||||
) => HandlerT master IO (Maybe (Entity val))
|
|
||||||
#endif
|
|
||||||
maybeAuth = runMaybeT $ do
|
maybeAuth = runMaybeT $ do
|
||||||
aid <- MaybeT maybeAuthId
|
aid <- MaybeT maybeAuthId
|
||||||
MaybeT $ cachedAuth aid
|
MaybeT $ cachedAuth aid
|
||||||
@ -445,7 +394,6 @@ newtype CachedMaybeAuth val = CachedMaybeAuth { unCachedMaybeAuth :: Maybe val }
|
|||||||
-- full informatin on a given user.
|
-- full informatin on a given user.
|
||||||
--
|
--
|
||||||
-- Since 1.2.0
|
-- Since 1.2.0
|
||||||
#if MIN_VERSION_persistent(2, 0, 0)
|
|
||||||
type YesodAuthPersist master =
|
type YesodAuthPersist master =
|
||||||
( YesodAuth master
|
( YesodAuth master
|
||||||
, YesodPersistBackend master
|
, YesodPersistBackend master
|
||||||
@ -456,18 +404,6 @@ type YesodAuthPersist master =
|
|||||||
, YesodPersist master
|
, YesodPersist master
|
||||||
, Typeable (AuthEntity master)
|
, Typeable (AuthEntity master)
|
||||||
)
|
)
|
||||||
#else
|
|
||||||
type YesodAuthPersist master =
|
|
||||||
( YesodAuth master
|
|
||||||
, PersistMonadBackend (YesodPersistBackend master (HandlerT master IO))
|
|
||||||
~ PersistEntityBackend (AuthEntity master)
|
|
||||||
, Key (AuthEntity master) ~ AuthId master
|
|
||||||
, PersistStore (YesodPersistBackend master (HandlerT master IO))
|
|
||||||
, PersistEntity (AuthEntity master)
|
|
||||||
, YesodPersist master
|
|
||||||
, Typeable (AuthEntity master)
|
|
||||||
)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
-- | If the @AuthId@ for a given site is a persistent ID, this will give the
|
-- | If the @AuthId@ for a given site is a persistent ID, this will give the
|
||||||
-- value for that entity. E.g.:
|
-- value for that entity. E.g.:
|
||||||
@ -477,10 +413,8 @@ type YesodAuthPersist master =
|
|||||||
--
|
--
|
||||||
-- Since 1.2.0
|
-- Since 1.2.0
|
||||||
type AuthEntity master = KeyEntity (AuthId master)
|
type AuthEntity master = KeyEntity (AuthId master)
|
||||||
#if MIN_VERSION_persistent(2, 0, 0)
|
|
||||||
type family KeyEntity key
|
type family KeyEntity key
|
||||||
type instance KeyEntity (Key x) = x
|
type instance KeyEntity (Key x) = x
|
||||||
#endif
|
|
||||||
|
|
||||||
-- | Similar to 'maybeAuthId', but redirects to a login page if user is not
|
-- | Similar to 'maybeAuthId', but redirects to a login page if user is not
|
||||||
-- authenticated or responds with error 401 if this is an API client (expecting JSON).
|
-- authenticated or responds with error 401 if this is an API client (expecting JSON).
|
||||||
|
|||||||
@ -66,17 +66,11 @@ import GhcBuild (buildPackage,
|
|||||||
import qualified Config as GHC
|
import qualified Config as GHC
|
||||||
import Data.Streaming.Network (bindPortTCP)
|
import Data.Streaming.Network (bindPortTCP)
|
||||||
import Network (withSocketsDo)
|
import Network (withSocketsDo)
|
||||||
#if MIN_VERSION_http_conduit(2, 0, 0)
|
|
||||||
import Network.HTTP.Conduit (conduitManagerSettings, newManager)
|
import Network.HTTP.Conduit (conduitManagerSettings, newManager)
|
||||||
import Data.Default.Class (def)
|
import Data.Default.Class (def)
|
||||||
#else
|
|
||||||
import Network.HTTP.Conduit (def, newManager)
|
|
||||||
#endif
|
|
||||||
import Network.HTTP.ReverseProxy (ProxyDest (ProxyDest),
|
import Network.HTTP.ReverseProxy (ProxyDest (ProxyDest),
|
||||||
waiProxyToSettings, wpsTimeout, wpsOnExc)
|
waiProxyToSettings, wpsTimeout, wpsOnExc)
|
||||||
#if MIN_VERSION_http_reverse_proxy(0, 2, 0)
|
|
||||||
import qualified Network.HTTP.ReverseProxy as ReverseProxy
|
import qualified Network.HTTP.ReverseProxy as ReverseProxy
|
||||||
#endif
|
|
||||||
import Network.HTTP.Types (status200, status503)
|
import Network.HTTP.Types (status200, status503)
|
||||||
import Network.Socket (sClose)
|
import Network.Socket (sClose)
|
||||||
import Network.Wai (responseLBS, requestHeaders)
|
import Network.Wai (responseLBS, requestHeaders)
|
||||||
@ -130,11 +124,7 @@ cabalProgram opts | isCabalDev opts = "cabal-dev"
|
|||||||
-- 3001, give an appropriate message to the user.
|
-- 3001, give an appropriate message to the user.
|
||||||
reverseProxy :: DevelOpts -> I.IORef Int -> IO ()
|
reverseProxy :: DevelOpts -> I.IORef Int -> IO ()
|
||||||
reverseProxy opts iappPort = do
|
reverseProxy opts iappPort = do
|
||||||
#if MIN_VERSION_http_conduit(2, 0, 0)
|
|
||||||
manager <- newManager conduitManagerSettings
|
manager <- newManager conduitManagerSettings
|
||||||
#else
|
|
||||||
manager <- newManager def
|
|
||||||
#endif
|
|
||||||
let refreshHtml = LB.fromChunks $ return $(embedFile "refreshing.html")
|
let refreshHtml = LB.fromChunks $ return $(embedFile "refreshing.html")
|
||||||
let onExc _ req
|
let onExc _ req
|
||||||
| maybe False (("application/json" `elem`) . parseHttpAccept)
|
| maybe False (("application/json" `elem`) . parseHttpAccept)
|
||||||
@ -154,18 +144,10 @@ reverseProxy opts iappPort = do
|
|||||||
(const $ do
|
(const $ do
|
||||||
appPort <- liftIO $ I.readIORef iappPort
|
appPort <- liftIO $ I.readIORef iappPort
|
||||||
return $
|
return $
|
||||||
#if MIN_VERSION_http_reverse_proxy(0, 2, 0)
|
|
||||||
ReverseProxy.WPRProxyDest
|
ReverseProxy.WPRProxyDest
|
||||||
#else
|
|
||||||
Right
|
|
||||||
#endif
|
|
||||||
$ ProxyDest "127.0.0.1" appPort)
|
$ ProxyDest "127.0.0.1" appPort)
|
||||||
def
|
def
|
||||||
#if MIN_VERSION_wai(3, 0, 0)
|
|
||||||
{ wpsOnExc = \e req f -> onExc e req >>= f
|
{ wpsOnExc = \e req f -> onExc e req >>= f
|
||||||
#else
|
|
||||||
{ wpsOnExc = onExc
|
|
||||||
#endif
|
|
||||||
, wpsTimeout =
|
, wpsTimeout =
|
||||||
if proxyTimeout opts == 0
|
if proxyTimeout opts == 0
|
||||||
then Nothing
|
then Nothing
|
||||||
|
|||||||
@ -76,15 +76,9 @@ injectDefaultP env path p@(OptP o)
|
|||||||
p <|> if any ((==Just "1") . getEnvValue env path) names then pure a else empty
|
p <|> if any ((==Just "1") . getEnvValue env path) names then pure a else empty
|
||||||
| otherwise = p
|
| otherwise = p
|
||||||
where
|
where
|
||||||
#if MIN_VERSION_optparse_applicative(0,6,0)
|
|
||||||
right= ReadM . Right
|
right= ReadM . Right
|
||||||
left = ReadM . Left
|
left = ReadM . Left
|
||||||
either' f g (ReadM x) = either f g x
|
either' f g (ReadM x) = either f g x
|
||||||
#else
|
|
||||||
right = Right
|
|
||||||
left = Left
|
|
||||||
either' = either
|
|
||||||
#endif
|
|
||||||
injectDefaultP env path (MultP p1 p2) =
|
injectDefaultP env path (MultP p1 p2) =
|
||||||
MultP (injectDefaultP env path p1) (injectDefaultP env path p2)
|
MultP (injectDefaultP env path p1) (injectDefaultP env path p2)
|
||||||
injectDefaultP env path (AltP p1 p2) =
|
injectDefaultP env path (AltP p1 p2) =
|
||||||
|
|||||||
@ -15,11 +15,7 @@ import Options (injectDefaults)
|
|||||||
import qualified Paths_yesod_bin
|
import qualified Paths_yesod_bin
|
||||||
import Scaffolding.Scaffolder
|
import Scaffolding.Scaffolder
|
||||||
|
|
||||||
#if MIN_VERSION_optparse_applicative(0,6,0)
|
|
||||||
import Options.Applicative.Types (ReadM (ReadM))
|
import Options.Applicative.Types (ReadM (ReadM))
|
||||||
#else
|
|
||||||
import Options.Applicative.Builder.Internal (Mod, OptionFields)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
import HsFile (mkHsFile)
|
import HsFile (mkHsFile)
|
||||||
#ifndef WINDOWS
|
#ifndef WINDOWS
|
||||||
@ -155,12 +151,6 @@ keterOptions = Keter <$> switch ( long "nobuild" <> short 'n' <> help "Skip rebu
|
|||||||
defaultRescan :: Int
|
defaultRescan :: Int
|
||||||
defaultRescan = 10
|
defaultRescan = 10
|
||||||
|
|
||||||
#if MIN_VERSION_optparse_applicative(0,10,0)
|
|
||||||
option' = option auto
|
|
||||||
#else
|
|
||||||
option' = option
|
|
||||||
#endif
|
|
||||||
|
|
||||||
develOptions :: Parser Command
|
develOptions :: Parser Command
|
||||||
develOptions = Devel <$> switch ( long "disable-api" <> short 'd'
|
develOptions = Devel <$> switch ( long "disable-api" <> short 'd'
|
||||||
<> help "Disable fast GHC API rebuilding")
|
<> help "Disable fast GHC API rebuilding")
|
||||||
@ -168,7 +158,7 @@ develOptions = Devel <$> switch ( long "disable-api" <> short 'd'
|
|||||||
<> help "Run COMMAND after rebuild succeeds")
|
<> help "Run COMMAND after rebuild succeeds")
|
||||||
<*> optStr ( long "failure-hook" <> short 'f' <> metavar "COMMAND"
|
<*> optStr ( long "failure-hook" <> short 'f' <> metavar "COMMAND"
|
||||||
<> help "Run COMMAND when rebuild fails")
|
<> help "Run COMMAND when rebuild fails")
|
||||||
<*> option' ( long "event-timeout" <> short 't' <> value defaultRescan <> metavar "N"
|
<*> option auto ( long "event-timeout" <> short 't' <> value defaultRescan <> metavar "N"
|
||||||
<> help ("Force rescan of files every N seconds (default "
|
<> help ("Force rescan of files every N seconds (default "
|
||||||
++ show defaultRescan
|
++ show defaultRescan
|
||||||
++ ", use -1 to rely on FSNotify alone)") )
|
++ ", use -1 to rely on FSNotify alone)") )
|
||||||
@ -178,9 +168,9 @@ develOptions = Devel <$> switch ( long "disable-api" <> short 'd'
|
|||||||
<> help "ignore file changes in DIR" )
|
<> help "ignore file changes in DIR" )
|
||||||
)
|
)
|
||||||
<*> extraCabalArgs
|
<*> extraCabalArgs
|
||||||
<*> option' ( long "port" <> short 'p' <> value 3000 <> metavar "N"
|
<*> option auto ( long "port" <> short 'p' <> value 3000 <> metavar "N"
|
||||||
<> help "Devel server listening port" )
|
<> help "Devel server listening port" )
|
||||||
<*> option' ( long "proxy-timeout" <> short 'x' <> value 0 <> metavar "N"
|
<*> option auto ( long "proxy-timeout" <> short 'x' <> value 0 <> metavar "N"
|
||||||
<> help "Devel server timeout before returning 'not ready' message (in seconds, 0 for none)" )
|
<> help "Devel server timeout before returning 'not ready' message (in seconds, 0 for none)" )
|
||||||
<*> switch ( long "disable-reverse-proxy" <> short 'n'
|
<*> switch ( long "disable-reverse-proxy" <> short 'n'
|
||||||
<> help "Disable reverse proxy" )
|
<> help "Disable reverse proxy" )
|
||||||
@ -195,17 +185,9 @@ extraCabalArgs = many (strOption ( long "extra-cabal-arg" <> short 'e' <> metava
|
|||||||
-- | Optional @String@ argument
|
-- | Optional @String@ argument
|
||||||
optStr :: Mod OptionFields (Maybe String) -> Parser (Maybe String)
|
optStr :: Mod OptionFields (Maybe String) -> Parser (Maybe String)
|
||||||
optStr m =
|
optStr m =
|
||||||
#if MIN_VERSION_optparse_applicative(0,10,0)
|
|
||||||
nullOption (success . str) $ value Nothing <> m
|
nullOption (success . str) $ value Nothing <> m
|
||||||
#else
|
|
||||||
nullOption $ value Nothing <> reader (success . str) <> m
|
|
||||||
#endif
|
|
||||||
where
|
where
|
||||||
#if MIN_VERSION_optparse_applicative(0,6,0)
|
|
||||||
success = ReadM . Right
|
success = ReadM . Right
|
||||||
#else
|
|
||||||
success = Right
|
|
||||||
#endif
|
|
||||||
|
|
||||||
-- | Like @rawSystem@, but exits if it receives a non-success result.
|
-- | Like @rawSystem@, but exits if it receives a non-success result.
|
||||||
rawSystem' :: String -> [String] -> IO ()
|
rawSystem' :: String -> [String] -> IO ()
|
||||||
|
|||||||
@ -70,7 +70,7 @@ executable yesod
|
|||||||
, system-fileio >= 0.3 && < 0.4
|
, system-fileio >= 0.3 && < 0.4
|
||||||
, unordered-containers
|
, unordered-containers
|
||||||
, yaml >= 0.8 && < 0.9
|
, yaml >= 0.8 && < 0.9
|
||||||
, optparse-applicative >= 0.5
|
, optparse-applicative >= 0.10
|
||||||
, fsnotify >= 0.0 && < 0.2
|
, fsnotify >= 0.0 && < 0.2
|
||||||
, split >= 0.2 && < 0.3
|
, split >= 0.2 && < 0.3
|
||||||
, file-embed
|
, file-embed
|
||||||
@ -79,9 +79,9 @@ executable yesod
|
|||||||
, resourcet >= 0.3 && < 1.2
|
, resourcet >= 0.3 && < 1.2
|
||||||
, base64-bytestring
|
, base64-bytestring
|
||||||
, lifted-base
|
, lifted-base
|
||||||
, http-reverse-proxy >= 0.1.1
|
, http-reverse-proxy >= 0.4
|
||||||
, network
|
, network
|
||||||
, http-conduit
|
, http-conduit >= 2.1.4
|
||||||
, project-template >= 0.1.1
|
, project-template >= 0.1.1
|
||||||
, transformers
|
, transformers
|
||||||
, warp >= 1.3.7.5
|
, warp >= 1.3.7.5
|
||||||
|
|||||||
@ -61,9 +61,6 @@ GOX(Monoid w, RWST r w s)
|
|||||||
GOX(Monoid w, Strict.RWST r w s)
|
GOX(Monoid w, Strict.RWST r w s)
|
||||||
GO(Strict.StateT s)
|
GO(Strict.StateT s)
|
||||||
GOX(Monoid w, Strict.WriterT w)
|
GOX(Monoid w, Strict.WriterT w)
|
||||||
#if !MIN_VERSION_resourcet(1,1,0)
|
|
||||||
GO(ExceptionT)
|
|
||||||
#endif
|
|
||||||
GO(Pipe l i o u)
|
GO(Pipe l i o u)
|
||||||
GO(ConduitM i o)
|
GO(ConduitM i o)
|
||||||
#undef GO
|
#undef GO
|
||||||
@ -87,9 +84,6 @@ GOX(Monoid w, RWST r w s)
|
|||||||
GOX(Monoid w, Strict.RWST r w s)
|
GOX(Monoid w, Strict.RWST r w s)
|
||||||
GO(Strict.StateT s)
|
GO(Strict.StateT s)
|
||||||
GOX(Monoid w, Strict.WriterT w)
|
GOX(Monoid w, Strict.WriterT w)
|
||||||
#if !MIN_VERSION_resourcet(1,1,0)
|
|
||||||
GO(ExceptionT)
|
|
||||||
#endif
|
|
||||||
GO(Pipe l i o u)
|
GO(Pipe l i o u)
|
||||||
GO(ConduitM i o)
|
GO(ConduitM i o)
|
||||||
#undef GO
|
#undef GO
|
||||||
|
|||||||
@ -40,16 +40,9 @@ import Data.Default (def)
|
|||||||
import Network.Wai.Parse (lbsBackEnd,
|
import Network.Wai.Parse (lbsBackEnd,
|
||||||
tempFileBackEnd)
|
tempFileBackEnd)
|
||||||
import System.IO (stdout)
|
import System.IO (stdout)
|
||||||
#if MIN_VERSION_fast_logger(2, 0, 0)
|
|
||||||
import Network.Wai.Logger (ZonedDate, clockDateCacher)
|
import Network.Wai.Logger (ZonedDate, clockDateCacher)
|
||||||
import System.Log.FastLogger
|
import System.Log.FastLogger
|
||||||
import qualified GHC.IO.FD
|
import qualified GHC.IO.FD
|
||||||
#else
|
|
||||||
import System.Log.FastLogger.Date (ZonedDate)
|
|
||||||
import System.Log.FastLogger (LogStr (..), Logger,
|
|
||||||
loggerDate, loggerPutStr,
|
|
||||||
mkLogger)
|
|
||||||
#endif
|
|
||||||
import Text.Blaze (customAttribute, textTag,
|
import Text.Blaze (customAttribute, textTag,
|
||||||
toValue, (!))
|
toValue, (!))
|
||||||
import Text.Blaze (preEscapedToMarkup)
|
import Text.Blaze (preEscapedToMarkup)
|
||||||
@ -216,18 +209,10 @@ class RenderRoute site => Yesod site where
|
|||||||
--
|
--
|
||||||
-- Default: Sends to stdout and automatically flushes on each write.
|
-- Default: Sends to stdout and automatically flushes on each write.
|
||||||
makeLogger :: site -> IO Logger
|
makeLogger :: site -> IO Logger
|
||||||
#if MIN_VERSION_fast_logger(2, 0, 0)
|
|
||||||
makeLogger _ = do
|
makeLogger _ = do
|
||||||
#if MIN_VERSION_fast_logger(2, 1, 0)
|
|
||||||
loggerSet <- newLoggerSet defaultBufSize Nothing
|
loggerSet <- newLoggerSet defaultBufSize Nothing
|
||||||
#else
|
|
||||||
loggerSet <- newLoggerSet defaultBufSize GHC.IO.FD.stdout
|
|
||||||
#endif
|
|
||||||
(getter, _) <- clockDateCacher
|
(getter, _) <- clockDateCacher
|
||||||
return $! Logger loggerSet getter
|
return $! Logger loggerSet getter
|
||||||
#else
|
|
||||||
makeLogger _ = mkLogger True stdout
|
|
||||||
#endif
|
|
||||||
|
|
||||||
-- | Send a message to the @Logger@ provided by @getLogger@.
|
-- | Send a message to the @Logger@ provided by @getLogger@.
|
||||||
--
|
--
|
||||||
@ -541,7 +526,6 @@ asyncHelper render scripts jscript jsLoc =
|
|||||||
Nothing -> Nothing
|
Nothing -> Nothing
|
||||||
Just j -> Just $ jelper j
|
Just j -> Just $ jelper j
|
||||||
|
|
||||||
#if MIN_VERSION_fast_logger(2, 0, 0)
|
|
||||||
formatLogMessage :: IO ZonedDate
|
formatLogMessage :: IO ZonedDate
|
||||||
-> Loc
|
-> Loc
|
||||||
-> LogSource
|
-> LogSource
|
||||||
@ -564,33 +548,6 @@ formatLogMessage getdate loc src level msg = do
|
|||||||
" @(" `mappend`
|
" @(" `mappend`
|
||||||
toLogStr (fileLocationToString loc) `mappend`
|
toLogStr (fileLocationToString loc) `mappend`
|
||||||
")\n"
|
")\n"
|
||||||
#else
|
|
||||||
formatLogMessage :: IO ZonedDate
|
|
||||||
-> Loc
|
|
||||||
-> LogSource
|
|
||||||
-> LogLevel
|
|
||||||
-> LogStr -- ^ message
|
|
||||||
-> IO [LogStr]
|
|
||||||
formatLogMessage getdate loc src level msg = do
|
|
||||||
now <- getdate
|
|
||||||
return
|
|
||||||
[ LB now
|
|
||||||
, LB " ["
|
|
||||||
, LS $
|
|
||||||
case level of
|
|
||||||
LevelOther t -> T.unpack t
|
|
||||||
_ -> drop 5 $ show level
|
|
||||||
, LS $
|
|
||||||
if T.null src
|
|
||||||
then ""
|
|
||||||
else "#" ++ T.unpack src
|
|
||||||
, LB "] "
|
|
||||||
, msg
|
|
||||||
, LB " @("
|
|
||||||
, LS $ fileLocationToString loc
|
|
||||||
, LB ")\n"
|
|
||||||
]
|
|
||||||
#endif
|
|
||||||
|
|
||||||
-- | Customize the cookies used by the session backend. You may
|
-- | Customize the cookies used by the session backend. You may
|
||||||
-- use this function on your definition of 'makeSessionBackend'.
|
-- use this function on your definition of 'makeSessionBackend'.
|
||||||
|
|||||||
@ -63,9 +63,7 @@ import Text.Blaze.Html.Renderer.Utf8 (renderHtmlBuilder)
|
|||||||
import Data.Conduit (Source, Flush (Chunk), ResumableSource, mapOutput)
|
import Data.Conduit (Source, Flush (Chunk), ResumableSource, mapOutput)
|
||||||
import Control.Monad.Trans.Resource (ResourceT)
|
import Control.Monad.Trans.Resource (ResourceT)
|
||||||
import Data.Conduit.Internal (ResumableSource (ResumableSource))
|
import Data.Conduit.Internal (ResumableSource (ResumableSource))
|
||||||
#if MIN_VERSION_conduit(1, 2, 0)
|
|
||||||
import qualified Data.Conduit.Internal as CI
|
import qualified Data.Conduit.Internal as CI
|
||||||
#endif
|
|
||||||
|
|
||||||
import qualified Data.Aeson as J
|
import qualified Data.Aeson as J
|
||||||
import Data.Aeson.Encode (fromValue)
|
import Data.Aeson.Encode (fromValue)
|
||||||
@ -118,10 +116,8 @@ instance ToContent Css where
|
|||||||
instance ToContent Javascript where
|
instance ToContent Javascript where
|
||||||
toContent = toContent . toLazyText . unJavascript
|
toContent = toContent . toLazyText . unJavascript
|
||||||
|
|
||||||
#if MIN_VERSION_conduit(1, 2, 0)
|
|
||||||
instance ToFlushBuilder builder => ToContent (CI.Pipe () () builder () (ResourceT IO) ()) where
|
instance ToFlushBuilder builder => ToContent (CI.Pipe () () builder () (ResourceT IO) ()) where
|
||||||
toContent src = ContentSource $ CI.ConduitM (CI.mapOutput toFlushBuilder src >>=)
|
toContent src = ContentSource $ CI.ConduitM (CI.mapOutput toFlushBuilder src >>=)
|
||||||
#endif
|
|
||||||
|
|
||||||
instance ToFlushBuilder builder => ToContent (Source (ResourceT IO) builder) where
|
instance ToFlushBuilder builder => ToContent (Source (ResourceT IO) builder) where
|
||||||
toContent src = ContentSource $ mapOutput toFlushBuilder src
|
toContent src = ContentSource $ mapOutput toFlushBuilder src
|
||||||
|
|||||||
@ -92,13 +92,8 @@ toWaiAppYre yre req =
|
|||||||
where
|
where
|
||||||
site = yreSite yre
|
site = yreSite yre
|
||||||
sendRedirect :: Yesod master => master -> [Text] -> W.Application
|
sendRedirect :: Yesod master => master -> [Text] -> W.Application
|
||||||
#if MIN_VERSION_wai(3, 0, 0)
|
|
||||||
sendRedirect y segments' env sendResponse =
|
sendRedirect y segments' env sendResponse =
|
||||||
sendResponse $ W.responseLBS status301
|
sendResponse $ W.responseLBS status301
|
||||||
#else
|
|
||||||
sendRedirect y segments' env =
|
|
||||||
return $ W.responseLBS status301
|
|
||||||
#endif
|
|
||||||
[ ("Content-Type", "text/plain")
|
[ ("Content-Type", "text/plain")
|
||||||
, ("Location", Blaze.ByteString.Builder.toByteString dest')
|
, ("Location", Blaze.ByteString.Builder.toByteString dest')
|
||||||
] "Redirecting"
|
] "Redirecting"
|
||||||
@ -180,12 +175,7 @@ warp port site = do
|
|||||||
(toLogStr $ "Exception from Warp: " ++ show e)
|
(toLogStr $ "Exception from Warp: " ++ show e)
|
||||||
}
|
}
|
||||||
where
|
where
|
||||||
shouldLog' =
|
shouldLog' = Network.Wai.Handler.Warp.defaultShouldDisplayException
|
||||||
#if MIN_VERSION_warp(2,1,3)
|
|
||||||
Network.Wai.Handler.Warp.defaultShouldDisplayException
|
|
||||||
#else
|
|
||||||
const True
|
|
||||||
#endif
|
|
||||||
|
|
||||||
-- | A default set of middlewares.
|
-- | A default set of middlewares.
|
||||||
--
|
--
|
||||||
@ -193,11 +183,7 @@ warp port site = do
|
|||||||
mkDefaultMiddlewares :: Logger -> IO W.Middleware
|
mkDefaultMiddlewares :: Logger -> IO W.Middleware
|
||||||
mkDefaultMiddlewares logger = do
|
mkDefaultMiddlewares logger = do
|
||||||
logWare <- mkRequestLogger def
|
logWare <- mkRequestLogger def
|
||||||
#if MIN_VERSION_fast_logger(2, 0, 0)
|
|
||||||
{ destination = Network.Wai.Middleware.RequestLogger.Logger $ loggerSet logger
|
{ destination = Network.Wai.Middleware.RequestLogger.Logger $ loggerSet logger
|
||||||
#else
|
|
||||||
{ destination = Logger logger
|
|
||||||
#endif
|
|
||||||
, outputFormat = Apache FromSocket
|
, outputFormat = Apache FromSocket
|
||||||
}
|
}
|
||||||
return $ logWare . defaultMiddlewaresNoLogging
|
return $ logWare . defaultMiddlewaresNoLogging
|
||||||
|
|||||||
@ -92,12 +92,8 @@ module Yesod.Core.Handler
|
|||||||
, sendResponseCreated
|
, sendResponseCreated
|
||||||
, sendWaiResponse
|
, sendWaiResponse
|
||||||
, sendWaiApplication
|
, sendWaiApplication
|
||||||
#if MIN_VERSION_wai(2, 1, 0)
|
|
||||||
, sendRawResponse
|
, sendRawResponse
|
||||||
#endif
|
|
||||||
#if MIN_VERSION_wai(3, 0, 0)
|
|
||||||
, sendRawResponseNoConduit
|
, sendRawResponseNoConduit
|
||||||
#endif
|
|
||||||
-- * Different representations
|
-- * Different representations
|
||||||
-- $representations
|
-- $representations
|
||||||
, selectRep
|
, selectRep
|
||||||
@ -206,21 +202,11 @@ import Data.CaseInsensitive (CI)
|
|||||||
import qualified Data.Conduit.List as CL
|
import qualified Data.Conduit.List as CL
|
||||||
import Control.Monad (unless)
|
import Control.Monad (unless)
|
||||||
import Control.Monad.Trans.Resource (MonadResource, InternalState, runResourceT, withInternalState, getInternalState, liftResourceT, resourceForkIO
|
import Control.Monad.Trans.Resource (MonadResource, InternalState, runResourceT, withInternalState, getInternalState, liftResourceT, resourceForkIO
|
||||||
#if MIN_VERSION_wai(2, 0, 0)
|
|
||||||
#else
|
|
||||||
, ResourceT
|
|
||||||
#endif
|
|
||||||
)
|
)
|
||||||
#if MIN_VERSION_wai(2, 0, 0)
|
|
||||||
import qualified System.PosixCompat.Files as PC
|
import qualified System.PosixCompat.Files as PC
|
||||||
#endif
|
|
||||||
#if MIN_VERSION_wai(2, 1, 0)
|
|
||||||
import Control.Monad.Trans.Control (control, MonadBaseControl)
|
import Control.Monad.Trans.Control (control, MonadBaseControl)
|
||||||
#endif
|
|
||||||
import Data.Conduit (Source, transPipe, Flush (Flush), yield, Producer
|
import Data.Conduit (Source, transPipe, Flush (Flush), yield, Producer
|
||||||
#if MIN_VERSION_wai(2, 1, 0)
|
|
||||||
, Sink
|
, Sink
|
||||||
#endif
|
|
||||||
)
|
)
|
||||||
|
|
||||||
get :: MonadHandler m => m GHState
|
get :: MonadHandler m => m GHState
|
||||||
@ -257,41 +243,22 @@ runRequestBody = do
|
|||||||
Just rbc -> return rbc
|
Just rbc -> return rbc
|
||||||
Nothing -> do
|
Nothing -> do
|
||||||
rr <- waiRequest
|
rr <- waiRequest
|
||||||
#if MIN_VERSION_wai_extra(2, 0, 1)
|
|
||||||
internalState <- liftResourceT getInternalState
|
internalState <- liftResourceT getInternalState
|
||||||
rbc <- liftIO $ rbHelper upload rr internalState
|
rbc <- liftIO $ rbHelper upload rr internalState
|
||||||
#elif MIN_VERSION_wai(2, 0, 0)
|
|
||||||
rbc <- liftIO $ rbHelper upload rr
|
|
||||||
#else
|
|
||||||
rbc <- liftResourceT $ rbHelper upload rr
|
|
||||||
#endif
|
|
||||||
put x { ghsRBC = Just rbc }
|
put x { ghsRBC = Just rbc }
|
||||||
return rbc
|
return rbc
|
||||||
|
|
||||||
#if MIN_VERSION_wai(2, 0, 0)
|
|
||||||
rbHelper :: FileUpload -> W.Request -> InternalState -> IO RequestBodyContents
|
rbHelper :: FileUpload -> W.Request -> InternalState -> IO RequestBodyContents
|
||||||
rbHelper upload req internalState =
|
rbHelper upload req internalState =
|
||||||
#else
|
|
||||||
rbHelper :: FileUpload -> W.Request -> ResourceT IO RequestBodyContents
|
|
||||||
rbHelper upload req =
|
|
||||||
#endif
|
|
||||||
case upload of
|
case upload of
|
||||||
FileUploadMemory s -> rbHelper' s mkFileInfoLBS req
|
FileUploadMemory s -> rbHelper' s mkFileInfoLBS req
|
||||||
#if MIN_VERSION_wai_extra(2, 0, 1)
|
|
||||||
FileUploadDisk s -> rbHelper' (s internalState) mkFileInfoFile req
|
FileUploadDisk s -> rbHelper' (s internalState) mkFileInfoFile req
|
||||||
#else
|
|
||||||
FileUploadDisk s -> rbHelper' s mkFileInfoFile req
|
|
||||||
#endif
|
|
||||||
FileUploadSource s -> rbHelper' s mkFileInfoSource req
|
FileUploadSource s -> rbHelper' s mkFileInfoSource req
|
||||||
|
|
||||||
rbHelper' :: NWP.BackEnd x
|
rbHelper' :: NWP.BackEnd x
|
||||||
-> (Text -> Text -> x -> FileInfo)
|
-> (Text -> Text -> x -> FileInfo)
|
||||||
-> W.Request
|
-> W.Request
|
||||||
#if MIN_VERSION_wai(2, 0, 0)
|
|
||||||
-> IO ([(Text, Text)], [(Text, FileInfo)])
|
-> IO ([(Text, Text)], [(Text, FileInfo)])
|
||||||
#else
|
|
||||||
-> ResourceT IO ([(Text, Text)], [(Text, FileInfo)])
|
|
||||||
#endif
|
|
||||||
rbHelper' backend mkFI req =
|
rbHelper' backend mkFI req =
|
||||||
(map fix1 *** mapMaybe fix2) <$> (NWP.parseRequestBody backend req)
|
(map fix1 *** mapMaybe fix2) <$> (NWP.parseRequestBody backend req)
|
||||||
where
|
where
|
||||||
@ -375,11 +342,7 @@ handlerToIO =
|
|||||||
where
|
where
|
||||||
oldReq = handlerRequest oldHandlerData
|
oldReq = handlerRequest oldHandlerData
|
||||||
oldWaiReq = reqWaiRequest oldReq
|
oldWaiReq = reqWaiRequest oldReq
|
||||||
#if MIN_VERSION_wai(3, 0, 0)
|
|
||||||
newWaiReq = oldWaiReq { W.requestBody = return mempty
|
newWaiReq = oldWaiReq { W.requestBody = return mempty
|
||||||
#else
|
|
||||||
newWaiReq = oldWaiReq { W.requestBody = mempty
|
|
||||||
#endif
|
|
||||||
, W.requestBodyLength = W.KnownLength 0
|
, W.requestBodyLength = W.KnownLength 0
|
||||||
}
|
}
|
||||||
oldEnv = handlerEnv oldHandlerData
|
oldEnv = handlerEnv oldHandlerData
|
||||||
@ -551,16 +514,12 @@ sendFilePart :: MonadHandler m
|
|||||||
-> Integer -- ^ count
|
-> Integer -- ^ count
|
||||||
-> m a
|
-> m a
|
||||||
sendFilePart ct fp off count = do
|
sendFilePart ct fp off count = do
|
||||||
#if MIN_VERSION_wai(2, 0, 0)
|
|
||||||
fs <- liftIO $ PC.getFileStatus fp
|
fs <- liftIO $ PC.getFileStatus fp
|
||||||
handlerError $ HCSendFile ct fp $ Just W.FilePart
|
handlerError $ HCSendFile ct fp $ Just W.FilePart
|
||||||
{ W.filePartOffset = off
|
{ W.filePartOffset = off
|
||||||
, W.filePartByteCount = count
|
, W.filePartByteCount = count
|
||||||
, W.filePartFileSize = fromIntegral $ PC.fileSize fs
|
, W.filePartFileSize = fromIntegral $ PC.fileSize fs
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
handlerError $ HCSendFile ct fp $ Just $ W.FilePart off count
|
|
||||||
#endif
|
|
||||||
|
|
||||||
-- | Bypass remaining handler code and output the given content with a 200
|
-- | Bypass remaining handler code and output the given content with a 200
|
||||||
-- status code.
|
-- status code.
|
||||||
@ -593,7 +552,6 @@ sendWaiResponse = handlerError . HCWai
|
|||||||
sendWaiApplication :: MonadHandler m => W.Application -> m b
|
sendWaiApplication :: MonadHandler m => W.Application -> m b
|
||||||
sendWaiApplication = handlerError . HCWaiApp
|
sendWaiApplication = handlerError . HCWaiApp
|
||||||
|
|
||||||
#if MIN_VERSION_wai(3, 0, 0)
|
|
||||||
-- | Send a raw response without conduit. This is used for cases such as
|
-- | Send a raw response without conduit. This is used for cases such as
|
||||||
-- WebSockets. Requires WAI 3.0 or later, and a web server which supports raw
|
-- WebSockets. Requires WAI 3.0 or later, and a web server which supports raw
|
||||||
-- responses (e.g., Warp).
|
-- responses (e.g., Warp).
|
||||||
@ -609,9 +567,7 @@ sendRawResponseNoConduit raw = control $ \runInIO ->
|
|||||||
where
|
where
|
||||||
fallback = W.responseLBS H.status500 [("Content-Type", "text/plain")]
|
fallback = W.responseLBS H.status500 [("Content-Type", "text/plain")]
|
||||||
"sendRawResponse: backend does not support raw responses"
|
"sendRawResponse: backend does not support raw responses"
|
||||||
#endif
|
|
||||||
|
|
||||||
#if MIN_VERSION_wai(2, 1, 0)
|
|
||||||
-- | Send a raw response. This is used for cases such as WebSockets. Requires
|
-- | Send a raw response. This is used for cases such as WebSockets. Requires
|
||||||
-- WAI 2.1 or later, and a web server which supports raw responses (e.g.,
|
-- WAI 2.1 or later, and a web server which supports raw responses (e.g.,
|
||||||
-- Warp).
|
-- Warp).
|
||||||
@ -620,7 +576,6 @@ sendRawResponseNoConduit raw = control $ \runInIO ->
|
|||||||
sendRawResponse :: (MonadHandler m, MonadBaseControl IO m)
|
sendRawResponse :: (MonadHandler m, MonadBaseControl IO m)
|
||||||
=> (Source IO S8.ByteString -> Sink S8.ByteString IO () -> m ())
|
=> (Source IO S8.ByteString -> Sink S8.ByteString IO () -> m ())
|
||||||
-> m a
|
-> m a
|
||||||
#if MIN_VERSION_wai(3, 0, 0)
|
|
||||||
sendRawResponse raw = control $ \runInIO ->
|
sendRawResponse raw = control $ \runInIO ->
|
||||||
runInIO $ sendWaiResponse $ flip W.responseRaw fallback
|
runInIO $ sendWaiResponse $ flip W.responseRaw fallback
|
||||||
$ \src sink -> runInIO (raw (src' src) (CL.mapM_ sink)) >> return ()
|
$ \src sink -> runInIO (raw (src' src) (CL.mapM_ sink)) >> return ()
|
||||||
@ -632,15 +587,6 @@ sendRawResponse raw = control $ \runInIO ->
|
|||||||
unless (S.null bs) $ do
|
unless (S.null bs) $ do
|
||||||
yield bs
|
yield bs
|
||||||
src' src
|
src' src
|
||||||
#else
|
|
||||||
sendRawResponse raw = control $ \runInIO ->
|
|
||||||
runInIO $ sendWaiResponse $ flip W.responseRaw fallback
|
|
||||||
$ \src sink -> runInIO (raw src sink) >> return ()
|
|
||||||
where
|
|
||||||
fallback = W.responseLBS H.status500 [("Content-Type", "text/plain")]
|
|
||||||
"sendRawResponse: backend does not support raw responses"
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
-- | Return a 404 not found page. Also denotes no handler available.
|
-- | Return a 404 not found page. Also denotes no handler available.
|
||||||
notFound :: MonadHandler m => m a
|
notFound :: MonadHandler m => m a
|
||||||
@ -1126,22 +1072,12 @@ provideRepType ct handler =
|
|||||||
rawRequestBody :: MonadHandler m => Source m S.ByteString
|
rawRequestBody :: MonadHandler m => Source m S.ByteString
|
||||||
rawRequestBody = do
|
rawRequestBody = do
|
||||||
req <- lift waiRequest
|
req <- lift waiRequest
|
||||||
#if MIN_VERSION_wai(3, 0, 0)
|
|
||||||
let loop = do
|
let loop = do
|
||||||
bs <- liftIO $ W.requestBody req
|
bs <- liftIO $ W.requestBody req
|
||||||
unless (S.null bs) $ do
|
unless (S.null bs) $ do
|
||||||
yield bs
|
yield bs
|
||||||
loop
|
loop
|
||||||
loop
|
loop
|
||||||
#else
|
|
||||||
transPipe
|
|
||||||
#if MIN_VERSION_wai(2, 0, 0)
|
|
||||||
liftIO
|
|
||||||
#else
|
|
||||||
liftResourceT
|
|
||||||
#endif
|
|
||||||
(W.requestBody req)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
-- | Stream the data from the file. Since Yesod 1.2, this has been generalized
|
-- | Stream the data from the file. Since Yesod 1.2, this has been generalized
|
||||||
-- to work in any @MonadResource@.
|
-- to work in any @MonadResource@.
|
||||||
|
|||||||
@ -48,7 +48,6 @@ import Data.IORef
|
|||||||
|
|
||||||
-- | Impose a limit on the size of the request body.
|
-- | Impose a limit on the size of the request body.
|
||||||
limitRequestBody :: Word64 -> W.Request -> IO W.Request
|
limitRequestBody :: Word64 -> W.Request -> IO W.Request
|
||||||
#if MIN_VERSION_wai(3, 0, 0)
|
|
||||||
limitRequestBody maxLen req = do
|
limitRequestBody maxLen req = do
|
||||||
ref <- newIORef maxLen
|
ref <- newIORef maxLen
|
||||||
return req
|
return req
|
||||||
@ -63,24 +62,6 @@ limitRequestBody maxLen req = do
|
|||||||
writeIORef ref remaining'
|
writeIORef ref remaining'
|
||||||
return bs
|
return bs
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
limitRequestBody maxLen req =
|
|
||||||
return req { W.requestBody = W.requestBody req $= limit maxLen }
|
|
||||||
where
|
|
||||||
tooLarge = liftIO $ throwIO $ HCWai tooLargeResponse
|
|
||||||
|
|
||||||
limit 0 = tooLarge
|
|
||||||
limit remaining =
|
|
||||||
await >>= maybe (return ()) go
|
|
||||||
where
|
|
||||||
go bs = do
|
|
||||||
let len = fromIntegral $ S8.length bs
|
|
||||||
if len > remaining
|
|
||||||
then tooLarge
|
|
||||||
else do
|
|
||||||
yield bs
|
|
||||||
limit $ remaining - len
|
|
||||||
#endif
|
|
||||||
|
|
||||||
tooLargeResponse :: W.Response
|
tooLargeResponse :: W.Response
|
||||||
tooLargeResponse = W.responseLBS
|
tooLargeResponse = W.responseLBS
|
||||||
|
|||||||
@ -13,13 +13,11 @@ import qualified Data.ByteString.Char8 as S8
|
|||||||
import Data.CaseInsensitive (CI)
|
import Data.CaseInsensitive (CI)
|
||||||
import qualified Data.CaseInsensitive as CI
|
import qualified Data.CaseInsensitive as CI
|
||||||
import Network.Wai
|
import Network.Wai
|
||||||
#if MIN_VERSION_wai(2, 0, 0)
|
|
||||||
import Data.Conduit (transPipe)
|
import Data.Conduit (transPipe)
|
||||||
import Control.Monad.Trans.Resource (runInternalState, getInternalState, runResourceT, InternalState, closeInternalState)
|
import Control.Monad.Trans.Resource (runInternalState, getInternalState, runResourceT, InternalState, closeInternalState)
|
||||||
import Control.Monad.Trans.Class (lift)
|
import Control.Monad.Trans.Class (lift)
|
||||||
import Network.Wai.Internal
|
import Network.Wai.Internal
|
||||||
import Control.Exception (finally)
|
import Control.Exception (finally)
|
||||||
#endif
|
|
||||||
import Prelude hiding (catch)
|
import Prelude hiding (catch)
|
||||||
import Web.Cookie (renderSetCookie)
|
import Web.Cookie (renderSetCookie)
|
||||||
import Yesod.Core.Content
|
import Yesod.Core.Content
|
||||||
@ -36,7 +34,6 @@ import Data.Text.Encoding (encodeUtf8)
|
|||||||
import Data.Conduit (Flush (..), ($$))
|
import Data.Conduit (Flush (..), ($$))
|
||||||
import qualified Data.Conduit.List as CL
|
import qualified Data.Conduit.List as CL
|
||||||
|
|
||||||
#if MIN_VERSION_wai(3, 0, 0)
|
|
||||||
yarToResponse :: YesodResponse
|
yarToResponse :: YesodResponse
|
||||||
-> (SessionMap -> IO [Header]) -- ^ save session
|
-> (SessionMap -> IO [Header]) -- ^ save session
|
||||||
-> YesodRequest
|
-> YesodRequest
|
||||||
@ -77,82 +74,6 @@ yarToResponse (YRPlain s' hs ct c newSess) saveSession yreq req is sendResponse
|
|||||||
| s' == defaultStatus = H.status200
|
| s' == defaultStatus = H.status200
|
||||||
| otherwise = s'
|
| otherwise = s'
|
||||||
|
|
||||||
#else
|
|
||||||
yarToResponse :: YesodResponse
|
|
||||||
-> (SessionMap -> IO [Header]) -- ^ save session
|
|
||||||
-> YesodRequest
|
|
||||||
-> Request
|
|
||||||
#if MIN_VERSION_wai(2, 0, 0)
|
|
||||||
-> InternalState
|
|
||||||
#endif
|
|
||||||
-> IO Response
|
|
||||||
#if MIN_VERSION_wai(2, 0, 0)
|
|
||||||
yarToResponse (YRWaiApp app) _ _ req _ = app req
|
|
||||||
yarToResponse (YRWai a) _ _ _ is =
|
|
||||||
case a of
|
|
||||||
ResponseSource s hs w -> return $ ResponseSource s hs $ \f ->
|
|
||||||
w f `finally` closeInternalState is
|
|
||||||
ResponseBuilder{} -> do
|
|
||||||
closeInternalState is
|
|
||||||
return a
|
|
||||||
ResponseFile{} -> do
|
|
||||||
closeInternalState is
|
|
||||||
return a
|
|
||||||
#if MIN_VERSION_wai(2, 1, 0)
|
|
||||||
-- Ignore the fallback provided, in case it refers to a ResourceT state
|
|
||||||
-- in a ResponseSource.
|
|
||||||
ResponseRaw raw _ -> return $ ResponseRaw
|
|
||||||
(\f -> raw f `finally` closeInternalState is)
|
|
||||||
(responseLBS H.status500 [("Content-Type", "text/plain")]
|
|
||||||
"yarToResponse: backend does not support raw responses")
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
yarToResponse (YRWai a) _ _ _ = return a
|
|
||||||
#endif
|
|
||||||
yarToResponse (YRPlain s' hs ct c newSess) saveSession yreq req
|
|
||||||
#if MIN_VERSION_wai(2, 0, 0)
|
|
||||||
is
|
|
||||||
#endif
|
|
||||||
= do
|
|
||||||
extraHeaders <- do
|
|
||||||
let nsToken = maybe
|
|
||||||
newSess
|
|
||||||
(\n -> Map.insert tokenKey (encodeUtf8 n) newSess)
|
|
||||||
(reqToken yreq)
|
|
||||||
sessionHeaders <- saveSession nsToken
|
|
||||||
return $ ("Content-Type", ct) : map headerToPair sessionHeaders
|
|
||||||
let finalHeaders = extraHeaders ++ map headerToPair hs
|
|
||||||
finalHeaders' len = ("Content-Length", S8.pack $ show len)
|
|
||||||
: finalHeaders
|
|
||||||
|
|
||||||
#if MIN_VERSION_wai(2, 0, 0)
|
|
||||||
let go (ContentBuilder b mlen) = do
|
|
||||||
let hs' = maybe finalHeaders finalHeaders' mlen
|
|
||||||
closeInternalState is
|
|
||||||
return $ ResponseBuilder s hs' b
|
|
||||||
go (ContentFile fp p) = do
|
|
||||||
closeInternalState is
|
|
||||||
return $ ResponseFile s finalHeaders fp p
|
|
||||||
go (ContentSource body) = return $ ResponseSource s finalHeaders $ \f ->
|
|
||||||
f (transPipe (flip runInternalState is) body) `finally`
|
|
||||||
closeInternalState is
|
|
||||||
go (ContentDontEvaluate c') = go c'
|
|
||||||
go c
|
|
||||||
#else
|
|
||||||
let go (ContentBuilder b mlen) =
|
|
||||||
let hs' = maybe finalHeaders finalHeaders' mlen
|
|
||||||
in ResponseBuilder s hs' b
|
|
||||||
go (ContentFile fp p) = ResponseFile s finalHeaders fp p
|
|
||||||
go (ContentSource body) = ResponseSource s finalHeaders body
|
|
||||||
go (ContentDontEvaluate c') = go c'
|
|
||||||
return $ go c
|
|
||||||
#endif
|
|
||||||
where
|
|
||||||
s
|
|
||||||
| s' == defaultStatus = H.status200
|
|
||||||
| otherwise = s'
|
|
||||||
#endif
|
|
||||||
|
|
||||||
-- | Indicates that the user provided no specific status code to be used, and
|
-- | Indicates that the user provided no specific status code to be used, and
|
||||||
-- therefore the default status code should be used. For normal responses, this
|
-- therefore the default status code should be used. For normal responses, this
|
||||||
-- would be a 200 response, whereas for error responses this would be an
|
-- would be a 200 response, whereas for error responses this would be an
|
||||||
|
|||||||
@ -34,13 +34,8 @@ import Data.Text.Encoding.Error (lenientDecode)
|
|||||||
import Language.Haskell.TH.Syntax (Loc, qLocation)
|
import Language.Haskell.TH.Syntax (Loc, qLocation)
|
||||||
import qualified Network.HTTP.Types as H
|
import qualified Network.HTTP.Types as H
|
||||||
import Network.Wai
|
import Network.Wai
|
||||||
#if MIN_VERSION_wai(2, 0, 0)
|
|
||||||
import Network.Wai.Internal
|
import Network.Wai.Internal
|
||||||
#endif
|
|
||||||
import Prelude hiding (catch)
|
import Prelude hiding (catch)
|
||||||
#if !MIN_VERSION_fast_logger(2, 0, 0)
|
|
||||||
import System.Log.FastLogger (Logger)
|
|
||||||
#endif
|
|
||||||
import System.Log.FastLogger (LogStr, toLogStr)
|
import System.Log.FastLogger (LogStr, toLogStr)
|
||||||
import System.Random (newStdGen)
|
import System.Random (newStdGen)
|
||||||
import Yesod.Core.Content
|
import Yesod.Core.Content
|
||||||
@ -220,22 +215,13 @@ runFakeHandler fakeSessionMap logger site handler = liftIO $ do
|
|||||||
, httpVersion = H.http11
|
, httpVersion = H.http11
|
||||||
, rawPathInfo = "/runFakeHandler/pathInfo"
|
, rawPathInfo = "/runFakeHandler/pathInfo"
|
||||||
, rawQueryString = ""
|
, rawQueryString = ""
|
||||||
#if MIN_VERSION_wai(2, 0, 0)
|
|
||||||
, requestHeaderHost = Nothing
|
, requestHeaderHost = Nothing
|
||||||
#else
|
|
||||||
, serverName = "runFakeHandler-serverName"
|
|
||||||
, serverPort = 80
|
|
||||||
#endif
|
|
||||||
, requestHeaders = []
|
, requestHeaders = []
|
||||||
, isSecure = False
|
, isSecure = False
|
||||||
, remoteHost = error "runFakeHandler-remoteHost"
|
, remoteHost = error "runFakeHandler-remoteHost"
|
||||||
, pathInfo = ["runFakeHandler", "pathInfo"]
|
, pathInfo = ["runFakeHandler", "pathInfo"]
|
||||||
, queryString = []
|
, queryString = []
|
||||||
#if MIN_VERSION_wai(3, 0, 0)
|
|
||||||
, requestBody = return mempty
|
, requestBody = return mempty
|
||||||
#else
|
|
||||||
, requestBody = mempty
|
|
||||||
#endif
|
|
||||||
, vault = mempty
|
, vault = mempty
|
||||||
, requestBodyLength = KnownLength 0
|
, requestBodyLength = KnownLength 0
|
||||||
}
|
}
|
||||||
@ -258,13 +244,8 @@ yesodRunner :: (ToTypedContent res, Yesod site)
|
|||||||
-> YesodRunnerEnv site
|
-> YesodRunnerEnv site
|
||||||
-> Maybe (Route site)
|
-> Maybe (Route site)
|
||||||
-> Application
|
-> Application
|
||||||
#if MIN_VERSION_wai(3, 0, 0)
|
|
||||||
yesodRunner handler' YesodRunnerEnv {..} route req sendResponse
|
yesodRunner handler' YesodRunnerEnv {..} route req sendResponse
|
||||||
| Just maxLen <- mmaxLen, KnownLength len <- requestBodyLength req, maxLen < len = sendResponse tooLargeResponse
|
| Just maxLen <- mmaxLen, KnownLength len <- requestBodyLength req, maxLen < len = sendResponse tooLargeResponse
|
||||||
#else
|
|
||||||
yesodRunner handler' YesodRunnerEnv {..} route req
|
|
||||||
| Just maxLen <- mmaxLen, KnownLength len <- requestBodyLength req, maxLen < len = return tooLargeResponse
|
|
||||||
#endif
|
|
||||||
| otherwise = do
|
| otherwise = do
|
||||||
let dontSaveSession _ = return []
|
let dontSaveSession _ = return []
|
||||||
(session, saveSession) <- liftIO $ do
|
(session, saveSession) <- liftIO $ do
|
||||||
@ -291,25 +272,11 @@ yesodRunner handler' YesodRunnerEnv {..} route req
|
|||||||
rhe = rheSafe
|
rhe = rheSafe
|
||||||
{ rheOnError = runHandler rheSafe . errorHandler
|
{ rheOnError = runHandler rheSafe . errorHandler
|
||||||
}
|
}
|
||||||
#if MIN_VERSION_wai(3, 0, 0)
|
|
||||||
|
|
||||||
E.bracket createInternalState closeInternalState $ \is -> do
|
E.bracket createInternalState closeInternalState $ \is -> do
|
||||||
yreq' <- yreq
|
yreq' <- yreq
|
||||||
yar <- runInternalState (runHandler rhe handler yreq') is
|
yar <- runInternalState (runHandler rhe handler yreq') is
|
||||||
yarToResponse yar saveSession yreq' req is sendResponse
|
yarToResponse yar saveSession yreq' req is sendResponse
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
#if MIN_VERSION_wai(2, 0, 0)
|
|
||||||
bracketOnError createInternalState closeInternalState $ \is -> do
|
|
||||||
yreq' <- yreq
|
|
||||||
yar <- runInternalState (runHandler rhe handler yreq') is
|
|
||||||
liftIO $ yarToResponse yar saveSession yreq' req is
|
|
||||||
#else
|
|
||||||
yar <- runHandler rhe handler yreq
|
|
||||||
liftIO $ yarToResponse yar saveSession yreq req
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
where
|
where
|
||||||
mmaxLen = maximumContentLength yreSite route
|
mmaxLen = maximumContentLength yreSite route
|
||||||
handler = yesodMiddleware handler'
|
handler = yesodMiddleware handler'
|
||||||
|
|||||||
@ -95,11 +95,7 @@ provideJson = provideRep . return . J.toJSON
|
|||||||
-- /Since: 0.3.0/
|
-- /Since: 0.3.0/
|
||||||
parseJsonBody :: (MonadHandler m, J.FromJSON a) => m (J.Result a)
|
parseJsonBody :: (MonadHandler m, J.FromJSON a) => m (J.Result a)
|
||||||
parseJsonBody = do
|
parseJsonBody = do
|
||||||
#if MIN_VERSION_resourcet(1,1,0)
|
|
||||||
eValue <- rawRequestBody $$ runCatchC (sinkParser JP.value')
|
eValue <- rawRequestBody $$ runCatchC (sinkParser JP.value')
|
||||||
#else
|
|
||||||
eValue <- runExceptionT $ rawRequestBody $$ sinkParser JP.value'
|
|
||||||
#endif
|
|
||||||
return $ case eValue of
|
return $ case eValue of
|
||||||
Left e -> J.Error $ show e
|
Left e -> J.Error $ show e
|
||||||
Right value -> J.fromJSON value
|
Right value -> J.fromJSON value
|
||||||
|
|||||||
@ -5,7 +5,6 @@
|
|||||||
{-# LANGUAGE MultiParamTypeClasses #-}
|
{-# LANGUAGE MultiParamTypeClasses #-}
|
||||||
{-# LANGUAGE TypeFamilies #-}
|
{-# LANGUAGE TypeFamilies #-}
|
||||||
{-# LANGUAGE UndecidableInstances #-}
|
{-# LANGUAGE UndecidableInstances #-}
|
||||||
{-# LANGUAGE CPP #-}
|
|
||||||
module Yesod.Core.Types where
|
module Yesod.Core.Types where
|
||||||
|
|
||||||
import qualified Blaze.ByteString.Builder as BBuilder
|
import qualified Blaze.ByteString.Builder as BBuilder
|
||||||
@ -17,17 +16,12 @@ import Control.Exception (Exception)
|
|||||||
import Control.Monad (liftM, ap)
|
import Control.Monad (liftM, ap)
|
||||||
import Control.Monad.Base (MonadBase (liftBase))
|
import Control.Monad.Base (MonadBase (liftBase))
|
||||||
import Control.Monad.Catch (MonadCatch (..))
|
import Control.Monad.Catch (MonadCatch (..))
|
||||||
#if MIN_VERSION_exceptions(0,6,0)
|
|
||||||
import Control.Monad.Catch (MonadMask (..))
|
import Control.Monad.Catch (MonadMask (..))
|
||||||
#endif
|
|
||||||
import Control.Monad.IO.Class (MonadIO (liftIO))
|
import Control.Monad.IO.Class (MonadIO (liftIO))
|
||||||
import Control.Monad.Logger (LogLevel, LogSource,
|
import Control.Monad.Logger (LogLevel, LogSource,
|
||||||
MonadLogger (..))
|
MonadLogger (..))
|
||||||
import Control.Monad.Trans.Control (MonadBaseControl (..))
|
import Control.Monad.Trans.Control (MonadBaseControl (..))
|
||||||
import Control.Monad.Trans.Resource (MonadResource (..), InternalState, runInternalState, MonadThrow (..), monadThrow, ResourceT)
|
import Control.Monad.Trans.Resource (MonadResource (..), InternalState, runInternalState, MonadThrow (..), monadThrow, ResourceT)
|
||||||
#if !MIN_VERSION_resourcet(1,1,0)
|
|
||||||
import Control.Monad.Trans.Resource (MonadUnsafeIO (..))
|
|
||||||
#endif
|
|
||||||
import Data.ByteString (ByteString)
|
import Data.ByteString (ByteString)
|
||||||
import qualified Data.ByteString.Lazy as L
|
import qualified Data.ByteString.Lazy as L
|
||||||
import Data.Conduit (Flush, Source)
|
import Data.Conduit (Flush, Source)
|
||||||
@ -52,12 +46,8 @@ import Network.Wai (FilePart,
|
|||||||
RequestBodyLength)
|
RequestBodyLength)
|
||||||
import qualified Network.Wai as W
|
import qualified Network.Wai as W
|
||||||
import qualified Network.Wai.Parse as NWP
|
import qualified Network.Wai.Parse as NWP
|
||||||
#if MIN_VERSION_fast_logger(2, 0, 0)
|
|
||||||
import System.Log.FastLogger (LogStr, LoggerSet, toLogStr, pushLogStr)
|
import System.Log.FastLogger (LogStr, LoggerSet, toLogStr, pushLogStr)
|
||||||
import Network.Wai.Logger (DateCacheGetter)
|
import Network.Wai.Logger (DateCacheGetter)
|
||||||
#else
|
|
||||||
import System.Log.FastLogger (LogStr, Logger, toLogStr)
|
|
||||||
#endif
|
|
||||||
import Text.Blaze.Html (Html)
|
import Text.Blaze.Html (Html)
|
||||||
import Text.Hamlet (HtmlUrl)
|
import Text.Hamlet (HtmlUrl)
|
||||||
import Text.Julius (JavascriptUrl)
|
import Text.Julius (JavascriptUrl)
|
||||||
@ -68,9 +58,7 @@ import Yesod.Routes.Class (RenderRoute (..), ParseRout
|
|||||||
import Control.Monad.Reader (MonadReader (..))
|
import Control.Monad.Reader (MonadReader (..))
|
||||||
import Prelude hiding (catch)
|
import Prelude hiding (catch)
|
||||||
import Control.DeepSeq (NFData (rnf))
|
import Control.DeepSeq (NFData (rnf))
|
||||||
#if MIN_VERSION_conduit(1, 1, 0)
|
|
||||||
import Data.Conduit.Lazy (MonadActive, monadActive)
|
import Data.Conduit.Lazy (MonadActive, monadActive)
|
||||||
#endif
|
|
||||||
|
|
||||||
-- Sessions
|
-- Sessions
|
||||||
type SessionMap = Map Text ByteString
|
type SessionMap = Map Text ByteString
|
||||||
@ -146,11 +134,7 @@ data FileInfo = FileInfo
|
|||||||
}
|
}
|
||||||
|
|
||||||
data FileUpload = FileUploadMemory !(NWP.BackEnd L.ByteString)
|
data FileUpload = FileUploadMemory !(NWP.BackEnd L.ByteString)
|
||||||
#if MIN_VERSION_wai_extra(2, 0, 1)
|
|
||||||
| FileUploadDisk !(InternalState -> NWP.BackEnd FilePath)
|
| FileUploadDisk !(InternalState -> NWP.BackEnd FilePath)
|
||||||
#else
|
|
||||||
| FileUploadDisk !(NWP.BackEnd FilePath)
|
|
||||||
#endif
|
|
||||||
| FileUploadSource !(NWP.BackEnd (Source (ResourceT IO) ByteString))
|
| FileUploadSource !(NWP.BackEnd (Source (ResourceT IO) ByteString))
|
||||||
|
|
||||||
-- | How to determine the root of the application for constructing URLs.
|
-- | How to determine the root of the application for constructing URLs.
|
||||||
@ -423,14 +407,11 @@ instance Monad m => MonadReader site (WidgetT site m) where
|
|||||||
instance MonadTrans (WidgetT site) where
|
instance MonadTrans (WidgetT site) where
|
||||||
lift = WidgetT . const . liftM (, mempty)
|
lift = WidgetT . const . liftM (, mempty)
|
||||||
instance MonadThrow m => MonadThrow (WidgetT site m) where
|
instance MonadThrow m => MonadThrow (WidgetT site m) where
|
||||||
#if MIN_VERSION_resourcet(1,1,0)
|
|
||||||
throwM = lift . throwM
|
throwM = lift . throwM
|
||||||
|
|
||||||
instance MonadCatch m => MonadCatch (HandlerT site m) where
|
instance MonadCatch m => MonadCatch (HandlerT site m) where
|
||||||
catch (HandlerT m) c = HandlerT $ \r -> m r `catch` \e -> unHandlerT (c e) r
|
catch (HandlerT m) c = HandlerT $ \r -> m r `catch` \e -> unHandlerT (c e) r
|
||||||
#if MIN_VERSION_exceptions(0,6,0)
|
|
||||||
instance MonadMask m => MonadMask (HandlerT site m) where
|
instance MonadMask m => MonadMask (HandlerT site m) where
|
||||||
#endif
|
|
||||||
mask a = HandlerT $ \e -> mask $ \u -> unHandlerT (a $ q u) e
|
mask a = HandlerT $ \e -> mask $ \u -> unHandlerT (a $ q u) e
|
||||||
where q u (HandlerT b) = HandlerT (u . b)
|
where q u (HandlerT b) = HandlerT (u . b)
|
||||||
uninterruptibleMask a =
|
uninterruptibleMask a =
|
||||||
@ -438,35 +419,24 @@ instance MonadMask m => MonadMask (HandlerT site m) where
|
|||||||
where q u (HandlerT b) = HandlerT (u . b)
|
where q u (HandlerT b) = HandlerT (u . b)
|
||||||
instance MonadCatch m => MonadCatch (WidgetT site m) where
|
instance MonadCatch m => MonadCatch (WidgetT site m) where
|
||||||
catch (WidgetT m) c = WidgetT $ \r -> m r `catch` \e -> unWidgetT (c e) r
|
catch (WidgetT m) c = WidgetT $ \r -> m r `catch` \e -> unWidgetT (c e) r
|
||||||
#if MIN_VERSION_exceptions(0,6,0)
|
|
||||||
instance MonadMask m => MonadMask (WidgetT site m) where
|
instance MonadMask m => MonadMask (WidgetT site m) where
|
||||||
#endif
|
|
||||||
mask a = WidgetT $ \e -> mask $ \u -> unWidgetT (a $ q u) e
|
mask a = WidgetT $ \e -> mask $ \u -> unWidgetT (a $ q u) e
|
||||||
where q u (WidgetT b) = WidgetT (u . b)
|
where q u (WidgetT b) = WidgetT (u . b)
|
||||||
uninterruptibleMask a =
|
uninterruptibleMask a =
|
||||||
WidgetT $ \e -> uninterruptibleMask $ \u -> unWidgetT (a $ q u) e
|
WidgetT $ \e -> uninterruptibleMask $ \u -> unWidgetT (a $ q u) e
|
||||||
where q u (WidgetT b) = WidgetT (u . b)
|
where q u (WidgetT b) = WidgetT (u . b)
|
||||||
#else
|
|
||||||
monadThrow = lift . monadThrow
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if MIN_VERSION_resourcet(1,1,0)
|
|
||||||
instance (Applicative m, MonadIO m, MonadBase IO m, MonadThrow m) => MonadResource (WidgetT site m) where
|
instance (Applicative m, MonadIO m, MonadBase IO m, MonadThrow m) => MonadResource (WidgetT site m) where
|
||||||
#else
|
|
||||||
instance (Applicative m, MonadIO m, MonadUnsafeIO m, MonadThrow m) => MonadResource (WidgetT site m) where
|
|
||||||
#endif
|
|
||||||
liftResourceT f = WidgetT $ \hd -> liftIO $ fmap (, mempty) $ runInternalState f (handlerResource hd)
|
liftResourceT f = WidgetT $ \hd -> liftIO $ fmap (, mempty) $ runInternalState f (handlerResource hd)
|
||||||
|
|
||||||
instance MonadIO m => MonadLogger (WidgetT site m) where
|
instance MonadIO m => MonadLogger (WidgetT site m) where
|
||||||
monadLoggerLog a b c d = WidgetT $ \hd ->
|
monadLoggerLog a b c d = WidgetT $ \hd ->
|
||||||
liftIO $ fmap (, mempty) $ rheLog (handlerEnv hd) a b c (toLogStr d)
|
liftIO $ fmap (, mempty) $ rheLog (handlerEnv hd) a b c (toLogStr d)
|
||||||
|
|
||||||
#if MIN_VERSION_conduit(1, 1, 0)
|
|
||||||
instance MonadActive m => MonadActive (WidgetT site m) where
|
instance MonadActive m => MonadActive (WidgetT site m) where
|
||||||
monadActive = lift monadActive
|
monadActive = lift monadActive
|
||||||
instance MonadActive m => MonadActive (HandlerT site m) where
|
instance MonadActive m => MonadActive (HandlerT site m) where
|
||||||
monadActive = lift monadActive
|
monadActive = lift monadActive
|
||||||
#endif
|
|
||||||
|
|
||||||
instance MonadTrans (HandlerT site) where
|
instance MonadTrans (HandlerT site) where
|
||||||
lift = HandlerT . const
|
lift = HandlerT . const
|
||||||
@ -507,17 +477,9 @@ instance MonadBaseControl b m => MonadBaseControl b (HandlerT site m) where
|
|||||||
restoreM (StH base) = HandlerT $ const $ restoreM base
|
restoreM (StH base) = HandlerT $ const $ restoreM base
|
||||||
|
|
||||||
instance MonadThrow m => MonadThrow (HandlerT site m) where
|
instance MonadThrow m => MonadThrow (HandlerT site m) where
|
||||||
#if MIN_VERSION_resourcet(1,1,0)
|
|
||||||
throwM = lift . monadThrow
|
throwM = lift . monadThrow
|
||||||
#else
|
|
||||||
monadThrow = lift . monadThrow
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if MIN_VERSION_resourcet(1,1,0)
|
|
||||||
instance (MonadIO m, MonadBase IO m, MonadThrow m) => MonadResource (HandlerT site m) where
|
instance (MonadIO m, MonadBase IO m, MonadThrow m) => MonadResource (HandlerT site m) where
|
||||||
#else
|
|
||||||
instance (MonadIO m, MonadUnsafeIO m, MonadThrow m) => MonadResource (HandlerT site m) where
|
|
||||||
#endif
|
|
||||||
liftResourceT f = HandlerT $ \hd -> liftIO $ runInternalState f (handlerResource hd)
|
liftResourceT f = HandlerT $ \hd -> liftIO $ runInternalState f (handlerResource hd)
|
||||||
|
|
||||||
instance MonadIO m => MonadLogger (HandlerT site m) where
|
instance MonadIO m => MonadLogger (HandlerT site m) where
|
||||||
@ -538,7 +500,6 @@ instance RenderRoute WaiSubsite where
|
|||||||
instance ParseRoute WaiSubsite where
|
instance ParseRoute WaiSubsite where
|
||||||
parseRoute (x, y) = Just $ WaiSubsiteRoute x y
|
parseRoute (x, y) = Just $ WaiSubsiteRoute x y
|
||||||
|
|
||||||
#if MIN_VERSION_fast_logger(2, 0, 0)
|
|
||||||
data Logger = Logger
|
data Logger = Logger
|
||||||
{ loggerSet :: !LoggerSet
|
{ loggerSet :: !LoggerSet
|
||||||
, loggerDate :: !DateCacheGetter
|
, loggerDate :: !DateCacheGetter
|
||||||
@ -546,4 +507,3 @@ data Logger = Logger
|
|||||||
|
|
||||||
loggerPutStr :: Logger -> LogStr -> IO ()
|
loggerPutStr :: Logger -> LogStr -> IO ()
|
||||||
loggerPutStr (Logger ls _) = pushLogStr ls
|
loggerPutStr (Logger ls _) = pushLogStr ls
|
||||||
#endif
|
|
||||||
|
|||||||
@ -15,9 +15,7 @@ import qualified YesodCoreTest.Redirect as Redirect
|
|||||||
import qualified YesodCoreTest.JsLoader as JsLoader
|
import qualified YesodCoreTest.JsLoader as JsLoader
|
||||||
import qualified YesodCoreTest.RequestBodySize as RequestBodySize
|
import qualified YesodCoreTest.RequestBodySize as RequestBodySize
|
||||||
import qualified YesodCoreTest.Json as Json
|
import qualified YesodCoreTest.Json as Json
|
||||||
#if MIN_VERSION_wai(2, 1, 0)
|
|
||||||
import qualified YesodCoreTest.RawResponse as RawResponse
|
import qualified YesodCoreTest.RawResponse as RawResponse
|
||||||
#endif
|
|
||||||
import qualified YesodCoreTest.Streaming as Streaming
|
import qualified YesodCoreTest.Streaming as Streaming
|
||||||
import qualified YesodCoreTest.Reps as Reps
|
import qualified YesodCoreTest.Reps as Reps
|
||||||
import qualified YesodCoreTest.Auth as Auth
|
import qualified YesodCoreTest.Auth as Auth
|
||||||
@ -41,9 +39,7 @@ specs = do
|
|||||||
JsLoader.specs
|
JsLoader.specs
|
||||||
RequestBodySize.specs
|
RequestBodySize.specs
|
||||||
Json.specs
|
Json.specs
|
||||||
#if MIN_VERSION_wai(2, 1, 0)
|
|
||||||
RawResponse.specs
|
RawResponse.specs
|
||||||
#endif
|
|
||||||
Streaming.specs
|
Streaming.specs
|
||||||
Reps.specs
|
Reps.specs
|
||||||
Auth.specs
|
Auth.specs
|
||||||
|
|||||||
@ -33,11 +33,7 @@ instance ParseRoute Subsite where
|
|||||||
parseRoute (x, _) = Just $ SubsiteRoute x
|
parseRoute (x, _) = Just $ SubsiteRoute x
|
||||||
|
|
||||||
instance YesodSubDispatch Subsite master where
|
instance YesodSubDispatch Subsite master where
|
||||||
#if MIN_VERSION_wai(3, 0, 0)
|
|
||||||
yesodSubDispatch _ req f = f $ responseLBS
|
yesodSubDispatch _ req f = f $ responseLBS
|
||||||
#else
|
|
||||||
yesodSubDispatch _ req = return $ responseLBS
|
|
||||||
#endif
|
|
||||||
status200
|
status200
|
||||||
[ ("Content-Type", "SUBSITE")
|
[ ("Content-Type", "SUBSITE")
|
||||||
] $ L8.pack $ show (pathInfo req)
|
] $ L8.pack $ show (pathInfo req)
|
||||||
|
|||||||
@ -6,11 +6,7 @@ import Yesod.Core
|
|||||||
import qualified Network.HTTP.Types as H
|
import qualified Network.HTTP.Types as H
|
||||||
|
|
||||||
myApp :: Application
|
myApp :: Application
|
||||||
#if MIN_VERSION_wai(3, 0, 0)
|
|
||||||
myApp _ f = f $ responseLBS H.status200 [("Content-type", "text/plain")] "WAI"
|
myApp _ f = f $ responseLBS H.status200 [("Content-type", "text/plain")] "WAI"
|
||||||
#else
|
|
||||||
myApp _ = return $ responseLBS H.status200 [("Content-type", "text/plain")] "WAI"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
getApp :: a -> WaiSubsite
|
getApp :: a -> WaiSubsite
|
||||||
getApp _ = WaiSubsite myApp
|
getApp _ = WaiSubsite myApp
|
||||||
|
|||||||
@ -49,7 +49,7 @@ library
|
|||||||
, directory >= 1
|
, directory >= 1
|
||||||
, vector >= 0.9 && < 0.11
|
, vector >= 0.9 && < 0.11
|
||||||
, aeson >= 0.5
|
, aeson >= 0.5
|
||||||
, fast-logger >= 0.2
|
, fast-logger >= 2.1
|
||||||
, wai-logger >= 0.2
|
, wai-logger >= 0.2
|
||||||
, monad-logger >= 0.3.1 && < 0.4
|
, monad-logger >= 0.3.1 && < 0.4
|
||||||
, conduit >= 1.2
|
, conduit >= 1.2
|
||||||
@ -62,7 +62,7 @@ library
|
|||||||
, warp >= 1.3.8
|
, warp >= 1.3.8
|
||||||
, unix-compat
|
, unix-compat
|
||||||
, conduit-extra
|
, conduit-extra
|
||||||
, exceptions
|
, exceptions >= 0.6
|
||||||
, deepseq
|
, deepseq
|
||||||
|
|
||||||
exposed-modules: Yesod.Core
|
exposed-modules: Yesod.Core
|
||||||
|
|||||||
@ -75,11 +75,7 @@ import Data.Maybe (listToMaybe, fromMaybe)
|
|||||||
import qualified Blaze.ByteString.Builder.Html.Utf8 as B
|
import qualified Blaze.ByteString.Builder.Html.Utf8 as B
|
||||||
import Blaze.ByteString.Builder (writeByteString, toLazyByteString)
|
import Blaze.ByteString.Builder (writeByteString, toLazyByteString)
|
||||||
import Blaze.ByteString.Builder.Internal.Write (fromWriteList)
|
import Blaze.ByteString.Builder.Internal.Write (fromWriteList)
|
||||||
#if MIN_VERSION_persistent(2, 0, 0)
|
|
||||||
import Database.Persist (PersistEntityBackend)
|
import Database.Persist (PersistEntityBackend)
|
||||||
#else
|
|
||||||
import Database.Persist (PersistMonadBackend, PersistEntityBackend)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
import Text.Blaze.Html.Renderer.String (renderHtml)
|
import Text.Blaze.Html.Renderer.String (renderHtml)
|
||||||
import qualified Data.ByteString as S
|
import qualified Data.ByteString as S
|
||||||
@ -559,21 +555,12 @@ optionsPairs opts = do
|
|||||||
optionsEnum :: (MonadHandler m, Show a, Enum a, Bounded a) => m (OptionList a)
|
optionsEnum :: (MonadHandler m, Show a, Enum a, Bounded a) => m (OptionList a)
|
||||||
optionsEnum = optionsPairs $ map (\x -> (pack $ show x, x)) [minBound..maxBound]
|
optionsEnum = optionsPairs $ map (\x -> (pack $ show x, x)) [minBound..maxBound]
|
||||||
|
|
||||||
#if MIN_VERSION_persistent(2, 0, 0)
|
|
||||||
optionsPersist :: ( YesodPersist site, PersistEntity a
|
optionsPersist :: ( YesodPersist site, PersistEntity a
|
||||||
, PersistQuery (PersistEntityBackend a)
|
, PersistQuery (PersistEntityBackend a)
|
||||||
, PathPiece (Key a)
|
, PathPiece (Key a)
|
||||||
, RenderMessage site msg
|
, RenderMessage site msg
|
||||||
, YesodPersistBackend site ~ PersistEntityBackend a
|
, YesodPersistBackend site ~ PersistEntityBackend a
|
||||||
)
|
)
|
||||||
#else
|
|
||||||
optionsPersist :: ( YesodPersist site, PersistEntity a
|
|
||||||
, PersistQuery (YesodPersistBackend site (HandlerT site IO))
|
|
||||||
, PathPiece (Key a)
|
|
||||||
, PersistEntityBackend a ~ PersistMonadBackend (YesodPersistBackend site (HandlerT site IO))
|
|
||||||
, RenderMessage site msg
|
|
||||||
)
|
|
||||||
#endif
|
|
||||||
=> [Filter a]
|
=> [Filter a]
|
||||||
-> [SelectOpt a]
|
-> [SelectOpt a]
|
||||||
-> (a -> msg)
|
-> (a -> msg)
|
||||||
@ -591,7 +578,6 @@ optionsPersist filts ords toDisplay = fmap mkOptionList $ do
|
|||||||
-- the entire @Entity@.
|
-- the entire @Entity@.
|
||||||
--
|
--
|
||||||
-- Since 1.3.2
|
-- Since 1.3.2
|
||||||
#if MIN_VERSION_persistent(2, 0, 0)
|
|
||||||
optionsPersistKey
|
optionsPersistKey
|
||||||
:: (YesodPersist site
|
:: (YesodPersist site
|
||||||
, PersistEntity a
|
, PersistEntity a
|
||||||
@ -600,15 +586,6 @@ optionsPersistKey
|
|||||||
, RenderMessage site msg
|
, RenderMessage site msg
|
||||||
, YesodPersistBackend site ~ PersistEntityBackend a
|
, YesodPersistBackend site ~ PersistEntityBackend a
|
||||||
)
|
)
|
||||||
#else
|
|
||||||
optionsPersistKey
|
|
||||||
:: (YesodPersist site
|
|
||||||
, PersistEntity a
|
|
||||||
, PersistQuery (YesodPersistBackend site (HandlerT site IO))
|
|
||||||
, PathPiece (Key a)
|
|
||||||
, RenderMessage site msg
|
|
||||||
, PersistEntityBackend a ~ PersistMonadBackend (YesodDB site))
|
|
||||||
#endif
|
|
||||||
=> [Filter a]
|
=> [Filter a]
|
||||||
-> [SelectOpt a]
|
-> [SelectOpt a]
|
||||||
-> (a -> msg)
|
-> (a -> msg)
|
||||||
|
|||||||
@ -20,9 +20,6 @@ module Yesod.Persist.Core
|
|||||||
) where
|
) where
|
||||||
|
|
||||||
import Database.Persist
|
import Database.Persist
|
||||||
#if !MIN_VERSION_persistent(2, 0, 0)
|
|
||||||
import Database.Persist.Sql (SqlPersistT, unSqlPersistT)
|
|
||||||
#endif
|
|
||||||
import Control.Monad.Trans.Reader (ReaderT, runReaderT)
|
import Control.Monad.Trans.Reader (ReaderT, runReaderT)
|
||||||
|
|
||||||
import Yesod.Core
|
import Yesod.Core
|
||||||
@ -34,24 +31,13 @@ import Control.Exception (throwIO)
|
|||||||
import Yesod.Core.Types (HandlerContents (HCError))
|
import Yesod.Core.Types (HandlerContents (HCError))
|
||||||
import qualified Database.Persist.Sql as SQL
|
import qualified Database.Persist.Sql as SQL
|
||||||
|
|
||||||
#if MIN_VERSION_persistent(2, 0, 0)
|
|
||||||
unSqlPersistT :: a -> a
|
unSqlPersistT :: a -> a
|
||||||
unSqlPersistT = id
|
unSqlPersistT = id
|
||||||
#endif
|
|
||||||
|
|
||||||
#if MIN_VERSION_persistent(2, 0, 0)
|
|
||||||
type YesodDB site = ReaderT (YesodPersistBackend site) (HandlerT site IO)
|
type YesodDB site = ReaderT (YesodPersistBackend site) (HandlerT site IO)
|
||||||
#else
|
|
||||||
type YesodDB site = YesodPersistBackend site (HandlerT site IO)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if MIN_VERSION_persistent(2, 0, 0)
|
|
||||||
class Monad (YesodDB site) => YesodPersist site where
|
class Monad (YesodDB site) => YesodPersist site where
|
||||||
type YesodPersistBackend site
|
type YesodPersistBackend site
|
||||||
#else
|
|
||||||
class Monad (YesodPersistBackend site (HandlerT site IO)) => YesodPersist site where
|
|
||||||
type YesodPersistBackend site :: (* -> *) -> * -> *
|
|
||||||
#endif
|
|
||||||
runDB :: YesodDB site a -> HandlerT site IO a
|
runDB :: YesodDB site a -> HandlerT site IO a
|
||||||
|
|
||||||
-- | Helper for creating 'runDB'.
|
-- | Helper for creating 'runDB'.
|
||||||
@ -94,11 +80,7 @@ newtype DBRunner site = DBRunner
|
|||||||
-- | Helper for implementing 'getDBRunner'.
|
-- | Helper for implementing 'getDBRunner'.
|
||||||
--
|
--
|
||||||
-- Since 1.2.0
|
-- Since 1.2.0
|
||||||
#if MIN_VERSION_persistent(2, 0, 0)
|
|
||||||
defaultGetDBRunner :: YesodPersistBackend site ~ SQL.SqlBackend
|
defaultGetDBRunner :: YesodPersistBackend site ~ SQL.SqlBackend
|
||||||
#else
|
|
||||||
defaultGetDBRunner :: YesodPersistBackend site ~ SqlPersistT
|
|
||||||
#endif
|
|
||||||
=> (site -> Pool SQL.Connection)
|
=> (site -> Pool SQL.Connection)
|
||||||
-> HandlerT site IO (DBRunner site, HandlerT site IO ())
|
-> HandlerT site IO (DBRunner site, HandlerT site IO ())
|
||||||
defaultGetDBRunner getPool = do
|
defaultGetDBRunner getPool = do
|
||||||
@ -142,20 +124,9 @@ respondSourceDB :: YesodPersistRunner site
|
|||||||
respondSourceDB ctype = respondSource ctype . runDBSource
|
respondSourceDB ctype = respondSource ctype . runDBSource
|
||||||
|
|
||||||
-- | Get the given entity by ID, or return a 404 not found if it doesn't exist.
|
-- | Get the given entity by ID, or return a 404 not found if it doesn't exist.
|
||||||
#if MIN_VERSION_persistent(2, 0, 0)
|
|
||||||
get404 :: (MonadIO m, PersistStore (PersistEntityBackend val), PersistEntity val)
|
get404 :: (MonadIO m, PersistStore (PersistEntityBackend val), PersistEntity val)
|
||||||
=> Key val
|
=> Key val
|
||||||
-> ReaderT (PersistEntityBackend val) m val
|
-> ReaderT (PersistEntityBackend val) m val
|
||||||
#else
|
|
||||||
get404 :: ( PersistStore (t m)
|
|
||||||
, PersistEntity val
|
|
||||||
, Monad (t m)
|
|
||||||
, m ~ HandlerT site IO
|
|
||||||
, MonadTrans t
|
|
||||||
, PersistMonadBackend (t m) ~ PersistEntityBackend val
|
|
||||||
)
|
|
||||||
=> Key val -> t m val
|
|
||||||
#endif
|
|
||||||
get404 key = do
|
get404 key = do
|
||||||
mres <- get key
|
mres <- get key
|
||||||
case mres of
|
case mres of
|
||||||
@ -164,20 +135,9 @@ get404 key = do
|
|||||||
|
|
||||||
-- | Get the given entity by unique key, or return a 404 not found if it doesn't
|
-- | Get the given entity by unique key, or return a 404 not found if it doesn't
|
||||||
-- exist.
|
-- exist.
|
||||||
#if MIN_VERSION_persistent(2, 0, 0)
|
|
||||||
getBy404 :: (PersistUnique (PersistEntityBackend val), PersistEntity val, MonadIO m)
|
getBy404 :: (PersistUnique (PersistEntityBackend val), PersistEntity val, MonadIO m)
|
||||||
=> Unique val
|
=> Unique val
|
||||||
-> ReaderT (PersistEntityBackend val) m (Entity val)
|
-> ReaderT (PersistEntityBackend val) m (Entity val)
|
||||||
#else
|
|
||||||
getBy404 :: ( PersistUnique (t m)
|
|
||||||
, PersistEntity val
|
|
||||||
, m ~ HandlerT site IO
|
|
||||||
, Monad (t m)
|
|
||||||
, MonadTrans t
|
|
||||||
, PersistEntityBackend val ~ PersistMonadBackend (t m)
|
|
||||||
)
|
|
||||||
=> Unique val -> t m (Entity val)
|
|
||||||
#endif
|
|
||||||
getBy404 key = do
|
getBy404 key = do
|
||||||
mres <- getBy key
|
mres <- getBy key
|
||||||
case mres of
|
case mres of
|
||||||
@ -188,11 +148,3 @@ getBy404 key = do
|
|||||||
-- GHC 7.4.2 that leads to segfaults. This is a workaround.
|
-- GHC 7.4.2 that leads to segfaults. This is a workaround.
|
||||||
notFound' :: MonadIO m => m a
|
notFound' :: MonadIO m => m a
|
||||||
notFound' = liftIO $ throwIO $ HCError NotFound
|
notFound' = liftIO $ throwIO $ HCError NotFound
|
||||||
|
|
||||||
#if !MIN_VERSION_persistent(2, 0, 0)
|
|
||||||
instance MonadHandler m => MonadHandler (SqlPersistT m) where
|
|
||||||
type HandlerSite (SqlPersistT m) = HandlerSite m
|
|
||||||
liftHandlerT = lift . liftHandlerT
|
|
||||||
instance MonadWidget m => MonadWidget (SqlPersistT m) where
|
|
||||||
liftWidgetT = lift . liftWidgetT
|
|
||||||
#endif
|
|
||||||
|
|||||||
@ -29,11 +29,7 @@ mkYesod "App" [parseRoutes|
|
|||||||
|
|
||||||
instance Yesod App
|
instance Yesod App
|
||||||
instance YesodPersist App where
|
instance YesodPersist App where
|
||||||
#if MIN_VERSION_persistent(2, 0, 0)
|
|
||||||
type YesodPersistBackend App = SqlBackend
|
type YesodPersistBackend App = SqlBackend
|
||||||
#else
|
|
||||||
type YesodPersistBackend App = SqlPersistT
|
|
||||||
#endif
|
|
||||||
runDB = defaultRunDB appConfig appPool
|
runDB = defaultRunDB appConfig appPool
|
||||||
instance YesodPersistRunner App where
|
instance YesodPersistRunner App where
|
||||||
getDBRunner = defaultGetDBRunner appPool
|
getDBRunner = defaultGetDBRunner appPool
|
||||||
|
|||||||
@ -90,11 +90,7 @@ instance Yesod master => YesodSubDispatch EmbeddedStatic (HandlerT master IO) wh
|
|||||||
resp = case pathInfo req of
|
resp = case pathInfo req of
|
||||||
("res":_) -> stApp site req
|
("res":_) -> stApp site req
|
||||||
("widget":_) -> staticApp (widgetSettings site) req
|
("widget":_) -> staticApp (widgetSettings site) req
|
||||||
#if MIN_VERSION_wai(3,0,0)
|
|
||||||
_ -> ($ responseLBS status404 [] "Not Found")
|
_ -> ($ responseLBS status404 [] "Not Found")
|
||||||
#else
|
|
||||||
_ -> return $ responseLBS status404 [] "Not Found"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
-- | Create the haskell variable for the link to the entry
|
-- | Create the haskell variable for the link to the entry
|
||||||
mkRoute :: ComputedEntry -> Q [Dec]
|
mkRoute :: ComputedEntry -> Q [Dec]
|
||||||
|
|||||||
@ -107,11 +107,7 @@ prodEmbed e = do
|
|||||||
return $ ComputedEntry (ebHaskellName e) st link
|
return $ ComputedEntry (ebHaskellName e) st link
|
||||||
|
|
||||||
toApp :: (Request -> IO Response) -> Application
|
toApp :: (Request -> IO Response) -> Application
|
||||||
#if MIN_VERSION_wai(3, 0, 0)
|
|
||||||
toApp f req g = f req >>= g
|
toApp f req g = f req >>= g
|
||||||
#else
|
|
||||||
toApp = id
|
|
||||||
#endif
|
|
||||||
|
|
||||||
tryExtraDevelFiles :: [[T.Text] -> IO (Maybe (MimeType, BL.ByteString))] -> Application
|
tryExtraDevelFiles :: [[T.Text] -> IO (Maybe (MimeType, BL.ByteString))] -> Application
|
||||||
tryExtraDevelFiles = toApp . tryExtraDevelFiles'
|
tryExtraDevelFiles = toApp . tryExtraDevelFiles'
|
||||||
@ -133,19 +129,11 @@ tryExtraDevelFiles' (f:fs) r = do
|
|||||||
|
|
||||||
-- | Helper to create the development application at runtime
|
-- | Helper to create the development application at runtime
|
||||||
develApp :: StaticSettings -> [[T.Text] -> IO (Maybe (MimeType, BL.ByteString))] -> Application
|
develApp :: StaticSettings -> [[T.Text] -> IO (Maybe (MimeType, BL.ByteString))] -> Application
|
||||||
#if MIN_VERSION_wai(3, 0, 0)
|
|
||||||
develApp settings extra req sendResponse = do
|
develApp settings extra req sendResponse = do
|
||||||
staticApp settings {ssMaxAge = NoMaxAge} req $ \resp ->
|
staticApp settings {ssMaxAge = NoMaxAge} req $ \resp ->
|
||||||
if statusCode (responseStatus resp) == 404
|
if statusCode (responseStatus resp) == 404
|
||||||
then tryExtraDevelFiles extra req sendResponse
|
then tryExtraDevelFiles extra req sendResponse
|
||||||
else sendResponse resp
|
else sendResponse resp
|
||||||
#else
|
|
||||||
develApp settings extra req = do
|
|
||||||
resp <- staticApp settings {ssMaxAge = NoMaxAge} req
|
|
||||||
if statusCode (responseStatus resp) == 404
|
|
||||||
then tryExtraDevelFiles extra req
|
|
||||||
else return resp
|
|
||||||
#endif
|
|
||||||
|
|
||||||
-- | The type of 'addStaticContent'
|
-- | The type of 'addStaticContent'
|
||||||
type AddStaticContent site = T.Text -> T.Text -> BL.ByteString
|
type AddStaticContent site = T.Text -> T.Text -> BL.ByteString
|
||||||
|
|||||||
@ -47,11 +47,7 @@ webSockets :: (Y.MonadBaseControl IO m, Y.MonadHandler m) => WebSocketsT m () ->
|
|||||||
webSockets inner = do
|
webSockets inner = do
|
||||||
req <- Y.waiRequest
|
req <- Y.waiRequest
|
||||||
when (WaiWS.isWebSocketsReq req) $
|
when (WaiWS.isWebSocketsReq req) $
|
||||||
#if MIN_VERSION_wai(3, 0, 0)
|
|
||||||
Y.sendRawResponseNoConduit
|
Y.sendRawResponseNoConduit
|
||||||
#else
|
|
||||||
Y.sendRawResponse
|
|
||||||
#endif
|
|
||||||
$ \src sink -> control $ \runInIO -> WaiWS.runWebSockets
|
$ \src sink -> control $ \runInIO -> WaiWS.runWebSockets
|
||||||
WS.defaultConnectionOptions
|
WS.defaultConnectionOptions
|
||||||
(WaiWS.getRequestHead req)
|
(WaiWS.getRequestHead req)
|
||||||
|
|||||||
@ -76,12 +76,7 @@ defaultMainLog load getApp = do
|
|||||||
(toLogStr $ "Exception from Warp: " ++ show e)
|
(toLogStr $ "Exception from Warp: " ++ show e)
|
||||||
} app
|
} app
|
||||||
where
|
where
|
||||||
shouldLog' =
|
shouldLog' = Warp.defaultShouldDisplayException
|
||||||
#if MIN_VERSION_warp(2,1,3)
|
|
||||||
Warp.defaultShouldDisplayException
|
|
||||||
#else
|
|
||||||
const True
|
|
||||||
#endif
|
|
||||||
|
|
||||||
-- | Run your application continously, listening for SIGINT and exiting
|
-- | Run your application continously, listening for SIGINT and exiting
|
||||||
-- when received
|
-- when received
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user