diff --git a/Web/Scotty/Action.hs b/Web/Scotty/Action.hs index 168fce1..6e984b6 100644 --- a/Web/Scotty/Action.hs +++ b/Web/Scotty/Action.hs @@ -13,7 +13,7 @@ module Web.Scotty.Action , rawResponse , files , filesOpts - , ParseRequestBodyOptions, defaultParseRequestBodyOptions + , W.ParseRequestBodyOptions, W.defaultParseRequestBodyOptions , finish , header , headers @@ -95,12 +95,11 @@ import Network.HTTP.Types.Status #endif import Network.Wai (Request, Response, StreamingBody, Application, requestHeaders) import Network.Wai.Handler.Warp (InvalidRequest(..)) -import qualified Network.Wai.Parse as W (FileInfo(..), File, Param, getRequestBodyType, BackEnd, lbsBackEnd, tempFileBackEnd, sinkRequestBody, RequestBodyType(..)) +import qualified Network.Wai.Parse as W (FileInfo(..), File, Param, getRequestBodyType, BackEnd, lbsBackEnd, tempFileBackEnd, sinkRequestBody, RequestBodyType(..), ParseRequestBodyOptions, defaultParseRequestBodyOptions, RequestParseException(..), parseRequestBodyEx) import Numeric.Natural import Web.Scotty.Internal.Types -import Web.Scotty.Internal.WaiParseSafe (ParseRequestBodyOptions, defaultParseRequestBodyOptions, RequestParseException(..), parseRequestBodyEx) import Web.Scotty.Util (mkResponse, addIfNotPresent, add, replace, lazyTextToStrictByteString, decodeUtf8Lenient) import UnliftIO.Exception (Handler(..), catch, catches, throwIO) @@ -284,7 +283,7 @@ files = do -- -- NB the temp files are deleted when the continuation exits. filesOpts :: MonadUnliftIO m => - ParseRequestBodyOptions + W.ParseRequestBodyOptions -> ([Param] -> [File FilePath] -> ActionT m a) -- ^ temp files validation, storage etc -> ActionT m a filesOpts prbo io = runResourceT $ withInternalState $ \istate -> do diff --git a/Web/Scotty/Body.hs b/Web/Scotty/Body.hs index ab61a8b..c46f472 100644 --- a/Web/Scotty/Body.hs +++ b/Web/Scotty/Body.hs @@ -9,7 +9,7 @@ module Web.Scotty.Body ( , getBodyAction , getBodyChunkAction -- wai-extra - , RequestParseException(..) + , W.RequestParseException(..) ) where import Control.Concurrent.MVar @@ -22,14 +22,13 @@ import qualified Data.ByteString.Lazy.Char8 as BL import qualified GHC.Exception as E (throw) import Network.Wai (Request(..), getRequestBodyChunk) import qualified Network.Wai.Handler.Warp as Warp (InvalidRequest(..)) -import qualified Network.Wai.Parse as W (File, Param, getRequestBodyType, BackEnd, lbsBackEnd, tempFileBackEnd, sinkRequestBody, RequestBodyType(..)) +import qualified Network.Wai.Parse as W (File, Param, getRequestBodyType, BackEnd, lbsBackEnd, tempFileBackEnd, sinkRequestBody, RequestBodyType(..), sinkRequestBodyEx, parseRequestBodyEx, RequestParseException(..), ParseRequestBodyOptions(..)) import UnliftIO (MonadUnliftIO(..)) import UnliftIO.Exception (Handler(..), catch, catches, throwIO) import Web.Scotty.Internal.Types (BodyInfo(..), BodyChunkBuffer(..), BodyPartiallyStreamed(..), RouteOptions(..), File, ScottyException(..), Param) import Web.Scotty.Util (readRequestBody, decodeUtf8Lenient) -import Web.Scotty.Internal.WaiParseSafe (sinkRequestBodyEx, parseRequestBodyEx, RequestParseException(..), ParseRequestBodyOptions(..)) -- | Make a new BodyInfo with readProgress at 0 and an empty BodyChunkBuffer. newBodyInfo :: (MonadIO m) => Request -> m BodyInfo @@ -50,7 +49,7 @@ cloneBodyInfo (BodyInfo _ chunkBufferVar getChunk) = liftIO $ do -- NB : catches exceptions from 'warp' and 'wai-extra' and wraps them into 'ScottyException' getFormParamsAndFilesAction :: InternalState - -> ParseRequestBodyOptions + -> W.ParseRequestBodyOptions -> Request -- ^ only used for its body type -> BodyInfo -- ^ the request body contents are read from here -> RouteOptions @@ -70,7 +69,7 @@ getFormParamsAndFilesAction istate prbo req bodyInfo opts = do handleWaiParseSafeExceptions :: MonadIO m => [Handler m a] handleWaiParseSafeExceptions = [h1, h2] where - h1 = Handler (\ (e :: RequestParseException ) -> throwIO $ WaiRequestParseException e) + h1 = Handler (\ (e :: W.RequestParseException ) -> throwIO $ WaiRequestParseException e) h2 = Handler (\(e :: Warp.InvalidRequest) -> throwIO $ WarpRequestException e) -- | Adapted from wai-extra's Network.Wai.Parse, modified to accept body as list of Bytestrings. @@ -79,7 +78,7 @@ handleWaiParseSafeExceptions = [h1, h2] -- the raw body, even if they also want to call wai-extra's parsing routines. parseRequestBodyExBS :: MonadIO m => InternalState - -> ParseRequestBodyOptions + -> W.ParseRequestBodyOptions -> [B.ByteString] -> Maybe W.RequestBodyType -> m ([W.Param], [W.File FilePath]) @@ -92,7 +91,7 @@ parseRequestBodyExBS istate o bl rty = let provider = modifyMVar mvar $ \bsold -> case bsold of [] -> return ([], B.empty) (b:bs) -> return (bs, b) - liftIO $ sinkRequestBodyEx o (W.tempFileBackEnd istate) rbt provider + liftIO $ W.sinkRequestBodyEx o (W.tempFileBackEnd istate) rbt provider -- | Retrieve the entire body, using the cached chunks in the BodyInfo and reading any other diff --git a/Web/Scotty/Internal/Types.hs b/Web/Scotty/Internal/Types.hs index 4b885c5..793bc12 100644 --- a/Web/Scotty/Internal/Types.hs +++ b/Web/Scotty/Internal/Types.hs @@ -40,10 +40,11 @@ import Network.Wai hiding (Middleware, Application) import qualified Network.Wai as Wai import qualified Network.Wai.Handler.Warp as W (Settings, defaultSettings, InvalidRequest(..)) import Network.Wai.Parse (FileInfo) +import qualified Network.Wai.Parse as WPS (ParseRequestBodyOptions(..), defaultParseRequestBodyOptions, RequestParseException(..)) import UnliftIO.Exception (Handler(..), catch, catches) -import qualified Web.Scotty.Internal.WaiParseSafe as WPS (ParseRequestBodyOptions(..), defaultParseRequestBodyOptions, RequestParseException(..)) + --------------------- Options ----------------------- diff --git a/Web/Scotty/Route.hs b/Web/Scotty/Route.hs index 64a633e..0410c71 100644 --- a/Web/Scotty/Route.hs +++ b/Web/Scotty/Route.hs @@ -17,6 +17,7 @@ import qualified Data.Text as T import Network.HTTP.Types import Network.Wai (Request(..)) +import Network.Wai.Parse (ParseRequestBodyOptions(..)) import qualified Text.Regex as Regex @@ -24,7 +25,7 @@ import Web.Scotty.Action import Web.Scotty.Internal.Types (RoutePattern(..), RouteOptions, ActionEnv(..), ActionT, ScottyState(..), ScottyT(..), File, ErrorHandler, Middleware, BodyInfo, handler, addRoute, defaultScottyResponse) import Web.Scotty.Util (decodeUtf8Lenient) import Web.Scotty.Body (cloneBodyInfo, getBodyAction, getBodyChunkAction, getFormParamsAndFilesAction) -import Web.Scotty.Internal.WaiParseSafe (ParseRequestBodyOptions(..)) + {- $setup >>> :{ diff --git a/scotty.cabal b/scotty.cabal index aa3e643..da1342a 100644 --- a/scotty.cabal +++ b/scotty.cabal @@ -66,7 +66,7 @@ Library Web.Scotty.Cookie other-modules: Web.Scotty.Action Web.Scotty.Body - Web.Scotty.Internal.WaiParseSafe + -- Web.Scotty.Internal.WaiParseSafe Web.Scotty.Route Web.Scotty.Trans.Lazy Web.Scotty.Util @@ -93,7 +93,7 @@ Library transformers-compat >= 0.4 && < 0.8, unliftio >= 0.2, wai >= 3.0.0 && < 3.3, - wai-extra >= 3.0.0 && < 3.2, + wai-extra >= 3.1.14, warp >= 3.0.13 && < 3.4 if impl(ghc < 8.0)