Skip to content

Commit

Permalink
use latest wai-extra
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Zocca committed Jan 12, 2024
1 parent 3ed744c commit 5519ee8
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
7 changes: 3 additions & 4 deletions Web/Scotty/Action.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Web.Scotty.Action
, rawResponse
, files
, filesOpts
, ParseRequestBodyOptions, defaultParseRequestBodyOptions
, W.ParseRequestBodyOptions, W.defaultParseRequestBodyOptions
, finish
, header
, headers
Expand Down Expand Up @@ -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)

Check warning on line 98 in Web/Scotty/Action.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.6.3

The qualified import of ‘BackEnd, File, Param, RequestBodyType,

Check warning on line 98 in Web/Scotty/Action.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.2.8

The qualified import of ‘BackEnd, File, Param, RequestBodyType,

Check warning on line 98 in Web/Scotty/Action.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.6.2

The qualified import of ‘BackEnd, File, Param, RequestBodyType,

Check warning on line 98 in Web/Scotty/Action.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.0.2

The qualified import of ‘BackEnd, File, Param, RequestBodyType,

Check warning on line 98 in Web/Scotty/Action.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 8.10.7

The qualified import of ‘BackEnd, File, Param, RequestBodyType,

Check warning on line 98 in Web/Scotty/Action.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.4.6

The qualified import of ‘BackEnd, File, Param, RequestBodyType,

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)

Check warning on line 103 in Web/Scotty/Action.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.6.3

The import of ‘decodeUtf8Lenient’

Check warning on line 103 in Web/Scotty/Action.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.6.2

The import of ‘decodeUtf8Lenient’

Check warning on line 103 in Web/Scotty/Action.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.4.6

The import of ‘decodeUtf8Lenient’
import UnliftIO.Exception (Handler(..), catch, catches, throwIO)

Expand Down Expand Up @@ -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
Expand Down
13 changes: 6 additions & 7 deletions Web/Scotty/Body.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Web.Scotty.Body (
, getBodyAction
, getBodyChunkAction
-- wai-extra
, RequestParseException(..)
, W.RequestParseException(..)
) where

import Control.Concurrent.MVar
Expand All @@ -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(..))

Check warning on line 25 in Web/Scotty/Body.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.6.3

The qualified import of ‘BackEnd, lbsBackEnd, parseRequestBodyEx,

Check warning on line 25 in Web/Scotty/Body.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.6.3

The import item ‘ParseRequestBodyOptions(..)’ suggests that

Check warning on line 25 in Web/Scotty/Body.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.2.8

The import item ‘ParseRequestBodyOptions(..)’ suggests that

Check warning on line 25 in Web/Scotty/Body.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.2.8

The qualified import of ‘BackEnd, lbsBackEnd, parseRequestBodyEx,

Check warning on line 25 in Web/Scotty/Body.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.6.2

The qualified import of ‘BackEnd, lbsBackEnd, parseRequestBodyEx,

Check warning on line 25 in Web/Scotty/Body.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.6.2

The import item ‘ParseRequestBodyOptions(..)’ suggests that

Check warning on line 25 in Web/Scotty/Body.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.0.2

The import item ‘ParseRequestBodyOptions(..)’ suggests that

Check warning on line 25 in Web/Scotty/Body.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.0.2

The qualified import of ‘BackEnd, lbsBackEnd, parseRequestBodyEx,

Check warning on line 25 in Web/Scotty/Body.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 8.10.7

The import item ‘ParseRequestBodyOptions(..)’ suggests that

Check warning on line 25 in Web/Scotty/Body.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 8.10.7

The qualified import of ‘BackEnd, lbsBackEnd, parseRequestBodyEx,

Check warning on line 25 in Web/Scotty/Body.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.4.6

The qualified import of ‘BackEnd, lbsBackEnd, parseRequestBodyEx,

Check warning on line 25 in Web/Scotty/Body.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.4.6

The import item ‘ParseRequestBodyOptions(..)’ suggests that
import UnliftIO (MonadUnliftIO(..))

Check warning on line 26 in Web/Scotty/Body.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.6.3

The import of ‘UnliftIO’ is redundant

Check warning on line 26 in Web/Scotty/Body.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.2.8

The import of ‘UnliftIO’ is redundant

Check warning on line 26 in Web/Scotty/Body.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.6.2

The import of ‘UnliftIO’ is redundant

Check warning on line 26 in Web/Scotty/Body.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.0.2

The import of ‘UnliftIO’ is redundant

Check warning on line 26 in Web/Scotty/Body.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 8.10.7

The import of ‘UnliftIO’ is redundant

Check warning on line 26 in Web/Scotty/Body.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.4.6

The import of ‘UnliftIO’ is redundant
import UnliftIO.Exception (Handler(..), catch, catches, throwIO)

Check warning on line 27 in Web/Scotty/Body.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.6.3

The import of ‘catch’ from module ‘UnliftIO.Exception’ is redundant

Check warning on line 27 in Web/Scotty/Body.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.2.8

The import of ‘catch’ from module ‘UnliftIO.Exception’ is redundant

Check warning on line 27 in Web/Scotty/Body.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.6.2

The import of ‘catch’ from module ‘UnliftIO.Exception’ is redundant

Check warning on line 27 in Web/Scotty/Body.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.0.2

The import of ‘catch’ from module ‘UnliftIO.Exception’ is redundant

Check warning on line 27 in Web/Scotty/Body.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 8.10.7

The import of ‘catch’ from module ‘UnliftIO.Exception’ is redundant

Check warning on line 27 in Web/Scotty/Body.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.4.6

The import of ‘catch’ from module ‘UnliftIO.Exception’ is redundant

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
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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])
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion Web/Scotty/Internal/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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(..))

Check warning on line 43 in Web/Scotty/Internal/Types.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.6.3

The import item ‘ParseRequestBodyOptions(..)’ suggests that

Check warning on line 43 in Web/Scotty/Internal/Types.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.2.8

The import item ‘ParseRequestBodyOptions(..)’ suggests that

Check warning on line 43 in Web/Scotty/Internal/Types.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.6.2

The import item ‘ParseRequestBodyOptions(..)’ suggests that

Check warning on line 43 in Web/Scotty/Internal/Types.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.0.2

The import item ‘ParseRequestBodyOptions(..)’ suggests that

Check warning on line 43 in Web/Scotty/Internal/Types.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 8.10.7

The import item ‘ParseRequestBodyOptions(..)’ suggests that

Check warning on line 43 in Web/Scotty/Internal/Types.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.4.6

The import item ‘ParseRequestBodyOptions(..)’ suggests that

import UnliftIO.Exception (Handler(..), catch, catches)

import qualified Web.Scotty.Internal.WaiParseSafe as WPS (ParseRequestBodyOptions(..), defaultParseRequestBodyOptions, RequestParseException(..))



--------------------- Options -----------------------
Expand Down
3 changes: 2 additions & 1 deletion Web/Scotty/Route.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ 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

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
>>> :{
Expand Down
4 changes: 2 additions & 2 deletions scotty.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 5519ee8

Please sign in to comment.