Skip to content
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
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ jobs:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 1.8
java-version: 11
- uses: coursier/cache-action@v5
with:
extraKey: ${{ secrets.BUILD_CACHE_VERSION }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pull.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ jobs:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 1.8
java-version: 11
- uses: coursier/cache-action@v5
with:
extraKey: pr-${GITHUB_HEAD_REF}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ jobs:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 1.8
java-version: 11
- uses: coursier/cache-action@v5
- name: Check/Compile/Test
run: sbt check
Expand Down
18 changes: 18 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ lazy val root = project
http4sServerBlaze,
http4sServerBlazePureConfig,
http4sServerMicrometer,
jdkHttpClient,
jdkHttpClientPureConfig,
jvm,
jvmMicrometer,
jvmPureConfig,
Expand Down Expand Up @@ -297,6 +299,22 @@ lazy val http4sServerMicrometer = project
)
)

lazy val jdkHttpClient = project
.in(file("jdk-http-client"))
.settings(BuildSettings.common)
.settings(
name := "sst-jdk-http-client"
)

lazy val jdkHttpClientPureConfig = project
.in(file("jdk-http-client-pureconfig"))
.dependsOn(jdkHttpClient)
.settings(BuildSettings.common)
.settings(
name := "sst-jdk-http-client-pureconfig",
libraryDependencies += Dependencies.pureConfig
)

lazy val jvm = project
.in(file("jvm"))
.settings(BuildSettings.common)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.avast.sst.jdk.httpclient.pureconfig

import com.avast.sst.jdk.httpclient.JdkHttpClientConfig
import pureconfig.ConfigReader
import pureconfig.generic.ProductHint
import pureconfig.generic.semiauto.deriveReader

trait ConfigReaders {

implicit protected def hint[T]: ProductHint[T] = ProductHint.default

implicit val jdkHttpClientConfigReader: ConfigReader[JdkHttpClientConfig] = deriveReader

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.avast.sst.jdk.httpclient.pureconfig

import pureconfig.ConfigFieldMapping
import pureconfig.generic.ProductHint

/** Contains [[pureconfig.ConfigReader]] instances with default "kebab-case" naming convention. */
object implicits extends ConfigReaders {

/** Contains [[pureconfig.ConfigReader]] instances with "kebab-case" naming convention.
*
* This is alias for the default `implicits._` import.
*/
object KebabCase extends ConfigReaders

/** Contains [[pureconfig.ConfigReader]] instances with "camelCase" naming convention. */
object CamelCase extends ConfigReaders {
implicit override protected def hint[T]: ProductHint[T] = ProductHint(ConfigFieldMapping(pureconfig.CamelCase, pureconfig.CamelCase))
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.avast.sst.jdk.httpclient

import java.net.http.HttpClient
import scala.concurrent.duration.FiniteDuration

final case class JdkHttpClientConfig(
connectTimeout: Option[FiniteDuration] = None,
followRedirects: Option[HttpClient.Redirect] = None,
version: Option[HttpClient.Version] = None,
priority: Option[Int] = None
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.avast.sst.jdk.httpclient

import java.net.http.HttpClient
import java.net.{Authenticator, CookieHandler, ProxySelector}
import java.time.{Duration => JDuration}
import java.util.concurrent.Executor
import javax.net.ssl.SSLContext

object JdkHttpClientModule {

/** Makes [[java.net.http.HttpClient]] initialized with the given config. */
def make(
config: JdkHttpClientConfig,
executor: Option[Executor] = None,
sslContext: Option[SSLContext] = None,
cookieHandler: Option[CookieHandler] = None,
proxySelector: Option[ProxySelector] = None,
authenticator: Option[Authenticator] = None
): HttpClient = {
val builder = HttpClient.newBuilder()

config.connectTimeout.map(d => JDuration.ofNanos(d.toNanos)).foreach(builder.connectTimeout)
executor.foreach(builder.executor)
sslContext.foreach(builder.sslContext)
config.followRedirects.foreach(builder.followRedirects)
config.priority.foreach(builder.priority)
cookieHandler.foreach(builder.cookieHandler)
proxySelector.foreach(builder.proxy)
authenticator.foreach(builder.authenticator)

builder.build()
}

}
1 change: 1 addition & 0 deletions project/BuildSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ object BuildSettings {
"-Ywarn-unused", // necessary for Scalafix RemoveUnused rule (not present in sbt-tpolecat for 2.13)
"-P:silencer:checkUnused"
) ++ (if (scalaVersion.value.startsWith("2.13")) List("-Wmacros:after") else List.empty),
javacOptions ++= Seq("-source", "1.8", "-target", "1.8"),
Test / publishArtifact := false
)

Expand Down