mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
fix(ws_transport): utility functions minor improvments
This commit is contained in:
parent
c42cfe1818
commit
c07bc80e90
@ -131,7 +131,7 @@ static int esp_transport_read_internal(transport_ws_t *ws, char *buffer, int len
|
|||||||
return to_read;
|
return to_read;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *trimwhitespace(const char *str)
|
static char *trimwhitespace(char *str)
|
||||||
{
|
{
|
||||||
char *end;
|
char *end;
|
||||||
|
|
||||||
@ -141,19 +141,19 @@ static char *trimwhitespace(const char *str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (*str == 0) {
|
if (*str == 0) {
|
||||||
return (char *)str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trim trailing space
|
// Trim trailing space
|
||||||
end = (char *)(str + strlen(str) - 1);
|
end = str + strlen(str) - 1;
|
||||||
while (end > str && isspace((unsigned char)*end)) {
|
while (end > str && isspace((unsigned char)*end)) {
|
||||||
end--;
|
end--;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write new null terminator
|
// Write new null terminator
|
||||||
*(end + 1) = 0;
|
*(end + 1) = '\0';
|
||||||
|
|
||||||
return (char *)str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_http_status_code(const char *buffer)
|
static int get_http_status_code(const char *buffer)
|
||||||
@ -162,11 +162,11 @@ static int get_http_status_code(const char *buffer)
|
|||||||
const char *found = strcasestr(buffer, http);
|
const char *found = strcasestr(buffer, http);
|
||||||
char status_code[4];
|
char status_code[4];
|
||||||
if (found) {
|
if (found) {
|
||||||
found += sizeof(http)/sizeof(http[0]) - 1;
|
found += sizeof(http) - 1;
|
||||||
found = strchr(found, ' ');
|
found = strchr(found, ' ');
|
||||||
if (found) {
|
if (found) {
|
||||||
found++;
|
found++;
|
||||||
strncpy(status_code, found, 4);
|
strncpy(status_code, found, 3);
|
||||||
status_code[3] = '\0';
|
status_code[3] = '\0';
|
||||||
int code = atoi(status_code);
|
int code = atoi(status_code);
|
||||||
ESP_LOGD(TAG, "HTTP status code is %d", code);
|
ESP_LOGD(TAG, "HTTP status code is %d", code);
|
||||||
@ -176,14 +176,14 @@ static int get_http_status_code(const char *buffer)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *get_http_header(const char *buffer, const char *key)
|
static char *get_http_header(char *buffer, const char *key)
|
||||||
{
|
{
|
||||||
char *found = strcasestr(buffer, key);
|
char *found = strcasestr(buffer, key);
|
||||||
if (found) {
|
if (found) {
|
||||||
found += strlen(key);
|
found += strlen(key);
|
||||||
char *found_end = strstr(found, "\r\n");
|
char *found_end = strstr(found, "\r\n");
|
||||||
if (found_end) {
|
if (found_end) {
|
||||||
found_end[0] = 0;//terminal string
|
*found_end = '\0'; // terminal string
|
||||||
|
|
||||||
return trimwhitespace(found);
|
return trimwhitespace(found);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user