Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions esp-idf-svc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Added
- HTTP client: `Configuration::save_client_session`, for resuming TLS sessions (ESP-IDF v5.3+ with `CONFIG_ESP_TLS_CLIENT_SESSION_TICKETS`)
- HTTP client: `EspHttpConnection::close`, which closes the connection but keeps the client
- Thread: a DNS client for DNS-SD, `dns_resolve_service_and_host_address` and `dns_browse` (with `CONFIG_OPENTHREAD_DNS_CLIENT`)
- Thread: `srp_wait_changed`, to wait for the SRP client to find or lose a server
- Thread: Sleepy End Device controls `set_link_mode`, `set_poll_period`, `set_child_timeout` and `set_child_supervision_check_timeout`
Expand Down
23 changes: 23 additions & 0 deletions esp-idf-svc/src/http/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ pub struct Configuration {
pub keep_alive_idle: Option<usize>,
pub keep_alive_interval: Option<usize>,
pub keep_alive_count: Option<usize>,
/// Resume the TLS session on the next connection with the ticket saved from the last one.
/// ESP-IDF keeps one ticket per client and offers it to whatever host the client connects
/// to next, so this is meant for a client per host. Needs ESP-IDF v5.3+ with
/// `CONFIG_ESP_TLS_CLIENT_SESSION_TICKETS`; ignored otherwise.
pub save_client_session: bool,
}

#[derive(Debug, Copy, Clone, Eq, PartialEq)]
Expand Down Expand Up @@ -124,10 +129,18 @@ impl EspHttpConnection {
use_global_ca_store: configuration.use_global_ca_store,
crt_bundle_attach: configuration.crt_bundle_attach,
keep_alive_enable: configuration.keep_alive_enable,
// The Kconfig option is older than this field, which came with ESP-IDF v5.3
#[cfg(all(esp_idf_esp_tls_client_session_tickets, esp_idf_version_at_least_5_3_0))]
save_client_session: configuration.save_client_session,

..Default::default()
};

#[cfg(not(all(esp_idf_esp_tls_client_session_tickets, esp_idf_version_at_least_5_3_0)))]
if configuration.save_client_session {
warn!("`save_client_session` is ignored: it needs ESP-IDF v5.3+ with `CONFIG_ESP_TLS_CLIENT_SESSION_TICKETS`");
}

if let Some(buffer_size) = configuration.buffer_size {
native_config.buffer_size = buffer_size as _;
};
Expand Down Expand Up @@ -415,6 +428,16 @@ impl EspHttpConnection {
}
}

/// Closes the connection to the server but keeps the client, so the next `initiate_request`
/// connects again (and resumes the TLS session with `Configuration::save_client_session`).
/// A response that was not read to the end is discarded.
pub fn close(&mut self) -> Result<(), EspError> {
// ESP-IDF resets the client even when closing the socket fails
self.state = State::New;

esp!(unsafe { esp_http_client_close(self.raw_client) })
}

fn flush_response(&mut self) -> Result<(), EspError> {
let mut len = 0_i32;
esp!(unsafe { esp_http_client_flush_response(self.raw_client, &mut len) })?;
Expand Down
Loading