Skip to content

Commit

Permalink
chore: Update http4s to 0.22.x and fix issues (#640)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubjanecek authored Aug 9, 2021
1 parent b541be8 commit 0fd2f1f
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ trait MonixServerApp extends TaskApp {

private val logger = LoggerFactory.getLogger(this.getClass)

def program: Resource[Task, Server[Task]]
def program: Resource[Task, Server]

override def run(args: List[String]): Task[ExitCode] = {
program
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ trait ZioServerApp extends CatsApp {

private val logger = LoggerFactory.getLogger(this.getClass)

def program: Resource[Task, Server[Task]]
def program: Resource[Task, Server]

@nowarn("msg=dead code")
override def run(args: List[String]): ZIO[ZEnv, Nothing, ExitCode] = {
Expand Down
2 changes: 1 addition & 1 deletion example/src/main/scala/com/avast/sst/example/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import scala.concurrent.ExecutionContext

object Main extends ZioServerApp {

def program: Resource[Task, Server[Task]] = {
def program: Resource[Task, Server] = {
for {
configuration <- Resource.eval(PureConfigModule.makeOrRaise[Task, Configuration])
executorModule <- ExecutorModule.makeFromExecutionContext[Task](runtime.platform.executor.asEC)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.avast.sst.http4s.client.pureconfig

import cats.syntax.either._
import com.avast.sst.http4s.client.Http4sBlazeClientConfig
import org.http4s.client.blaze.ParserMode
import org.http4s.blaze.client.ParserMode
import org.http4s.headers.`User-Agent`
import pureconfig.ConfigReader
import pureconfig.error.CannotConvert
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.avast.sst.http4s.client

import org.http4s.BuildInfo
import org.http4s.client.blaze.ParserMode
import org.http4s.blaze.client.ParserMode
import org.http4s.client.defaults
import org.http4s.headers.{AgentComment, AgentProduct, `User-Agent`}
import org.http4s.headers.`User-Agent`
import org.http4s.{BuildInfo, ProductComment, ProductId}

import java.util.concurrent.TimeUnit
import scala.concurrent.duration.{Duration, FiniteDuration}
Expand All @@ -13,7 +13,7 @@ final case class Http4sBlazeClientConfig(
idleTimeout: FiniteDuration = Duration(1, TimeUnit.MINUTES),
requestTimeout: FiniteDuration = defaults.RequestTimeout,
connectTimeout: FiniteDuration = defaults.ConnectTimeout,
userAgent: `User-Agent` = `User-Agent`(AgentProduct("http4s-blaze-client", Some(BuildInfo.version)), List(AgentComment("Server"))),
userAgent: `User-Agent` = `User-Agent`(ProductId("http4s-blaze-client", Some(BuildInfo.version)), List(ProductComment("Server"))),
maxTotalConnections: Int = 10,
maxWaitQueueLimit: Int = 256,
maxConnectionsPerRequestkey: Int = 256,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.avast.sst.http4s.client

import cats.effect.{ConcurrentEffect, Resource}
import org.http4s.blaze.client.BlazeClientBuilder
import org.http4s.client.Client
import org.http4s.client.blaze.BlazeClientBuilder

import javax.net.ssl.SSLContext
import scala.concurrent.ExecutionContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.avast.sst.http4s.client

import cats.effect._
import org.http4s.headers._
import org.http4s.{ProductComment, ProductId}
import org.scalatest.funsuite.AsyncFunSuite

import scala.concurrent.ExecutionContext
Expand All @@ -19,7 +20,7 @@ class Http4SBlazeClientTest extends AsyncFunSuite {
val test = for {
client <- Http4sBlazeClientModule.make[IO](
Http4sBlazeClientConfig(
userAgent = `User-Agent`(AgentProduct("http4s-client", Some("1.2.3")), List(AgentComment("Test")))
userAgent = `User-Agent`(ProductId("http4s-client", Some("1.2.3")), List(ProductComment("Test")))
),
ExecutionContext.global
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.avast.sst.http4s.server

import cats.effect.{ConcurrentEffect, Resource, Timer}
import org.http4s.HttpApp
import org.http4s.blaze.server.BlazeServerBuilder
import org.http4s.server.Server
import org.http4s.server.blaze.BlazeServerBuilder

import java.net.{InetSocketAddress, StandardSocketOptions}
import scala.concurrent.ExecutionContext
Expand All @@ -19,7 +19,7 @@ object Http4sBlazeServerModule {
config: Http4sBlazeServerConfig,
httpApp: HttpApp[F],
executionContext: ExecutionContext
): Resource[F, Server[F]] = {
): Resource[F, Server] = {
for {
inetSocketAddress <- Resource.eval(
ConcurrentEffect[F].delay(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.avast.sst.http4s.server.middleware

import cats.data.{Kleisli, OptionT}
import cats.data.{Kleisli, NonEmptyList, OptionT}
import cats.effect.Sync
import cats.syntax.functor._
import com.avast.sst.http4s.server.middleware.CorrelationIdMiddleware.CorrelationId
import io.chrisdavenport.vault.Key
import org.http4s.util.CaseInsensitiveString
import org.http4s.{Header, HttpRoutes, Request, Response}
import org.slf4j.LoggerFactory
import org.typelevel.ci.CIString
import org.typelevel.vault.Key

import java.util.UUID

Expand All @@ -17,7 +17,7 @@ import java.util.UUID
* Use method `retrieveCorrelationId` to get the value from request attributes.
*/
class CorrelationIdMiddleware[F[_]: Sync](
correlationIdHeaderName: CaseInsensitiveString,
correlationIdHeaderName: CIString,
attributeKey: Key[CorrelationId],
generator: () => String
) {
Expand All @@ -29,7 +29,7 @@ class CorrelationIdMiddleware[F[_]: Sync](
def wrap(routes: HttpRoutes[F]): HttpRoutes[F] =
Kleisli[OptionT[F, *], Request[F], Response[F]] { request =>
request.headers.get(correlationIdHeaderName) match {
case Some(header) =>
case Some(NonEmptyList(header, _)) =>
val requestWithAttribute = request.withAttribute(attributeKey, CorrelationId(header.value))
routes(requestWithAttribute).map(r => r.withHeaders(r.headers.put(header)))
case None =>
Expand All @@ -38,7 +38,7 @@ class CorrelationIdMiddleware[F[_]: Sync](
_ <- log(newCorrelationId)
requestWithAttribute = request.withAttribute(attributeKey, CorrelationId(newCorrelationId))
response <- routes(requestWithAttribute)
} yield response.withHeaders(response.headers.put(Header(correlationIdHeaderName.value, newCorrelationId)))
} yield response.withHeaders(response.headers.put(Header.Raw(correlationIdHeaderName, newCorrelationId)))
}
}

Expand All @@ -62,7 +62,7 @@ object CorrelationIdMiddleware {
@SuppressWarnings(Array("scalafix:Disable.toString"))
def default[F[_]: Sync]: F[CorrelationIdMiddleware[F]] = {
Key.newKey[F, CorrelationId].map { attributeKey =>
new CorrelationIdMiddleware(CaseInsensitiveString("Correlation-ID"), attributeKey, () => UUID.randomUUID().toString)
new CorrelationIdMiddleware(CIString("Correlation-ID"), attributeKey, () => UUID.randomUUID().toString)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package com.avast.sst.http4s.server.middleware

import cats.effect.{ContextShift, IO, Resource, Timer}
import com.avast.sst.http4s.server.Http4sRouting
import org.http4s.client.blaze.BlazeClientBuilder
import org.http4s.blaze.client.BlazeClientBuilder
import org.http4s.blaze.server.BlazeServerBuilder
import org.http4s.dsl.Http4sDsl
import org.http4s.server.blaze.BlazeServerBuilder
import org.http4s.util.CaseInsensitiveString
import org.http4s.{Header, HttpRoutes, Request, Uri}
import org.scalatest.funsuite.AsyncFunSuite
import org.typelevel.ci.CIString

import java.net.InetSocketAddress
import scala.concurrent.ExecutionContext
Expand All @@ -25,7 +25,7 @@ class CorrelationIdMiddlewareTest extends AsyncFunSuite with Http4sDsl[IO] {
middleware.wrap {
HttpRoutes.of[IO] { case req @ GET -> Root / "test" =>
val id = middleware.retrieveCorrelationId(req)
Ok("test").map(_.withHeaders(Header("Attribute-Value", id.toString)))
Ok("test").map(_.withHeaders(Header.Raw(CIString("Attribute-Value"), id.toString)))
}
}
}
Expand All @@ -41,12 +41,12 @@ class CorrelationIdMiddlewareTest extends AsyncFunSuite with Http4sDsl[IO] {
client
.run(
Request[IO](uri = Uri.unsafeFromString(s"http://${server.address.getHostString}:${server.address.getPort}/test"))
.withHeaders(Header("Correlation-Id", "test-value"))
.withHeaders(Header.Raw(CIString("Correlation-Id"), "test-value"))
)
.use { response =>
IO.delay {
assert(response.headers.get(CaseInsensitiveString("Correlation-Id")).get.value === "test-value")
assert(response.headers.get(CaseInsensitiveString("Attribute-Value")).get.value === "Some(CorrelationId(test-value))")
assert(response.headers.get(CIString("Correlation-Id")).get.head.value === "test-value")
assert(response.headers.get(CIString("Attribute-Value")).get.head.value === "Some(CorrelationId(test-value))")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ object Dependencies {
val datastaxJavaDriverCore = "4.13.0"
val doobie = "0.13.4"
val grpc = "1.39.0"
val http4s = "0.21.25"
val http4s = "0.22.2"
val micrometerCore = "1.7.2"
val micrometerJmx = "1.7.2"
val micrometerStatsD = "1.7.2"
Expand Down

0 comments on commit 0fd2f1f

Please sign in to comment.