diff --git a/src/ReverseProxy/Transforms/RequestTransformContext.cs b/src/ReverseProxy/Transforms/RequestTransformContext.cs index 74d87f21e..52255e428 100644 --- a/src/ReverseProxy/Transforms/RequestTransformContext.cs +++ b/src/ReverseProxy/Transforms/RequestTransformContext.cs @@ -53,8 +53,9 @@ public QueryTransformContext Query /// /// The URI prefix for the proxy request. This includes the scheme and host and can optionally include a /// port and path base. The 'Path' and 'Query' properties will be appended to this after the transforms have run. + /// Changing this value can have side effects on load balancing and health checks. /// - public string DestinationPrefix { get; init; } = default!; + public string DestinationPrefix { get; set; } = default!; /// /// A indicating that the request is being aborted. diff --git a/test/ReverseProxy.Tests/Transforms/DestinationPrefixTransformTests.cs b/test/ReverseProxy.Tests/Transforms/DestinationPrefixTransformTests.cs new file mode 100644 index 000000000..c6b6ba8be --- /dev/null +++ b/test/ReverseProxy.Tests/Transforms/DestinationPrefixTransformTests.cs @@ -0,0 +1,31 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System.Threading.Tasks; +using Xunit; + +namespace Yarp.ReverseProxy.Transforms.Tests; + +public class DestinationPrefixTransformTests +{ + [Fact] + public async Task UpdateDestinationPrefix() + { + const string newDestinationPrefix = "http://localhost:8080"; + var context = new RequestTransformContext() + { + DestinationPrefix = "http://contoso.com:5000" + }; + var transform = new DestinationPrefixTransform(newDestinationPrefix); + await transform.ApplyAsync(context); + } + + private class DestinationPrefixTransform(string newDestinationPrefix) : RequestTransform + { + public override ValueTask ApplyAsync(RequestTransformContext context) + { + context.DestinationPrefix = newDestinationPrefix; + return ValueTask.CompletedTask; + } + } +}