, inputChunk -- Int -> Resource String
, inputBS -- Int -> Resource ByteString
, inputChunkBS -- Int -> Resource ByteString
+ , inputForm -- Int -> Resource [(String, String)]
, defaultLimit -- Int
, setStatus -- StatusCode -> Resource ()
return chunk
+-- application/x-www-form-urlencoded または multipart/form-data をパー
+-- スする。もし Content-Type が無かったら BadRequest で終了し、未對應の
+-- タイプであったら UnsupportedMediaType で終了する。
+inputForm :: Int -> Resource [(String, String)]
+inputForm limit
+ = do cTypeM <- getContentType
+ case cTypeM of
+ Nothing
+ -> abort BadRequest [] (Just "Missing Content-Type")
+ Just (MIMEType "application" "x-www-form-urlencoded" _)
+ -> readWWWFormURLEncoded
+ Just (MIMEType "multipart" "form-data" _)
+ -> readMultipartFormData
+ Just cType
+ -> abort UnsupportedMediaType [] (Just $ "Unsupported media type: "
+ ++ show cType)
+ where
+ readWWWFormURLEncoded
+ = do src <- input limit
+ return $ do pairStr <- splitBy (\ c -> c == ';' || c == '&') src
+ let pair = break (== '=') pairStr
+ return ( unEscapeString $ fst pair
+ , unEscapeString $ snd pair
+ )
+ readMultipartFormData -- FIXME: 未對應
+ = abort UnsupportedMediaType []
+ (Just $ "Sorry, inputForm does not currently support multipart/form-data.")
+
+
defaultLimit :: Int
defaultLimit = (-1)