All Downloads are FREE. Search and download functionalities are using the official Maven repository.

sttp.tapir.server.akkahttp.AkkaModel.scala Maven / Gradle / Ivy

There is a newer version: 1.11.9
Show newest version
package sttp.tapir.server.akkahttp

import akka.http.scaladsl.model.HttpHeader
import akka.http.scaladsl.model.HttpHeader.ParsingResult
import sttp.model.{HasHeaders, Header, HeaderNames}

import scala.collection.immutable.Seq

private[akkahttp] object AkkaModel {
  private val ctHeaderNameLowerCase = HeaderNames.ContentType.toLowerCase
  private val clHeaderNameLowerCase = HeaderNames.ContentLength.toLowerCase
  private val teHeaderNameLowerCase = HeaderNames.TransferEncoding.toLowerCase

  def parseHeadersOrThrowWithoutContentHeaders(hs: HasHeaders): Seq[HttpHeader] =
    hs.headers
      .filterNot(h => h.is(ctHeaderNameLowerCase) || h.is(clHeaderNameLowerCase) || h.is(teHeaderNameLowerCase))
      .map(parseHeaderOrThrow)

  def parseHeaderOrThrow(h: Header): HttpHeader =
    HttpHeader.parse(h.name, h.value) match {
      case ParsingResult.Ok(h, _)     => h
      case ParsingResult.Error(error) => throw new IllegalArgumentException(s"Cannot parse header (${h.name}, ${h.value}): $error")
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy