0

I have currently setup yarp to proxy request going into to host:444 to host:443 - only port has changed. But doing this i seemed to run into some cors issues, which I tried to resolve by setting the correct location after the redirect was created as such:

builder.Services.AddReverseProxy()
    .LoadFromConfig(builder.Configuration.GetSection("ReverseProxy"))
    .AddTransforms(builderContext =>
    {
        builderContext.AddResponseTransform(async context => {
        if (context.HttpContext.Response.StatusCode == 302 || context.HttpContext.Response.StatusCode == 301)
        {
            if (context.ProxyResponse == null)
            {
                return;
            }

            var proxyResponse = context.ProxyResponse.Headers;
            var stronglyTypedoldLocation = context.HttpContext.Response.GetTypedHeaders().Location;
            var oldLocation  = context.HttpContext.Response.Headers.Location;
            var oldLocationScheme = stronglyTypedoldLocation.IsAbsoluteUri ? stronglyTypedoldLocation.Scheme : context.HttpContext.Request.Scheme;
            var oldLocationHost = stronglyTypedoldLocation.IsAbsoluteUri ? stronglyTypedoldLocation.Host : context.HttpContext.Request.Host.ToString();
            var oldLocationsPath = stronglyTypedoldLocation.IsAbsoluteUri ? stronglyTypedoldLocation.PathAndQuery : oldLocation.ToString();
            var newLocation = new UriBuilder()
            {
                Scheme = oldLocationScheme,
                Host = oldLocationHost,
                Path = oldLocationsPath
            }.Uri;

            context.HttpContext.Response.GetTypedHeaders().Location = proxyResponse.Location = newLocation;
            context.SuppressResponseBody = true;
        }
    });
});

This in turn has caused a different problem, namely now the location path is case insensitive, which is a big issue with all the request where *.axd are requested.

How do i handle that - I seem to be unable to get an case sensesitive path and query out?

I am not Fat
  • 283
  • 11
  • 36

0 Answers0