diff --git a/ngrok/src/config/http.rs b/ngrok/src/config/http.rs index a22a568..f55020b 100644 --- a/ngrok/src/config/http.rs +++ b/ngrok/src/config/http.rs @@ -167,7 +167,8 @@ impl TunnelConfig for HttpOptions { fn opts(&self) -> Option { let http_endpoint = HttpEndpoint { proxy_proto: self.common_opts.proxy_proto, - hostname: self.domain.clone().unwrap_or_default(), + domain: self.domain.clone().unwrap_or_default(), + hostname: String::new(), compression: self.compression.then_some(Compression {}), circuit_breaker: (self.circuit_breaker != 0f64).then_some(CircuitBreaker { error_threshold: self.circuit_breaker, @@ -597,7 +598,7 @@ mod test { let opts = tunnel_cfg.opts().unwrap(); assert!(matches!(opts, BindOpts::Http { .. })); if let BindOpts::Http(endpoint) = opts { - assert_eq!(DOMAIN, endpoint.hostname); + assert_eq!(DOMAIN, endpoint.domain); assert_eq!(String::default(), endpoint.subdomain); assert!(matches!(endpoint.proxy_proto, ProxyProto::V2)); @@ -715,4 +716,28 @@ mod test { builder.binding("public"); builder.binding("internal"); } + + #[test] + fn test_binding_with_domain() { + let mut builder = HttpTunnelBuilder { + session: None, + options: Default::default(), + }; + builder.binding("internal").domain("foo.internal"); + + // Check that both binding and domain are set + assert_eq!(vec!["internal"], builder.options.bindings); + assert_eq!(Some("foo.internal".to_string()), builder.options.domain); + + // Check that they're properly included in extra() and opts() + let extra = builder.options.extra(); + assert_eq!(vec!["internal"], extra.bindings); + + let opts = builder.options.opts().unwrap(); + if let BindOpts::Http(endpoint) = opts { + assert_eq!("foo.internal", endpoint.domain); + } else { + panic!("Expected Http endpoint"); + } + } } diff --git a/ngrok/src/config/tls.rs b/ngrok/src/config/tls.rs index 72c32a7..e4133c8 100644 --- a/ngrok/src/config/tls.rs +++ b/ngrok/src/config/tls.rs @@ -76,8 +76,7 @@ impl TunnelConfig for TlsOptions { let mut tls_endpoint = proto::TlsEndpoint::default(); if let Some(domain) = self.domain.as_ref() { - // note: hostname and subdomain are going away in favor of just domain - tls_endpoint.hostname = domain.clone(); + tls_endpoint.domain = domain.clone(); } tls_endpoint.proxy_proto = self.common_opts.proxy_proto; @@ -318,7 +317,7 @@ mod test { let opts = tunnel_cfg.opts().unwrap(); assert!(matches!(opts, BindOpts::Tls { .. })); if let BindOpts::Tls(endpoint) = opts { - assert_eq!(DOMAIN, endpoint.hostname); + assert_eq!(DOMAIN, endpoint.domain); assert_eq!(String::default(), endpoint.subdomain); assert!(matches!(endpoint.proxy_proto, ProxyProto::V2)); assert!(!endpoint.mutual_tls_at_agent); diff --git a/ngrok/src/internals/proto.rs b/ngrok/src/internals/proto.rs index cdcb495..016f91b 100644 --- a/ngrok/src/internals/proto.rs +++ b/ngrok/src/internals/proto.rs @@ -672,6 +672,8 @@ impl From for PolicyWrapper { #[derive(Serialize, Deserialize, Debug, Clone, Default)] #[serde(rename_all = "PascalCase")] pub struct HttpEndpoint { + #[serde(default)] + pub domain: String, pub hostname: String, pub auth: String, pub subdomain: String, @@ -833,6 +835,8 @@ pub struct TcpEndpoint { #[derive(Serialize, Deserialize, Debug, Clone, Default)] #[serde(rename_all = "PascalCase")] pub struct TlsEndpoint { + #[serde(default)] + pub domain: String, pub hostname: String, pub subdomain: String, pub proxy_proto: ProxyProto,