@@ -3,16 +3,11 @@ module Hyper.Form
33 , optional
44 , required
55 , parseForm
6- , fromForm
7- , toForm
8- , class FromForm
9- , class ToForm
10- , parseFromForm
116 ) where
127
138import Prelude
14- import Data.Tuple as Tuple
15- import Control.IxMonad (ibind , ipure , (:>>=) )
9+
10+ import Control.IxMonad (ibind , ipure )
1611import Control.Monad.Error.Class (throwError )
1712import Data.Array (head )
1813import Data.Either (Either (..))
@@ -25,7 +20,9 @@ import Data.Newtype (class Newtype, unwrap)
2520import Data.StrMap (lookup )
2621import Data.String (Pattern (Pattern), split )
2722import Data.Tuple (Tuple )
23+ import Data.Tuple as Tuple
2824import Hyper.Conn (Conn )
25+ import Hyper.Form.Urlencoded (Options ) as Urlencoded
2926import Hyper.Form.Urlencoded (parseUrlencoded )
3027import Hyper.Middleware (Middleware )
3128import Hyper.Middleware.Class (getConn )
@@ -64,45 +61,22 @@ parseForm ∷ forall m req res c
6461 . Monad m
6562 => Request req m
6663 => ReadableBody req m String
67- => Middleware
64+ => Urlencoded.Options
65+ -> Middleware
6866 m
6967 (Conn req res c )
7068 (Conn req res c )
7169 (Either String Form )
72- parseForm = do
70+ parseForm opts = do
7371 conn <- getConn
7472 { headers } <- getRequestData
7573 body <- readBody
7674 case lookup " content-type" headers >>= parseContentMediaType of
7775 Nothing ->
7876 ipure (Left " Missing or invalid content-type header." )
7977 Just mediaType | mediaType == applicationFormURLEncoded ->
80- ipure (Form <$> parseUrlencoded body)
78+ ipure (Form <$> parseUrlencoded opts body)
8179 Just mediaType ->
8280 ipure (Left (" Cannot parse media of type: " <> show mediaType))
8381 where bind = ibind
8482
85-
86- class ToForm a where
87- toForm ∷ a → Form
88-
89-
90- class FromForm a where
91- fromForm ∷ Form → Either String a
92-
93-
94- parseFromForm ∷ forall m req res c a
95- . Monad m
96- => Request req m
97- => ReadableBody req m String
98- => FromForm a
99- => Middleware
100- m
101- (Conn req res c )
102- (Conn req res c )
103- (Either String a )
104- parseFromForm =
105- parseForm :>>=
106- case _ of
107- Left err -> ipure (Left err)
108- Right form -> ipure (fromForm form)
0 commit comments