Skip to content

feat: preserve the HTTP/2 OPTIONS asterisk target - #981

Open
He-Pin wants to merge 1 commit into
apache:mainfrom
He-Pin:port/http2-bad-header-response
Open

He-Pin wants to merge 1 commit into
apache:mainfrom
He-Pin:port/http2-bad-header-response

Conversation

@He-Pin

@He-Pin He-Pin commented Mar 8, 2026 •

Copy link
Copy Markdown
Member

Motivation

HTTP/2 applications need to distinguish a server-wide OPTIONS * request from OPTIONS / without changing the default routing behavior or interfering with outbound URI rewriting.

Modification

Add the default-off pekko.http.server.http2.accept-asterisk-options setting. When enabled, retain the effective URI's scheme and authority and expose * in the typed request attribute AttributeKeys.asteriskRequestTarget in Scala and Java, instead of adding a synthetic Raw-Request-URI header. Document the HTTP/2 opt-in and the existing HTTP/1.1 behavior. Ordinary path parsing and CONNECT handling are unchanged.

Result

Without opt-in, an HTTP/2 server continues rejecting OPTIONS *. With opt-in, application handlers can distinguish it from OPTIONS /. The attribute is not written to the wire and does not override a rewritten outbound URI. HTTP/1.1 wire and request-model behavior remain unchanged.

Tests

  • Eight focused tests passed on Scala 2.13.18 / Temurin 17: two settings cases, three HTTP/2 request parsing cases, one HTTP/2 application-handler case, one outbound rendering case, and one HTTP/1.1 parser case.
  • Scoped Scala and Java style checks, a targeted comparison of existing JVM method signatures, and git diff --check passed. Independent review of the exact code diff found no blocking issue.
  • No h2spec, full binary-compatibility suite, or remote CI was run as part of this validation.

References

override def parse(name: String, value: String, parserSettings: ParserSettings): (Uri.Path, Option[String]) =
try {
if (value.isEmpty) {
protocolError("Pseudo-header ':path' must not be empty")

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The ":path" pseudo-header field includes the path and query parts
of the target URI (the "path-absolute" production and optionally a
'?' character followed by the "query" production (see Sections 3.3
and 3.4 of [RFC3986]). A request in asterisk form includes the
value '*' for the ":path" pseudo-header field.

  This pseudo-header field MUST NOT be empty for "http" or "https"
  URIs; "http" or "https" URIs that do not contain a path component
  MUST include a value of '/'.  The exception to this rule is an
  OPTIONS request for an "http" or "https" URI that does not include
  a path component; these MUST include a ":path" pseudo-header field
  with a value of '*' (see [[RFC7230], Section 5.3.4](https://datatracker.ietf.org/doc/html/rfc7230#section-5.3.4)).

Belshe, et al. Standards Track [Page 55]

RFC 7540 HTTP/2 May 2015

All HTTP/2 requests MUST include exactly one valid value for the
":method", ":scheme", and ":path" pseudo-header fields, unless it is
a CONNECT request (Section 8.3). An HTTP request that omits
mandatory pseudo-header fields is malformed (Section 8.1.2.6).

HTTP/2 does not define a way to carry the version identifier that is
included in the HTTP/1.1 request line.

@pjfanning

Copy link
Copy Markdown
Member

There is also #961

@He-Pin
He-Pin force-pushed the port/http2-bad-header-response branch from c7ae010 to a0f6379 Compare March 8, 2026 09:40
@He-Pin
He-Pin marked this pull request as ready for review March 8, 2026 09:53
@He-Pin
He-Pin marked this pull request as draft March 8, 2026 09:56
@He-Pin
He-Pin force-pushed the port/http2-bad-header-response branch from 53c8772 to 4696e75 Compare March 8, 2026 12:34
@He-Pin He-Pin changed the title fix: return HTTP 400 for malformed HTTP/2 request headers instead of silent stream reset fix: align HTTP/2 malformed-header handling Mar 8, 2026
@He-Pin

He-Pin commented Mar 8, 2026

Copy link
Copy Markdown
Member Author

Rebased and will update the comments too.

@He-Pin
He-Pin force-pushed the port/http2-bad-header-response branch from 4696e75 to bad9ff0 Compare March 8, 2026 12:54
@He-Pin

He-Pin commented Mar 8, 2026

Copy link
Copy Markdown
Member Author

based on #961

@pjfanning

Copy link
Copy Markdown
Member

Isn't the main reason for this PR is to fix this test: "handle a ':path' with an asterisk"

@He-Pin
He-Pin marked this pull request as ready for review March 8, 2026 13:13
@He-Pin He-Pin changed the title fix: align HTTP/2 malformed-header handling fix: handle a ':path' with an asterisk as the RFC required Mar 8, 2026

@jrudolph jrudolph left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure how important these changes are. CONNECT is not really supported (afair), so I'm somewhat reluctant changing behaviour and adding extra code for that.

The OPTIONS change seems like a thing that might be needed (though, it's somewhat weird that no one found it missing so far). It doesn't feel fully addressed, though, tests and demonstrations how to use it are missing.

In any case, these should be two separate PRs, but right now I'm not convinced any of these are changes we should do.

@He-Pin
He-Pin force-pushed the port/http2-bad-header-response branch from bad9ff0 to 7dea820 Compare June 15, 2026 04:01
@He-Pin
He-Pin force-pushed the port/http2-bad-header-response branch from 7dea820 to b0edc50 Compare November 21, 2026 04:28
@He-Pin He-Pin changed the title fix: handle a ':path' with an asterisk as the RFC required fix: preserve the HTTP/2 OPTIONS asterisk target Nov 21, 2026
@He-Pin
He-Pin requested a review from pjfanning November 21, 2026 04:30
He-Pin added a commit to He-Pin/incubator-pekko-http that referenced this pull request Nov 22, 2026
Motivation:
HTTP/2 applications need to distinguish a server-wide OPTIONS request
from OPTIONS on the root resource.

Modification:
Preserve the scheme and authority and expose the asterisk using the
existing Raw-Request-URI marker. Document how Scala and Java handlers
can read it. Cover both targets in the same HTTP/2 server test.

Result:
Application handlers can recognize server-wide OPTIONS while OPTIONS /
keeps its existing URI and does not gain the marker.

Tests:
One focused Http2ServerSpec case (two requests) and two focused
RequestParsingSpec cases passed on Scala 2.13.18 / Temurin 17.0.21.1.
The http2-tests/Test and http-core Scalafmt checks and git diff --check
passed.

References:
RFC 9113 section 8.3.1; apache#981.
@He-Pin
He-Pin force-pushed the port/http2-bad-header-response branch from b0edc50 to b9ef4ef Compare November 22, 2026 13:16

@pjfanning pjfanning left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for picking up the asterisk-form TODO. Accepting OPTIONS * on HTTP/2 is right per RFC 9113 §8.3.1, and rejecting * for other methods is a good guard. My concerns are about how the request is then presented to existing handlers, see inline. The first two are the ones I'd like to settle before this goes in.

":scheme" -> "http",
":path" -> "*"))
request.uri.toString should ===("*") // FIXME: Compare in a better way
"handle server-wide OPTIONS with an application-visible asterisk target" in {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The accepting cases are covered, but the new rejection paths aren't. Could tests be added that GET with :path: * (and HEAD with transparent-head-requests on, since the check uses method rather than effectiveMethod) is answered with a 400 naming :path, and that *?q, */x and ** are rejected by the new grammar alternative?

@He-Pin
He-Pin force-pushed the port/http2-bad-header-response branch from b9ef4ef to 5198420 Compare November 22, 2026 23:44
@He-Pin
He-Pin requested a review from pjfanning November 22, 2026 23:45
@He-Pin
He-Pin force-pushed the port/http2-bad-header-response branch from 5198420 to 3988aec Compare November 23, 2026 17:26

@pjfanning pjfanning left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, the opt-in setting and the attribute instead of a synthetic Raw-Request-URI header resolve my two blocking points. What is left:

  • Rejection-path tests (from the earlier comment on RequestParsingSpec). The only new negative test is "disabled by default". With the setting on, could we cover GET with :path: *, HEAD with transparent-head-requests, and *?q, */x and **? As far as I can see the grammar and the match in RequestParsing reject all of them, so these should just pin it.
  • Where the flag is stored. It is kept by wrapping the internalSettings slot in a private AsteriskOptionsEnabled case class, with the constructor parameter renamed to storedInternalSettings. It works and the test shows it survives withInternalSettings, but it leaks into toString/equals and is easy to break later. Http2ServerSettingsImpl is private[http], so could this be a normal field with MiMa filters for the impl's constructor and copy?
  • No programmatic API. acceptAsteriskOptions is private[http] and there is no withAcceptAsteriskOptions on the scaladsl or javadsl Http2ServerSettings, unlike the other HTTP/2 settings, so it can only be enabled through config. Was that intended?
  • Nit: the title says fix, but this now adds a setting and a public attribute key, so feat fits better, and the new AttributeKeys.asteriskRequestTarget (Scala and Java) could carry a @since.
  • Nit: the attribute is a String whose only possible value is "*". Fine if you want room for other targets later, otherwise a marker would be simpler.

@He-Pin He-Pin changed the title fix: preserve the HTTP/2 OPTIONS asterisk target feat: preserve the HTTP/2 OPTIONS asterisk target Nov 24, 2026
Motivation:
Applications need to distinguish server-wide OPTIONS from the root
resource without changing the behavior of existing routes or forwarding
a synthetic header. Applications using programmatic settings also need
the same explicit opt-in as applications using HOCON.

Modification:
Add a default-off HTTP/2 server setting and expose its Java and Scala
accessors. Store the Boolean separately from internal settings. When
enabled, retain the effective URI and expose the original asterisk
through the typed request attribute. Leave HTTP/1.1 and CONNECT
unchanged. Document the API and exclude only the two former generated
signatures of the internal implementation from MiMa.

Result:
Applications can enable the setting per server without disturbing
internal settings. Rewritten requests still select their outbound URI.
The previous public settings method descriptors are unchanged.

Tests:
JDK 17 and Scala 2.13.18: Http2ServerSettingsSpec, 14 tests passed.
JDK 17: http-core compiled and MiMa passed on Scala 2.13.18 and 3.3.9.
Scoped Scala/Java formatting, headers and diff whitespace check passed.
No new wire tests were added or run in this settings-only follow-up.

References:
RFC 9113 section 8.3.1 and RFC 9110 section 9.3.7.
@He-Pin
He-Pin force-pushed the port/http2-bad-header-response branch from 3988aec to 858c650 Compare November 24, 2026 02:35
@He-Pin
He-Pin requested review from pjfanning and a balanced review from Copilot and removed request for pjfanning November 24, 2026 03:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants