Skip to content
Snippets Groups Projects
Verified Commit aad94594 authored by jan.hamal.dvorak's avatar jan.hamal.dvorak
Browse files

Clean up Action types a bit

parent eee85ce3
No related branches found
No related tags found
No related merge requests found
...@@ -221,6 +221,12 @@ where ...@@ -221,6 +221,12 @@ where
type ResponseMaker = Status -> ResponseHeaders -> Response type ResponseMaker = Status -> ResponseHeaders -> Response
-- |
-- Fields and files sent using a web form.
--
type FormData = ([(Text, Text)], [(Text, FileInfo FilePath)])
-- | -- |
-- Types of the request body. -- Types of the request body.
-- --
...@@ -229,7 +235,7 @@ where ...@@ -229,7 +235,7 @@ where
-- ^ Body has not yet been touched. -- ^ Body has not yet been touched.
| BodyTainted | BodyTainted
-- ^ Body has been partially consumed. -- ^ Body has been partially consumed.
| BodyForm ([(Text, Text)], [(Text, FileInfo FilePath)]) | BodyForm FormData
-- ^ Body has been successfully parsed as a form. -- ^ Body has been successfully parsed as a form.
| BodyJSON Value | BodyJSON Value
-- ^ Body has been successfully parsed as a JSON. -- ^ Body has been successfully parsed as a JSON.
...@@ -608,7 +614,7 @@ where ...@@ -608,7 +614,7 @@ where
-- Use 'setBodyLimit' to adjust the limit to your liking. -- Use 'setBodyLimit' to adjust the limit to your liking.
-- --
getFields :: (MonadAction m) => m [(Text, Text)] getFields :: (MonadAction m) => m [(Text, Text)]
getFields = map cs2 <$> fst <$> getForm getFields = map cs2 <$> fst <$> getFormData
-- | -- |
...@@ -644,7 +650,7 @@ where ...@@ -644,7 +650,7 @@ where
-- files uploaded through the form. -- files uploaded through the form.
-- --
getFiles :: (MonadAction m) => m [(Text, FileInfo FilePath)] getFiles :: (MonadAction m) => m [(Text, FileInfo FilePath)]
getFiles = snd <$> getForm getFiles = snd <$> getFormData
-- | -- |
...@@ -667,9 +673,16 @@ where ...@@ -667,9 +673,16 @@ where
-- Backend for both 'getFields' and 'getFiles' that parses, -- Backend for both 'getFields' and 'getFiles' that parses,
-- caches and returns form data. -- caches and returns form data.
-- --
getForm :: (MonadAction m) -- * Throws 'UnsupportedMediaType' if the Content-Type does not
=> m ([(Text, Text)], [(Text, FileInfo FilePath)]) -- indicate a form payload.
getForm = do --
-- * Throws 'BadRequest' if the payload fails to parse.
--
-- * Throws 'PayloadTooLarge' if the payload size limit is exceeded.
-- Use 'setBodyLimit' to adjust the limit to your liking.
--
getFormData :: (MonadAction m) => m FormData
getFormData = do
cache <- getActionField aeBody cache <- getActionField aeBody
case cache of case cache of
...@@ -708,8 +721,7 @@ where ...@@ -708,8 +721,7 @@ where
-- | -- |
-- Convert form names and fields from 'ByteString' to 'Text'. -- Convert form names and fields from 'ByteString' to 'Text'.
-- --
csForm :: ([Param], [File FilePath]) csForm :: ([Param], [File FilePath]) -> FormData
-> ([(Text, Text)], [(Text, FileInfo FilePath)])
csForm (ps, fs) = (map cs2 ps, map cs1 fs) csForm (ps, fs) = (map cs2 ps, map cs1 fs)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment