Skip to content
Open
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
2 changes: 2 additions & 0 deletions docs/src/main/paradox/client-side/http2.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,5 @@ Java
: @@snip [HttpClientExampleDocTest.java](/docs/src/test/java/docs/http/javadsl/Http2ClientApp.java) { #response-future-association }

Connection-specific headers set on the model are dropped with a warning when sent over HTTP/2.

The `:authority` pseudo-header carries the request host and port, without the optional URI userinfo.
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,18 @@ private[http2] class RequestRendering(
headerPairs
}

// a `Host` header names the authority of a relative URI, as it does in HTTP/1.1, ahead of the connection's
private def authority(request: HttpRequest): String =
if (!request.uri.authority.isEmpty) request.uri.authority.toString
else
request.header[Host] match {
case Some(host) if !host.isEmpty => Uri.Authority(host.host, host.port).toString
case _ => connectionAuthority.toString
}
private def authority(request: HttpRequest): String = {
val uriAuthority = request.uri.authority
val effectiveAuthority =
if (uriAuthority.nonEmpty) uriAuthority
else
// A Host header names the authority of a relative URI ahead of the connection's authority.
request.header[Host] match {
case Some(host) if !host.isEmpty => Uri.Authority(host.host, host.port)
case _ => connectionAuthority
}
HttpMessageRendering.renderRequestAuthority(effectiveAuthority)
}

// `Raw-Request-URI` is a SyntheticHeader, so it is already excluded from the rendered header block by the
// `renderInRequests` filter and is only consumed here. As in HTTP/1.1, the value is taken as given; the header
Expand Down Expand Up @@ -157,6 +161,11 @@ private[http2] sealed abstract class MessageRendering[R <: HttpMessage] extends
@InternalApi
private[http2] object HttpMessageRendering {

// RFC 9113 Section 8.3.1 excludes userinfo from the HTTP(S) :authority field.
def renderRequestAuthority(authority: Uri.Authority): String =
if (authority.userinfo.isEmpty) authority.toString
else authority.copy(userinfo = "").toString

// One policy for initial fields and both streamed and attribute-supplied trailers.
def allowsHeader(header: HttpHeader, isServer: Boolean, isTrailer: Boolean,
log: LoggingAdapter): Boolean = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,19 @@ class HttpMessageRenderingSpec extends AnyWordSpec with Matchers {
value1.exists(_._1 == "date") shouldBe false
}

"render only the host and port of a modeled HTTP/2 request authority" in {
val host = Uri.Host("example.test")
val ipv6 = Uri.Host("[2001:db8::7]")
val syntheticUserInfo = "synthetic-component"
val cases = Seq(
Uri.Authority(host) -> "example.test",
Uri.Authority(host, userinfo = syntheticUserInfo) -> "example.test",
Uri.Authority(host, 8443, syntheticUserInfo) -> "example.test:8443",
Uri.Authority(ipv6, 8443, syntheticUserInfo) -> "[2001:db8::7]:8443")
for ((authority, expected) <- cases)
HttpMessageRendering.renderRequestAuthority(authority) shouldBe expected
}

"take ':scheme' and ':authority' of a relative URI from the connection" in {
// RFC 9113 8.3.1: ':scheme' is mandatory and ':authority' must not be empty
pseudoHeaders(HttpRequest(uri = "/foo"), "https", Uri.Authority(Uri.Host("example.com"))) shouldEqual
Expand Down