def apply()

in http-core/src/main/scala/org/apache/pekko/http/impl/engine/http2/OutgoingConnectionBuilderImpl.scala [45:115]


  def apply(host: String, system: ClassicActorSystemProvider): OutgoingConnectionBuilder =
    Impl(
      host,
      None,
      clientConnectionSettings = ClientConnectionSettings(system),
      connectionContext = None,
      log = system.classicSystem.log,
      system = system,
      usingHttp2 = false)

  private final case class Impl(
      host: String,
      port: Option[Int],
      clientConnectionSettings: ClientConnectionSettings,
      connectionContext: Option[HttpsConnectionContext],
      log: LoggingAdapter,
      system: ClassicActorSystemProvider,
      usingHttp2: Boolean) extends OutgoingConnectionBuilder {

    override def toHost(host: String): OutgoingConnectionBuilder = copy(host = host)

    override def toPort(port: Int): OutgoingConnectionBuilder = copy(port = Some(port))

    override def withCustomHttpsConnectionContext(
        httpsConnectionContext: HttpsConnectionContext): OutgoingConnectionBuilder =
      copy(connectionContext = Some(httpsConnectionContext))

    override def withClientConnectionSettings(settings: ClientConnectionSettings): OutgoingConnectionBuilder =
      copy(clientConnectionSettings = settings)

    override def logTo(logger: LoggingAdapter): OutgoingConnectionBuilder = copy(log = logger)

    override def http(): Flow[HttpRequest, HttpResponse, Future[OutgoingConnection]] = {
      // http/1.1 plaintext
      Http(system.classicSystem).outgoingConnectionUsingContext(host, port.getOrElse(80),
        ConnectionContext.noEncryption(), clientConnectionSettings, log)
    }

    override def https(): Flow[HttpRequest, HttpResponse, Future[OutgoingConnection]] = {
      // http/1.1 tls
      Http(system.classicSystem).outgoingConnectionHttps(host, port.getOrElse(443),
        connectionContext.getOrElse(Http(system.classicSystem).defaultClientHttpsContext), None,
        clientConnectionSettings, log)
    }

    override def http2(): Flow[HttpRequest, HttpResponse, Future[OutgoingConnection]] = {
      // http/2 tls
      val port = this.port.getOrElse(443)
      Http2(system.classicSystem).outgoingConnection(host, port,
        connectionContext.getOrElse(Http(system.classicSystem).defaultClientHttpsContext), clientConnectionSettings,
        log)
    }

    override def managedPersistentHttp2(): Flow[HttpRequest, HttpResponse, NotUsed] =
      PersistentConnection.managedConnection(
        http2(),
        clientConnectionSettings.http2Settings)

    override def http2WithPriorKnowledge(): Flow[HttpRequest, HttpResponse, Future[OutgoingConnection]] = {
      // http/2 prior knowledge plaintext
      Http2(system.classicSystem).outgoingConnectionPriorKnowledge(host, port.getOrElse(80), clientConnectionSettings,
        log)
    }

    override def managedPersistentHttp2WithPriorKnowledge(): Flow[HttpRequest, HttpResponse, NotUsed] =
      PersistentConnection.managedConnection(
        http2WithPriorKnowledge(),
        clientConnectionSettings.http2Settings)

    override private[pekko] def toJava: JOutgoingConnectionBuilder = new JavaAdapter(this)
  }