Store central secure origin

This commit is contained in:
2024-08-18 17:40:41 +02:00
parent 3867a38ff9
commit 3b6e79e5e4
6 changed files with 80 additions and 23 deletions

View File

@ -118,7 +118,7 @@ esp_err_t _http_event_handler(esp_http_client_event_t *evt)
char *http_client_exec(const http_request_opts *opts)
{
char local_response_buffer[MAX_HTTP_OUTPUT_BUFFER + 1] = {0};
char *local_response_buffer = calloc(MAX_HTTP_OUTPUT_BUFFER + 1, 1);
ESP_LOGI(TAG, "Perform HTTP request on %s", opts->url);
@ -129,26 +129,39 @@ char *http_client_exec(const http_request_opts *opts)
.disable_auto_redirect = true,
};
esp_http_client_handle_t client = esp_http_client_init(&config);
if (client == NULL)
{
ESP_LOGE(TAG, "Failed to initialize HTTP connection!");
free(local_response_buffer);
return NULL;
}
ESP_LOGD(TAG, "esp_http_client_perform start");
esp_err_t err = esp_http_client_perform(client);
ESP_LOGD(TAG, "esp_http_client_perform end");
if (err != ESP_OK)
{
esp_http_client_cleanup(client);
free(local_response_buffer);
ESP_LOGE(TAG, "HTTP request failed with code %d!", err);
return NULL;
}
const int status = esp_http_client_get_status_code(client);
const int64_t resp_len = esp_http_client_get_content_length(client);
esp_http_client_cleanup(client);
if (err != ESP_OK)
{
ESP_LOGE(TAG, "HTTP request failed with code %xd!", err);
return NULL;
}
if (status < 200 || status > 299)
{
ESP_LOGE(TAG, "HTTP request failed with status %d!", status);
free(local_response_buffer);
return NULL;
}
local_response_buffer[resp_len] = 0;
return strdup(local_response_buffer);
return local_response_buffer;
}