Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Other
- Changed endpoint construction to set origin for compatibility with SNI based servers.

## [0.9.0](https://github.com/TrueLayer/ginepro/compare/ginepro-v0.8.2...ginepro-v0.8.1) - 2025-07-24

### Breaking changes
Expand Down
16 changes: 15 additions & 1 deletion ginepro/src/service_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ pub struct ServiceDefinition {
hostname: String,
/// The service port.
port: u16,
/// Authority
authority: http::uri::Authority,
}

impl ServiceDefinition {
Expand All @@ -21,14 +23,26 @@ impl ServiceDefinition {
.map_err(anyhow::Error::from)
.context("invalid 'hostname'")?;

Ok(Self { hostname, port })
let authority = format!("{}:{}", hostname, port)
.parse()
.context("invalid 'hostname'")?;

Ok(Self {
hostname,
port,
authority,
})
}

/// Get the `hostname` part of a `ServiceDefinition`.
pub fn hostname(&self) -> &str {
&self.hostname
}

pub(crate) fn authority(&self) -> &http::uri::Authority {
&self.authority
}

/// Get the `port` part of a `ServiceDefinition`.
pub fn port(&self) -> u16 {
self.port
Expand Down
22 changes: 21 additions & 1 deletion ginepro/src/service_probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ where
Lookup: LookupService,
{
service_definition: ServiceDefinition,
origin: http::uri::Uri,
scheme: http::uri::Scheme,
dns_lookup: Lookup,
probe_interval: tokio::time::Duration,
Expand Down Expand Up @@ -70,8 +71,10 @@ impl<Lookup: LookupService> GrpcServiceProbe<Lookup> {
config: GrpcServiceProbeConfig<Lookup>,
endpoint_reporter: Sender<Change<SocketAddr, Endpoint>>,
) -> GrpcServiceProbe<Lookup> {
let origin = create_origin(config.service_definition.authority().clone());
Self {
service_definition: config.service_definition,
origin,
dns_lookup: config.dns_lookup,
probe_interval: config.probe_interval,
endpoint_timeout: config.endpoint_timeout,
Expand All @@ -85,9 +88,15 @@ impl<Lookup: LookupService> GrpcServiceProbe<Lookup> {

/// Enable tls for all endpoints.
pub fn with_tls(self, tls_config: ClientTlsConfig) -> GrpcServiceProbe<Lookup> {
let mut parts = self.origin.into_parts();
parts.scheme = Some(http::uri::Scheme::HTTPS);
let origin = parts
.try_into()
.expect("Invalid URI. Impossible as all parts are present");
Self {
tls_config: Some(tls_config),
scheme: http::uri::Scheme::HTTPS,
origin,
..self
}
}
Expand Down Expand Up @@ -215,7 +224,8 @@ impl<Lookup: LookupService> GrpcServiceProbe<Lookup> {
.map_err(|err| {
tracing::warn!("endpoint creation error: {:?}", err);
})
.ok()?;
.ok()?
.origin(self.origin.clone());

if let Some(ref tls_config) = self.tls_config {
endpoint = endpoint
Expand All @@ -237,3 +247,13 @@ impl<Lookup: LookupService> GrpcServiceProbe<Lookup> {
Some(endpoint)
}
}

fn create_origin(authority: http::uri::Authority) -> http::uri::Uri {
let mut parts = http::uri::Parts::default();
parts.scheme = Some(http::uri::Scheme::HTTP);
parts.authority = Some(authority);
parts.path_and_query = Some(http::uri::PathAndQuery::from_static("/"));
parts
.try_into()
.expect("Invalid URI. Impossible as all parts are present")
}