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 a typed, independent acceptAsteriskOptions flag, default off, in the Scala and Java HTTP/2 server settings. It does not wrap or change the original internalSettings slot. When enabled, retain the effective URI scheme and authority and expose * using AttributeKeys.asteriskRequestTarget, without a synthetic Raw-Request-URI header. The guide explains how to identify server-wide OPTIONS on both HTTP/1.1 and HTTP/2. Ordinary path parsing and CONNECT behavior 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

  • JDK 17: six focused positive cases passed on each of Scala 2.13.18 and Scala 3.3.9, including HTTP/2 request target and settings behavior. The earlier rejection-path tests remain in the branch; they were not rerun in this scoped validation.
  • Project MiMa against published 2.0.0 passed on both axes using the exact precompiled artifacts. Old compiled Scala and Java callers linked against the retained constructor, copy, and companion factory API. No MiMa filters were added; this does not claim compatibility of the internal case-class Product shape or a full CI run.

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.

@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
@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.

pjfanning added a commit to He-Pin/incubator-pekko-http that referenced this pull request Nov 25, 2026
Motivation:
With server-wide OPTIONS enabled, only the accepting cases and the
"disabled by default" case were tested. The rejection paths added with
the asterisk-form grammar had no coverage.

Modification:
Add RequestParsingSpec cases, all with accept-asterisk-options on:
- ":path: *" with GET, HEAD, POST and DELETE is rejected and the error
  names ":path"
- HEAD with transparent-head-requests on is rejected as well
- "*?q", "*?", "*/x", "**" and "*/" are rejected by the path grammar
- "/*" and "/a/../*" stay ordinary origin-form paths without the
  asterisk request target attribute

Result:
The rejection paths are pinned by tests. No production code changed.

Tests:
- sbt "http2-tests/testOnly org.apache.pekko.http.impl.engine.http2.RequestParsingSpec -- -z asterisk" - 6 passed
- sbt http2-tests/Test/scalafmt - no changes

References:
Refs apache#981
@He-Pin
He-Pin force-pushed the port/http2-bad-header-response branch from 5a60c19 to 1b47818 Compare November 25, 2026 11:06

@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.

The latest revision moves accept-asterisk-options back into the internalSettings slot and drops the MiMa filter file, which undoes the change made after my earlier review. One comment inline; it applies to two other open PRs as well. The rejection-path tests are still in place and I have resolved that thread.

He-Pin added a commit to He-Pin/incubator-pekko-http that referenced this pull request Nov 26, 2026
Motivation
----------
An HTTP/2 application needs to distinguish server-wide OPTIONS from
OPTIONS on the root resource without changing default routing behavior.

Modification
------------
Add a default-off server setting and a typed request attribute in Java
and Scala. Store opt-in choices together in the existing settings slot,
keeping its original constructor and copy signatures. A legacy settings
update transfers only the legacy value, not another instance's opt-in.

Result
------
Applications can handle OPTIONS * explicitly. Normal targets and
outbound request rendering are unchanged. When disabled, the settings
slot retains the old representation.

Tests
-----
Six focused settings tests each on Scala 2.13.18, 3.3.9 and 3.9.0;
Scala format and license checks. Validate binary compatibility with
MiMa and unchanged Pekko HTTP 2.0.0 Java and Scala consumers.

References
----------
RFC 9113 section 8.3.1 and RFC 9110 section 9.3.7
apache#981

Co-authored-by: PJ Fanning <pjfanning@users.noreply.github.com>
@He-Pin
He-Pin force-pushed the port/http2-bad-header-response branch from 1b47818 to c8aa427 Compare November 26, 2026 03:03
He-Pin added a commit to He-Pin/incubator-pekko-http that referenced this pull request Nov 26, 2026
Motivation
----------
An HTTP/2 application needs to distinguish server-wide OPTIONS from
OPTIONS on the root resource without changing default routing behavior.

Modification
------------
Add a default-off server setting and a typed request attribute in Java
and Scala. Store opt-in choices together in the existing settings slot,
keeping its original constructor and copy signatures. A legacy settings
update transfers only the legacy value, not another instance's opt-in.

Result
------
Applications can handle OPTIONS * explicitly. Normal targets and
outbound request rendering are unchanged. When disabled, the settings
slot retains the old representation.

Tests
-----
Six focused settings tests each on Scala 2.13.18, 3.3.9 and 3.9.0;
Scala format and license checks. Validate binary compatibility with
MiMa and unchanged Pekko HTTP 2.0.0 Java and Scala consumers.

References
----------
RFC 9113 section 8.3.1 and RFC 9110 section 9.3.7
apache#981

Co-authored-by: PJ Fanning <pjfanning@users.noreply.github.com>
@He-Pin
He-Pin force-pushed the port/http2-bad-header-response branch from c8aa427 to 45aa908 Compare November 26, 2026 03:12

@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 the update; the public acceptAsteriskOptions / withAcceptAsteriskOptions API and @since tags look good. The open thread on internalSettings still stands. New points:

  • Docs (should-fix): on HTTP/1.1, OPTIONS * always reaches the application with no opt-in: HttpServerBluePrint turns Uri(authority = Host("*")) into the effective URI http://* with an empty path, so pathEnd / pathEndOrSingleSlash match it just as on HTTP/2. In uri-model.md, "the default is off, so existing routes do not start receiving these requests" and "check the attribute before dispatching" only hold for HTTP/2, and a handler that checks only the attribute will treat HTTP/1.1 OPTIONS * as OPTIONS /. Could the docs give the HTTP/1.1 check too (e.g. request.uri.authority.host.address == "*"), or recommend checking both so one handler works for both protocols?
  • Nit: the new test in HttpMessageRenderingSpec can't fail because of this change, since HTTP/2 request rendering never reads request attributes. Fine as a guard, but a short comment saying so would help.
  • Nit: the Tests section of the description still lists "three HTTP/2 request parsing cases"; the branch now also has the rejection cases.

He-Pin added a commit to He-Pin/incubator-pekko-http that referenced this pull request Nov 26, 2026
Motivation:
An HTTP/2 server needs to distinguish a server-wide OPTIONS request
from the ordinary root resource without changing the existing default
or rewriting an outbound request.

Modification:
Retain the default-off Scala and Java opt-in and the typed request
attribute. Store the option in its own immutable implementation
field, not in the internal settings slot. Preserve the published
constructor and inferred copy entry points. Document the distinct
existing HTTP/1.1 representation and the opt-in HTTP/2 one.

Result:
The opt-in and internal settings compose independently across
ordinary withers and copies. The request attribute is not rendered
on outbound requests. Existing HTTP/1.1 handling is unchanged.

Tests:
JDK 17, Scala 2.13.18 and 3.3.9: six scoped settings tests per
version. On each version, scoped MiMa against 2.0.0 and old JVM
consumer linkage passed, without new filters. The two ordinary
HTTP/2 handler/renderer cases passed on Scala 2.13. No full CI.

References:
RFC 9113 section 8.3.1 and PJF feedback on apache#981.

Co-authored-by: PJ Fanning <pjfanning@users.noreply.github.com>
@He-Pin
He-Pin force-pushed the port/http2-bad-header-response branch from 45aa908 to 640aecf Compare November 26, 2026 12:46
@He-Pin
He-Pin requested a review from pjfanning November 26, 2026 12:48
He-Pin added a commit to He-Pin/incubator-pekko-http that referenced this pull request Nov 27, 2026
Motivation:
High-cardinality outbound values can displace useful dynamic HPACK
table entries. Applications need an opt-in compression policy.

Modification:
Add role-specific configured names and an optional typed Scala/Java
policy. Use ordinary settings fields, independent of internalSettings;
preserve the released JVM constructors and copy descriptors. Keep the
Latin-1 guard, exact index reuse, and never-index behavior. Rebase on
current main and keep both imports required by the HTTP/2 server spec.

Result:
Unconfigured applications keep their existing behavior. A configured
policy can decline eligible new entries without changing index reuse.

Tests:
JDK 17 on Scala 2.13.18 and 3.3.9: 14 focused ordinary settings,
HPACK, and client/server tests per axis and a released 2.0.0 Scala
copy caller. Scoped settings MiMa and Scala formatting passed.

References:
Netty #18501, RFC 7541 Section 6.2.2; related apache#981 and apache#1589.
He-Pin added a commit to He-Pin/incubator-pekko-http that referenced this pull request Nov 27, 2026
Motivation:
Keep the explicit server-side CONNECT opt-in composable with other HTTP/2
settings while preserving released JVM constructor and copy linkage.

Modification:
Retain the existing application-owned draft on current main. Replace
the settings subclass with a default-off field; keep the released
constructor and copy bridges and keep internal settings independent.

Result:
The draft's default behavior and tunnel API are unchanged. Existing
copies preserve the new setting. Tunnel lifecycle design remains open.

Tests:
- Focused settings: 4 passed on each of Scala 2.13.18 and 3.3.9.
- Java wither smoke, linked 2.0.0 consumers, and scoped MiMa passed on both.
- Compatibility-guide checker: 2 passed on Scala 2.13.18.
- Cached overlays; no full CI, native sbt test graph, or tunnel tests.

References:
Refs apache#1588, apache#1589, apache#981, apache#1556.
https://www.rfc-editor.org/rfc/rfc9113.html#section-8.5
He-Pin added a commit to He-Pin/incubator-pekko-http that referenced this pull request Nov 27, 2026
Motivation:
HTTP/2 applications need to distinguish server-wide OPTIONS from an
ordinary resource request without changing default request routing.

Modification:
Use the opt-in HTTP/2 server setting and a typed asterisk request
attribute, preserving the effective scheme and authority. Assert an
ordinary OPTIONS root remains ordinary when its query is present,
even an empty query. Preserve the released internal settings factory,
constructor and copy entries. Keep HTTP/1.x behavior and outbound
request rewriting independent of the marker.

Result:
Applications can identify server-wide requests explicitly, without
changing existing default routing or ordinary OPTIONS query handling.

Tests:
- Six named positive cases passed with JDK 17 on Scala 2.13.18 and 3.3.9,
  compiling the exact changed sources against current-main build outputs.
- JVM descriptor checks and direct calls compiled against Pekko HTTP
  2.0.0 passed on both axes. Scoped Scalafmt and whitespace checks passed.
- Full CI was not run.

References:
Refs apache#981 - RFC 9113 §8.3.1 (erratum 9175 held) and RFC 9110 §9.3.7.
@He-Pin
He-Pin force-pushed the port/http2-bad-header-response branch from 640aecf to 14200db Compare November 27, 2026 13:10
He-Pin added a commit to He-Pin/incubator-pekko-http that referenced this pull request Nov 28, 2026
Motivation:
A valid HTTP/1.1 OPTIONS * request exposed "*" as the effective URI host
instead of the authority from Host. The asterisk form provides no
authority or path and query for target URI reconstruction.

Modification:
Preserve the raw asterisk target, but pass an empty target URI to the
existing effective URI reconstruction for successfully parsed HTTP/1.1
OPTIONS * requests. Document the observable behavior change. Keep the
existing Accept negotiation release note when resolving the rebase.

Result:
The effective URI now uses the Host authority with an empty path and
no query. Applications can still opt in to capture the literal target
through Raw-Request-URI. Origin-form OPTIONS is unchanged.

Tests:
- Prior scoped JDK 17 runs on Scala 2.13.18 and 3.3.9: 4/4 on each axis;
  the two asterisk cases failed on the old baseline and both origin-form
  controls passed.
- This rebase preserves the tested source and fixture except for an
  independent comment already on main. The release-note conflict is
  resolved without changing either entry. Patch whitespace checked.
  No tests rerun on this rebased commit.

References:
None - RFC 9112 sections 3.2.4 and 3.3. HTTP/2 work in apache#981 is separate.
He-Pin added a commit that referenced this pull request Nov 28, 2026
Motivation:
A valid HTTP/1.1 OPTIONS * request exposed "*" as the effective URI host
instead of the authority from Host. The asterisk form provides no
authority or path and query for target URI reconstruction.

Modification:
Preserve the raw asterisk target, but pass an empty target URI to the
existing effective URI reconstruction for successfully parsed HTTP/1.1
OPTIONS * requests. Document the observable behavior change. Keep the
existing Accept negotiation release note when resolving the rebase.

Result:
The effective URI now uses the Host authority with an empty path and
no query. Applications can still opt in to capture the literal target
through Raw-Request-URI. Origin-form OPTIONS is unchanged.

Tests:
- Prior scoped JDK 17 runs on Scala 2.13.18 and 3.3.9: 4/4 on each axis;
  the two asterisk cases failed on the old baseline and both origin-form
  controls passed.
- This rebase preserves the tested source and fixture except for an
  independent comment already on main. The release-note conflict is
  resolved without changing either entry. Patch whitespace checked.
  No tests rerun on this rebased commit.

References:
None - RFC 9112 sections 3.2.4 and 3.3. HTTP/2 work in #981 is separate.
Motivation:
HTTP/2 applications need to distinguish server-wide OPTIONS from an
ordinary resource request without changing default request routing.

Modification:
Use the opt-in HTTP/2 server setting and a typed asterisk request
attribute, preserving the effective scheme and authority. Assert an
ordinary OPTIONS root remains ordinary when its query is present,
even an empty query. Preserve the released internal settings factory,
constructor and copy entries. Keep HTTP/1.x behavior and outbound
request rewriting independent of the marker.

Result:
Applications can identify server-wide requests explicitly, without
changing existing default routing or ordinary OPTIONS query handling.

Tests:
- Six named positive cases passed with JDK 17 on Scala 2.13.18 and 3.3.9,
  compiling the exact changed sources against current-main build outputs.
- JVM descriptor checks and direct calls compiled against Pekko HTTP
  2.0.0 passed on both axes. Scoped Scalafmt and whitespace checks passed.
- Full CI was not run.

References:
Refs apache#981 - RFC 9113 §8.3.1 (erratum 9175 held) and RFC 9110 §9.3.7.
@He-Pin
He-Pin force-pushed the port/http2-bad-header-response branch from 14200db to 8543e47 Compare November 29, 2026 14:05
He-Pin added a commit to He-Pin/incubator-pekko-http that referenced this pull request Nov 29, 2026
Motivation:
High-cardinality outbound values can displace useful dynamic HPACK
table entries. Applications need an opt-in compression policy.

Modification:
Add role-specific configured names and an optional typed Scala/Java
policy. Use ordinary settings fields, independent of internalSettings;
preserve the released JVM constructors and copy descriptors. Keep the
Latin-1 guard, exact index reuse, and never-index behavior. Rebase on
current main and keep both imports required by the HTTP/2 server spec.

Result:
Unconfigured applications keep their existing behavior. A configured
policy can decline eligible new entries without changing index reuse.

Tests:
JDK 17 on Scala 2.13.18 and 3.3.9: 14 focused ordinary settings,
HPACK, and client/server tests per axis and a released 2.0.0 Scala
copy caller. Scoped settings MiMa and Scala formatting passed.

References:
Netty #18501, RFC 7541 Section 6.2.2; related apache#981 and apache#1589.
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