-
Is it possible to obtain (from code) an httpclient for the proxied connection, so I can send requests outside of the proxy to the destination. var clusterConfig = _ProxyConfigProvider.GetConfig().Clusters.FirstOrDefault(a => a.ClusterId == ProxyConstants.RouteId);
if (clusterConfig is not null && clusterConfig.Destinations is not null)
{
var context = new ForwarderHttpClientContext
{
ClusterId = clusterConfig.ClusterId,
NewMetadata = clusterConfig.Metadata,
OldMetadata = clusterConfig.Metadata,
OldConfig = clusterConfig.HttpClient ?? HttpClientConfig.Empty,
NewConfig = clusterConfig.HttpClient ?? HttpClientConfig.Empty
};
var destination = clusterConfig.Destinations.FirstOrDefault().Value.Address;
if (string.IsNullOrEmpty(destination))
{
return;
}
var forwarderClient = _ForwarderHttpClientFactory.CreateClient(context);
var info = new Payload();
var body = JsonSerializer.SerializeToUtf8Bytes(info, s_JsonSerializerOptions);
var uri = new UriBuilder(destination) { Path = ProxyConstants.Endpoint };
using var message = new HttpRequestMessage(HttpMethod.Post, uri.Uri);
message.Content = new ByteArrayContent(body);
message.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
using var response = await forwarderClient.SendAsync(message, cancellationToken).ConfigureAwait(false);
} Is there an easier approach than building my own context and getting it via the factory? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Similar to #1165 |
Beta Was this translation helpful? Give feedback.
-
Getting it from the IClusterChangeListener is the easiest option right now. |
Beta Was this translation helpful? Give feedback.
Getting it from the IClusterChangeListener is the easiest option right now.