reverse-proxy icon indicating copy to clipboard operation
reverse-proxy copied to clipboard

Header transform https -> http working.

Open snorrid opened this issue 4 years ago • 3 comments

Describe the bug

I have a YARP proxy https://example.com that is trying to proxy to a http backend service http://backend-service. When trying to add a header or remove a header with a transform it never applies the header transforms. This works fine for pathprefix transforms etc. When changing to a https backend service the transforms work fine. Is this a known limitation or a bug?

To Reproduce

builder.Services.AddReverseProxy()
    .LoadFromConfig(builder.Configuration.GetSection("ReverseProxy"))
    .AddTransforms(builderContext =>
    
    {
        // Works fine
        builderContext.AddPathPrefix("/testing");
        // Does nothing
        builderContext.AddRequestHeaderRemove("X-Vendor-Id");
        builderContext.AddRequestHeader("X-Vendor-Id", "example");
        // Does nothing
        builderContext.RequestTransforms.Add(new RequestHeaderRemoveTransform("X-Vendor-Id"));
        builderContext.AddRequestTransform(async context =>
        {
            // Does nothing
            context.ProxyRequest.Headers.Remove("X-Vendor-Id");
            // Does nothing
            context.HttpContext.Request.Headers.Remove("X-Vendor-Id");
        });
    });

Further technical details

Version 1.1.1

snorrid avatar Oct 06 '22 14:10 snorrid

The issue is that the backend service was responding with a https redirect and yarp doesn't run the transform on subsequent requests.

snorrid avatar Oct 06 '22 15:10 snorrid

YARP doesn't even follow redirects by default, did you enable that? Most redirects should be forwarded back to the client. In this case since the destination requires https you should start with that to avoid the redirect.

Tratcher avatar Oct 06 '22 15:10 Tratcher

@Tratcher You are correct. It's my mistake the client is getting the raw redirect and following that and sending the unwanted header to the server. Thanks for the reply.

snorrid avatar Oct 07 '22 12:10 snorrid