diff --git a/spanner/src/apiv1/conn_pool.rs b/spanner/src/apiv1/conn_pool.rs index 7666a777..70785f71 100644 --- a/spanner/src/apiv1/conn_pool.rs +++ b/spanner/src/apiv1/conn_pool.rs @@ -21,8 +21,23 @@ impl ConnectionManager { domain: &str, conn_options: &ConnectionOptions, ) -> Result { + // Support Private Service Connect (PSC) endpoints for Spanner. + // + // When `domain` is a full HTTPS URL (e.g. "https://spanner-nonprod.p.googleapis.com") + // we use it as both the TLS SNI hostname and the gRPC connection target, mirroring + // the Java SDK's `SpannerOptions.setHost("https://...")` behaviour. + // + // When `domain` is a plain hostname (default: "spanner.googleapis.com") the existing + // behaviour is preserved: the public AUDIENCE constant is used as the target. + let (sni_domain, audience): (String, &str) = if domain.starts_with("https://") { + let host = domain.trim_start_matches("https://").trim_end_matches('/'); + (host.to_string(), domain) + } else { + (domain.to_string(), AUDIENCE) + }; + Ok(ConnectionManager { - inner: GRPCConnectionManager::new(pool_size, domain, AUDIENCE, environment, conn_options).await?, + inner: GRPCConnectionManager::new(pool_size, sni_domain, audience, environment, conn_options).await?, }) }