Skip to content

fix: complete HTTP QUERY protocol handling - #1858

Open
He-Pin wants to merge 2 commits into
apache:mainfrom
He-Pin:fix/query-date-revalidation
Open

He-Pin wants to merge 2 commits into
apache:mainfrom
He-Pin:fix/query-date-revalidation

Conversation

@He-Pin

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

Copy link
Copy Markdown
Member

Motivation

RFC 10008 defines QUERY request metadata, preconditions on the selected result, structured format advertisements, and byte-range semantics. The existing method registration does not implement all of those behaviors.

Modification

  • Require declared, usable QUERY content types in HTTP/1.1 and HTTP/2.
  • Evaluate selected-result date and tag preconditions in RFC order. Document the valid-date comparison and keep conditional GET/HEAD behavior unchanged.
  • For an existing representation with only Last-Modified, honor a wildcard If-Match before evaluating If-Unmodified-Since. The change applies to ordinary requests as well as QUERY.
  • Interpret Accept-Query once after collecting the response section's original field values. Preserve disabled header modeling and existing per-field trailer modeling.
  • Add opt-in QUERY response ranges in Scala and Java, documenting how validator selection composes with conditional. Do not change the GET range directive.
  • Cover media validation, discovery, result URIs, redirect responses, and explicit application cache/CORS policies.

Result

Application code supplies the query decoder, selected representation metadata and any result URIs. An unverifiable If-Range leaves an otherwise successful 200 intact. An applicable range request that exceeds the configured count is rejected even when the result length is unknown; within the limit, unknown-length results stay intact. Redirect following and cache eligibility are not enabled globally.

Tests

  • The appended fix: honor wildcard If-Match for date-only conditional requests #1909 commit was independently reviewed. Its date-only PUT regression failed with 412 before the fix; after the fix, all 22 conditional directive tests and scoped formatting passed on JDK 21 / Scala 2.13.18.
  • Before the appended commit, 49 selected tests passed on JDK 21 / Scala 2.13.18: conditional and range routes plus a native HTTP/2 QUERY exchange that combines two Accept-Query field lines into one modeled header.
  • The earlier revision also passed Paradox and git diff checks. No hosted CI result is claimed for the appended commit.

References

He-Pin added a commit to He-Pin/incubator-pekko-http that referenced this pull request Nov 28, 2026
Motivation:
HTTP QUERY skipped date revalidation, could silently supply a default media type for a missing declaration, and did not consistently handle Accept-Query Structured Field metadata.

Modification:
Use the selected QUERY result's validator for date revalidation and require a usable Content-Type before server entity construction. Parse Structured Field lists, combine repeated Accept-Query response fields, and reject media parameters that cannot be represented as Structured Fields.

Result:
An unchanged result can return a bodyless 304. Both HTTP versions enforce declaration presence, and both DSLs expose the complete advertised media list without changing public signatures.

References:
https://www.rfc-editor.org/rfc/rfc10008.html
https://www.rfc-editor.org/rfc/rfc9651.html#section-4.2
apache#1077
apache#1858
@He-Pin
He-Pin force-pushed the fix/query-date-revalidation branch 2 times, most recently from c6f15b8 to 101e36d Compare November 28, 2026 15:39
@He-Pin He-Pin changed the title fix: revalidate HTTP QUERY results with If-Modified-Since fix: complete HTTP QUERY protocol handling Nov 28, 2026
@He-Pin
He-Pin requested an adaptive review from Copilot November 28, 2026 15:42

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.

@He-Pin
He-Pin force-pushed the fix/query-date-revalidation branch from 101e36d to 7b250c2 Compare November 28, 2026 15:55
@He-Pin
He-Pin requested review from pjfanning and an adaptive review from Copilot November 28, 2026 16:06

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.

@He-Pin

He-Pin commented Nov 28, 2026

Copy link
Copy Markdown
Member Author

Deep review of the updated PR (commit 7b250c2). Overall the design is sound and I found no blockers.

Verified correct:

  • RFC 10008 conformance: 400 on missing/inconsistent Content-Type (§2), negotiation codes (§2.1), redirects (§2.5), cache key including request content (§2.7), CORS preflight (§4).
  • RFC 9651 SFL grammar: rejects trailing comma / empty members, SP after ';', wildcards limited to / and type/; renderer lowercases keys and quotes/escapes non-tokens (injection-safe).
  • Parser exception safety: a malformed Accept-Query is ignored (HeaderParser.failure catches NonFatal -> Failure -> onIllegalHeader -> None), not a connection crash.
  • HTTP/2 production path: clientStack's forResponse master parser reaches HeaderDecompression, ResponseParsing and clientDemux, so accept-query stays raw through HPACK and is combined once at the response boundary; trailers are modeled per-field and never combined with initial headers.
  • GET range path is byte-identical (withRangeSupport delegates to withByteRangeSupport(forQuery=false)); javadsl overloads are Java-friendly.

Left 6 inline comments (2 design, 1 test, 3 minor correctness/consistency) — all suggestions/nits, none blocking. Main themes: document the QUERY-vs-GET future-date divergence and the conditional -> range attribute ordering contract, and add an e2e HTTP/2 split Accept-Query test.

@He-Pin
He-Pin force-pushed the fix/query-date-revalidation branch from 7b250c2 to ec37410 Compare November 28, 2026 16:30

@He-Pin He-Pin left a comment

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.

Overall LGTM — the RFC 10008 QUERY protocol handling, Accept-Query deferred parsing, conditional ordering, and opt-in withQueryRangeSupport look solid and all 6 CI checks pass. Left two minor non-blocking notes inline.

@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. Source review only, I have not run it. A few points:

  1. conditional (CacheConditionDirectives): for QUERY a matching If-None-Match (or * with a selected representation) gives 412, while If-Modified-Since gives 304. A client that revalidates a QUERY result by ETag can then never get a 304. The PR's own reference (RFC 10008 section 2.6 and appendix A.5) treats QUERY like GET for revalidation, so I would expect 304 for the ETag case too. I saw this is marked as intentional; could you say why?
  2. The 400 for a QUERY request without Content-Type is not opt-in and changes behaviour for 2.0.x users. Our own client renders HttpRequest(QUERY, uri) with an empty entity without a Content-Type, so it would now get a 400 from a Pekko HTTP server. This needs a release note under Behavior Changes, and I think the client side should either fail early or be documented.
  3. withQueryRangeSupport: the rangeCountLimit check is inside mapRouteResultWithPF, so the inner route has already run when the request is rejected with TooManyRangesRejection. The GET path checks before running the route. Could QUERY do the same?
  4. An invalid Accept-Query on a response is now dropped, where main keeps it as a RawHeader (and the trailer path still does). Is that intended? It is also one more scan of the headers for every client response.
  5. withQueryRangeSupport (Scala and both Java overloads) has no @since 2.1.0, no directive page or alphabetically.md entry, and the Java lastModifiedIsStrong overload has no test.
  6. The new require in the Accept-Query constructor is not mentioned in the description.

Motivation:
HTTP QUERY needs selected-result preconditions, structured format
advertisements, and opt-in byte ranges beyond method registration.

Modification:
Validate QUERY content metadata and evaluate preconditions against the
selected result. Model Accept-Query after collecting initial response
fields, leaving trailers unchanged. Add opt-in QUERY range handling
and apply the range count limit before selecting an entity strategy.
Reject unrepresentable parameters when building typed Accept-Query values.

Result:
Default GET handling is unchanged. QUERY preserves the full otherwise
successful response when If-Range has no matching strong validator.

Tests:
Exercise typed date and range routing, including streamed results,
as well as a native HTTP/2 exchange with two Accept-Query field lines.
Verify the Java strong Last-Modified overload with a matching date and
check the new range guide and migration notes.

References:
RFC 10008 sections 2 and 3, RFC 9110 sections 13 and 14, RFC 9651 section 4.2.
@He-Pin
He-Pin force-pushed the fix/query-date-revalidation branch from ec37410 to 4c0b7d7 Compare November 28, 2026 20:19
@He-Pin
He-Pin requested a review from pjfanning November 29, 2026 11:56
Motivation: A known representation must satisfy wildcard If-Match even when the route supplies only Last-Modified.

Modification: Skip If-Unmodified-Since for that matched wildcard, while retaining later preconditions and tagged behavior.

Result: A stale date alone still rejects PUT; the same request with a matching wildcard runs the route.

References: RFC 9110 §§13.1.1, 13.1.4 and 13.2.2; apache#1858.

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 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 six points from my last review are addressed: the release notes cover the Content-Type 400 and the Accept-Query constructor checks, withQueryRangeSupport has @since, a directive page and a Java test for lastModifiedIsStrong, and the docs now explain the 412 for If-None-Match and the dropped invalid Accept-Query.

One new point. The appended commit (wildcard If-Match taking precedence over If-Unmodified-Since when only Last-Modified is supplied) changes conditional for PUT and other non-QUERY methods: a request that got 412 on main now runs the inner route. That is unrelated to QUERY and has no entry in releases-2.1.md. I would prefer it as its own PR; at the least it needs a Behavior Changes entry.

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.

3 participants