Skip to content

Commit

Permalink
Http4s jdk client accept java.net.http....Builder
Browse files Browse the repository at this point in the history
  • Loading branch information
hnaderi committed May 18, 2023
1 parent 4d70e70 commit eb0c0aa
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ package http4s

import cats.effect.kernel.Async
import cats.effect.kernel.Resource
import cats.effect.std.Env
import fs2.io.file.Files
import fs2.io.net.Network
import fs2.io.net.tls.TLSContext
import org.http4s.client.Client
import org.http4s.ember.client.EmberClientBuilder
import fs2.io.file.Files
import cats.effect.std.Env

final class EmberKubernetesClient[F[_]: Async: Network: Files: Env] private (
builder: EmberClientBuilder[F]
Expand Down
32 changes: 22 additions & 10 deletions modules/http4s-jdk/src/main/scala/JDKKubernetesClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,38 @@ package http4s

import cats.effect.kernel.Async
import cats.effect.kernel.Resource
import cats.effect.std.Env
import cats.syntax.all._
import fs2.io.file.Files
import org.http4s.client.Client
import org.http4s.jdkhttpclient.JdkHttpClient

import java.net.http
import java.net.http.HttpClient.Builder
import javax.net.ssl.SSLContext
import cats.effect.std.Env
import fs2.io.file.Files

final class JDKKubernetesClient[F[_]: Async: Files: Env]
extends JVMPlatform[F] {
final class JDKKubernetesClient[F[_]: Async: Files: Env] private (
builder: Builder
) extends JVMPlatform[F] {

override protected def buildClient: Resource[F, Client[F]] =
Resource.eval(JdkHttpClient.simple[F])
override protected def buildClient: Resource[F, Client[F]] = from(b => b)

override protected def buildWithSSLContext
: SSLContext => Resource[F, Client[F]] = ssl =>
Resource.eval(Async[F].executor.flatMap { exec =>
from(_.sslContext(ssl)).preAllocate(
Async[F].delay {
val builder = http.HttpClient.newBuilder()
// workaround for https://github.com/http4s/http4s-jdk-http-client/issues/200
if (Runtime.version().feature() == 11) {
val params = ssl.getDefaultSSLParameters()
params.setProtocols(params.getProtocols().filter(_ != "TLSv1.3"))
}
}
)

val client = builder
.sslContext(ssl)
private def from(customize: Builder => Builder) =
Resource.eval(Async[F].executor.flatMap { exec =>
Async[F].delay {
val client = customize(builder)
.executor(exec)
.build()

Expand All @@ -55,3 +59,11 @@ final class JDKKubernetesClient[F[_]: Async: Files: Env]
})

}

object JDKKubernetesClient {
def apply[F[_]: Async: Files: Env]: JDKKubernetesClient[F] =
new JDKKubernetesClient[F](http.HttpClient.newBuilder())

def apply[F[_]: Async: Files: Env](builder: Builder): JDKKubernetesClient[F] =
new JDKKubernetesClient[F](builder)
}

0 comments on commit eb0c0aa

Please sign in to comment.