-
Hi, So the question is if it is possible to disable query string encoding on Yarp side? I would like to make it behave just like Kong in order to avoid changing legacy part of my application. I have tried to search for such option in Yarp documentation and source code but without success. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
If in this case you know that this specific character is something you would want to let through, you can manually create the Uri and tell it not to make any more changes. Something along the lines of services.AddReverseProxy()
.AddTransforms(transforms =>
{
if (transforms.Route.RouteId == "myLegacyAppRoute")
{
transforms.AddRequestTransform(context =>
{
var query = context.Query.QueryString;
if (query.HasValue && query.Value.Contains('\\'))
{
var uri = RequestUtilities.MakeDestinationAddress(context.DestinationPrefix, context.Path, query);
// Uri will escape '\' characters in the query string. Revert that transformation here.
var newUri = uri.AbsoluteUri.Replace("%5C", @"\", StringComparison.OrdinalIgnoreCase);
context.ProxyRequest.RequestUri = new Uri(newUri, new UriCreationOptions
{
DangerousDisablePathAndQueryCanonicalization = true
});
}
return default;
});
}
}) |
Beta Was this translation helpful? Give feedback.
Uri
will escape such characters that it deems not safe to use in requests.If in this case you know that this specific character is something you would want to let through, you can manually create the Uri and tell it not to make any more changes. Something along the lines of