From 59eb67e087f52b07175ede0fafd199969d29f665 Mon Sep 17 00:00:00 2001 From: Konstantine Rybnikov Date: Fri, 9 Aug 2013 23:13:56 +0300 Subject: [PATCH] Add error-reporting when trying to add file or post-param after binary content is set. --- yesod-test/Yesod/Test.hs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/yesod-test/Yesod/Test.hs b/yesod-test/Yesod/Test.hs index 74bdcc02..591e660d 100644 --- a/yesod-test/Yesod/Test.hs +++ b/yesod-test/Yesod/Test.hs @@ -49,6 +49,7 @@ module Yesod.Test , addPostParam , addGetParam , addFile + , setRequestBody , RequestBuilder , setUrl @@ -375,7 +376,7 @@ printMatches query = do addPostParam :: T.Text -> T.Text -> RequestBuilder site () addPostParam name value = ST.modify $ \rbd -> rbd { rbdPostData = (addPostData (rbdPostData rbd)) } - where addPostData x@(BinaryPostData _) = x + where addPostData (BinaryPostData _) = error "Trying to add post param to binary content." addPostData (MultipleItemsPostData posts) = MultipleItemsPostData $ ReqKvPart name value : posts @@ -392,7 +393,7 @@ addFile :: T.Text -> FilePath -> T.Text -> RequestBuilder site () addFile name path mimetype = do contents <- liftIO $ BSL8.readFile path ST.modify $ \rbd -> rbd { rbdPostData = (addPostData (rbdPostData rbd) contents) } - where addPostData x@(BinaryPostData _) _ = x + where addPostData (BinaryPostData _) _ = error "Trying to add file after setting binary content." addPostData (MultipleItemsPostData posts) contents = MultipleItemsPostData $ ReqFilePart name path contents mimetype : posts @@ -576,7 +577,7 @@ request reqBuilder = do SRequest simpleRequest' (simpleRequestBody' rbdPostData) where simpleRequestBody' (MultipleItemsPostData x) = BSL8.fromChunks [multiPartBody x] - simpleRequestBody' (BinaryPostData _) = "" + -- simpleRequestBody' (BinaryPostData _) = "" simpleRequest' = mkRequest [ ("Cookie", cookieValue) , ("Content-Type", contentTypeValue)]