Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add withHttp2 and withoutHttp2 #523

Merged
merged 1 commit into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ lazy val client = project
ProblemFilters.exclude[Problem]("org.http4s.netty.client.Http4sChannelPoolMap.*"),
ProblemFilters.exclude[Problem]("org.http4s.netty.client.NettyClientBuilder.*"),
ProblemFilters.exclude[Problem]("org.http4s.netty.client.NettyWSClientBuilder.*"),
ProblemFilters.exclude[MissingTypesProblem](
"org.http4s.netty.client.Http4sChannelPoolMap$Config$"),
ProblemFilters.exclude[MissingFieldProblem](
"org.http4s.netty.client.NettyClientBuilder.SSLContextOption"),
ProblemFilters.exclude[MissingClassProblem]("org.http4s.netty.client.Http4sHandler$"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ private[client] class Http4sChannelPoolMap[F[_]](
)
}

def run(request: Request[F]): Resource[F, Response[F]] = {
def run(request0: Request[F]): Resource[F, Response[F]] = {
val request =
if (config.http2 && request0.uri.scheme.contains(Uri.Scheme.https))
request0.withHttpVersion(HttpVersion.`HTTP/2`)
else request0
val key = Key(RequestKey.fromRequest(request), request.httpVersion)

for {
Expand Down Expand Up @@ -235,7 +239,9 @@ private[client] object Http4sChannelPoolMap {
maxConnections: Int,
idleTimeout: Duration,
proxy: Option[Proxy],
sslConfig: SSLContextOption)
sslConfig: SSLContextOption,
http2: Boolean
)

private[client] def fromFuture[F[_]: Async, A](future: => Future[A]): F[A] =
Async[F].async { callback =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class NettyClientBuilder[F[_]](
transport: NettyTransport,
sslContext: SSLContextOption,
nettyChannelOptions: NettyChannelOptions,
proxy: Option[Proxy]
proxy: Option[Proxy],
http2: Boolean
)(implicit F: Async[F]) {
type Self = NettyClientBuilder[F]

Expand All @@ -49,7 +50,8 @@ class NettyClientBuilder[F[_]](
transport: NettyTransport = transport,
sslContext: SSLContextOption = sslContext,
nettyChannelOptions: NettyChannelOptions = nettyChannelOptions,
proxy: Option[Proxy] = proxy
proxy: Option[Proxy] = proxy,
http2: Boolean = http2
): NettyClientBuilder[F] =
new NettyClientBuilder[F](
idleTimeout,
Expand All @@ -61,7 +63,8 @@ class NettyClientBuilder[F[_]](
transport,
sslContext,
nettyChannelOptions,
proxy
proxy,
http2
)

def withNativeTransport: Self = copy(transport = NettyTransport.defaultFor(Os.get))
Expand Down Expand Up @@ -96,6 +99,8 @@ class NettyClientBuilder[F[_]](
def withProxy(proxy: Proxy): Self = copy(proxy = Some(proxy))
def withProxyFromSystemProperties: Self = copy(proxy = Proxy.fromSystemProperties)
def withoutProxy: Self = copy(proxy = None)
def withHttp2: Self = copy(http2 = true)
def withoutHttp2: Self = copy(http2 = false)

private def createBootstrap: Resource[F, Bootstrap] =
Resource.make(F.delay {
Expand All @@ -116,7 +121,8 @@ class NettyClientBuilder[F[_]](
maxConnectionsPerKey,
idleTimeout,
proxy,
sslContext
sslContext,
http2
)
Client[F](new Http4sChannelPoolMap[F](bs, config).run)
}
Expand All @@ -134,6 +140,7 @@ object NettyClientBuilder {
transport = NettyTransport.defaultFor(Os.get),
sslContext = SSLContextOption.TryDefaultSSLContext,
nettyChannelOptions = NettyChannelOptions.empty,
proxy = Proxy.fromSystemProperties
proxy = Proxy.fromSystemProperties,
http2 = false
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ class EmberHttp2Test extends IOSuite {
val client: IOFixture[Client[IO]] = resourceFixture(
NettyClientBuilder[IO].withNioTransport
.withSSLContext(EmberHttp2Test.sslContextForClient)
.resource
.map(client =>
Client((req: Request[IO]) => client.run(req.withHttpVersion(HttpVersion.`HTTP/2`)))),
.withHttp2
.resource,
"client"
)

Expand Down