diff --git a/src/apps/http/http_client.c b/src/apps/http/http_client.c index a7d5d9f8..c3ea3698 100644 --- a/src/apps/http/http_client.c +++ b/src/apps/http/http_client.c @@ -280,7 +280,19 @@ httpc_tcp_recv(void *arg, struct altcp_pcb *pcb, struct pbuf *p, err_t r) LWIP_UNUSED_ARG(r); if (p == NULL) { - return httpc_close(req, HTTPC_RESULT_OK, req->rx_status, ERR_OK); + httpc_result_t result; + if (req->parse_state != HTTPC_PARSE_RX_DATA) { + /* did not get RX data yet */ + result = HTTPC_RESULT_ERR_CLOSED; + } else if ((req->hdr_content_len != HTTPC_CONTENT_LEN_INVALID) && + (req->hdr_content_len != req->rx_content_len)) { + /* header has been received with content length but not all data received */ + result = HTTPC_RESULT_ERR_CONTENT_LEN; + } else { + /* receiving data and either all data received or no content length header */ + result = HTTPC_RESULT_OK; + } + return httpc_close(req, result, req->rx_status, ERR_OK); } if (req->parse_state != HTTPC_PARSE_RX_DATA) { if (req->rx_hdrs == NULL) { diff --git a/src/include/lwip/apps/http_client.h b/src/include/lwip/apps/http_client.h index 685420f0..3071d185 100644 --- a/src/include/lwip/apps/http_client.h +++ b/src/include/lwip/apps/http_client.h @@ -86,7 +86,9 @@ typedef enum ehttpc_result { /** Local memory error */ HTTPC_RESULT_ERR_MEM = 7, /** Local abort */ - HTTPC_RESULT_LOCAL_ABORT = 8 + HTTPC_RESULT_LOCAL_ABORT = 8, + /** Content length mismatch */ + HTTPC_RESULT_ERR_CONTENT_LEN = 9 } httpc_result_t; typedef struct _httpc_state httpc_state_t;