Commit 493be790 authored by Robert Lubos's avatar Robert Lubos Committed by Benjamin Cabé
Browse files

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: default avatarRobert Lubos <robert.lubos@nordicsemi.no>
parent 306faea6
Loading
Loading
Loading
Loading
+7 −1
Changes for subsys/net/lib/http/http_client.c: 7 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -530,6 +530,9 @@ static int http_wait_data(int sock, struct http_request *req, const k_timepoint_
			total_received += received;
			offset += received;

			/* Initialize the data length with the received data length. */
			req->internal.response.data_len = offset;

			processed = http_parser_execute(
				&req->internal.parser, &req->internal.parser_settings,
				req->internal.response.recv_buf, offset);
@@ -547,7 +550,10 @@ static int http_wait_data(int sock, struct http_request *req, const k_timepoint_
				goto error;
			}

			req->internal.response.data_len += processed;
			/* Update the response data length with the actually
			 * processed bytes.
			 */
			req->internal.response.data_len = processed;
			offset -= processed;

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