mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-30 10:47:19 +02:00
esp_http_client: Fixed exception on 401 without Www-Authenticate header
Closes https://github.com/espressif/esp-idf/issues/2246
This commit is contained in:
@ -557,10 +557,10 @@ static esp_err_t esp_http_check_response(esp_http_client_handle_t client)
|
|||||||
break;
|
break;
|
||||||
case HttpStatus_Unauthorized:
|
case HttpStatus_Unauthorized:
|
||||||
auth_header = client->auth_header;
|
auth_header = client->auth_header;
|
||||||
http_utils_trim_whitespace(&auth_header);
|
|
||||||
ESP_LOGI(TAG, "UNAUTHORIZED: %s", auth_header);
|
|
||||||
client->redirect_counter ++;
|
|
||||||
if (auth_header) {
|
if (auth_header) {
|
||||||
|
http_utils_trim_whitespace(&auth_header);
|
||||||
|
ESP_LOGD(TAG, "UNAUTHORIZED: %s", auth_header);
|
||||||
|
client->redirect_counter ++;
|
||||||
if (http_utils_str_starts_with(auth_header, "Digest") == 0) {
|
if (http_utils_str_starts_with(auth_header, "Digest") == 0) {
|
||||||
ESP_LOGD(TAG, "type = Digest");
|
ESP_LOGD(TAG, "type = Digest");
|
||||||
client->connection_info.auth_type = HTTP_AUTH_TYPE_DIGEST;
|
client->connection_info.auth_type = HTTP_AUTH_TYPE_DIGEST;
|
||||||
@ -569,7 +569,7 @@ static esp_err_t esp_http_check_response(esp_http_client_handle_t client)
|
|||||||
client->connection_info.auth_type = HTTP_AUTH_TYPE_BASIC;
|
client->connection_info.auth_type = HTTP_AUTH_TYPE_BASIC;
|
||||||
} else {
|
} else {
|
||||||
client->connection_info.auth_type = HTTP_AUTH_TYPE_NONE;
|
client->connection_info.auth_type = HTTP_AUTH_TYPE_NONE;
|
||||||
ESP_LOGE(TAG, "Unsupport Auth Type");
|
ESP_LOGE(TAG, "This authentication method is not supported: %s", auth_header);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -584,6 +584,9 @@ static esp_err_t esp_http_check_response(esp_http_client_handle_t client)
|
|||||||
client->auth_data->nonce = http_utils_get_string_between(auth_header, "nonce=\"", "\"");
|
client->auth_data->nonce = http_utils_get_string_between(auth_header, "nonce=\"", "\"");
|
||||||
client->auth_data->opaque = http_utils_get_string_between(auth_header, "opaque=\"", "\"");
|
client->auth_data->opaque = http_utils_get_string_between(auth_header, "opaque=\"", "\"");
|
||||||
client->process_again = 1;
|
client->process_again = 1;
|
||||||
|
} else {
|
||||||
|
client->connection_info.auth_type = HTTP_AUTH_TYPE_NONE;
|
||||||
|
ESP_LOGW(TAG, "This request requires authentication, but does not provide header information for that");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
|
@ -63,8 +63,14 @@ char *http_utils_assign_string(char **str, const char *new_str, int len)
|
|||||||
|
|
||||||
void http_utils_trim_whitespace(char **str)
|
void http_utils_trim_whitespace(char **str)
|
||||||
{
|
{
|
||||||
char *end;
|
char *end, *start;
|
||||||
char *start = *str;
|
if (str == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
start = *str;
|
||||||
|
if (start == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Trim leading space
|
// Trim leading space
|
||||||
while (isspace((unsigned char)*start)) start ++;
|
while (isspace((unsigned char)*start)) start ++;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user