Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix partial match #622

Merged
merged 7 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Comment on lines 100 to +102
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the question here is if someone added a AttributeKeys.trailer but it contained no headers, should we produce a ParsedHeadersFrame here? Looking at Http2SubStream/OutStreamImpl, it does seem safe (it will produce an empty DataFrame with endStream = true if necessary). It seems unlikely that any downstream implementation would rely on receiving an empty frame of trailing headers.

All in all I think this is OK, though adding a AttributeKeys.trailer without any headers seems strange, the code that caused that might deserve a closer look.

}

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._
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep the imports in some order - why are you changing the order of these imports?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've committed a change to the PR branch to try to order the imports

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was a bit too slow 😄

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)],
NavidJalali marked this conversation as resolved.
Show resolved Hide resolved
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 = ???
}
}
Loading