mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
esp_http_client: Fix minor bugs in esp_http_client_write and esp_http_client_open APIs
`esp_http_client_write` API puts a constraint on the maximum length of the data that can be written, which is equal to client handle buffer size, but the data to be sent can be more than that, so in this case, this API has to be called multiple times. In `esp_http_client_open` API, the return value of `transport_write` API, used to send HTTP request, is not checked, and in rare cases, data written will be less than expected which will cause a problem. So there are fixes for these minor issues in this MR.
This commit is contained in:
parent
76f864511d
commit
2122e5f83d
@ -932,10 +932,17 @@ esp_err_t esp_http_client_open(esp_http_client_handle_t client, int write_len)
|
||||
}
|
||||
client->request->buffer->data[wlen] = 0;
|
||||
ESP_LOGD(TAG, "Write header[%d]: %s", header_index, client->request->buffer->data);
|
||||
if (transport_write(client->transport, client->request->buffer->data, wlen, client->timeout_ms) <= 0) {
|
||||
ESP_LOGE(TAG, "Error write request");
|
||||
esp_http_client_close(client);
|
||||
return ESP_ERR_HTTP_WRITE_DATA;
|
||||
|
||||
int widx = 0, wret = 0;
|
||||
while (wlen > 0) {
|
||||
wret = transport_write(client->transport, client->request->buffer->data + widx, wlen, client->timeout_ms);
|
||||
if (wret <= 0) {
|
||||
ESP_LOGE(TAG, "Error write request");
|
||||
esp_http_client_close(client);
|
||||
return ESP_ERR_HTTP_WRITE_DATA;
|
||||
}
|
||||
widx += wret;
|
||||
wlen -= wret;
|
||||
}
|
||||
wlen = client->buffer_size;
|
||||
}
|
||||
@ -949,14 +956,10 @@ int esp_http_client_write(esp_http_client_handle_t client, const char *buffer, i
|
||||
if (client->state < HTTP_STATE_REQ_COMPLETE_HEADER) {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
int need_write;
|
||||
|
||||
int wlen = 0, widx = 0;
|
||||
while (len > 0) {
|
||||
need_write = len;
|
||||
if (need_write > client->buffer_size) {
|
||||
need_write = client->buffer_size;
|
||||
}
|
||||
wlen = transport_write(client->transport, buffer + widx, need_write, client->timeout_ms);
|
||||
wlen = transport_write(client->transport, buffer + widx, len, client->timeout_ms);
|
||||
if (wlen <= 0) {
|
||||
return wlen;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user