Skip to content

Commit

Permalink
Make RequestTransformContext.DestinationPrefix read-write
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminpetit committed Nov 10, 2023
1 parent 3a5a68f commit d9d6984
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/ReverseProxy/Transforms/RequestTransformContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ public QueryTransformContext Query
/// <summary>
/// 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.
/// </summary>
public string DestinationPrefix { get; init; } = default!;
public string DestinationPrefix { get; set; } = default!;

/// <summary>
/// A <see cref="CancellationToken"/> indicating that the request is being aborted.
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
}

0 comments on commit d9d6984

Please sign in to comment.