From e9c0d001faedb8062c8eb9530477497b4618772e Mon Sep 17 00:00:00 2001 From: Michael Scott Date: Thu, 9 Nov 2017 16:13:04 -0800 Subject: [PATCH] net: http: client: remove payload send_chunk logic Logic for sending chunks of data is incompatible with adding Content-Length: header. Per https://tools.ietf.org/html/rfc7230#section-3.3.1: "A sender MUST NOT send a Content-Length header field in any message that contains a Transfer-Encoding header field." Going a bit further in my mind: also don't send Transfer-Encoded chunked data either when the Content-Length header is present. In general, there will be problems if the http client library makes payload changes without the user code knowing about it. This patch removes the use of http_send_chunk() from the new HTTP client code and instead sends the payload directly to http_prepare_and_send() This fixes an issue where every available buffer would be allocated with repeating payload data because the for loop in http_request() wasn't ending until we ran out of memory. NOTE: This patch was previously applied but was lost when commit d1675bf3e658 ("net: http: Remove the old legacy API") moved code around. Signed-off-by: Michael Scott --- subsys/net/lib/http/http_client.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/subsys/net/lib/http/http_client.c b/subsys/net/lib/http/http_client.c index 9563f052e88..12b69f8eade 100644 --- a/subsys/net/lib/http/http_client.c +++ b/subsys/net/lib/http/http_client.c @@ -123,7 +123,6 @@ int http_request(struct http_ctx *ctx, struct http_request *req, s32_t timeout, if (req->payload && req->payload_size) { char content_len_str[HTTP_CONT_LEN_SIZE]; - int i; ret = snprintk(content_len_str, HTTP_CONT_LEN_SIZE, "%u", req->payload_size); @@ -143,17 +142,10 @@ int http_request(struct http_ctx *ctx, struct http_request *req, s32_t timeout, goto out; } - for (i = 0; i < req->payload_size;) { - ret = http_send_chunk(ctx, - req->payload + i, - req->payload_size - i, - user_data); - if (ret < 0) { - NET_ERR("Cannot send data to peer (%d)", ret); - return ret; - } - - i += ret; + ret = http_prepare_and_send(ctx, req->payload, + req->payload_size, user_data); + if (ret < 0) { + goto out; } } else { ret = http_add_header(ctx, HTTP_EOF, user_data);