mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
esp_http_server : Logging of purged data to monitor made configurable
List of changes: * Kconfig option HTTPD_LOG_PURGE_DATA enables logging of purged data * Kconfig option HTTPD_PURGE_BUF_LEN sets purge buffer length * Purged data is logged in hex Closes https://github.com/espressif/esp-idf/issues/3359
This commit is contained in:
parent
df61612f8f
commit
6bf423d1e1
@ -20,4 +20,23 @@ menu "HTTP Server"
|
|||||||
Using TCP_NODEALY socket option ensures that HTTP error response reaches the client before the
|
Using TCP_NODEALY socket option ensures that HTTP error response reaches the client before the
|
||||||
underlying socket is closed. Please note that turning this off may cause multiple test failures
|
underlying socket is closed. Please note that turning this off may cause multiple test failures
|
||||||
|
|
||||||
|
config HTTPD_PURGE_BUF_LEN
|
||||||
|
int "Length of temporary buffer for purging data"
|
||||||
|
default 32
|
||||||
|
help
|
||||||
|
This sets the size of the temporary buffer used to receive and discard any remaining data that is
|
||||||
|
received from the HTTP client in the request, but not processed as part of the server HTTP request
|
||||||
|
handler.
|
||||||
|
|
||||||
|
If the remaining data is larger than the available buffer size, the buffer will be filled in multiple
|
||||||
|
iterations. The buffer should be small enough to fit on the stack, but large enough to avoid excessive
|
||||||
|
iterations.
|
||||||
|
|
||||||
|
config HTTPD_LOG_PURGE_DATA
|
||||||
|
bool "Log purged content data at Debug level"
|
||||||
|
default n
|
||||||
|
help
|
||||||
|
Enabling this will log discarded binary HTTP request data at Debug level.
|
||||||
|
For large content data this may not be desirable as it will clutter the log.
|
||||||
|
|
||||||
endmenu
|
endmenu
|
||||||
|
@ -711,18 +711,25 @@ esp_err_t httpd_req_delete(struct httpd_data *hd)
|
|||||||
/* Finish off reading any pending/leftover data */
|
/* Finish off reading any pending/leftover data */
|
||||||
while (ra->remaining_len) {
|
while (ra->remaining_len) {
|
||||||
/* Any length small enough not to overload the stack, but large
|
/* Any length small enough not to overload the stack, but large
|
||||||
* enough to finish off the buffers fast
|
* enough to finish off the buffers fast */
|
||||||
*/
|
char dummy[CONFIG_HTTPD_PURGE_BUF_LEN];
|
||||||
char dummy[32];
|
int recv_len = MIN(sizeof(dummy), ra->remaining_len);
|
||||||
int recv_len = MIN(sizeof(dummy) - 1, ra->remaining_len);
|
recv_len = httpd_req_recv(r, dummy, recv_len);
|
||||||
int ret = httpd_req_recv(r, dummy, recv_len);
|
if (recv_len < 0) {
|
||||||
if (ret < 0) {
|
|
||||||
httpd_req_cleanup(r);
|
httpd_req_cleanup(r);
|
||||||
return ESP_FAIL;
|
return ESP_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
dummy[ret] = '\0';
|
ESP_LOGD(TAG, LOG_FMT("purging data size : %d bytes"), recv_len);
|
||||||
ESP_LOGD(TAG, LOG_FMT("purging data : %s"), dummy);
|
|
||||||
|
#ifdef CONFIG_HTTPD_LOG_PURGE_DATA
|
||||||
|
/* Enabling this will log discarded binary HTTP content data at
|
||||||
|
* Debug level. For large content data this may not be desirable
|
||||||
|
* as it will clutter the log */
|
||||||
|
ESP_LOGD(TAG, "================= PURGED DATA =================");
|
||||||
|
ESP_LOG_BUFFER_HEX_LEVEL(TAG, dummy, recv_len, ESP_LOG_DEBUG);
|
||||||
|
ESP_LOGD(TAG, "===============================================");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
httpd_req_cleanup(r);
|
httpd_req_cleanup(r);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user