Skip to content

Commit

Permalink
Leave only blaze server
Browse files Browse the repository at this point in the history
  • Loading branch information
pondzix committed Nov 2, 2023
1 parent 791346d commit fea6397
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 85 deletions.
2 changes: 0 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ lazy val http4s = project
.settings(
libraryDependencies ++= Seq(
Dependencies.Libraries.http4sDsl,
Dependencies.Libraries.http4sEmber,
Dependencies.Libraries.http4sBlaze,
Dependencies.Libraries.http4sNetty,
Dependencies.Libraries.http4sClient,
Dependencies.Libraries.log4cats,
Dependencies.Libraries.thrift,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,65 +1,27 @@
package com.snowplowanalytics.snowplow.collector.core

import java.net.InetSocketAddress
import javax.net.ssl.SSLContext

import io.netty.handler.ssl._

import org.typelevel.log4cats.Logger
import org.typelevel.log4cats.slf4j.Slf4jLogger

import com.comcast.ip4s.{IpAddress, Port}

import cats.implicits._

import cats.effect.{Async, Resource}

import cats.implicits._
import org.http4s.HttpApp
import org.http4s.server.Server
import org.http4s.ember.server.EmberServerBuilder
import org.http4s.blaze.server.BlazeServerBuilder
import org.http4s.netty.server.NettyServerBuilder
import org.http4s.server.Server
import org.typelevel.log4cats.Logger
import org.typelevel.log4cats.slf4j.Slf4jLogger

import fs2.io.net.Network
import fs2.io.net.tls.TLSContext
import java.net.InetSocketAddress
import javax.net.ssl.SSLContext

object HttpServer {

implicit private def logger[F[_]: Async] = Slf4jLogger.getLogger[F]

def build[F[_]: Async](
app: HttpApp[F],
interface: String,
port: Int,
secure: Boolean,
networking: Config.Networking
): Resource[F, Server] =
sys.env.get("HTTP4S_BACKEND").map(_.toUpperCase()) match {
case Some("BLAZE") | None => buildBlazeServer[F](app, port, secure, networking)
case Some("EMBER") => buildEmberServer[F](app, interface, port, secure, networking)
case Some("NETTY") => buildNettyServer[F](app, port, secure, networking)
case Some(other) => throw new IllegalArgumentException(s"Unrecognized http4s backend $other")
}

private def buildEmberServer[F[_]: Async](
app: HttpApp[F],
interface: String,
port: Int,
secure: Boolean,
networking: Config.Networking
) = {
implicit val network = Network.forAsync[F]
Resource.eval(Logger[F].info("Building ember server")) >>
EmberServerBuilder
.default[F]
.withHost(IpAddress.fromString(interface).get)
.withPort(Port.fromInt(port).get)
.withHttpApp(app)
.withIdleTimeout(networking.idleTimeout)
.withMaxConnections(networking.maxConnections)
.cond(secure, _.withTLS(TLSContext.Builder.forAsync.fromSSLContext(SSLContext.getDefault)))
.build
}
buildBlazeServer[F](app, port, secure, networking)

private def buildBlazeServer[F[_]: Async](
app: HttpApp[F],
Expand All @@ -76,40 +38,6 @@ object HttpServer {
.cond(secure, _.withSslContext(SSLContext.getDefault))
.resource

private def buildNettyServer[F[_]: Async](
app: HttpApp[F],
port: Int,
secure: Boolean,
networking: Config.Networking
) =
Resource.eval(Logger[F].info("Building netty server")) >>
NettyServerBuilder[F]
.bindLocal(port)
.withHttpApp(app)
.withIdleTimeout(networking.idleTimeout)
.cond(
secure,
_.withSslContext(
new JdkSslContext(
SSLContext.getDefault,
false,
null,
IdentityCipherSuiteFilter.INSTANCE,
new ApplicationProtocolConfig(
ApplicationProtocolConfig.Protocol.ALPN,
ApplicationProtocolConfig.SelectorFailureBehavior.NO_ADVERTISE,
ApplicationProtocolConfig.SelectedListenerFailureBehavior.ACCEPT,
ApplicationProtocolNames.HTTP_2,
ApplicationProtocolNames.HTTP_1_1
),
ClientAuth.NONE,
null,
false
)
)
)
.resource

implicit class ConditionalAction[A](item: A) {
def cond(cond: Boolean, action: A => A): A =
if (cond) action(item) else item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ object Run {
)
httpServer = HttpServer.build[F](
new Routes[F](config.enableDefaultRedirect, collectorService).value,
config.interface,
if (config.ssl.enable) config.ssl.port else config.port,
config.ssl.enable,
config.networking
Expand Down
3 changes: 0 additions & 3 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ object Dependencies {
val log4cats = "2.6.0"
val http4s = "0.23.23"
val blaze = "0.23.15"
val http4sNetty = "0.5.9"
val decline = "2.4.1"
val circe = "0.14.1"
val circeConfig = "0.10.0"
Expand Down Expand Up @@ -74,9 +73,7 @@ object Dependencies {

// http4s
val http4sDsl = "org.http4s" %% "http4s-dsl" % V.http4s
val http4sEmber = "org.http4s" %% "http4s-ember-server" % V.http4s
val http4sBlaze = "org.http4s" %% "http4s-blaze-server" % V.blaze
val http4sNetty = "org.http4s" %% "http4s-netty-server" % V.http4sNetty
val http4sClient = "org.http4s" %% "http4s-blaze-client" % V.blaze
val decline = "com.monovore" %% "decline-effect" % V.decline
val circeGeneric = "io.circe" %% "circe-generic" % V.circe
Expand Down

0 comments on commit fea6397

Please sign in to comment.