@@ -47,7 +47,7 @@ import Data.Text.Lazy.Builder (Builder)
4747import qualified Data.Text.Lazy.Builder as Build
4848import GHC.Generics
4949import GHC.TypeLits
50−import Network.HTTP.Client (HttpException, RequestBody (..))
50+import Network.HTTP.Client (HttpException)
5151import Network.HTTP.Media hiding (Accept)
5252import Network.HTTP.Types hiding (Header)
5353import qualified Network.HTTP.Types as HTTP
@@ -98,6 +98,7 @@ _Default = iso f Just
9898 f (Just x) = x
9999 f Nothing = mempty
100100
101+type Body = Source IO ByteString
101102type Stream = ResumableSource (ResourceT IO) ByteString
102103
103104newtype ServiceId = ServiceId Text
@@ -187,7 +188,7 @@ data Request = Request
187188 { _rqPath :: Builder
188189 , _rqQuery :: DList (ByteString, Maybe ByteString)
189190 , _rqHeaders :: DList (HeaderName, ByteString)
190− , _rqBody :: Maybe (MediaType, RequestBody)
191+ , _rqBody :: Maybe (MediaType, Body)
191192 }
192193
193194instance Monoid Request where
@@ -215,7 +216,7 @@ appendHeader rq k (Just v) = rq
215216 { _rqHeaders = DList.snoc (_rqHeaders rq) (CI.mk k, Text.encodeUtf8 v)
216217 }
217218
218−setBody :: Request -> MediaType -> RequestBody -> Request
219+setBody :: Request -> MediaType -> Body -> Request
219220setBody rq c x = rq { _rqBody = Just (c, x) }
220221
221222-- | A materialised 'http-client' request and associated response parser.
@@ -251,21 +252,25 @@ client f cs m ns rq s = Client
251252 }
252253
253254class Accept c => ToBody c a where
254− toBody :: Proxy c -> a -> RequestBody
255+ toBody :: Proxy c -> a -> Body
255256
256−instance ToBody OctetStream RequestBody where
257+instance ToBody OctetStream Body where
257258 toBody Proxy = id
258259
259−instance ToBody OctetStream ByteString where toBody Proxy = RequestBodyBS
260−instance ToBody OctetStream LBS.ByteString where toBody Proxy = RequestBodyLBS
261−instance ToBody PlainText ByteString where toBody Proxy = RequestBodyBS
262−instance ToBody PlainText LBS.ByteString where toBody Proxy = RequestBodyLBS
260+instance ToBody OctetStream ByteString where
261+ toBody Proxy = CL.sourceList . (:[])
263262
264−instance ToJSON a => ToBody JSON a where
265− toBody Proxy = RequestBodyLBS . encode
263+instance ToBody OctetStream LBS.ByteString where
264+ toBody Proxy = CL.sourceList . LBS.toChunks
265+
266+instance ToBody PlainText ByteString where
267+ toBody Proxy = CL.sourceList . (:[])
266268
267−instance ToBody JSON Value where
268− toBody Proxy = RequestBodyLBS . encode
269+instance ToBody PlainText LBS.ByteString where
270+ toBody Proxy = CL.sourceList . LBS.toChunks
271+
272+instance ToJSON a => ToBody JSON a where
273+ toBody Proxy = CL.sourceList . LBS.toChunks . encode
269274
270275class Accept c => FromStream c a where
271276 fromStream :: Proxy c -> Stream -> ResourceT IO (Either String a)