esp_http_client: fix truncated headers

Signed-off-by: yuanjm <yuanjianmin@espressif.com>

Merges https://github.com/espressif/esp-idf/pull/6370
This commit is contained in:
Clickau
2021-01-07 13:47:22 +02:00
committed by yuanjm
parent b92c290e56
commit 308c31e2f1
3 changed files with 65 additions and 13 deletions

View File

@@ -61,6 +61,30 @@ char *http_utils_assign_string(char **str, const char *new_str, int len)
return old_str;
}
char *http_utils_append_string(char **str, const char *new_str, int len)
{
if (new_str == NULL) {
return NULL;
}
char *old_str = *str;
if (len <= 0) {
len = strlen(new_str);
}
if (old_str) {
int old_len = strlen(old_str);
old_str = realloc(old_str, old_len + len + 1);
mem_check(old_str);
memcpy(old_str + old_len, new_str, len);
old_str[old_len + len] = 0;
} else {
old_str = calloc(1, len + 1);
mem_check(old_str);
memcpy(old_str, new_str, len);
}
*str = old_str;
return old_str;
}
void http_utils_trim_whitespace(char **str)
{
char *end, *start;

View File

@@ -30,6 +30,19 @@
*/
char *http_utils_assign_string(char **str, const char *new_str, int len);
/**
* @brief Realloc *str and append new_str to it, if not NULL; assign new_str to *str pointer if NULL
*
* @param str pointer to string pointer
* @param new_str assign this string to str
* @param len length of string, 0 if new_str is zero terminated
*
* @return
* - new_str pointer
* - NULL
*/
char *http_utils_append_string(char **str, const char *new_str, int len);
/**
* @brief Remove white space at begin and end of string
*