Skip to content

Add basic RFC 10008 (QUERY method) support - #1511

Closed
desiderantes wants to merge 7 commits into
nginx:masterfrom
desiderantes:query-method
Closed

desiderantes wants to merge 7 commits into
nginx:masterfrom
desiderantes:query-method

Conversation

@desiderantes

@desiderantes desiderantes commented Jun 26, 2026 •

Copy link
Copy Markdown

Problem

Missing support for HTTP QUERY method (RFC 10008) and caching support for QUERY requests.

Solution

This change adds support for the HTTP QUERY method, as described in RFC 10008. QUERY is a safe and idempotent method, designed to function as a sort of "GET with body".

Testing

Verified using a simple script

All tests passed successfully.

Checklist

Before submitting this PR, please confirm:

  • I have read the CONTRIBUTING guidelines
  • I have added tests (if applicable) to validate my changes
  • All existing tests pass
  • I have updated documentation where necessary
  • My branch is rebased on the latest master
  • This PR targets the master branch from my fork
  • My commit message follows NGINX standards

@github-actions

github-actions Bot commented Jun 26, 2026 •

Copy link
Copy Markdown

✅ All required contributors have signed the F5 CLA for this PR. Thank you!
Posted by the CLA Assistant Lite bot.

@desiderantes

Copy link
Copy Markdown
Author

I have hereby read the F5 CLA and agree to its terms

@desiderantes
desiderantes marked this pull request as ready for review June 26, 2026 10:50
Copilot AI review requested due to automatic review settings June 26, 2026 10:50

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.

Pull request overview

This PR introduces basic support for the HTTP QUERY method (RFC 10008) across nginx’s request parsing paths, allowing nginx to recognize and route QUERY requests similarly to other standard methods.

Changes:

  • Add a new method bitmask constant NGX_HTTP_QUERY.
  • Teach HTTP/1.1 request-line parsing and HTTP/2/HTTP/3 :method parsing to recognize QUERY.
  • Allow QUERY to be referenced in method-related configuration parsing (e.g., limit_except) and (optionally) in upstream cache method masks.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/http/v3/ngx_http_v3_request.c Recognize QUERY in HTTP/3 :method parsing.
src/http/v2/ngx_http_v2.c Recognize QUERY in HTTP/2 :method parsing table.
src/http/ngx_http_upstream.c Add QUERY to the cacheable-method bitmask list (config parsing).
src/http/ngx_http_request.h Define NGX_HTTP_QUERY method bit.
src/http/ngx_http_parse.c Recognize QUERY in HTTP/1.1 request-line parsing.
src/http/ngx_http_core_module.c Allow QUERY in method-name parsing for directives like limit_except.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/http/ngx_http_upstream.c Resolved
Comment thread src/http/v2/ngx_http_v2.c Resolved

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.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Comment thread src/http/ngx_http_variables.c Resolved
Comment thread src/http/ngx_http_variables.c Resolved

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.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Comment thread src/http/ngx_http_upstream.c Resolved
Comment on lines +3889 to +3892
if (conf->cache_query_key.value.data == NULL) {
ngx_str_t s = ngx_string("$scheme$proxy_host$request_uri|$request_body");
ngx_http_compile_complex_value_t ccv;

Co-authored-by: Copilot Autofix powered by AI <[email protected]>
@HanadaLee

HanadaLee commented Jun 26, 2026 •

Copy link
Copy Markdown

I do not think it is necessary to introduce a separate cache key directive for QUERY, as this would complicate cache key handling.The current combination of directives already enables the inclusion of the request body in the cache key.

If you need to use different cache keys based on the request method, you can certainly use the following approach.

map $request_method $cache_key {
    volatile
    QUERY $scheme$proxy_host$request_uri$request_body;
    default $scheme$proxy_host$request_uri;
}

proxy_cache_key $cache_key;

@desiderantes

Copy link
Copy Markdown
Author

I do not think it is necessary to introduce a separate cache key directive for QUERY, as this would complicate cache key handling.The current combination of directives already enables the inclusion of the request body in the cache key.

If you need to use different cache keys based on the request method, you can certainly use the following approach.

map $request_method $cache_key {
    volatile
    QUERY $scheme$proxy_host$request_uri$request_body;
    default $scheme$proxy_host$request_uri;
}

proxy_cache_key $cache_key;

Given that this is the first (outside of WebDAV) safe and idempotent HTTP method with a body, I just made it so that if QUERY is in the list of cacheble methods, the body has to be part of the cache (luckily, it's already skipped for requests with no body).

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.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Comment on lines +2282 to +2301
if (r->request_body->temp_file) {
file = &r->request_body->temp_file->file;
offset = 0;

for ( ;; ) {
n = ngx_read_file(file, buffer, 4096, offset);

if (n == NGX_ERROR) {
return NGX_ERROR;
}

if (n == 0) {
break;
}

ngx_md5_update(&md5, buffer, n);
offset += n;
}

} else if (r->request_body->bufs) {
Comment on lines +3866 to +3889
if (conf->upstream.cache_methods & NGX_HTTP_QUERY) {
if (conf->cache_key.value.data == NULL) {
ngx_str_t s = ngx_string("$scheme$proxy_host$request_uri|$request_body_md5");
ngx_http_compile_complex_value_t ccv;

ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));

ccv.cf = cf;
ccv.value = &s;
ccv.complex_value = &conf->cache_key;

if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
return NGX_CONF_ERROR;
}
}

if (ngx_strnstr(conf->cache_key.value.data, "request_body",
conf->cache_key.value.len) == NULL)
{
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
"proxy_cache_key must contain \"$request_body\" or \"$request_body_md5\" when QUERY caching is enabled");
return NGX_CONF_ERROR;
}
}
@vinaykumar-1591
vinaykumar-1591 self-requested a review June 29, 2026 11:24
@vinaykumar-1591

Copy link
Copy Markdown
Contributor

There is other PR which adds QUERY Method support except caching
#1488

@desiderantes

Copy link
Copy Markdown
Author

There is other PR which adds QUERY Method support except caching
#1488

Oh cool, hadn't seen that one. I'll close this one since that already has some traction.

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

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants