Skip to content

Report the responding server in a custom header #1203

Answered by MihaZupan
rootix asked this question in Q&A
Discussion options

You must be logged in to vote

The YARP pipeline will add an IReverseProxyFeature to the HttpContext. The feature also stores the destination that was chosen for proxying by health checks and load balancing.

var responseServer = ctx.HttpContext.Features.Get<IReverseProxyFeature>()?.ProxiedDestination;
if (responseServer is not null)
{
    ctx.HttpContext.Response.Headers.Add("yarp-response-server", responseServer.DestinationId);
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@rootix
Comment options

Answer selected by MihaZupan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants