Repository navigation
Add support for HTTP QUERY method - #2474
Merged
Merged
Conversation
seanpdoyle
added a commit
to seanpdoyle/puma
that referenced
this pull request
Jul 6, 2026
As of June 2026, [RFC 10008][] is a proposed standard. From the RFC Abstract: > This specification defines the QUERY method for HTTP. A QUERY requests > that the request target process the enclosed content in a safe and > idempotent manner and then respond with the result of that processing. > This is similar to POST requests, but QUERY requests can be > automatically repeated or restarted without concern for partial state > changes. This commit adds `QUERY` to the `IANA_HTTP_METHODS` constant in order to support parsing the new HTTP method. Once parsed, the value is transformed injected as a `Rack::REQUEST_METHOD`-compatible `QUERY` value proposed in [rack/rack#2474][]. [RFC 10008]: https://www.rfc-editor.org/rfc/rfc10008.html [rack/rack#2474]: rack/rack#2474
This was referenced Jul 6, 2026
seanpdoyle
added a commit
to seanpdoyle/puma
that referenced
this pull request
Jul 8, 2026
As of June 2026, [RFC 10008][] is a proposed standard. From the RFC Abstract: > This specification defines the QUERY method for HTTP. A QUERY requests > that the request target process the enclosed content in a safe and > idempotent manner and then respond with the result of that processing. > This is similar to POST requests, but QUERY requests can be > automatically repeated or restarted without concern for partial state > changes. This commit adds `QUERY` to the `IANA_HTTP_METHODS` constant in order to support parsing the new HTTP method. Once parsed, the value is transformed injected as a `Rack::REQUEST_METHOD`-compatible `QUERY` value proposed in [rack/rack#2474][]. [RFC 10008]: https://www.rfc-editor.org/rfc/rfc10008.html [rack/rack#2474]: rack/rack#2474
jeremyevans
approved these changes
Jul 10, 2026
jeremyevans
left a comment
Contributor
There was a problem hiding this comment.
This seems reasonable to add. net/http recently added support for QUERY. We might want to wait until there are Ruby web servers supporting it before merging, though.
Contributor
Author
That is reasonable. For reference, puma/puma#3973 adds support to Puma. |
Contributor
Author
|
@jeremyevans puma/puma#3973 has been merged, adding |
jeremyevans
removed their request for review
July 11, 2026 01:01
Contributor
|
I've already approved this, there is no need to rerequest review. Might want to rebase on main to get the JRuby tests passing. We'll see what other committers think, though I expect they will be fine with it. |
As of June 2026, [RFC 10008][] is a proposed standard. From the RFC Abstract: > This specification defines the QUERY method for HTTP. A QUERY requests > that the request target process the enclosed content in a safe and > idempotent manner and then respond with the result of that processing. > This is similar to POST requests, but QUERY requests can be > automatically repeated or restarted without concern for partial state > changes. This commit proposes support for the HTTP Query method by way of the `Rack::QUERY` constant and the corresponding `#query?` methods for both `Rack::Request` and `Rack::MockRequest` classes. [RFC 10008]: https://www.rfc-editor.org/rfc/rfc10008.html
ioquatix
force-pushed
the
rfc-10008-query
branch
from
July 12, 2026 06:38
7bd2ca6 to
c5efe86
Compare
Member
|
Thanks. |
jeremy
added a commit
to magnogouveia/rails
that referenced
this pull request
Aug 13, 2026
* Cross-origin JavaScript response protection covers QUERY exactly as GET: mark_for_same_origin_verification! includes query?, so a non-XHR cross-origin QUERY returning JavaScript raises InvalidCrossOriginRequest. * SSL middleware: document that QUERY intentionally receives a 307 (not 301) when redirecting to HTTPS — 301 permits clients to rewrite the method to GET, which would drop the QUERY body (RFC 10008 redirect semantics). * Conditional requests: no code change needed — fresh_when/stale? are verb-agnostic. Pin that QUERY with a matching If-None-Match gets 304 Not Modified and a fresh QUERY gets 200 + ETag. Deliberate non-changes: ActionDispatch::Static keeps serving files for GET/HEAD only, and implicit-render behavior is untouched — QUERY is a programmatic method, not a browser navigation. Rack::ConditionalGet handles QUERY upstream on rack main (rack/rack#2474, unreleased); controller-level freshness covers it in the meantime.
jeremy
added a commit
to magnogouveia/rails
that referenced
this pull request
Aug 13, 2026
Rack merged QUERY into Rack::MethodOverride's override whitelist (rack/rack#2474, unreleased). Once a rack release ships it, an ordinary cross-origin form POST carrying _method=query would be dispatched as QUERY by the default middleware stack — and, without this change, inherit QUERY's CSRF exemption. That would silently void the structural rationale for the exemption: HTML forms cannot emit QUERY, and cross-origin QUERY is always preflighted. Neither is true of a form POST. Key the exemption on the method the request actually arrived with: request.method reports the pre-override method, so native QUERY remains exempt while a tunneled POST is verified like any other POST. The cross-origin JavaScript response protection uses the same predicate. This defends the invariant ahead of rack's release rather than reacting after it ships.
jeremy
added a commit
to jeremy/rack
that referenced
this pull request
Aug 14, 2026
Frameworks exempt the safe QUERY method (RFC 10008) from CSRF verification on the strength of two structural facts: HTML forms cannot emit it, and cross-origin fetch() QUERY is never CORS-safelisted, so it always preflights. Rewriting a form POST into QUERY via _method falsifies the first fact for any framework that checks the post-override method — the natural way to write the check. Unlike PATCH/PUT/DELETE, a tunneled QUERY also gains nothing: the wire request is a POST, so none of QUERY's caching, retry, or idempotency semantics survive, while its CSRF exemption becomes reachable from an ordinary cross-origin form. Request#query?, ConditionalGet, and MockRequest support from rack#2474 are unchanged. Since rack#2474 is unreleased, this is a no-op relative to the last release and needs no CHANGELOG entry.
jeremy
added a commit
to magnogouveia/rails
that referenced
this pull request
Aug 14, 2026
Rack merged QUERY into Rack::MethodOverride's override whitelist (rack/rack#2474, unreleased). Once a rack release ships it, an ordinary cross-origin form POST carrying _method=query would be dispatched as QUERY by the default middleware stack — and, without this change, inherit QUERY's CSRF exemption. That would silently void the structural rationale for the exemption: HTML forms cannot emit QUERY, and cross-origin QUERY is always preflighted. Neither is true of a form POST. Key the exemption on the method the request actually arrived with: request.method reports the pre-override method, so native QUERY remains exempt while a tunneled POST is verified like any other POST. The cross-origin JavaScript response protection uses the same predicate. This defends the invariant ahead of rack's release rather than reacting after it ships.
jeremy
added a commit
to rails/rails
that referenced
this pull request
Aug 14, 2026
* Add support for the HTTP QUERY method
RFC 10008 defines QUERY as a safe and idempotent HTTP method that
conveys the query in the request content instead of the URL query
string. It is registered in the IANA HTTP Method Registry (safe: yes,
idempotent: yes) and is intended for queries too large or structured
for a query string: complex filters, search APIs, GraphQL, and
JSON-RPC style endpoints.
This registers QUERY as a known HTTP method in ActionDispatch::Request
and wires it through the framework:
* Add the RFC10008 constant to ActionDispatch::Request::HTTP_METHODS,
so QUERY requests no longer raise
ActionController::UnknownHttpMethod.
* Add ActionDispatch::Request#query?, mirroring the other verb
predicates (Rack::Request::Helpers does not define one for QUERY).
* Add a QUERY verb matcher to Journey (VerbMatchers::VERBS), so
`via: :query` routes match without the Unknown fallback.
* Add the `query` routing DSL method to
ActionDispatch::Routing::Mapper::HttpHelpers:
query "search", to: "search#index"
match "filter", to: "search#filter", via: :query
* Add the `query` request helper to integration tests:
query "/search", params: { filters: { q: "video" } }, as: :json
* Exempt QUERY requests from forgery protection, like GET and HEAD.
HTML forms cannot issue QUERY requests, and cross-origin QUERY
requests always require a CORS preflight (QUERY is not a
CORS-safelisted method), so the forgery surface is strictly smaller
than GET's. This exemption is kept in an isolated hunk so it is easy
to change if the exemption is not wanted.
Body parameter parsing needs no changes: parsing is keyed on
Content-Type rather than on the request method, so JSON and
form-encoded QUERY bodies already parse into params.
There are no behavior changes for existing applications: QUERY
requests previously raised ActionController::UnknownHttpMethod (405)
before reaching any application code.
Note that the application server must also accept the method. Puma
currently allows only the eight standard methods by default; QUERY can
be enabled with its `supported_http_methods` option.
References:
- RFC 10008: https://www.rfc-editor.org/rfc/rfc10008.html
- IANA HTTP Method Registry:
https://www.iana.org/assignments/http-methods/http-methods.xhtml
- Rails core forum proposal:
https://discuss.rubyonrails.org/t/proposal-support-for-the-http-query-method-rfc-10008/91255
* Count QUERY as a safe request method
QUERY is safe and idempotent per RFC 10008 §2, so Request#safe_method?
now includes it alongside RFC 9110 §9.2.1's GET, HEAD, OPTIONS, and
TRACE.
* Complete QUERY support in the test harnesses
* Add "query" to the integration Runner delegation list so top-level
query calls reset the HTML document and copy session variables, and
so follow_redirect! can re-issue QUERY after a 307/308 (it dispatches
via public_send on the request method). Cover 307-preserves /
303-switches-to-GET redirect behavior.
* Add the query helper to ActionController::TestCase, mirroring the
integration helper. TestRequest#assign_parameters already routes
non-GET methods through the body-encoding branch, so params land in
request_parameters with no query string.
* Document that both helpers default the Content-Type to
application/x-www-form-urlencoded, as RFC 10008 requires QUERY
requests to declare one; pass as: :json for a JSON body.
* Cover params-to-body encoding (urlencoded and as: :json) end to end.
* Round out QUERY routing coverage
* Mapper tests for the query helper (verb, defaults, format).
* query works on resource collections/members through the existing
scope machinery: query :search, on: :collection.
* Pin that Journey's HEAD->GET fallback does not extend to QUERY: a
via: :get route never matches a QUERY request.
* Add RFC10008 to the TestHttpMethods matrix.
* Apply GET-like safe-method semantics to QUERY
* Cross-origin JavaScript response protection covers QUERY exactly as
GET: mark_for_same_origin_verification! includes query?, so a non-XHR
cross-origin QUERY returning JavaScript raises
InvalidCrossOriginRequest.
* SSL middleware: document that QUERY intentionally receives a 307 (not
301) when redirecting to HTTPS — 301 permits clients to rewrite the
method to GET, which would drop the QUERY body (RFC 10008 redirect
semantics).
* Conditional requests: no code change needed — fresh_when/stale? are
verb-agnostic. Pin that QUERY with a matching If-None-Match gets
304 Not Modified and a fresh QUERY gets 200 + ETag.
Deliberate non-changes: ActionDispatch::Static keeps serving files for
GET/HEAD only, and implicit-render behavior is untouched — QUERY is a
programmatic method, not a browser navigation. Rack::ConditionalGet
handles QUERY upstream on rack main (rack/rack#2474, unreleased);
controller-level freshness covers it in the meantime.
* Restrict QUERY's CSRF exemption to native QUERY requests
Rack merged QUERY into Rack::MethodOverride's override whitelist
(rack/rack#2474, unreleased). Once a rack release ships it, an ordinary
cross-origin form POST carrying _method=query would be dispatched as
QUERY by the default middleware stack — and, without this change,
inherit QUERY's CSRF exemption. That would silently void the structural
rationale for the exemption: HTML forms cannot emit QUERY, and
cross-origin QUERY is always preflighted. Neither is true of a form
POST.
Key the exemption on the method the request actually arrived with:
request.method reports the pre-override method, so native QUERY remains
exempt while a tunneled POST is verified like any other POST. The
cross-origin JavaScript response protection uses the same predicate.
This defends the invariant ahead of rack's release rather than reacting
after it ships.
* Pin QUERY's routing reach and pre-override method semantics
* Routes drawn via: :all (and custom constraints that don't check the
request method) now receive QUERY requests, where previously such
requests 405'd before routing ran. Note this in the CHANGELOG entry
and pin it with a test — it's the one observable behavior change for
existing applications.
* Cover request.method/method_symbol reporting the pre-override method
for a POST masquerading as QUERY, matching the existing masquerading
tests and underpinning the native-QUERY CSRF exemption.
* Guides: show query on resource collections in the routing guide, and
place QUERY alongside GET in the security guide's GET-vs-POST
checklist.
* DatabaseSelector treats QUERY requests as reads
QUERY is safe and idempotent per RFC 10008, so the database selector
middleware routes it to the replica like GET and HEAD. A QUERY arriving
within the configured write window still reads from the primary, same
as any other read.
* current_page? matches QUERY requests with method: :query
No code change needed — method: :query matches via
request.method_symbol now that QUERY is a recognized method. The
default method: :get deliberately does not match QUERY.
Form helper QUERY generation (button_to/form_with method: :query via
_method tunneling) is deliberately not included: a POST tunnel offers
none of QUERY's intermediary-visible caching or retry semantics, and it
would make QUERY endpoints reachable through an ordinary cross-origin
form POST, undermining the structural CSRF protections that justify
QUERY's forgery-protection exemption.
* Document HTTP QUERY across the guides
* testing: query request helper with a body-sending example, and query
in the xhr: true helper list
* action_controller_overview: body params framing, request predicate
table (query?, safe_method?/unsafe_method?), and a 'Handling HTTP
QUERY Requests' section covering routing, params, CSRF, and
conditional-request behavior
* caching_with_rails: conditional requests apply to QUERY via
fresh_when/stale? (Rack::ConditionalGet remains GET/HEAD-only in
released rack)
* action_controller_advanced_topics: CSRF safe-method exemption
* routing: query in the member/collection verb list
---------
Co-authored-by: Jeremy Daer <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As of June 2026, RFC 10008 is a proposed standard.
From the RFC Abstract:
This commit proposes support for the HTTP Query method by way of the
Rack::QUERYconstant and the corresponding#query?methods for bothRack::RequestandRack::MockRequestclasses.