mirror of
https://github.com/espressif/esp-idf.git
synced 2025-12-07 09:02:08 +00:00
http_server examples : Updated tests and examples to demonstrate usage of httpd_register_err_handler() and accommodate for changes in default error handler behavior
This commit is contained in:
@@ -55,6 +55,7 @@ esp_err_t echo_post_handler(httpd_req_t *req)
|
||||
int ret;
|
||||
|
||||
if (!buf) {
|
||||
ESP_LOGE(TAG, "Failed to allocate memory of %d bytes!", req->content_len + 1);
|
||||
httpd_resp_send_500(req);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
@@ -84,12 +85,15 @@ esp_err_t echo_post_handler(httpd_req_t *req)
|
||||
if (hdr_len) {
|
||||
/* Read Custom header value */
|
||||
req_hdr = malloc(hdr_len + 1);
|
||||
if (req_hdr) {
|
||||
httpd_req_get_hdr_value_str(req, "Custom", req_hdr, hdr_len + 1);
|
||||
|
||||
/* Set as additional header for response packet */
|
||||
httpd_resp_set_hdr(req, "Custom", req_hdr);
|
||||
if (!req_hdr) {
|
||||
ESP_LOGE(TAG, "Failed to allocate memory of %d bytes!", hdr_len + 1);
|
||||
httpd_resp_send_500(req);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
httpd_req_get_hdr_value_str(req, "Custom", req_hdr, hdr_len + 1);
|
||||
|
||||
/* Set as additional header for response packet */
|
||||
httpd_resp_set_hdr(req, "Custom", req_hdr);
|
||||
}
|
||||
httpd_resp_send(req, buf, req->content_len);
|
||||
free (req_hdr);
|
||||
|
||||
Reference in New Issue
Block a user