digestive-functors-snap 0.3.2.0 → 0.3.2.1
raw patch · 2 files changed
+10/−19 lines, 2 files
Files
digestive-functors-snap.cabal view
@@ -1,5 +1,5 @@ Name: digestive-functors-snap-Version: 0.3.2.0+Version: 0.3.2.1 Synopsis: Snap backend for the digestive-functors library Description: Snap backend for the digestive-functors library Homepage: http://github.com/jaspervdj/digestive-functors
src/Text/Digestive/Snap.hs view
@@ -28,25 +28,21 @@ type SnapPartPolicy = Snap.PartInfo -> Snap.PartUploadPolicy data SnapFormConfig = SnapFormConfig- { -- | Can be used to override the method detected by Snap, in case you e.g.- -- want to perform a 'postForm' even in case of a GET request.- method :: Maybe Method- , temporaryDirectory :: Maybe FilePath+ { temporaryDirectory :: Maybe FilePath , uploadPolicy :: Snap.UploadPolicy , partPolicy :: SnapPartPolicy } defaultSnapFormConfig :: SnapFormConfig defaultSnapFormConfig = SnapFormConfig- { method = Nothing- , temporaryDirectory = Nothing+ { temporaryDirectory = Nothing , uploadPolicy = Snap.defaultUploadPolicy , partPolicy = const $ Snap.allowWithMaximumSize (128 * 1024) } snapEnv :: Snap.MonadSnap m => [(Text, FilePath)] -> Env m snapEnv allFiles path = do- inputs <- map (TextInput . T.decodeUtf8) . findParams <$> Snap.getParams+ inputs <- map (TextInput . T.decodeUtf8) . findParams <$> Snap.getPostParams let files = map (FileInput . snd) $ filter ((== name) . fst) allFiles return $ inputs ++ files where@@ -76,7 +72,7 @@ -- | Runs a form with the HTTP input provided by Snap. -- -- Automatically picks between 'getForm' and 'postForm' based on the request--- method. Set 'method' in the 'SnapFormConfig' to override this behaviour.+-- method. runForm :: Snap.MonadSnap m => Text -- ^ Name for the form -> Form v m a -- ^ Form to run@@ -86,22 +82,17 @@ -- | Runs a form with a custom upload policy, and HTTP input from snap. -- -- Automatically picks between 'getForm' and 'postForm' based on request--- method. Set 'method' in the 'SnapFormConfig' to override this behaviour.+-- method. runFormWith :: Snap.MonadSnap m => SnapFormConfig -- ^ Tempdir and upload policies -> Text -- ^ Name for the form -> Form v m a -- ^ Form to run -> m (View v, Maybe a) -- ^ Result-runFormWith config name form = do- m <- maybe snapMethod return (method config)- case m of- Get -> return (getForm name form, Nothing)- Post -> do+runFormWith config name form = Snap.getRequest >>= \rq ->+ case Snap.rqMethod rq of+ Snap.GET -> return (getForm name form, Nothing)+ _ -> do files <- case formEncType form of UrlEncoded -> return [] MultiPart -> snapFiles config postForm name form (snapEnv files)- where- snapMethod = toMethod . Snap.rqMethod <$> Snap.getRequest- toMethod Snap.GET = Get- toMethod _ = Post