def apply()

in server/src/main/scala/com/twitter/server/handler/ClientRegistryHandler.scala [125:167]


  def apply(req: Request): Future[Response] = {
    val uri = Uri.fromRequest(req)
    uri.path.stripPrefix(uriPrefix) match {
      case idx @ ("index.html" | "index.htm" | "index.txt" | "clients") =>
        val leastPerformant = clientProfiles.sorted(profileOrdering).take(4)
        val html =
          if (leastPerformant.isEmpty) ""
          else {
            render("Least Performant Downstream Clients", leastPerformant)
          }
        // This is useful to avoid the returned fragment being wrapped
        // with an index in the context of an ajax call.
        val typ = if (idx.endsWith(".txt")) "text/plain" else "text/html"
        newResponse(
          contentType = s"$typ;charset=UTF-8",
          content = Buf.Utf8(html)
        )

      case name =>
        val decodedName = URLDecoder.decode(name, StandardCharsets.UTF_8.name)
        val clientEntries = stackRegistry.registrants.filter(_.name == decodedName)
        if (clientEntries.isEmpty) new404(s"$name could not be found.")
        else {
          val client = clientEntries.head

          val scope = findClientScope(client.name)
          val stackHtml = StackRegistryView.render(client, scope)

          val loadBalancerData = LoadBalancersHandler.getBalancer(Some(name))
          val loadBalancerView =
            new BalancerHtmlView(loadBalancerData, LoadBalancersHandler.RoutePath)
          val loadBalancerHtml = loadBalancerView.render

          val endpointEntry = EndpointRegistry.registry.endpoints(name)
          val endpointHtml = EndpointRegistryView.render(endpointEntry)

          newResponse(
            contentType = "text/html;charset=UTF-8",
            content = Buf.Utf8(stackHtml + loadBalancerHtml + endpointHtml)
          )
        }
    }
  }