Skip to content

Commit 1ca0d2d

Browse files
authored
Merge pull request #818 from http4s/update/main/http4s-core-1.0.0-M40
Update http4s-circe, http4s-client, ... to 1.0.0-M40 in main
2 parents b4c5565 + e08d147 commit 1ca0d2d

File tree

32 files changed

+383
-42
lines changed

32 files changed

+383
-42
lines changed

blaze-client/src/main/scala/org/http4s/blaze/client/BlazeClient.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import org.http4s.client.RequestKey
3434
import org.http4s.client.UnexpectedStatus
3535
import org.http4s.client.middleware.Retry
3636
import org.http4s.client.middleware.RetryPolicy
37+
import org.typelevel.log4cats.LoggerFactory
3738

3839
import java.net.SocketException
3940
import java.nio.ByteBuffer
@@ -51,7 +52,7 @@ object BlazeClient {
5152
ec: ExecutionContext,
5253
retries: Int,
5354
dispatcher: Dispatcher[F],
54-
)(implicit F: Async[F]): Client[F] = {
55+
)(implicit F: Async[F], lf: LoggerFactory[F]): Client[F] = {
5556
val base = new BlazeClient[F, A](
5657
manager,
5758
responseHeaderTimeout,

blaze-client/src/main/scala/org/http4s/blaze/client/BlazeClientBuilder.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,16 @@ import org.http4s.blaze.channel.ChannelOptions
2626
import org.http4s.blaze.core.BlazeBackendBuilder
2727
import org.http4s.blaze.core.ExecutionContextConfig
2828
import org.http4s.blaze.core.tickWheelResource
29+
import org.http4s.blaze.internal.SSLContextOption
2930
import org.http4s.blaze.util.TickWheelExecutor
3031
import org.http4s.client.Client
3132
import org.http4s.client.RequestKey
3233
import org.http4s.client.defaults
3334
import org.http4s.headers.`User-Agent`
3435
import org.http4s.internal.BackendBuilder
35-
import org.http4s.internal.SSLContextOption
3636
import org.log4s.Logger
3737
import org.log4s.getLogger
38+
import org.typelevel.log4cats.LoggerFactory
3839

3940
import java.net.InetSocketAddress
4041
import java.nio.channels.AsynchronousChannelGroup
@@ -93,7 +94,7 @@ final class BlazeClientBuilder[F[_]] private (
9394
val customDnsResolver: Option[RequestKey => Either[Throwable, InetSocketAddress]],
9495
val retries: Int,
9596
val maxIdleDuration: Duration,
96-
)(implicit protected val F: Async[F])
97+
)(implicit protected val F: Async[F], lf: LoggerFactory[F])
9798
extends BlazeBackendBuilder[Client[F]]
9899
with BackendBuilder[F, Client[F]] {
99100
type Self = BlazeClientBuilder[F]
@@ -392,7 +393,7 @@ final class BlazeClientBuilder[F[_]] private (
392393

393394
object BlazeClientBuilder {
394395

395-
def apply[F[_]: Async]: BlazeClientBuilder[F] =
396+
def apply[F[_]: Async: LoggerFactory]: BlazeClientBuilder[F] =
396397
new BlazeClientBuilder[F](
397398
responseHeaderTimeout = Duration.Inf,
398399
idleTimeout = 1.minute,
@@ -424,7 +425,7 @@ object BlazeClientBuilder {
424425
"If you have a specific reason to use a custom one, use `.withExecutionContext`",
425426
"0.23.5",
426427
)
427-
def apply[F[_]: Async](executionContext: ExecutionContext): BlazeClientBuilder[F] =
428+
def apply[F[_]: Async: LoggerFactory](executionContext: ExecutionContext): BlazeClientBuilder[F] =
428429
BlazeClientBuilder[F].withExecutionContext(executionContext)
429430

430431
def getAddress(requestKey: RequestKey): Either[Throwable, InetSocketAddress] =

blaze-client/src/main/scala/org/http4s/blaze/client/Http1Connection.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ private final class Http1Connection[F[_]](
381381
cleanUpAfterReceivingResponse(closeOnFinish, headers)
382382
attributes -> rawEntity
383383
} else
384-
attributes -> Entity(rawEntity.body.onFinalizeCaseWeak {
384+
attributes -> Entity.stream(rawEntity.body.onFinalizeCaseWeak {
385385
case ExitCase.Succeeded =>
386386
F.delay { trailerCleanup(); cleanUpAfterReceivingResponse(closeOnFinish, headers); }
387387
.evalOn(executionContext)
@@ -400,8 +400,8 @@ private final class Http1Connection[F[_]](
400400
httpVersion = httpVersion,
401401
headers = headers,
402402
entity = entity match {
403-
case Entity.Default(body, length) =>
404-
Entity[F](body.interruptWhen(idleTimeoutS), length)
403+
case Entity.Streamed(body, length) =>
404+
Entity.stream[F](body.interruptWhen(idleTimeoutS), length)
405405
case Entity.Strict(_) | Entity.Empty =>
406406
entity
407407
},

blaze-client/src/main/scala/org/http4s/blaze/client/Http1Support.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import org.http4s.blaze.channel.nio2.ClientChannelFactory
2626
import org.http4s.blaze.core.ExecutionContextConfig
2727
import org.http4s.blaze.core.IdleTimeoutStage
2828
import org.http4s.blaze.core.util.fromFutureNoShift
29+
import org.http4s.blaze.internal.SSLContextOption
2930
import org.http4s.blaze.pipeline.Command
3031
import org.http4s.blaze.pipeline.HeadStage
3132
import org.http4s.blaze.pipeline.LeafBuilder
@@ -34,7 +35,6 @@ import org.http4s.blaze.util.TickWheelExecutor
3435
import org.http4s.client.ConnectionFailure
3536
import org.http4s.client.RequestKey
3637
import org.http4s.headers.`User-Agent`
37-
import org.http4s.internal.SSLContextOption
3838

3939
import java.net.InetSocketAddress
4040
import java.nio.ByteBuffer

blaze-client/src/test/scala/org/http4s/blaze/client/BlazeClientBase.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ import org.http4s.blaze.util.TickWheelExecutor
3535
import org.http4s.client.testkit.scaffold._
3636
import org.http4s.client.testkit.testroutes.GetRoutes
3737
import org.http4s.dsl.io._
38+
import org.typelevel.log4cats.LoggerFactory
39+
import org.typelevel.log4cats.slf4j.Slf4jFactory
3840

3941
import java.security.SecureRandom
4042
import java.security.cert.X509Certificate
@@ -43,6 +45,9 @@ import javax.net.ssl.X509TrustManager
4345
import scala.concurrent.duration._
4446

4547
trait BlazeClientBase extends CatsEffectSuite {
48+
49+
implicit val loggerFactory: LoggerFactory[IO] = Slf4jFactory.create[IO]
50+
4651
val tickWheel: TickWheelExecutor = new TickWheelExecutor(tick = 50.millis)
4752

4853
val TrustingSslContext: IO[SSLContext] = IO.blocking {

blaze-client/src/test/scala/org/http4s/blaze/client/BlazeClientBuilderSuite.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@ package client
2121
import cats.effect.IO
2222
import munit.CatsEffectSuite
2323
import org.http4s.blaze.channel.ChannelOptions
24+
import org.typelevel.log4cats.LoggerFactory
25+
import org.typelevel.log4cats.slf4j.Slf4jFactory
2426

2527
class BlazeClientBuilderSuite extends CatsEffectSuite {
28+
29+
implicit val loggerFactory: LoggerFactory[IO] = Slf4jFactory.create[IO]
30+
2631
private def builder = BlazeClientBuilder[IO]
2732

2833
test("default to empty") {

blaze-client/src/test/scala/org/http4s/blaze/client/ClientTimeoutSuite.scala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ import org.http4s.blaze.util.TickWheelExecutor
3535
import org.http4s.client.Client
3636
import org.http4s.client.RequestKey
3737
import org.http4s.syntax.all._
38+
import org.typelevel.log4cats.LoggerFactory
39+
import org.typelevel.log4cats.slf4j.Slf4jFactory
3840

3941
import java.io.IOException
4042
import java.nio.ByteBuffer
@@ -52,6 +54,8 @@ class ClientTimeoutSuite extends CatsEffectSuite with DispatcherIOFixture {
5254
)
5355
)
5456

57+
implicit val loggerFactory: LoggerFactory[IO] = Slf4jFactory.create[IO]
58+
5559
private def fixture = (tickWheelFixture, dispatcher).mapN(FunFixture.map2(_, _))
5660

5761
private val www_foo_com = uri"http://www.foo.com"
@@ -141,7 +145,7 @@ class ClientTimeoutSuite extends CatsEffectSuite with DispatcherIOFixture {
141145
case (tickWheel, dispatcher) =>
142146
// Sending request body hangs so the idle timeout will kick-in after 1s and interrupt the request
143147
val body = Stream.emit[IO, Byte](1.toByte) ++ Stream.never[IO]
144-
val req = Request(method = Method.POST, uri = www_foo_com, entity = Entity(body))
148+
val req = Request(method = Method.POST, uri = www_foo_com, entity = Entity.stream(body))
145149
val h = new SlowTestHead(Seq(mkBuffer(resp)), 3.seconds, tickWheel)
146150
val c = mkClient(h, tickWheel, dispatcher)(idleTimeout = 1.second)
147151

@@ -155,7 +159,7 @@ class ClientTimeoutSuite extends CatsEffectSuite with DispatcherIOFixture {
155159
(for {
156160
_ <- IO.unit
157161
body = Stream.emit[IO, Byte](1.toByte) ++ Stream.never[IO]
158-
req = Request(method = Method.POST, uri = www_foo_com, entity = Entity(body))
162+
req = Request(method = Method.POST, uri = www_foo_com, entity = Entity.stream(body))
159163
q <- Queue.unbounded[IO, Option[ByteBuffer]]
160164
h = new QueueTestHead(q)
161165
(f, b) = resp.splitAt(resp.length - 1)
@@ -176,7 +180,7 @@ class ClientTimeoutSuite extends CatsEffectSuite with DispatcherIOFixture {
176180
.fixedRate[IO](500.millis)
177181
.take(3)
178182
.mapChunks(_ => Chunk.array(Array.fill(chunkBufferMaxSize + 1)(1.toByte)))
179-
val req = Request(method = Method.POST, uri = www_foo_com, entity = Entity(body))
183+
val req = Request(method = Method.POST, uri = www_foo_com, entity = Entity.stream(body))
180184
val h = new SlowTestHead(Seq(mkBuffer(resp)), 2000.millis, tickWheel)
181185
val c = mkClient(h, tickWheel, dispatcher)(idleTimeout = 1.second)
182186

blaze-core/src/main/scala/org/http4s/blaze/core/Http1Stage.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ private[blaze] trait Http1Stage[F[_]] { self: TailStage[ByteBuffer] =>
192192

193193
case Some(buff) =>
194194
val (rst, end) = streamingEntity(buffer, eofCondition)
195-
Entity(Stream.chunk(Chunk.byteBuffer(buff)) ++ rst.body) -> end
195+
Entity.stream(Stream.chunk(Chunk.byteBuffer(buff)) ++ rst.body) -> end
196196

197197
case None if contentComplete() =>
198198
if (buffer.hasRemaining) Entity.Empty -> Http1Stage.futureBufferThunk(buffer)
@@ -256,7 +256,7 @@ private[blaze] trait Http1Stage[F[_]] { self: TailStage[ByteBuffer] =>
256256
}
257257
}
258258

259-
(Entity(repeatEval(t).unNoneTerminate.flatMap(chunk(_))), () => drainBody(currentBuffer))
259+
(Entity.stream(repeatEval(t).unNoneTerminate.flatMap(chunk(_))), () => drainBody(currentBuffer))
260260
}
261261

262262
/** Called when a fatal error has occurred

blaze-core/src/main/scala/org/http4s/blaze/core/util/BodylessWriter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ private[blaze] class BodylessWriter[F[_]](pipe: TailStage[ByteBuffer], close: Bo
4444
*/
4545
override def writeEntityBody(entity: Entity[F]): F[Boolean] =
4646
entity match {
47-
case Entity.Default(body, _) =>
47+
case Entity.Streamed(body, _) =>
4848
body.compile.drain.as(close)
4949

5050
case Entity.Strict(_) | Entity.Empty =>

blaze-core/src/main/scala/org/http4s/blaze/core/util/EntityBodyWriter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ private[blaze] trait EntityBodyWriter[F[_]] {
5252
*/
5353
def writeEntityBody(entity: Entity[F]): F[Boolean] =
5454
entity match {
55-
case Entity.Default(body, _) =>
55+
case Entity.Streamed(body, _) =>
5656
val writeBody: F[Unit] = writePipe(body).compile.drain
5757
val writeBodyEnd: F[Boolean] = fromFutureNoShift(F.delay(writeEnd(Chunk.empty)))
5858
writeBody *> writeBodyEnd

0 commit comments

Comments
 (0)