spin_factor_outbound_http/runtime_config/
spin.rs

1use serde::Deserialize;
2use spin_factors::runtime_config::toml::GetTomlValue;
3
4/// Get the runtime configuration for outbound HTTP from a TOML table.
5///
6/// Expects table to be in the format:
7/// ```toml
8/// [outbound_http]
9/// connection_pooling = true # optional, defaults to true
10/// max_concurrent_requests = 10 # optional, defaults to unlimited
11/// ```
12pub fn config_from_table(
13    table: &impl GetTomlValue,
14) -> anyhow::Result<Option<super::RuntimeConfig>> {
15    if let Some(outbound_http) = table.get("outbound_http") {
16        let outbound_http_toml = outbound_http.clone().try_into::<OutboundHttpToml>()?;
17        Ok(Some(super::RuntimeConfig {
18            connection_pooling_enabled: outbound_http_toml.connection_pooling,
19            max_concurrent_connections: outbound_http_toml.max_concurrent_requests,
20        }))
21    } else {
22        Ok(None)
23    }
24}
25
26#[derive(Debug, Default, Deserialize)]
27#[serde(deny_unknown_fields)]
28struct OutboundHttpToml {
29    #[serde(default)]
30    connection_pooling: bool,
31    #[serde(default)]
32    max_concurrent_requests: Option<usize>,
33}