@@ -18,6 +18,8 @@ package zio.http
18
18
19
19
import java .net .{InetSocketAddress , URI }
20
20
21
+ import scala .annotation .nowarn
22
+
21
23
import zio ._
22
24
import zio .stacktracer .TracingImplicits .disableAutoTrace
23
25
@@ -37,6 +39,7 @@ final case class ZClient[-Env, ReqEnv, -In, +Err, +Out](
37
39
bodyDecoder : ZClient .BodyDecoder [Env , Err , Out ],
38
40
driver : ZClient .Driver [Env , ReqEnv , Err ],
39
41
) extends HeaderOps [ZClient [Env , ReqEnv , In , Err , Out ]] { self =>
42
+ @ nowarn(" cat=deprecation" )
40
43
def apply (request : Request )(implicit ev : Body <:< In , trace : Trace ): ZIO [Env & ReqEnv , Err , Out ] =
41
44
self.request(request)
42
45
@@ -175,6 +178,7 @@ final case class ZClient[-Env, ReqEnv, -In, +Err, +Out](
175
178
): ZClient [Env , ReqEnv , In , Err2 , Out ] =
176
179
transform(bodyEncoder.refineOrDie(pf), bodyDecoder.refineOrDie(pf), driver.refineOrDie(pf))
177
180
181
+ @ deprecated(" Use `batched` or `streaming` instead" , since = " 3.0.0" )
178
182
def request (request : Request )(implicit ev : Body <:< In , trace : Trace ): ZIO [Env & ReqEnv , Err , Out ] = {
179
183
def makeRequest (body : Body ) = {
180
184
driver.request(
@@ -233,11 +237,33 @@ final case class ZClient[-Env, ReqEnv, -In, +Err, +Out](
233
237
ev2 : ReqEnv =:= Scope ,
234
238
): ZStream [R & Env , E0 , A ] = ZStream .unwrapScoped[R & Env ] {
235
239
self
236
- .request (request)
240
+ .streaming (request)
237
241
.asInstanceOf [ZIO [R & Env & Scope , Err , Out ]]
238
242
.fold(ZStream .fail(_), f)
239
243
}
240
244
245
+ def streaming (
246
+ request : Request ,
247
+ )(implicit ev : Body <:< In , trace : Trace , ev1 : ReqEnv =:= Scope ): ZIO [Env & ReqEnv , Err , Out ] = {
248
+ def makeRequest (body : Body ) = {
249
+ driver.request(
250
+ self.version ++ request.version,
251
+ request.method,
252
+ self.url ++ request.url,
253
+ self.headers ++ request.headers,
254
+ body,
255
+ sslConfig,
256
+ proxy,
257
+ )
258
+ }
259
+ if (bodyEncoder == ZClient .BodyEncoder .identity)
260
+ bodyDecoder.decodeZIO(makeRequest(request.body))
261
+ else
262
+ bodyEncoder
263
+ .encode(ev(request.body))
264
+ .flatMap(body => bodyDecoder.decodeZIO(makeRequest(body)))
265
+ }
266
+
241
267
def ssl (ssl : ClientSSLConfig ): ZClient [Env , ReqEnv , In , Err , Out ] =
242
268
copy(sslConfig = Some (ssl))
243
269
@@ -279,7 +305,7 @@ object ZClient extends ZClientPlatformSpecific {
279
305
* memory, allowing to stream response bodies
280
306
*/
281
307
def batched (request : Request )(implicit trace : Trace ): ZIO [Client , Throwable , Response ] =
282
- ZIO .serviceWithZIO[Client ](_.batched.request (request))
308
+ ZIO .serviceWithZIO[Client ](_.batched(request))
283
309
284
310
def fromDriver [Env , ReqEnv , Err ](driver : Driver [Env , ReqEnv , Err ]): ZClient [Env , ReqEnv , Body , Err , Response ] =
285
311
ZClient (
@@ -312,7 +338,7 @@ object ZClient extends ZClientPlatformSpecific {
312
338
* request's resources (i.e., `Scope`)
313
339
*/
314
340
def streaming (request : Request )(implicit trace : Trace ): ZIO [Client & Scope , Throwable , Response ] =
315
- ZIO .serviceWithZIO[Client ](_.request (request))
341
+ ZIO .serviceWithZIO[Client ](_.batched (request))
316
342
317
343
/**
318
344
* Executes an HTTP request, and transforms the response to a `ZStream` using
0 commit comments