Merge branch 'backport/bugfix_url_redirect_v32' into 'release/v3.2'

Fix url redirection issue. (backport v3.2)

See merge request idf/esp-idf!4852
This commit is contained in:
Jiang Jiang Jian 2019-04-28 10:36:09 +08:00
commit 8f4e7d2456

View file

@ -652,7 +652,9 @@ esp_err_t esp_http_client_set_url(esp_http_client_handle_t client, const char *u
ESP_LOGE(TAG, "Error parse url %s", url);
return ESP_ERR_INVALID_ARG;
}
old_host = client->connection_info.host;
if (client->connection_info.host) {
old_host = strdup(client->connection_info.host);
}
old_port = client->connection_info.port;
if (purl.field_data[UF_HOST].len) {
@ -664,11 +666,17 @@ esp_err_t esp_http_client_set_url(esp_http_client_handle_t client, const char *u
&& strcasecmp(old_host, (const void *)client->connection_info.host) != 0) {
ESP_LOGD(TAG, "New host assign = %s", client->connection_info.host);
if (esp_http_client_set_header(client, "Host", client->connection_info.host) != ESP_OK) {
free(old_host);
return ESP_ERR_NO_MEM;
}
esp_http_client_close(client);
}
if (old_host) {
free(old_host);
old_host = NULL;
}
if (purl.field_data[UF_SCHEMA].len) {
http_utils_assign_string(&client->connection_info.scheme, url + purl.field_data[UF_SCHEMA].off, purl.field_data[UF_SCHEMA].len);
HTTP_MEM_CHECK(TAG, client->connection_info.scheme, return ESP_ERR_NO_MEM);