fix(esp_http_server): Add support for custom HTTP status codes

Closes https://github.com/espressif/esp-idf/issues/12399
This commit is contained in:
Harshit Malpani
2023-11-27 14:29:37 +05:30
parent 3140fcadf2
commit ae71e1ddb9
2 changed files with 63 additions and 0 deletions
@@ -1293,6 +1293,30 @@ esp_err_t httpd_resp_set_hdr(httpd_req_t *r, const char *field, const char *valu
*/
esp_err_t httpd_resp_send_err(httpd_req_t *req, httpd_err_code_t error, const char *msg);
/**
* @brief For sending out custom error code in response to HTTP request.
*
* @note
* - This API is supposed to be called only from the context of
* a URI handler where httpd_req_t* request pointer is valid.
* - Once this API is called, all request headers are purged, so
* request headers need be copied into separate buffers if
* they are required later.
* - If you wish to send additional data in the body of the
* response, please use the lower-level functions directly.
*
* @param[in] req Pointer to the HTTP request for which the response needs to be sent
* @param[in] status Error status to send
* @param[in] msg Error message string
*
* @return
* - ESP_OK : On successfully sending the response packet
* - ESP_ERR_INVALID_ARG : Null arguments
* - ESP_ERR_HTTPD_RESP_SEND : Error in raw send
* - ESP_ERR_HTTPD_INVALID_REQ : Invalid request pointer
*/
esp_err_t httpd_resp_send_custom_err(httpd_req_t *req, const char *status, const char *msg);
/**
* @brief Helper function for HTTP 404
*