X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FMultipartForm.hs;h=16d8f28017425e35fe0273e9c39e7326bea458a1;hb=e49345ce5e6c0190c826d130d51ec42ee9f09a67;hp=edba0d50f1e33e589feeb10b57ec71dbe4ebb3da;hpb=2089e7b8c07ae67292073b4113eb14d858a4a2c0;p=Lucu.git diff --git a/Network/HTTP/Lucu/MultipartForm.hs b/Network/HTTP/Lucu/MultipartForm.hs index edba0d5..16d8f28 100644 --- a/Network/HTTP/Lucu/MultipartForm.hs +++ b/Network/HTTP/Lucu/MultipartForm.hs @@ -39,6 +39,7 @@ import Data.Text (Text) import qualified Data.Text as T import Network.HTTP.Lucu.Headers import Network.HTTP.Lucu.MIMEType +import Network.HTTP.Lucu.Parser import Network.HTTP.Lucu.Parser.Http import Network.HTTP.Lucu.RFC2231 import Prelude.Unicode @@ -47,8 +48,11 @@ import Prelude.Unicode -- name. data FormData = FormData { + -- | @'Nothing'@ for non-file values. fdFileName ∷ !(Maybe Text) + -- | MIME Type of this value, defaulted to \"text/plain\". , fdMIMEType ∷ !MIMEType + -- | The form value. , fdContent ∷ !(LS.ByteString) } @@ -77,13 +81,13 @@ printContDispo d -- limitations: -- -- * Multiple files embedded as \"multipart/mixed\" within the --- \"multipart/form-data\" aren't decomposed. +-- \"multipart/form-data\" won't be decomposed. -- --- * \"Content-Transfer-Encoding\"s are always ignored. +-- * \"Content-Transfer-Encoding\" is always ignored. -- -- * RFC 2388 says that non-ASCII field names are encoded according -- to the method in RFC 2047 --- , but they aren't +-- , but they won't be -- decoded. parseMultipartFormData ∷ Ascii -- ^boundary → LS.ByteString -- ^input @@ -128,12 +132,7 @@ prologue boundary "prologue" epilogue ∷ Parser () -epilogue = ( (string "--" "suffix") - *> - crlf - *> - endOfInput - ) +epilogue = finishOff ((string "--" "suffix") *> crlf) "epilogue" @@ -169,16 +168,12 @@ getContDispo hdrs Nothing → throwError "Content-Disposition is missing" Just str - → case parseOnly p $ A.toByteString str of + → case parseOnly (finishOff contentDisposition) $ A.toByteString str of Right d → return d Left err → throwError $ "malformed Content-Disposition: " ⧺ A.toString str ⧺ ": " ⧺ err - where - p = do dispo ← contentDisposition - endOfInput - return dispo contentDisposition ∷ Parser ContDispo contentDisposition @@ -193,16 +188,12 @@ getContType hdrs Nothing → return Nothing Just str - → case parseOnly p $ A.toByteString str of + → case parseOnly (finishOff mimeType) $ A.toByteString str of Right d → return $ Just d Left err → throwError $ "malformed Content-Type: " ⧺ A.toString str ⧺ ": " ⧺ err - where - p = do t ← mimeType - endOfInput - return t getBody ∷ MonadError String m ⇒ Ascii