packages feed

digestive-functors-snap 0.3.1.0 → 0.3.2.0

raw patch · 2 files changed

+19/−10 lines, 2 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

+ Text.Digestive.Snap: method :: SnapFormConfig -> Maybe Method
- Text.Digestive.Snap: SnapFormConfig :: Maybe FilePath -> UploadPolicy -> SnapPartPolicy -> SnapFormConfig
+ Text.Digestive.Snap: SnapFormConfig :: Maybe Method -> Maybe FilePath -> UploadPolicy -> SnapPartPolicy -> SnapFormConfig

Files

digestive-functors-snap.cabal view
@@ -1,5 +1,5 @@ Name:          digestive-functors-snap-Version:       0.3.1.0+Version:       0.3.2.0 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,21 +28,25 @@ type SnapPartPolicy = Snap.PartInfo -> Snap.PartUploadPolicy  data SnapFormConfig = SnapFormConfig-    { temporaryDirectory :: Maybe FilePath+    { -- | 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     , uploadPolicy       :: Snap.UploadPolicy     , partPolicy         :: SnapPartPolicy     }  defaultSnapFormConfig :: SnapFormConfig defaultSnapFormConfig = SnapFormConfig-    { temporaryDirectory = Nothing+    { method             = 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.getPostParams+    inputs <- map (TextInput . T.decodeUtf8) . findParams <$> Snap.getParams     let files = map (FileInput . snd) $ filter ((== name) . fst) allFiles     return $ inputs ++ files   where@@ -72,7 +76,7 @@ -- | Runs a form with the HTTP input provided by Snap. -- -- Automatically picks between 'getForm' and 'postForm' based on the request--- method.+-- method. Set 'method' in the 'SnapFormConfig' to override this behaviour. runForm :: Snap.MonadSnap m         => Text                 -- ^ Name for the form         -> Form v m a           -- ^ Form to run@@ -82,17 +86,22 @@ -- | Runs a form with a custom upload policy, and HTTP input from snap. -- -- Automatically picks between 'getForm' and 'postForm' based on request--- method.+-- method. Set 'method' in the 'SnapFormConfig' to override this behaviour. 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 = Snap.getRequest >>= \rq ->-    case Snap.rqMethod rq of-        Snap.GET -> return (getForm name form, Nothing)-        _        -> do+runFormWith config name form = do+    m <- maybe snapMethod return (method config)+    case m of+        Get  -> return (getForm name form, Nothing)+        Post -> 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