Merge branch 'contrib/github_pr_13746' into 'master'

feat(http_server): add 413 Payload Too Large response (GitHub PR)

Closes IDFGH-12767

See merge request espressif/esp-idf!31058
This commit is contained in:
Harshit Malpani 2024-05-30 14:02:57 +08:00
commit 245ec91456
4 changed files with 17 additions and 10 deletions

View File

@ -468,7 +468,7 @@ static const esp_err_msg_t esp_err_msg_table[] = {
ERR_TBL_IT(ESP_ERR_DPP_INVALID_ATTR), /* 12441 0x3099 Encountered invalid DPP Attribute */
# endif
# ifdef ESP_ERR_DPP_AUTH_TIMEOUT
ERR_TBL_IT(ESP_ERR_DPP_AUTH_TIMEOUT), /* 12442 0x309a DPP Auth response was not recieved in time */
ERR_TBL_IT(ESP_ERR_DPP_AUTH_TIMEOUT), /* 12442 0x309a DPP Auth response was not received in time */
# endif
// components/esp_common/include/esp_err.h
# ifdef ESP_ERR_MESH_BASE
@ -781,7 +781,7 @@ static const esp_err_msg_t esp_err_msg_table[] = {
ERR_TBL_IT(ESP_ERR_HTTPD_RESP_HDR), /* 45061 0xb005 Response header field larger than supported */
# endif
# ifdef ESP_ERR_HTTPD_RESP_SEND
ERR_TBL_IT(ESP_ERR_HTTPD_RESP_SEND), /* 45062 0xb006 Error occured while sending response packet */
ERR_TBL_IT(ESP_ERR_HTTPD_RESP_SEND), /* 45062 0xb006 Error occurred while sending response packet */
# endif
# ifdef ESP_ERR_HTTPD_ALLOC_MEM
ERR_TBL_IT(ESP_ERR_HTTPD_ALLOC_MEM), /* 45063 0xb007 Failed to dynamically allocate memory

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2018-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2018-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -85,7 +85,7 @@ initializer that should be kept in sync
#define ESP_ERR_HTTPD_INVALID_REQ (ESP_ERR_HTTPD_BASE + 3) /*!< Invalid request pointer */
#define ESP_ERR_HTTPD_RESULT_TRUNC (ESP_ERR_HTTPD_BASE + 4) /*!< Result string truncated */
#define ESP_ERR_HTTPD_RESP_HDR (ESP_ERR_HTTPD_BASE + 5) /*!< Response header field larger than supported */
#define ESP_ERR_HTTPD_RESP_SEND (ESP_ERR_HTTPD_BASE + 6) /*!< Error occured while sending response packet */
#define ESP_ERR_HTTPD_RESP_SEND (ESP_ERR_HTTPD_BASE + 6) /*!< Error occurred while sending response packet */
#define ESP_ERR_HTTPD_ALLOC_MEM (ESP_ERR_HTTPD_BASE + 7) /*!< Failed to dynamically allocate memory for resource */
#define ESP_ERR_HTTPD_TASK (ESP_ERR_HTTPD_BASE + 8) /*!< Failed to launch server task/thread */
@ -608,6 +608,9 @@ typedef enum {
*/
HTTPD_411_LENGTH_REQUIRED,
/* Incoming payload is too large */
HTTPD_413_CONTENT_TOO_LARGE,
/* URI length greater than CONFIG_HTTPD_MAX_URI_LEN */
HTTPD_414_URI_TOO_LONG,
@ -1028,7 +1031,7 @@ esp_err_t httpd_query_key_value(const char *qry, const char *key, char *val, siz
* @param[in] cookie_name The cookie name to be searched in the request
* @param[out] val Pointer to the buffer into which the value of cookie will be copied if the cookie is found
* @param[inout] val_size Pointer to size of the user buffer "val". This variable will contain cookie length if
* ESP_OK is returned and required buffer length incase ESP_ERR_HTTPD_RESULT_TRUNC is returned.
* ESP_OK is returned and required buffer length in case ESP_ERR_HTTPD_RESULT_TRUNC is returned.
*
* @return
* - ESP_OK : Key is found in the cookie string and copied to buffer
@ -1048,9 +1051,9 @@ esp_err_t httpd_req_get_cookie_val(httpd_req_t *req, const char *cookie_name, ch
*
* Example:
* - * matches everything
* - /foo/? matches /foo and /foo/
* - /foo/\* (sans the backslash) matches /foo/ and /foo/bar, but not /foo or /fo
* - /foo/?* or /foo/\*? (sans the backslash) matches /foo/, /foo/bar, and also /foo, but not /foox or /fo
* - /api/? matches /api and /api/
* - /api/\* (sans the backslash) matches /api/ and /api/status, but not /api or /ap
* - /api/?* or /api/\*? (sans the backslash) matches /api/, /api/status, and also /api, but not /apix or /ap
*
* The special characters "?" and "*" anywhere else in the template will be taken literally.
*
@ -1400,7 +1403,7 @@ static inline esp_err_t httpd_resp_send_500(httpd_req_t *r) {
* Call this API if you wish to construct your custom response packet.
* When using this, all essential header, eg. HTTP version, Status Code,
* Content Type and Length, Encoding, etc. will have to be constructed
* manually, and HTTP delimeters (CRLF) will need to be placed correctly
* manually, and HTTP delimiters (CRLF) will need to be placed correctly
* for separating sub-sections of the HTTP response packet.
*
* If the send override function is set, this API will end up

View File

@ -432,6 +432,10 @@ esp_err_t httpd_resp_send_err(httpd_req_t *req, httpd_err_code_t error, const ch
status = "411 Length Required";
msg = "Client must specify Content-Length";
break;
case HTTPD_413_CONTENT_TOO_LARGE:
status = "413 Content Too Large";
msg = "Content is too large";
break;
case HTTPD_431_REQ_HDR_FIELDS_TOO_LARGE:
status = "431 Request Header Fields Too Large";
msg = "Header fields are too long";

View File

@ -21,7 +21,7 @@ extern "C" {
#define ESP_ERR_DPP_FAILURE (ESP_ERR_WIFI_BASE + 151) /*!< Generic failure during DPP Operation */
#define ESP_ERR_DPP_TX_FAILURE (ESP_ERR_WIFI_BASE + 152) /*!< DPP Frame Tx failed OR not Acked */
#define ESP_ERR_DPP_INVALID_ATTR (ESP_ERR_WIFI_BASE + 153) /*!< Encountered invalid DPP Attribute */
#define ESP_ERR_DPP_AUTH_TIMEOUT (ESP_ERR_WIFI_BASE + 154) /*!< DPP Auth response was not recieved in time */
#define ESP_ERR_DPP_AUTH_TIMEOUT (ESP_ERR_WIFI_BASE + 154) /*!< DPP Auth response was not received in time */
/** @brief Types of Bootstrap Methods for DPP. */
typedef enum dpp_bootstrap_type {
DPP_BOOTSTRAP_QR_CODE, /**< QR Code Method */