spin_factor_outbound_http/runtime_config/
spin.rs1use serde::Deserialize;
2use spin_factors::runtime_config::toml::GetTomlValue;
3
4pub fn config_from_table(
14 table: &impl GetTomlValue,
15) -> anyhow::Result<Option<super::RuntimeConfig>> {
16 if let Some(outbound_http) = table.get("outbound_http") {
17 let toml = outbound_http.clone().try_into::<OutboundHttpToml>()?;
18
19 let max_connections = match (toml.max_connections, toml.max_concurrent_requests) {
20 (Some(_), Some(_)) => anyhow::bail!(
21 "cannot set both `max_connections` and `max_concurrent_requests` in \
22 `[outbound_http]`; use `max_connections` only"
23 ),
24 (Some(n), None) => Some(n),
25 (None, Some(n)) => {
26 terminal::warn!(
27 "`max_concurrent_requests` in `[outbound_http]` is deprecated; \
28 use `max_connections` instead (note: `max_connections = 0` blocks all \
29 connections, whereas `max_concurrent_requests = 0` allowed 1 connection)"
30 );
31 Some(n + 1)
33 }
34 (None, None) => None,
35 };
36
37 Ok(Some(super::RuntimeConfig {
38 connection_pooling_enabled: toml.connection_pooling,
39 max_concurrent_connections: max_connections,
40 wait_timeout: None,
41 }))
42 } else {
43 Ok(None)
44 }
45}
46
47#[derive(Debug, Default, Deserialize)]
48#[serde(deny_unknown_fields)]
49struct OutboundHttpToml {
50 #[serde(default)]
51 connection_pooling: bool,
52 #[serde(default)]
53 max_connections: Option<usize>,
54 #[serde(default)]
56 max_concurrent_requests: Option<usize>,
57}