feat: support HTTP_ANY method in esp_http_server

Closes https://github.com/espressif/esp-idf/issues/12794
This commit is contained in:
Harshit Malpani
2024-01-09 11:27:15 +05:30
parent 7be04869d2
commit 1d81af367d
3 changed files with 28 additions and 3 deletions

View File

@@ -300,6 +300,28 @@ static const httpd_uri_t echo = {
.user_ctx = NULL
};
/* An HTTP_ANY handler */
static esp_err_t any_handler(httpd_req_t *req)
{
/* Send response with body set as the
* string passed in user context*/
const char* resp_str = (const char*) req->user_ctx;
httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN);
// End response
httpd_resp_send_chunk(req, NULL, 0);
return ESP_OK;
}
static const httpd_uri_t any = {
.uri = "/any",
.method = HTTP_ANY,
.handler = any_handler,
/* Let's pass response string in user
* context to demonstrate it's usage */
.user_ctx = "Hello World!"
};
/* This handler allows the custom error handling functionality to be
* tested from client side. For that, when a PUT request 0 is sent to
* URI /ctrl, the /hello and /echo URIs are unregistered and following
@@ -391,6 +413,7 @@ static httpd_handle_t start_webserver(void)
httpd_register_uri_handler(server, &hello);
httpd_register_uri_handler(server, &echo);
httpd_register_uri_handler(server, &ctrl);
httpd_register_uri_handler(server, &any);
#if CONFIG_EXAMPLE_BASIC_AUTH
httpd_register_basic_auth(server);
#endif