Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/requests.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

```cpp
request->version(); // uint8_t: 0 = HTTP/1.0, 1 = HTTP/1.1
request->method(); // enum: HTTP_GET, HTTP_POST, HTTP_DELETE, HTTP_PUT, HTTP_PATCH, HTTP_HEAD, HTTP_OPTIONS
request->method(); // enum: HTTP_GET, HTTP_POST, HTTP_DELETE, HTTP_PUT, HTTP_PATCH, HTTP_HEAD, HTTP_OPTIONS, HTTP_QUERY
request->url(); // String: URL of the request (not including host, port or GET parameters)
request->host(); // String: The requested host (can be used for virtual hosting)
request->contentType(); // String: ContentType of the request (not available in Handler::canHandle)
Expand Down
10 changes: 10 additions & 0 deletions examples/arduino/HTTPMethodsWithArduino/HTTPMethodsWithArduino.ino
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ void setup() {
request->send(200, "text/plain", "Hello");
});

// HTTP_Method.h / http_parser.h is included above: use the namespaced bit, not HTTP_QUERY.
// curl -v -X QUERY -H 'Content-Type: application/json' -d '{"q":1}' http://192.168.4.1/query
server.on("/query", AsyncWebRequestMethod::HTTP_QUERY, [](AsyncWebServerRequest *request) {
request->send(200, "text/plain", request->methodToString());
});

#if ASYNC_JSON_SUPPORT == 1
// curl -v http://192.168.4.1/test => Not Implemented
// curl -v -X POST -H 'Content-Type: application/json' -d '{"name":"You"}' http://192.168.4.1/test => OK
Expand Down Expand Up @@ -116,6 +122,10 @@ void setup() {
assert(composite3 == composite4);
assert(composite1 != composite3);
assert(composite5 == AsyncWebRequestMethod::HTTP_GET);

WebRequestMethodComposite queryMethod = AsyncWebRequestMethod::HTTP_QUERY;
assert(queryMethod.matches(AsyncWebRequestMethod::HTTP_QUERY));
assert(!queryMethod.matches(AsyncWebRequestMethod::HTTP_GET));
}

// not needed
Expand Down
10 changes: 10 additions & 0 deletions examples/arduino/HTTPMethodsWithESPIDF/HTTPMethodsWithESPIDF.ino
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ void setup() {
request->send(200, "text/plain", "Hello");
});

// http_parser.h is included above: use the namespaced bit, not HTTP_QUERY (platform enum 33).
// curl -v -X QUERY -H 'Content-Type: application/json' -d '{"q":1}' http://192.168.4.1/query
server.on("/query", AsyncWebRequestMethod::HTTP_QUERY, [](AsyncWebServerRequest *request) {
request->send(200, "text/plain", request->methodToString());
});

#if ASYNC_JSON_SUPPORT == 1
// curl -v http://192.168.4.1/test => Not Implemented
// curl -v -X POST -H 'Content-Type: application/json' -d '{"name":"You"}' http://192.168.4.1/test => OK
Expand Down Expand Up @@ -119,6 +125,10 @@ void setup() {
assert(composite3 == composite4);
assert(composite1 != composite3);
assert(composite5 == AsyncWebRequestMethod::HTTP_GET);

WebRequestMethodComposite queryMethod = AsyncWebRequestMethod::HTTP_QUERY;
assert(queryMethod.matches(AsyncWebRequestMethod::HTTP_QUERY));
assert(!queryMethod.matches(AsyncWebRequestMethod::HTTP_GET));
}

// not needed
Expand Down
14 changes: 14 additions & 0 deletions examples/arduino/Json/Json.ino
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@ void setup() {

server.addHandler(handler);

// curl -v -X QUERY -H 'Content-Type: application/json' -d '{"q":1}' http://192.168.4.1/json-query
AsyncCallbackJsonWebHandler *queryHandler = new AsyncCallbackJsonWebHandler("/json-query");
queryHandler->setMethod(HTTP_QUERY);
queryHandler->onRequest([](AsyncWebServerRequest *request, JsonVariant &json) {
serializeJson(json, Serial);
Serial.println();
AsyncJsonResponse *response = new AsyncJsonResponse();
JsonObject root = response->getRoot().to<JsonObject>();
root["hello"] = json.as<JsonObject>()["q"];
response->setLength();
request->send(response);
});
server.addHandler(queryHandler);

// New Json API since 3.8.2, which works for both Json and MessagePack bodies
// curl -v -X POST -H 'Content-Type: application/json' -d '{"name":"You"}' http://192.168.4.1/json3

Expand Down
3 changes: 3 additions & 0 deletions src/ESPAsyncWebServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ enum AsyncWebRequestMethodType : uint32_t {
HTTP_LINK = 1u << 22,
HTTP_UNLINK = 1u << 23,

/* RFC 10008 */
HTTP_QUERY = 1u << 24,

/* icecast */
// HTTP_SOURCE

Expand Down
4 changes: 4 additions & 0 deletions src/WebRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1544,6 +1544,8 @@ WebRequestMethod stringToMethod(const String &m) {
return AsyncWebRequestMethod::HTTP_UNBIND;
} else if (m == T_ACL) {
return AsyncWebRequestMethod::HTTP_ACL;
} else if (m == T_QUERY) {
return AsyncWebRequestMethod::HTTP_QUERY;
} else {
return AsyncWebRequestMethod::HTTP_INVALID;
}
Expand Down Expand Up @@ -1579,6 +1581,8 @@ const char *methodToString(WebRequestMethod method) {
/* RFC-2068, section 19.6.1.2 */
case AsyncWebRequestMethod::HTTP_LINK: return T_LINK;
case AsyncWebRequestMethod::HTTP_UNLINK: return T_UNLINK;
/* RFC 10008 */
case AsyncWebRequestMethod::HTTP_QUERY: return T_QUERY;
// Unsupported
default: return T_UNKNOWN;
}
Expand Down
2 changes: 2 additions & 0 deletions src/literals.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ static constexpr const char T__opaque[] = "\", opaque=\"";
static constexpr const char T_100_CONTINUE[] = "100-continue";
static constexpr const char T_13[] = "13";
static constexpr const char T_ACCEPT[] = "Accept";
static constexpr const char T_Accept_Query[] = "Accept-Query";
static constexpr const char T_Accept_Ranges[] = "Accept-Ranges";
static constexpr const char T_attachment[] = "attachment; filename=\"";
static constexpr const char T_AUTH[] = "Authorization";
Expand Down Expand Up @@ -137,6 +138,7 @@ static constexpr const char T_ACL[] = "ACL";
static constexpr const char T_PURGE[] = "PURGE";
static constexpr const char T_LINK[] = "LINK";
static constexpr const char T_UNLINK[] = "UNLINK";
static constexpr const char T_QUERY[] = "QUERY";

// Req content types
static constexpr const char T_RCT_HTTP[] = "RCT_HTTP";
Expand Down
Loading