git.iko.soy/typeable/servant
on master help sign in
Merge pull request #661 from kosmikus/pr/servant-client-streaming-request-body

servant-client: generalize the function to set the request body

commiteac364e98c1956bdb6322ff4747151d02f8ab175 authorAlp Mestanogullari <alpmestan@gmail.com> dateThu 12 Jan 2017, 15:58 (10 years ago) parent875f592bc04d12
3 files changed+28−5
servant-client/servant-client.cabal+1−1 servant-client/src/Servant/Client.hs+1−1 servant-client/src/Servant/Common/Req.hs+26−3
servant-client/servant-client.cabal+1−1
@@ -1,5 +1,5 @@
11name: servant-client
2−version: 0.9.1.1
2+version: 0.9.2.0
33synopsis: automatical derivation of querying functions for servant webservices
44description:
55 This library lets you derive automatically Haskell functions that
servant-client/src/Servant/Client.hs+1−1
@@ -406,7 +406,7 @@ instance (MimeRender ct a, HasClient api)
406406 clientWithRoute Proxy req body =
407407 clientWithRoute (Proxy :: Proxy api)
408408 (let ctProxy = Proxy :: Proxy ct
409− in setRQBody (mimeRender ctProxy body)
409+ in setReqBodyLBS (mimeRender ctProxy body)
410410 -- We use first contentType from the Accept list
411411 (contentType ctProxy)
412412 req
servant-client/src/Servant/Common/Req.hs+26−3
@@ -87,7 +87,7 @@ instance Exception ServantError
8787data Req = Req
8888 { reqPath :: String
8989 , qs :: QueryText
90− , reqBody :: Maybe (ByteString, MediaType)
90+ , reqBody :: Maybe (RequestBody, MediaType)
9191 , reqAccept :: [MediaType]
9292 , headers :: [(String, Text)]
9393 }
@@ -112,8 +112,31 @@ addHeader name val req = req { headers = headers req
112112 ++ [(name, decodeUtf8 (toHeader val))]
113113 }
114114
115+-- | Set body and media type of the request being constructed.
116+--
117+-- The body is set to the given bytestring using the 'RequestBodyLBS'
118+-- constructor.
119+--
120+{-# DEPRECATED setRQBody "Use setReqBodyLBS instead" #-}
115121setRQBody :: ByteString -> MediaType -> Req -> Req
116−setRQBody b t req = req { reqBody = Just (b, t) }
122+setRQBody = setReqBodyLBS
123+
124+-- | Set body and media type of the request being constructed.
125+--
126+-- The body is set to the given bytestring using the 'RequestBodyLBS'
127+-- constructor.
128+--
129+-- @since 0.9.2.0
130+--
131+setReqBodyLBS :: ByteString -> MediaType -> Req -> Req
132+setReqBodyLBS b t req = req { reqBody = Just (RequestBodyLBS b, t) }
133+
134+-- | Set body and media type of the request being constructed.
135+--
136+-- @since 0.9.2.0
137+--
138+setReqBody :: RequestBody -> MediaType -> Req -> Req
139+setReqBody b t req = req { reqBody = Just (b, t) }
117140
118141reqToRequest :: (Functor m, MonadThrow m) => Req -> BaseUrl -> m Request
119142reqToRequest req (BaseUrl reqScheme reqHost reqPort path) =
@@ -132,7 +155,7 @@ reqToRequest req (BaseUrl reqScheme reqHost reqPort path) =
132155
133156 setrqb r = case reqBody req of
134157 Nothing -> r
135− Just (b,t) -> r { requestBody = RequestBodyLBS b
158+ Just (b,t) -> r { requestBody = b
136159 , requestHeaders = requestHeaders r
137160 ++ [(hContentType, cs . show $ t)] }
138161 setQS = setQueryString $ queryTextToQuery (qs req)