Skip to content

Commit

Permalink
add a test for handling empty trailers
Browse files Browse the repository at this point in the history
  • Loading branch information
NavidJalali committed Oct 23, 2024
1 parent 5dd4203 commit af2e0db
Showing 1 changed file with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@

package org.apache.pekko.http.impl.engine.http2

import com.typesafe.config.ConfigFactory
import java.time.format.DateTimeFormatter
import org.apache.pekko
import org.apache.pekko.http.scaladsl.settings.{ ClientConnectionSettings, ServerSettings }
import pekko.event.NoLogging
import pekko.http.impl.engine.rendering.DateHeaderRendering
import pekko.http.scaladsl.model.headers._
import pekko.http.scaladsl.model.{ ContentTypes, DateTime, HttpHeader, TransferEncodings }

import scala.collection.immutable.Seq
import pekko.http.scaladsl.model._
import scala.collection.immutable.VectorBuilder
import scala.util.Try
import org.scalatest.matchers.should.Matchers
Expand Down Expand Up @@ -147,6 +147,22 @@ class HttpMessageRenderingSpec extends AnyWordSpec with Matchers {
value1.exists(_._1 == "date") shouldBe false
}

"handle empty trailer" in {
val config = ConfigFactory.load("reference.conf")
Try {
val rendering = new RequestRendering(ClientConnectionSettings(config), NoLogging)
rendering(HttpRequest().withAttributes(Map(AttributeKeys.trailer -> Trailer())))
}.isSuccess shouldBe true
Try {
val rendering = new ResponseRendering(ServerSettings(config), NoLogging, dateHeaderRendering)
rendering(
HttpResponse().withAttributes(
Map(
AttributeKeys.trailer -> Trailer(),
Http2.streamId -> 0)))
}.isSuccess shouldBe true
}

}

private def renderClientHeaders(headers: immutable.Seq[HttpHeader], builder: VectorBuilder[(String, String)],

Check warning on line 168 in http2-tests/src/test/scala/org/apache/pekko/http/impl/engine/http2/HttpMessageRenderingSpec.scala

View workflow job for this annotation

GitHub Actions / Compile and test (2.12, 8)

private method renderClientHeaders in class HttpMessageRenderingSpec is never used

Check warning on line 168 in http2-tests/src/test/scala/org/apache/pekko/http/impl/engine/http2/HttpMessageRenderingSpec.scala

View workflow job for this annotation

GitHub Actions / Compile and test (2.12, 11)

private method renderClientHeaders in class HttpMessageRenderingSpec is never used
Expand All @@ -158,10 +174,12 @@ class HttpMessageRenderingSpec extends AnyWordSpec with Matchers {
peerIdHeader: Option[(String, String)] = None): Unit =
HttpMessageRendering.renderHeaders(headers, builder, peerIdHeader, NoLogging, isServer = true,
shouldRenderAutoHeaders = true,
dateHeaderRendering = new DateHeaderRendering {
// fake date rendering
override def renderHeaderPair(): (String, String) = "date" -> DateTime.now.toRfc1123DateTimeString
override def renderHeaderBytes(): Array[Byte] = ???
override def renderHeaderValue(): String = ???
})
dateHeaderRendering = dateHeaderRendering)

private lazy val dateHeaderRendering = new DateHeaderRendering {
// fake date rendering
override def renderHeaderPair(): (String, String) = "date" -> DateTime.now.toRfc1123DateTimeString
override def renderHeaderBytes(): Array[Byte] = ???
override def renderHeaderValue(): String = ???
}
}

0 comments on commit af2e0db

Please sign in to comment.