http_client: check current state when receiving FIN

This commit is contained in:
goldsimon 2018-03-06 21:51:13 +01:00
parent 91a2d9e237
commit b6d9bb6b2a
2 changed files with 16 additions and 2 deletions

View File

@ -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) {

View File

@ -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;