Skip to content

Commit e7cbb2f

Browse files
committed
Address review: drop drive-by Json refactor, IDF mapping, and extra docs
Keep HTTP_QUERY as a first-class method. Leave platform http_method mapping out until IDF settles on a detection macro. Docs only list the enum; Json.ino still shows setMethod(HTTP_QUERY).
1 parent aab445a commit e7cbb2f

4 files changed

Lines changed: 2 additions & 35 deletions

File tree

docs/requests.md

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,6 @@ request->contentLength(); // size_t: ContentLength of the request (not availabl
1414
request->multipart(); // bool: True if the request has content type "multipart"
1515
```
1616

17-
`HTTP_QUERY` is [RFC 10008](https://www.rfc-editor.org/rfc/rfc10008.html): a safe, idempotent method that carries the query in the request body (same body path as POST/PUT/PATCH whenever `Content-Length` or chunked transfer is present). Unknown methods still abort the connection.
18-
19-
`AsyncCallbackJsonWebHandler` does **not** enable QUERY by default. Call `setMethod(HTTP_QUERY)` (alone or combined with POST/PUT). QUERY still requires `Content-Type: application/json` (or MessagePack). Advertise supported query media types with `Accept-Query` (`asyncsrv::T_Accept_Query`), e.g. `application/json`.
20-
21-
Platform `http_method` mapping is compiled in only when the platform parser defines `HTTP_PARSER_HAS_QUERY` (ESP-IDF after QUERY support). The library parser always recognizes `QUERY`.
22-
23-
Register it like any other verb:
24-
25-
```cpp
26-
server.on("/search", AsyncWebRequestMethod::HTTP_QUERY, [](AsyncWebServerRequest *request) {
27-
AsyncWebServerResponse *res = request->beginResponse(200, "text/plain", "ok");
28-
res->addHeader(asyncsrv::T_Accept_Query, "application/json");
29-
request->send(res);
30-
});
31-
32-
auto *json = new AsyncCallbackJsonWebHandler("/search", [](AsyncWebServerRequest *request, JsonVariant &json) {
33-
request->send(200, "application/json", "{\"ok\":true}");
34-
});
35-
json->setMethod(AsyncWebRequestMethod::HTTP_QUERY);
36-
server.addHandler(json);
37-
```
38-
39-
Use `AsyncWebRequestMethod::HTTP_QUERY` when `http_parser.h` is included: the platform enumerator `HTTP_QUERY` is `33`, not the library bit flag.
40-
4117
### Headers
4218

4319
```cpp

examples/arduino/HTTPMethodsWithESPIDF/HTTPMethodsWithESPIDF.ino

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,6 @@ void setup() {
119119
assert(composite3 == composite4);
120120
assert(composite1 != composite3);
121121
assert(composite5 == AsyncWebRequestMethod::HTTP_GET);
122-
123-
#if defined(HTTP_PARSER_HAS_QUERY)
124-
// http_parser.h is included above, so HTTP_QUERY is the platform enumerator
125-
// (33), not the Async bit. The integration ctor must map it.
126-
static_assert(WebRequestMethodComposite(HTTP_QUERY).matches(AsyncWebRequestMethod::HTTP_QUERY), "platform HTTP_QUERY must map onto AsyncWebRequestMethod::HTTP_QUERY");
127-
#endif
128122
}
129123

130124
// not needed

src/AsyncJson.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,12 @@ constexpr static WebRequestMethodComposite JsonHandlerMethods =
118118
#if ARDUINOJSON_VERSION_MAJOR == 6
119119
AsyncCallbackJsonWebHandler::AsyncCallbackJsonWebHandler(AsyncURIMatcher uri, ArJsonRequestHandlerFunction onRequest, size_t maxJsonBufferSize)
120120
: _uri(std::move(uri)),
121-
_method(JsonHandlerMethods),
121+
_method(AsyncWebRequestMethod::HTTP_GET | AsyncWebRequestMethod::HTTP_POST | AsyncWebRequestMethod::HTTP_PUT | AsyncWebRequestMethod::HTTP_PATCH),
122122
_onRequest(onRequest), maxJsonBufferSize(maxJsonBufferSize), _maxContentLength(16384) {}
123123
#else
124124
AsyncCallbackJsonWebHandler::AsyncCallbackJsonWebHandler(AsyncURIMatcher uri, ArJsonRequestHandlerFunction onRequest)
125125
: _uri(std::move(uri)),
126-
_method(JsonHandlerMethods),
126+
_method(AsyncWebRequestMethod::HTTP_GET | AsyncWebRequestMethod::HTTP_POST | AsyncWebRequestMethod::HTTP_PUT | AsyncWebRequestMethod::HTTP_PATCH),
127127
_onRequest(onRequest), _maxContentLength(16384) {}
128128
#endif
129129

src/ESPAsyncWebServer.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,6 @@ class WebRequestMethodComposite {
230230
: MAP_EXTERNAL_TERNARY(HTTP_PURGE)
231231
: MAP_EXTERNAL_TERNARY(HTTP_LINK)
232232
: MAP_EXTERNAL_TERNARY(HTTP_UNLINK)
233-
#if defined(HTTP_PARSER_HAS_QUERY)
234-
: MAP_EXTERNAL_TERNARY(HTTP_QUERY)
235-
#endif
236233
#if defined(HTTP_ANY)
237234
: (t == HTTP_ANY) ? static_cast<uint32_t>(WebRequestMethod::HTTP_INVALID) - 1
238235
#endif

0 commit comments

Comments
 (0)