feat(http_client): Add support for using custom tcp_transport

pull/12732/head
David Cermak 2023-11-19 18:32:00 +01:00
rodzic 7e22a13afe
commit 96069eef3b
3 zmienionych plików z 31 dodań i 2 usunięć

Wyświetl plik

@ -21,4 +21,12 @@ menu "ESP HTTP client"
This option will enable HTTP Digest Authentication. It is enabled by default, but use of this
configuration is not recommended as the password can be derived from the exchange, so it introduces
a vulnerability when not using TLS
config ESP_HTTP_CLIENT_ENABLE_CUSTOM_TRANSPORT
bool "Enable custom transport"
default n
help
This option will enable injection of a custom tcp_transport handle, so the http operation
will be performed on top of the user defined transport abstraction (if configured)
endmenu

Wyświetl plik

@ -758,6 +758,12 @@ esp_http_client_handle_t esp_http_client_init(const esp_http_client_config_t *co
}
#endif
#if CONFIG_ESP_HTTP_CLIENT_ENABLE_CUSTOM_TRANSPORT
if (config->transport) {
client->transport = config->transport;
}
#endif
if (config->client_key_pem) {
if (!config->client_key_len) {
esp_transport_ssl_set_client_key_data(ssl, config->client_key_pem, strlen(config->client_key_pem));
@ -1398,8 +1404,15 @@ static esp_err_t esp_http_client_connect(esp_http_client_handle_t client)
}
if (client->state < HTTP_STATE_CONNECTED) {
ESP_LOGD(TAG, "Begin connect to: %s://%s:%d", client->connection_info.scheme, client->connection_info.host, client->connection_info.port);
client->transport = esp_transport_list_get_transport(client->transport_list, client->connection_info.scheme);
#ifdef CONFIG_ESP_HTTP_CLIENT_ENABLE_CUSTOM_TRANSPORT
// If the custom transport is enabled and defined, we skip the selection of appropriate transport from the list
// based on the scheme, since we already have the transport
if (!client->transport)
#endif
{
ESP_LOGD(TAG, "Begin connect to: %s://%s:%d", client->connection_info.scheme, client->connection_info.host, client->connection_info.port);
client->transport = esp_transport_list_get_transport(client->transport_list, client->connection_info.scheme);
}
#ifdef CONFIG_ESP_TLS_CLIENT_SESSION_TICKETS
if (client->session_ticket_state == SESSION_TICKET_SAVED) {

Wyświetl plik

@ -24,6 +24,11 @@ ESP_EVENT_DECLARE_BASE(ESP_HTTP_CLIENT_EVENT);
typedef struct esp_http_client *esp_http_client_handle_t;
typedef struct esp_http_client_event *esp_http_client_event_handle_t;
#if CONFIG_ESP_HTTP_CLIENT_ENABLE_CUSTOM_TRANSPORT
// Forward declares transport handle item to keep the dependency private (even if ENABLE_CUSTOM_TRANSPORT=y)
struct esp_transport_item_t;
#endif
/**
* @brief HTTP Client events id
*/
@ -181,6 +186,9 @@ typedef struct {
#if CONFIG_ESP_TLS_CLIENT_SESSION_TICKETS
bool save_client_session;
#endif
#if CONFIG_ESP_HTTP_CLIENT_ENABLE_CUSTOM_TRANSPORT
struct esp_transport_item_t *transport;
#endif
} esp_http_client_config_t;
/**