Skip to content

feat: make HTTP/2 HPACK insertion configurable - #1556

Open
He-Pin wants to merge 1 commit into
apache:mainfrom
He-Pin:feat/hpack-no-index-headers
Open

He-Pin wants to merge 1 commit into
apache:mainfrom
He-Pin:feat/hpack-no-index-headers

Conversation

@He-Pin

@He-Pin He-Pin commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Motivation

Out-of-band values that rarely repeat can evict useful entries from the outbound HTTP/2 HPACK dynamic table. Applications and frameworks need a way to decline those insertions.

Modification

Provide separate opt-in header-name lists and a typed policy for the Java and Scala HTTP/2 client and server settings. The Java getters return the effective policy (configured list or explicit callback) so a framework can compose its own rule with the user's rule before installing it. The default is empty; an explicit policy replaces the list unless the caller composes them. No reflective configuration is added.
Store the policy in dedicated settings fields. Retain the released JVM constructors, positional copy methods, and old copy defaults. Legacy copies preserve the receiver's policy. The generated private implementation companion, extractor and Product shape are not asserted compatible.

Result

Defaults and exact index reuse are unchanged. The policy declines only eligible new insertions and is not a Never Indexed or confidentiality control.

Validation: JDK 21 / Scala 2.13.18: 7 Java settings tests, 8 Scala settings tests, 3 codec tests, and 4 client/server HTTP/2 tests passed; scoped Java/Scala formatting, http-core MiMa, and Paradox generation passed. An unchanged Scala caller separately compiled against released Pekko HTTP 2.0.0 also called the old client/server constructors and positional copy methods against this build. This covers those four linkage paths, not all private case-class methods or a combined build of open PRs.

References

RFC 7541 §6.2.2 · Review feedback · Separate Never Indexed follow-up

@He-Pin
He-Pin marked this pull request as ready for review November 23, 2026 16:42
@He-Pin
He-Pin marked this pull request as draft November 23, 2026 16:52
@He-Pin
He-Pin force-pushed the feat/hpack-no-index-headers branch from dd2dacf to 4d1c173 Compare November 23, 2026 17:09
@He-Pin He-Pin changed the title feat: make HTTP/2 HPACK insertion optional by header name feat: make HTTP/2 HPACK insertion configurable Nov 23, 2026
@He-Pin
He-Pin marked this pull request as ready for review November 23, 2026 17:10
@He-Pin
He-Pin force-pushed the feat/hpack-no-index-headers branch from 4d1c173 to d268b2c Compare November 23, 2026 17:23

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

Some points from a first read. Source review only, I have not run it.

  • The rebase needs care. The conflict is in the if (useIndexing) block of Encoder.encodeHeader that #1552 rewrote. This PR's side has no Latin-1 guard, so taking it would bring back the encoder/peer table mismatch for chars above 0xFF. The merged condition needs both: the Latin-1 check from #1552 and the policy check. Please also make sure the #1552 tests in HpackEncoderSpec still run against the new 5-argument overload.
  • The policy lives in the internalSettings slot. HpackPolicyOptions extends the internal-settings marker traits and withHpackIndexingPolicy calls withInternalSettings, which replaces the whole value. Nothing else uses the slot today, but a later withInternalSettings call drops the user's policy and vice versa. For a public feature I would prefer a real field on the private[http] impls with MiMa filters. (#981 does something similar for its flag, so it would be good to settle both the same way.)
  • A wrong hpack-indexing-policy-class fails per connection, not at startup. The class is resolved in HeaderCompression.preStart, so a typo lets the server bind and then fails every HTTP/2 connection, with a reflective instantiation per connection. Could the class and its constructor be validated when the settings are read?
  • Java API shape. The server method is on javadsl Http2ServerSettings but the client one is on javadsl ClientConnectionSettings rather than Http2ClientSettings, where the other with* methods are.
  • Tests. ClientConnectionSettingsTest.testConfigureHpackIndexingPolicy only asserts non-null, so it shows the API compiles from Java but not that the policy is kept or applied. The two end-to-end tests exercise only the name list; the programmatic policy and the configured class are tested at the HeaderCompression stage only. Could one test show a policy set through withHpackIndexingPolicy reaching a real client and server connection?
  • Pseudo-headers cannot be listed in hpack-no-index-headers because names are validated as tokens. :path is the usual source of table churn, so needing a custom class for it is a notable limit. It is documented; is it intended?
  • Nit: HpackPolicyOptions is a case class holding a Config and a function, so the settings toString prints the http2 config section when a class is configured, and equality is by identity for explicit policies.

He-Pin added a commit to He-Pin/incubator-pekko-http that referenced this pull request Nov 24, 2026
Motivation: High-cardinality outgoing fields can churn the dynamic table.
The opt-in needs to preserve the encoder's existing indexing invariants
and coexist with internal HTTP/2 settings.

Modification: Provide independent client and server options with a
case-insensitive name list or Java/Scala policy. Keep the policy outside
internalSettings and validate a configured class and constructor when
loading settings; create one instance per materialized connection.
Expose the policy on both Java HTTP/2 settings types. Keep existing
indexes, sensitive representation and Latin-1 insertion eligibility.
Cover positive endpoint, settings and encoder behavior.

Result: Outbound insertion can skip selected eligible fields, including
standard pseudo-header names, without changing defaults or wire grammar.

Risks: A policy can trade a larger header block for reduced table churn.
The two MiMa exclusions are limited to the package-private server
settings implementation's previous generated copy and constructor.

References: Netty #18501; RFC 7541 section 6.2.2; RFC 9113 section 8.3;
Pekko HTTP apache#1556 review.
@He-Pin
He-Pin force-pushed the feat/hpack-no-index-headers branch from d268b2c to 5b9bbea Compare November 24, 2026 02:06
@He-Pin
He-Pin requested a review from pjfanning November 24, 2026 02: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.

Thanks for this. I did not find a correctness problem: the policy is only consulted when an entry would be inserted, exact matches and never-indexed fields are untouched, and the default path stays allocation-free when nothing is configured.

Two design questions before I approve:

  • How the configured class is loaded (inline).
  • Scope: this adds three ways to express the same thing (name list, config class, programmatic policy). The name list plus withHpackIndexingPolicy would cover the use cases I can think of. Is there a concrete need for hpack-indexing-policy-class as well? Dropping it would remove the reflection, the per-connection construction and its failure mode.

He-Pin added a commit to He-Pin/incubator-pekko-http that referenced this pull request Nov 24, 2026
Motivation: High-cardinality outgoing fields can churn the dynamic table.
The opt-in needs to preserve the encoder's existing indexing invariants
and coexist with internal HTTP/2 settings.

Modification: Provide independent client and server options with a
case-insensitive name list or Java/Scala policy. Keep the policy outside
internalSettings and resolve the configured class through the actor
system's class loader at connection startup and construct one policy per
materialized connection.
Expose the policy on both Java HTTP/2 settings types. Keep existing
indexes, sensitive representation and Latin-1 insertion eligibility.
Cover positive endpoint, settings and encoder behavior.

Result: Outbound insertion can skip selected eligible fields, including
standard pseudo-header names, without changing defaults or wire grammar.

Risks: A policy can trade a larger header block for reduced table churn.
The two MiMa exclusions are limited to the package-private server
settings implementation's previous generated copy and constructor.

References: Netty #18501; RFC 7541 section 6.2.2; RFC 9113 section 8.3;
Pekko HTTP apache#1556 review.
@He-Pin
He-Pin force-pushed the feat/hpack-no-index-headers branch from 5b9bbea to 9b921f9 Compare November 24, 2026 10:24
He-Pin added a commit to He-Pin/incubator-pekko-http that referenced this pull request Nov 24, 2026
Motivation: High-cardinality outgoing fields can churn the dynamic table.
The opt-in needs to preserve the encoder's existing indexing invariants
and coexist with internal HTTP/2 settings.

Modification: Provide independent client and server options with a
case-insensitive name list or Java/Scala policy. Keep the policy outside
internalSettings and resolve the configured class through the actor
system's class loader at connection startup and construct one policy per
materialized connection.
Expose the policy on both Java HTTP/2 settings types. Keep existing
indexes, sensitive representation and Latin-1 insertion eligibility.
Cover positive endpoint, settings and encoder behavior.

Result: Outbound insertion can skip selected eligible fields, including
standard pseudo-header names, without changing defaults or wire grammar.

Risks: A policy can trade a larger header block for reduced table churn.
The two MiMa exclusions are limited to the package-private server
settings implementation's previous generated copy and constructor.

References: Netty #18501; RFC 7541 section 6.2.2; RFC 9113 section 8.3;
Pekko HTTP apache#1556 review.
@He-Pin
He-Pin force-pushed the feat/hpack-no-index-headers branch from 9b921f9 to d930c5e Compare November 24, 2026 13:15
@He-Pin
He-Pin requested a review from pjfanning November 24, 2026 13:15

@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. I read the current head (source review only, I have not run it). The points from my earlier reviews are addressed: the Latin-1 guard from #1552 is kept next to the policy check, the policy is a field of its own rather than living in the internal settings slot, the configured class goes through dynamicAccess at connection start, the Java setter is on Http2ClientSettings, pseudo-header names can be listed, and the client and server specs now cover both the name list and a programmatic policy end to end. I did not find a correctness problem.

Two things left:

  • hpack-indexing-policy-class. My earlier question is still open: is there a concrete use case that the name list plus withHpackIndexingPolicy does not cover? As it stands there are three ways to configure the same thing, and the class option is the one that brings reflection, one instance per connection and a failure that only shows when a connection starts. If there is a need for it, could the PR description say what it is? Otherwise I would prefer to leave it out for now; it can be added later without breaking anything.
  • Nit: ClientConnectionSettingsTest.testConfigureHpackIndexingPolicy only checks that the settings object survives withHttp2Settings / getHttp2Settings. It shows the API is usable from Java, but not that the policy is kept. Not blocking, since the Scala specs cover the behaviour.

@He-Pin
He-Pin force-pushed the feat/hpack-no-index-headers branch from d930c5e to 916fa4a Compare November 25, 2026 04:53
@pjfanning pjfanning added this to the 2.1.0 milestone Nov 25, 2026

@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, and for the added test that the Java-configured policy is kept and applied.

I would prefer to see the hpack-indexing-policy-class option removed from this PR.

The name list (hpack-no-index-headers) plus withHpackIndexingPolicy cover the use cases I can think of, and the class option is the part that brings the reflection, the per-connection construction and a failure that only shows when a connection starts. It can be added later without breaking anything if a concrete need comes up.

Roughly what that would mean:

  • Http2CommonSettings: remove ConfiguredPolicy, and reduce HpackPolicyOptions to the name set plus the optional explicit policy (so resolve no longer needs the actor system)
  • reference.conf: remove hpack-indexing-policy-class from the client and server http2 sections
  • docs: remove the paragraph on the configured class
  • tests: remove the configured-class cases in HeaderCompressionSpec (and any in Http2CommonSettingsSpec); the name-list and programmatic-policy tests stay as they are
  • PR description: update Modification and Result to match

With that done I am happy to approve.

Edited: an earlier version of this comment said the head had gone back to loading the class with the thread context class loader. That was wrong (I was looking at a stale local copy of the branch); the head resolves it through dynamicAccess as the description says.

@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 removing hpack-indexing-policy-class; that resolves my main point, and the description now matches the code. One thing changed in the other direction: the policy is stored in the internalSettings slot again (ServerHpackSettings / ClientHpackSettings), which was the second point of my first review. Comment inline; it applies to two other open PRs as well. Source review only, I have not run it.

@He-Pin
He-Pin force-pushed the feat/hpack-no-index-headers branch from 28d248e to 0940618 Compare November 27, 2026 02:10
He-Pin added a commit to He-Pin/incubator-pekko-http that referenced this pull request Nov 27, 2026
Motivation:
Allow direct HTTP/2 clients to announce that they have stopped
sending requests before closing an otherwise healthy connection.

Modification:
Queue a single GOAWAY(NO_ERROR) on a normal request-source completion
when the option is enabled. Keep the existing response drain and do
not change managed cancellation or application-failure behavior.
Store the opt-in in an independent immutable settings field; preserve
released constructor, factory and copy descriptors.

Result:
Existing applications keep the default and error behavior. A caller
can opt into graceful close without replacing the internal settings,
and an older settings copy preserves the active opt-in.

Tests:
JDK 17 on Scala 2.13.18 and 3.3.9: ten focused settings, direct and
managed lifecycle cases per axis, an actual Java settings caller,
released 2.0.0 Scala linkage probes and zero scoped MiMa findings.
Scoped Scala formatting and whitespace checks passed.

References:
RFC 9113 Section 6.8. Addresses PJ's review on apache#1665; related apache#1556.
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:
Applications with a ready companion representation can offer it on
the same established HTTP/2 connection without affecting applications
that leave the feature off or peers that disallow push.

Modification:
Add a default-off native server setting and typed Scala and Java
plans for a rooted same-origin GET with a complete strict 200
representation. Only hand off a push when the peer allows it, its
original request is still eligible and the outgoing path has demand.
Keep separately owned pushed streams on the existing data scheduler
and use the same connection HPACK encoder as ordinary responses.

Result:
A push is best effort and is neither queued nor acknowledged to
the application. Skipped pushes leave the primary response on its
ordinary path. The HTTP/1.1 fallback, upgrade path, client behavior
and Pekko Core requirements are unchanged.

Tests:
JDK 17 with Scala 2.13.18 and 3.3.9: three native-stack in-memory
tests, two settings tests and one named Java Jupiter test passed
per axis. The earlier transport-level fixture separately passed
three tests per axis. Checked settings constructor, copy and
default descriptors against main and the stacked V2 artifact.
No real sockets or TLS handshake, full CI, h2spec or full MiMa.

References:
Pekko HTTP apache#1556 (stacked shared HPACK policy).
RFC 9113 sections 6.5.2, 6.6 and 8.4.
He-Pin added a commit to He-Pin/incubator-pekko-http that referenced this pull request Nov 27, 2026
Motivation:
Applications with a ready companion representation can offer it on
the same established HTTP/2 connection without affecting applications
that leave the feature off or peers that disallow push.

Modification:
Add a default-off native server setting and typed Scala and Java
plans for a rooted same-origin GET with a complete strict 200
representation. Only hand off a push when the peer allows it, its
original request is still eligible and the outgoing path has demand.
Keep separately owned pushed streams on the existing data scheduler
and use the same connection HPACK encoder as ordinary responses.

Result:
A push is best effort and is neither queued nor acknowledged to
the application. Skipped pushes leave the primary response on its
ordinary path. The HTTP/1.1 fallback, upgrade path, client behavior
and Pekko Core requirements are unchanged.

Tests:
On JDK 17, Scala 2.13.18 and 3.3.9 each passed the producer fixture
followed by three native-stack cases in one JVM. Previous unchanged
settings and named Java Jupiter unit cases passed on both axes;
settings constructor/copy/default descriptors were compared with main.
No local sockets, real TLS/ALPN peer, full CI, h2spec or full MiMa.

References:
Pekko HTTP apache#1556 (stacked shared HPACK policy).
RFC 9113 sections 6.5.2, 6.6 and 8.4.

@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, this resolves my point about the internalSettings slot: the policy is a field of its own and the 2.0.0 constructor and copy signatures are kept. Source review only, I have not run it.

  1. Needs a rebase: docs/src/main/paradox/client-side/http2.md conflicts with the paragraph added by #1682. Both should be kept.
  2. The earlier test of the compatibility bridges was removed, and the new specs only reach the copy with defaults. Could you add one that calls the 2.0.0-shaped constructor and positional copy (server and client) and checks that the policy is kept?
  3. There is withHpackIndexingPolicy in the Java settings but no getter. The other settings there have a getter next to the with method. Not blocking.
  4. #981 and #1589 now use the same field-plus-bridge pattern in the same constructor/copy blocks. Whichever merges second should keep only the 2.0.0 bridge and extend the full copy, not add a second bridge.

Happy to approve once 1 and 2 are done.

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
He-Pin force-pushed the feat/hpack-no-index-headers branch from 242a67d to 68cf565 Compare November 29, 2026 14:54
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.

2 participants