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 d1675bf3e6
("net: http: Remove the old legacy API")
moved code around.
Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
This commit is contained in:
parent
311d0ac66c
commit
e9c0d001fa
1 changed files with 4 additions and 12 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue