Method UseSshTunnel
- Namespace
- Microsoft.Extensions.DependencyInjection
- Assembly
- SshSharp.Extensions.DependencyInjection.dll
UseSshTunnel(IHttpClientBuilder, string, Action<SocketsHttpHandler>?)
Makes the named or typed HttpClient connect through the shared connection of the SSH endpoint
endpointName (ISshConnectionProvider): each of its TCP connections is a direct-tcpip channel
from the server, as ssh -L opens, so it reaches services only the server reaches, such as an internal API behind a bastion.
Host names in request URIs are resolved by the server. TLS still runs end to end, from here to the service.
public static IHttpClientBuilder UseSshTunnel(this IHttpClientBuilder builder, string endpointName, Action<SocketsHttpHandler>? configureHandler = null)
Parameters
builderIHttpClientBuilderThe HttpClient's builder, from
AddHttpClient.endpointNamestringThe SSH endpoint, as registered with
AddSshClient.configureHandlerAction<SocketsHttpHandler>Adjusts the handler, or null.
Returns
- IHttpClientBuilder
The builder.
Remarks
It sets the client's primary handler to a SocketsHttpHandler whose
ConnectCallback opens the channel, with UseProxy false (a system
proxy would otherwise be connected to through the server instead of the service). configureHandler can adjust
that handler (TLS options, connection pool settings), but must leave those two as they are.
The shared connection is opened on the first request, and again after it drops, as GetClientAsync(string, CancellationToken) opens it. A channel that fails because the connection had just dropped is opened once more on a new connection; nothing had been sent through it. Requests already running on the dropped connection fail, and are not retried.
Exceptions
- InvalidOperationException
(When the handler is built.) No SSH endpoint is registered as
endpointName.