-
Hi, is it possible to have something similar to functionality called "DownstreamHeaderTransform" in Ocelot. In Ocelot you can define below sample rule:
so all incoming request using url: "http://www.bbc.co.uk" will be replaced with "http://ocelot.com/". What is the best way to achieve similar functionality in YARP? Best regards |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
There's no built-in configuration to replace request headers value but you can add your own transform. Something like this : builder.Services
.AddReverseProxy()
.AddTransforms(transforms =>
{
// transforms.Cluster.Metadata
// get values from cluster metadata
transforms.AddRequestTransform(context =>
{
if (context.ProxyRequest.Headers.TryGetValues("Test", out var value) && value.FirstOrDefault() == "http://www.bbc.co.uk/")
{
context.ProxyRequest.Headers.Remove("Test");
context.ProxyRequest.Headers.Add("Test", "http://ocelot.com/");
}
return default;
});
}); |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot for quick answear. Indeed, the provided sample give me a hint how to implement it :) |
Beta Was this translation helpful? Give feedback.
There's no built-in configuration to replace request headers value but you can add your own transform. Something like this :