Skip to content

Commit 493be79

Browse files
rluboskartben
authored andcommitted
net: http: client: Fix the body callback processing
Response "data_len" field needs to be set with the size of the received data before calling the parser as it's used inside the on_body callback, this commit fixes it. Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
1 parent 306faea commit 493be79

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

subsys/net/lib/http/http_client.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,9 @@ static int http_wait_data(int sock, struct http_request *req, const k_timepoint_
530530
total_received += received;
531531
offset += received;
532532

533+
/* Initialize the data length with the received data length. */
534+
req->internal.response.data_len = offset;
535+
533536
processed = http_parser_execute(
534537
&req->internal.parser, &req->internal.parser_settings,
535538
req->internal.response.recv_buf, offset);
@@ -547,7 +550,10 @@ static int http_wait_data(int sock, struct http_request *req, const k_timepoint_
547550
goto error;
548551
}
549552

550-
req->internal.response.data_len += processed;
553+
/* Update the response data length with the actually
554+
* processed bytes.
555+
*/
556+
req->internal.response.data_len = processed;
551557
offset -= processed;
552558

553559
if (offset >= req->internal.response.recv_buf_len) {

0 commit comments

Comments
 (0)