<commit_before>package com.twitter.finagle

import com.twitter.finagle.client._
import com.twitter.finagle.context.Contexts
import com.twitter.finagle.dispatch.GenSerialClientDispatcher
import com.twitter.finagle.filter.{NackAdmissionFilter, PayloadSizeFilter}
import com.twitter.finagle.http._
import com.twitter.finagle.http.codec.{HttpClientDispatcher, HttpServerDispatcher}
import com.twitter.finagle.http.exp.StreamTransport
import com.twitter.finagle.http.filter._
import com.twitter.finagle.http.service.HttpResponseClassifier
import com.twitter.finagle.http2.transport.MultiplexTransporter
import com.twitter.finagle.http2.{Http2Listener, Http2Transporter}
import com.twitter.finagle.netty4.http.{Netty4HttpListener, Netty4HttpTransporter}
import com.twitter.finagle.netty4.http.{Netty4ClientStreamTransport, Netty4ServerStreamTransport}
import com.twitter.finagle.server._
import com.twitter.finagle.service.{ResponseClassifier, RetryBudget}
import com.twitter.finagle.ssl.ApplicationProtocols
import com.twitter.finagle.stats.{ExceptionStatsHandler, StatsReceiver}
import com.twitter.finagle.toggle.Toggle
import com.twitter.finagle.tracing._
import com.twitter.finagle.transport.{Transport, TransportContext}
import com.twitter.util.{Duration, Future, Monitor, StorageUnit, Time}
import java.net.{InetSocketAddress, SocketAddress}

/**
 * A rich HTTP/1.1 client with a *very* basic URL fetcher. (It does not handle
 * redirects, does not have a cookie jar, etc.)
 */
trait HttpRichClient { self: Client[Request, Response] =>
  def fetchUrl(url: String): Future[Response] = fetchUrl(new java.net.URL(url))
  def fetchUrl(url: java.net.URL): Future[Response] = {
    val addr = {
      val port = if (url.getPort < 0) url.getDefaultPort else url.getPort
      Address(url.getHost, port)
    }
    val req = http.RequestBuilder().url(url).buildGet()
    val service = newService(Name.bound(addr), "")
    service(req) ensure {
      service.close()
    }
  }
}

/**
 * HTTP/1.1 protocol support, including client and server.
 */
object Http extends Client[Request, Response] with HttpRichClient with Server[Request, Response] {

  // Toggles transport implementation to Http/2.
  private[this] object useH2 {
    private[this] val underlying: Toggle[Int] = Toggles("com.twitter.finagle.http.UseH2")
    def apply(): Boolean = underlying(ServerInfo().id.hashCode)
  }
  private[this] object useH2CClients {
    private[this] val underlying: Toggle[Int] = Toggles("com.twitter.finagle.http.UseH2CClients2")
    def apply(): Boolean = underlying(ServerInfo().id.hashCode)
  }
  private[this] object useH2CServers {
    private[this] val underlying: Toggle[Int] = Toggles("com.twitter.finagle.http.UseH2CServers")
    def apply(): Boolean = underlying(ServerInfo().id.hashCode)
  }
  private[this] object useHttp2MultiplexCodecClient {
    private[this] val underlying: Toggle[Int] = Toggles(
      "com.twitter.finagle.http.UseHttp2MultiplexCodecClient"
    )
    def apply(): Boolean = underlying(ServerInfo().id.hashCode)
  }

  /**
   * configure alternative http 1.1 implementations
   *
   * @param clientTransport client [[StreamTransport]] factory
   * @param serverTransport server [[StreamTransport]] factory
   * @param transporter [[Transporter]] factory
   * @param listener [[Listener]] factory
   */<commit_msg>csl: Http2ToggleTest demonstrates the test issue<commit_after>package com.twitter.finagle

import com.twitter.finagle.client._
import com.twitter.finagle.context.Contexts
import com.twitter.finagle.dispatch.GenSerialClientDispatcher
import com.twitter.finagle.filter.{NackAdmissionFilter, PayloadSizeFilter}
import com.twitter.finagle.http._
import com.twitter.finagle.http.codec.{HttpClientDispatcher, HttpServerDispatcher}
import com.twitter.finagle.http.exp.StreamTransport
import com.twitter.finagle.http.filter._
import com.twitter.finagle.http.service.HttpResponseClassifier
import com.twitter.finagle.http2.transport.MultiplexTransporter
import com.twitter.finagle.http2.{Http2Listener, Http2Transporter}
import com.twitter.finagle.netty4.http.{Netty4HttpListener, Netty4HttpTransporter}
import com.twitter.finagle.netty4.http.{Netty4ClientStreamTransport, Netty4ServerStreamTransport}
import com.twitter.finagle.server._
import com.twitter.finagle.service.{ResponseClassifier, RetryBudget}
import com.twitter.finagle.ssl.ApplicationProtocols
import com.twitter.finagle.stats.{ExceptionStatsHandler, StatsReceiver}
import com.twitter.finagle.toggle.Toggle
import com.twitter.finagle.tracing._
import com.twitter.finagle.transport.{Transport, TransportContext}
import com.twitter.util.{Duration, Future, Monitor, StorageUnit, Time}
import java.net.{InetSocketAddress, SocketAddress}

/**
 * A rich HTTP/1.1 client with a *very* basic URL fetcher. (It does not handle
 * redirects, does not have a cookie jar, etc.)
 */
trait HttpRichClient { self: Client[Request, Response] =>
  def fetchUrl(url: String): Future[Response] = fetchUrl(new java.net.URL(url))
  def fetchUrl(url: java.net.URL): Future[Response] = {
    val addr = {
      val port = if (url.getPort < 0) url.getDefaultPort else url.getPort
      Address(url.getHost, port)
    }
    val req = http.RequestBuilder().url(url).buildGet()
    val service = newService(Name.bound(addr), "")
    service(req) ensure {
      service.close()
    }
  }
}

/**
 * HTTP/1.1 protocol support, including client and server.
 */
object Http extends Client[Request, Response] with HttpRichClient with Server[Request, Response] {

  // Toggles transport implementation to Http/2.
  private[this] object useH2 {
    private[this] val underlying: Toggle[Int] = Toggles("com.twitter.finagle.http.UseH2")
    def apply(): Boolean = underlying(ServerInfo().id.hashCode)
  }
  object useH2CClients {
    private[twitter] val underlying: Toggle[Int] = Toggles(
      "com.twitter.finagle.http.UseH2CClients2")
    def apply(): Boolean = underlying(ServerInfo().id.hashCode)
  }
  private[this] object useH2CServers {
    private[this] val underlying: Toggle[Int] = Toggles("com.twitter.finagle.http.UseH2CServers")
    def apply(): Boolean = underlying(ServerInfo().id.hashCode)
  }
  private[this] object useHttp2MultiplexCodecClient {
    private[this] val underlying: Toggle[Int] = Toggles(
      "com.twitter.finagle.http.UseHttp2MultiplexCodecClient"
    )
    def apply(): Boolean = underlying(ServerInfo().id.hashCode)
  }

  /**
   * configure alternative http 1.1 implementations
   *
   * @param clientTransport client [[StreamTransport]] factory
   * @param serverTransport server [[StreamTransport]] factory
   * @param transporter [[Transporter]] factory
   * @param listener [[Listener]] factory
   */
{'fraction_non_alphanumeric': 0.11463159467942012, 'fraction_numerical': 0.008219997010910177, 'mean_word_length': 5.007181328545781, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7484899', 'n_tokens_mistral': 2039, 'n_tokens_neox': 2017, 'n_words': 427}