platform/config/bind/
http.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
8pub struct HttpBindConfig {
9 pub domain_name: String,
13
14 pub advertised_ip: String,
19
20 pub ip: String,
25
26 pub port: u16,
30
31 #[serde(default)]
36 pub advertised_port: Option<u16>,
37
38 #[serde(default)]
42 pub cert: Option<String>,
43
44 #[serde(default)]
48 pub key: Option<String>,
49}
50
51impl HttpBindConfig {
52 pub fn is_tls(&self) -> bool {
56 self.cert.as_ref().is_some_and(|c| !c.is_empty())
57 && self.key.as_ref().is_some_and(|k| !k.is_empty())
58 }
59
60 pub fn effective_advertised_port(&self) -> u16 {
64 self.advertised_port.unwrap_or(self.port)
65 }
66
67 pub fn scheme(&self) -> &'static str {
69 if self.is_tls() { "https" } else { "http" }
70 }
71
72 pub fn ws_scheme(&self) -> &'static str {
74 if self.is_tls() { "wss" } else { "ws" }
75 }
76}
77
78impl Default for HttpBindConfig {
79 fn default() -> Self {
80 Self {
81 domain_name: "localhost".to_string(),
82 advertised_ip: "127.0.0.1".to_string(),
83 ip: "::".to_string(),
84 port: 8080,
85 advertised_port: None,
86 cert: None,
87 key: None,
88 }
89 }
90}