Repository navigation
Add basic RFC 10008 (QUERY method) support - #1511
desiderantes wants to merge 7 commits into
Conversation
|
✅ All required contributors have signed the F5 CLA for this PR. Thank you! |
|
I have hereby read the F5 CLA and agree to its terms |
There was a problem hiding this comment.
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
:methodparsing to recognizeQUERY. - Allow
QUERYto 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.
| 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]>
|
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. |
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). |
| 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) { |
| 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; | ||
| } | ||
| } |
|
There is other PR which adds QUERY Method support except caching |
Oh cool, hadn't seen that one. I'll close this one since that already has some traction. |
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: