Skip to content
Merged
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
8 changes: 8 additions & 0 deletions source/Halibut/ServiceEndPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ public ServiceEndPoint(Uri baseUri, string? remoteThumbprint, ProxyDetails? prox

public ProxyDetails? Proxy { get; }

/// <summary>
/// When set, TCP connections will be made to the host and port of this URI instead of those in
/// <see cref="BaseUri"/>, while the original <see cref="BaseUri"/> host is still used for TLS SNI.
/// This is equivalent to curl's --resolve flag and is useful when routing through a local proxy
/// (e.g. Toxiproxy) while preserving the correct TLS handshake.
/// </summary>
public Uri? ForceResolveHost { get; set; }

public bool IsWebSocketEndpoint => IsWebSocketAddress(BaseUri);

public override string ToString() => baseUriString;
Expand Down
8 changes: 5 additions & 3 deletions source/Halibut/Transport/TcpConnectionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,21 @@ await ssl.AuthenticateAsClientAsync(
internal static async Task<TcpClient> CreateConnectedTcpClientAsync(ServiceEndPoint endPoint, HalibutTimeoutsAndLimits halibutTimeoutsAndLimits, IStreamFactory streamFactory, ILog log, CancellationToken cancellationToken)
{
TcpClient client;
var connectHost = endPoint.ForceResolveHost?.Host ?? endPoint.BaseUri.Host;
var connectPort = endPoint.ForceResolveHost?.Port ?? endPoint.BaseUri.Port;
if (endPoint.Proxy is null)
{
client = CreateTcpClientAsync(halibutTimeoutsAndLimits);
await client.ConnectWithTimeoutAsync(endPoint.BaseUri, endPoint.TcpClientConnectTimeout, cancellationToken);
await client.ConnectWithTimeoutAsync(connectHost, connectPort, endPoint.TcpClientConnectTimeout, cancellationToken);
}
else
{
log.Write(EventType.Diagnostic, "Creating a proxy client");

client = await new ProxyClientFactory(streamFactory)
.CreateProxyClient(log, endPoint.Proxy)
.WithTcpClientFactory(() => CreateTcpClientAsync(halibutTimeoutsAndLimits))
.CreateConnectionAsync(endPoint.BaseUri.Host, endPoint.BaseUri.Port, endPoint.TcpClientConnectTimeout, cancellationToken);
.CreateConnectionAsync(connectHost, connectPort, endPoint.TcpClientConnectTimeout, cancellationToken);
}
return client;
}
Expand Down