import Data.Attempt
import Data.Attoparsec
import qualified Data.Attoparsec.Lazy as LP
+import Data.Attoparsec.Parsable
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as LS
import Data.ByteString.Lazy.Search
import Data.Text (Text)
import Network.HTTP.Lucu.Headers
import Network.HTTP.Lucu.MIMEParams
-import Network.HTTP.Lucu.MIMEType (MIMEType)
-import qualified Network.HTTP.Lucu.MIMEType as MT
-import Network.HTTP.Lucu.MIMEType.TH
+import Network.HTTP.Lucu.MIMEType
import Network.HTTP.Lucu.Parser
import Network.HTTP.Lucu.Parser.Http
import Network.HTTP.Lucu.Utils
, ([t| ContDispo |], [t| AsciiBuilder |])
]
--- |Parse \"multipart/form-data\" and return either @'Left' err@ or
--- @'Right' result@. Note that there are currently the following
+-- |Parse \"multipart/form-data\" to a list of @(name,
+-- formData)@. Note that there are currently the following
-- limitations:
--
-- * Multiple files embedded as \"multipart/mixed\" within the
-- * \"Content-Transfer-Encoding\" is always ignored.
--
-- * RFC 2388 (<http://tools.ietf.org/html/rfc2388#section-3>) says
--- that non-ASCII field names are encoded according to the method in
--- RFC 2047 (<http://tools.ietf.org/html/rfc2047>), but they won't
--- be decoded.
+-- that non-ASCII field names are encoded according to the method
+-- in RFC 2047 (<http://tools.ietf.org/html/rfc2047>), but this
+-- function currently doesn't decode them.
parseMultipartFormData ∷ Ascii -- ^boundary
→ LS.ByteString -- ^input
→ Either String [(Ascii, FormData)]
defaultCType = [mimeType| text/plain |]
partHeader ∷ Parser Headers
-partHeader = crlf *> headers
+partHeader = crlf *> parser
getContDispo ∷ MonadError String m ⇒ Headers → m ContDispo
{-# INLINEABLE getContDispo #-}
contentDisposition ∷ Parser ContDispo
contentDisposition
- = (ContDispo <$> (cs <$> token) ⊛ mimeParams)
+ = (ContDispo <$> (cs <$> token) ⊛ parser)
<?>
"contentDisposition"
Nothing
→ return Nothing
Just str
- → case parseOnly (finishOff MT.mimeType) $ cs str of
+ → case parseOnly (finishOff parser) $ cs str of
Right d → return $ Just d
Left err → throwError $ "malformed Content-Type: "
⊕ cs str