forked from espressif/esp-idf
feat(http_client): Add support for using custom tcp_transport
This commit is contained in:
@ -21,4 +21,12 @@ menu "ESP HTTP client"
|
|||||||
This option will enable HTTP Digest Authentication. It is enabled by default, but use of this
|
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
|
configuration is not recommended as the password can be derived from the exchange, so it introduces
|
||||||
a vulnerability when not using TLS
|
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
|
endmenu
|
||||||
|
@ -758,6 +758,12 @@ esp_http_client_handle_t esp_http_client_init(const esp_http_client_config_t *co
|
|||||||
}
|
}
|
||||||
#endif
|
#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_pem) {
|
||||||
if (!config->client_key_len) {
|
if (!config->client_key_len) {
|
||||||
esp_transport_ssl_set_client_key_data(ssl, config->client_key_pem, strlen(config->client_key_pem));
|
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) {
|
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);
|
#ifdef CONFIG_ESP_HTTP_CLIENT_ENABLE_CUSTOM_TRANSPORT
|
||||||
client->transport = esp_transport_list_get_transport(client->transport_list, client->connection_info.scheme);
|
// 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
|
#ifdef CONFIG_ESP_TLS_CLIENT_SESSION_TICKETS
|
||||||
if (client->session_ticket_state == SESSION_TICKET_SAVED) {
|
if (client->session_ticket_state == SESSION_TICKET_SAVED) {
|
||||||
|
@ -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 *esp_http_client_handle_t;
|
||||||
typedef struct esp_http_client_event *esp_http_client_event_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
|
* @brief HTTP Client events id
|
||||||
*/
|
*/
|
||||||
@ -181,6 +186,9 @@ typedef struct {
|
|||||||
#if CONFIG_ESP_TLS_CLIENT_SESSION_TICKETS
|
#if CONFIG_ESP_TLS_CLIENT_SESSION_TICKETS
|
||||||
bool save_client_session;
|
bool save_client_session;
|
||||||
#endif
|
#endif
|
||||||
|
#if CONFIG_ESP_HTTP_CLIENT_ENABLE_CUSTOM_TRANSPORT
|
||||||
|
struct esp_transport_item_t *transport;
|
||||||
|
#endif
|
||||||
} esp_http_client_config_t;
|
} esp_http_client_config_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user