@@ -23,11 +23,10 @@ import Data.MediaType.Common (applicationFormURLEncoded)
2323import Data.Monoid (class Monoid )
2424import Data.Newtype (class Newtype , unwrap )
2525import Data.StrMap (lookup )
26- import Data.String (split , joinWith , Pattern (Pattern))
27- import Data.Traversable (sequence )
28- import Data.Tuple (Tuple (Tuple))
29- import Global (decodeURIComponent )
26+ import Data.String (Pattern (Pattern), split )
27+ import Data.Tuple (Tuple )
3028import Hyper.Conn (Conn )
29+ import Hyper.Form.Urlencoded (parseUrlencoded )
3130import Hyper.Middleware (Middleware )
3231import Hyper.Middleware.Class (getConn )
3332import Hyper.Request (class Request , class ReadableBody , getRequestData , readBody )
@@ -60,24 +59,6 @@ parseContentMediaType = split (Pattern ";")
6059 >>> head
6160 >>> map MediaType
6261
63-
64- toTuple :: Array String -> Either String (Tuple String (Maybe String ))
65- toTuple kv =
66- case kv of
67- [key] ->
68- pure (Tuple (decodeURIComponent key) Nothing )
69- [key, value] ->
70- pure (Tuple (decodeURIComponent key) (Just (decodeURIComponent value)))
71- parts ->
72- throwError (" Invalid form key-value pair: " <> joinWith " " parts)
73-
74-
75- splitPairs :: String → Either String (Array (Tuple String (Maybe String )))
76- splitPairs = split (Pattern " &" )
77- >>> map (split (Pattern " =" ))
78- >>> map toTuple
79- >>> sequence
80-
8162parseForm ∷ forall m req res c
8263 . Monad m
8364 => Request req m
@@ -95,7 +76,7 @@ parseForm = do
9576 Nothing ->
9677 ipure (Left " Missing or invalid content-type header." )
9778 Just mediaType | mediaType == applicationFormURLEncoded ->
98- ipure (Form <$> splitPairs body)
79+ ipure (Form <$> parseUrlencoded body)
9980 Just mediaType ->
10081 ipure (Left (" Cannot parse media of type: " <> show mediaType))
10182 where bind = ibind
0 commit comments