-
Notifications
You must be signed in to change notification settings - Fork 39
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
Fix partial match #622
Changes from all commits
5dd4203
af2e0db
8f09a3e
94779d3
eb66229
f755008
569ccfd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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._ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
|
@@ -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
|
||
|
@@ -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 = ??? | ||
} | ||
} |
There was a problem hiding this comment.
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 aParsedHeadersFrame
here? Looking atHttp2SubStream
/OutStreamImpl
, it does seem safe (it will produce an emptyDataFrame
withendStream = 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.