Skip to content

Does yarp use the incoming port on destinations? #2388

Answered by MihaZupan
Marbry asked this question in General
Discussion options

You must be logged in to vote

No, YARP will use the address prefix as-is, the port is not copied over.

You can either specify the exact ports you want to use on the backend, or you can use a transform to modify requests, e.g.

builder.Services.AddReverseProxy()
    .LoadFromMemory(GetRoutes(), GetClusters())
    .AddTransforms(transforms =>
    {
        transforms.AddRequestTransform(context =>
        {
            var uri = RequestUtilities.MakeDestinationAddress(context.DestinationPrefix, context.Path, context.Query.QueryString);
            uri = new UriBuilder(uri) { Port = context.HttpContext.Connection.LocalPort }.Uri;
            context.ProxyRequest.RequestUri = uri;
            return default;
        });
    }

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by Marbry
Comment options

You must be logged in to vote
2 replies
@Tratcher
Comment options

@Marbry
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants