HTTP Server Examples : Updated examples to manually return 408 and 500 errors

This commit is contained in:
Anurag Kar
2018-10-09 18:07:38 +05:30
parent 1437646ae0
commit 6a3fa5c180
4 changed files with 40 additions and 19 deletions
@@ -122,7 +122,11 @@ esp_err_t echo_post_handler(httpd_req_t *req)
while (remaining > 0) {
/* Read the data for the request */
if ((ret = httpd_req_recv(req, buf,
MIN(remaining, sizeof(buf)))) < 0) {
MIN(remaining, sizeof(buf)))) <= 0) {
if (ret == HTTPD_SOCK_ERR_TIMEOUT) {
/* Retry receiving if timeout occurred */
continue;
}
return ESP_FAIL;
}
@@ -156,7 +160,10 @@ esp_err_t ctrl_put_handler(httpd_req_t *req)
char buf;
int ret;
if ((ret = httpd_req_recv(req, &buf, 1)) < 0) {
if ((ret = httpd_req_recv(req, &buf, 1)) <= 0) {
if (ret == HTTPD_SOCK_ERR_TIMEOUT) {
httpd_resp_send_408(req);
}
return ESP_FAIL;
}