opentalk_roomserver_common/settings/runtime_settings/
http.rs1use std::net::{Ipv4Addr, Ipv6Addr, TcpListener};
5
6use opentalk_service_auth::service::ApiKeys;
7
8use crate::settings::settings_file;
9
10#[derive(Debug, Clone)]
12pub struct Http {
13 pub address: String,
15
16 pub port: u16,
18
19 pub service_url: Option<url::Url>,
21
22 pub public_url: url::Url,
24
25 pub api_keys: ApiKeys,
27
28 pub enable_openapi: bool,
31}
32
33impl From<settings_file::http::Http> for Http {
34 fn from(value: settings_file::http::Http) -> Self {
35 let address = match value.address {
36 Some(address) => address,
37 None => {
38 if is_ipv6_available() {
39 Ipv6Addr::UNSPECIFIED.to_string()
40 } else {
41 Ipv4Addr::UNSPECIFIED.to_string()
42 }
43 }
44 };
45
46 Self {
47 address,
48 port: value.port,
49 service_url: value.service_url,
50 public_url: value.public_url,
51 api_keys: value.api_keys,
52 enable_openapi: value.enable_openapi,
53 }
54 }
55}
56
57fn is_ipv6_available() -> bool {
58 TcpListener::bind((Ipv6Addr::UNSPECIFIED, 0)).is_ok()
59}