Steeltoe
Steeltoe copied to clipboard
Eureka service registry http header support to pass token
we are not able to submit eureka registry and heath check due to no option to provide customize http header.
We want to send token using http header, but no option is available in eurekaclientconfig.
There are several settings available for using OAuth2 with Eureka, are you looking to also use a custom header name here too?
IHttpClientHandlerProvider is available for customizing HttpClient interactions with Eureka
I need to pass an http header with the name of "xmsh-token" and value is some string. How can i pass extra headers while calling my custom eureka registry api..
After the merge of #1280, this can be accomplished by adding a custom handler (which adds your header) to the Eureka HttpClientFactory pipeline.
For example, to send an extra header to Eureka:
public class ExtraRequestHeaderDelegatingHandler : DelegatingHandler
{
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request,
CancellationToken cancellationToken)
{
request.Headers.Add("X-Special-Feature", "enabled");
return base.SendAsync(request, cancellationToken);
}
}
WebApplicationBuilder builder = WebApplication.CreateBuilder();
builder.Services.AddTransient<ExtraRequestHeaderDelegatingHandler>();
builder.Services.AddEurekaDiscoveryClient();
builder.Services.Configure<HttpClientFactoryOptions>("Eureka",
options => options.HttpMessageHandlerBuilderActions.Add(handlerBuilder =>
handlerBuilder.AdditionalHandlers.Add(
handlerBuilder.Services.GetRequiredService<ExtraRequestHeaderDelegatingHandler>())));
To send an extra header to the OAuth2 endpoint, replace "Eureka" with "AccessTokenForEureka" in the example above.