Skip to content

Commit

Permalink
Fix partial match (#622)
Browse files Browse the repository at this point in the history
* fix partial match

* add a test for handling empty trailers

* fix imports

* put back the immutable

* add back the Seq import

* bundle pekko http imports together

* order of imports

---------

Co-authored-by: PJ Fanning <[email protected]>
  • Loading branch information
NavidJalali and pjfanning authored Oct 24, 2024
1 parent 91315b3 commit 750e8f9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private[http2] sealed abstract class MessageRendering[R <: HttpMessage] extends
r.attribute(AttributeKeys.trailer) match {
case Some(trailer) if trailer.headers.nonEmpty =>
OptionVal.Some(ParsedHeadersFrame(streamId, endStream = true, trailer.headers, None))
case None => OptionVal.None
case _ => OptionVal.None
}

Http2SubStream(r.entity, headersFrame, trailingHeadersFrame,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,21 @@
package org.apache.pekko.http.impl.engine.http2

import java.time.format.DateTimeFormatter

import com.typesafe.config.ConfigFactory
import org.apache.pekko
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 scala.collection.immutable.VectorBuilder
import scala.util.Try
import pekko.http.scaladsl.model._
import pekko.http.scaladsl.settings.{ ClientConnectionSettings, ServerSettings }
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec

import scala.collection.immutable.VectorBuilder
import scala.collection.immutable.Seq
import scala.collection.immutable
import scala.util.Try

object MyCustomHeader extends ModeledCustomHeaderCompanion[MyCustomHeader] {
override def name: String = "custom-header"
Expand Down Expand Up @@ -147,6 +149,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)],
Expand All @@ -158,10 +176,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: 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 750e8f9

Please sign in to comment.