@tailrec private def contentType()

in http-core/src/main/scala/org/apache/pekko/http/impl/model/parser/ContentTypeHeader.scala [30:53]


  @tailrec private def contentType(
      main: String,
      sub: String,
      params: Seq[(String, String)],
      charset: Option[HttpCharset] = None,
      builder: StringMapBuilder = null): ContentType =
    params match {
      case Nil =>
        val parameters = if (builder eq null) Map.empty[String, String] else builder.result()
        getMediaType(main, sub, charset.isDefined, parameters) match {
          case x: MediaType.Binary                               => ContentType.Binary(x)
          case x: MediaType.WithFixedCharset                     => ContentType.WithFixedCharset(x)
          case x: MediaType.WithOpenCharset if charset.isDefined => ContentType.WithCharset(x, charset.get)
          case x: MediaType.WithOpenCharset if charset.isEmpty   => ContentType.WithMissingCharset(x)
        }

      case Seq((key, value), tail @ _*) if equalsAsciiCaseInsensitive(key, "charset") =>
        contentType(main, sub, tail, Some(getCharset(value)), builder)

      case Seq(kvp, tail @ _*) =>
        val b = if (builder eq null) TreeMap.newBuilder[String, String] else builder
        b += kvp
        contentType(main, sub, tail, charset, b)
    }