|
@@ -563,9 +563,11 @@ esp_http_client_handle_t esp_http_client_init(const esp_http_client_config_t *co
|
|
|
goto error;
|
|
goto error;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ const char *user_agent = config->user_agent == NULL ? DEFAULT_HTTP_USER_AGENT : config->user_agent;
|
|
|
|
|
+
|
|
|
if (config->host != NULL && config->path != NULL) {
|
|
if (config->host != NULL && config->path != NULL) {
|
|
|
_success = (
|
|
_success = (
|
|
|
- (esp_http_client_set_header(client, "User-Agent", DEFAULT_HTTP_USER_AGENT) == ESP_OK) &&
|
|
|
|
|
|
|
+ (esp_http_client_set_header(client, "User-Agent", user_agent) == ESP_OK) &&
|
|
|
(esp_http_client_set_header(client, "Host", client->connection_info.host) == ESP_OK)
|
|
(esp_http_client_set_header(client, "Host", client->connection_info.host) == ESP_OK)
|
|
|
);
|
|
);
|
|
|
|
|
|
|
@@ -576,7 +578,7 @@ esp_http_client_handle_t esp_http_client_init(const esp_http_client_config_t *co
|
|
|
} else if (config->url != NULL) {
|
|
} else if (config->url != NULL) {
|
|
|
_success = (
|
|
_success = (
|
|
|
(esp_http_client_set_url(client, config->url) == ESP_OK) &&
|
|
(esp_http_client_set_url(client, config->url) == ESP_OK) &&
|
|
|
- (esp_http_client_set_header(client, "User-Agent", DEFAULT_HTTP_USER_AGENT) == ESP_OK) &&
|
|
|
|
|
|
|
+ (esp_http_client_set_header(client, "User-Agent", user_agent) == ESP_OK) &&
|
|
|
(esp_http_client_set_header(client, "Host", client->connection_info.host) == ESP_OK)
|
|
(esp_http_client_set_header(client, "Host", client->connection_info.host) == ESP_OK)
|
|
|
);
|
|
);
|
|
|
|
|
|
|
@@ -650,6 +652,9 @@ esp_err_t esp_http_client_set_redirection(esp_http_client_handle_t client)
|
|
|
|
|
|
|
|
static esp_err_t esp_http_check_response(esp_http_client_handle_t client)
|
|
static esp_err_t esp_http_check_response(esp_http_client_handle_t client)
|
|
|
{
|
|
{
|
|
|
|
|
+ if (client->response->status_code >= HttpStatus_Ok && client->response->status_code < HttpStatus_MultipleChoices) {
|
|
|
|
|
+ return ESP_OK;
|
|
|
|
|
+ }
|
|
|
if (client->redirect_counter >= client->max_redirection_count || client->disable_auto_redirect) {
|
|
if (client->redirect_counter >= client->max_redirection_count || client->disable_auto_redirect) {
|
|
|
ESP_LOGE(TAG, "Error, reach max_redirection_count count=%d", client->redirect_counter);
|
|
ESP_LOGE(TAG, "Error, reach max_redirection_count count=%d", client->redirect_counter);
|
|
|
return ESP_ERR_HTTP_MAX_REDIRECT;
|
|
return ESP_ERR_HTTP_MAX_REDIRECT;
|