@@ -47,7 +47,7 @@ import Data.Text.Lazy.Builder (Builder)
47import qualified Data.Text.Lazy.Builder as Build
47import qualified Data.Text.Lazy.Builder as Build
48import GHC.Generics
48import GHC.Generics
49import GHC.TypeLits
49import GHC.TypeLits
50−import Network.HTTP.Client (HttpException, RequestBody (..))
50+import Network.HTTP.Client (HttpException)
51import Network.HTTP.Media hiding (Accept)
51import Network.HTTP.Media hiding (Accept)
52import Network.HTTP.Types hiding (Header)
52import Network.HTTP.Types hiding (Header)
53import qualified Network.HTTP.Types as HTTP
53import qualified Network.HTTP.Types as HTTP
@@ -98,6 +98,7 @@ _Default = iso f Just
98 f (Just x) = x
98 f (Just x) = x
99 f Nothing = mempty
99 f Nothing = mempty
101+type Body = Source IO ByteString
101type Stream = ResumableSource (ResourceT IO) ByteString
102type Stream = ResumableSource (ResourceT IO) ByteString
103newtype ServiceId = ServiceId Text
104newtype ServiceId = ServiceId Text
@@ -187,7 +188,7 @@ data Request = Request
187 { _rqPath :: Builder
188 { _rqPath :: Builder
188 , _rqQuery :: DList (ByteString, Maybe ByteString)
189 , _rqQuery :: DList (ByteString, Maybe ByteString)
189 , _rqHeaders :: DList (HeaderName, ByteString)
190 , _rqHeaders :: DList (HeaderName, ByteString)
190− , _rqBody :: Maybe (MediaType, RequestBody)
191+ , _rqBody :: Maybe (MediaType, Body)
193instance Monoid Request where
194instance Monoid Request where
@@ -215,7 +216,7 @@ appendHeader rq k (Just v) = rq
215 { _rqHeaders = DList.snoc (_rqHeaders rq) (CI.mk k, Text.encodeUtf8 v)
216 { _rqHeaders = DList.snoc (_rqHeaders rq) (CI.mk k, Text.encodeUtf8 v)
218−setBody :: Request -> MediaType -> RequestBody -> Request
219+setBody :: Request -> MediaType -> Body -> Request
219setBody rq c x = rq { _rqBody = Just (c, x) }
220setBody rq c x = rq { _rqBody = Just (c, x) }
221-- | A materialised 'http-client' request and associated response parser.
222-- | A materialised 'http-client' request and associated response parser.
@@ -251,21 +252,25 @@ client f cs m ns rq s = Client
253class Accept c => ToBody c a where
254class Accept c => ToBody c a where
254− toBody :: Proxy c -> a -> RequestBody
255+ toBody :: Proxy c -> a -> Body
256−instance ToBody OctetStream RequestBody where
257+instance ToBody OctetStream Body where
257 toBody Proxy = id
258 toBody Proxy = id
259−instance ToBody OctetStream ByteString where toBody Proxy = RequestBodyBS
260+instance ToBody OctetStream ByteString where
260−instance ToBody OctetStream LBS.ByteString where toBody Proxy = RequestBodyLBS
261+ toBody Proxy = CL.sourceList . (:[])
261−instance ToBody PlainText ByteString where toBody Proxy = RequestBodyBS
262−instance ToBody PlainText LBS.ByteString where toBody Proxy = RequestBodyLBS
264−instance ToJSON a => ToBody JSON a where
263+instance ToBody OctetStream LBS.ByteString where
264+ toBody Proxy = CL.sourceList . LBS.toChunks
266+instance ToBody PlainText ByteString where
265− toBody Proxy = RequestBodyLBS . encode
267+ toBody Proxy = CL.sourceList . (:[])
267−instance ToBody JSON Value where
269+instance ToBody PlainText LBS.ByteString where
270+ toBody Proxy = CL.sourceList . LBS.toChunks
272+instance ToJSON a => ToBody JSON a where
268− toBody Proxy = RequestBodyLBS . encode
273+ toBody Proxy = CL.sourceList . LBS.toChunks . encode
270class Accept c => FromStream c a where
275class Accept c => FromStream c a where
271 fromStream :: Proxy c -> Stream -> ResourceT IO (Either String a)
276 fromStream :: Proxy c -> Stream -> ResourceT IO (Either String a)