microsoft / reverse-proxy

A toolkit for developing high-performance HTTP reverse proxy applications.
https://microsoft.github.io/reverse-proxy
MIT License
8.44k stars 829 forks source link

YARP and NotFoundHandler pipeline processing order #2101

Closed AgentLintZeal closed 1 year ago

AgentLintZeal commented 1 year ago

I have an installation using both the NotFoundHandler and Yarp reverse proxy. The NotFoundHandler is being loaded in the ConfigureServices method and Yarp is loaded after in the Application builder Configure method.

Everything works as expected until you try to redirect a URL that also needs to be reverse proxied. In this instance, the reverse proxy gets the URL before the NotFoundHandler and this results in a 404. The redirector should change the path and then let the reverse proxy alter the URL, but the NotFoundHandler never gets called.

For example:

This is the NotFoundHandler URL that is mapped

Then the reverse proxy needs to adjust the browser URL to look like this:

The reverse proxy sees:

before the redirector can change the URL - even though it should be coming first in the pipeline.

Yarp.ReverseProxy version 2.0.0 Geta.NotFoundHandler.Optimiziely version 5.0.4 EPiServer.CMS version 12.13.2 Windows

karelz commented 1 year ago

Triage: Looks like IIS routing problem to us, involving 3rd party (Geta) Nuget package. We do not have expertise in IIS routing. Can you either debug it, or ask on IIS forums?

karelz commented 1 year ago

Triage: No response for 1 week, we assume the above was sufficient, closing. Let us know if that is not the case and there is indeed a problem with YARP itself. Thanks!

AgentLintZeal commented 1 year ago

I took a while to respond as I have been working the issue. It seems that Yarp an the Geta redirector function at very different levels so I ended up adding a piece of code to read the Geta DB table and perform the redirect as part of a custom proxy transformer. This works for 90% of the situations however I was not able to find a way to cancel or abort a proxy that has already begun. This is needed due to CloudFlare complaining if the redirection ends up not being needed. It is hard to explain without a lot of supporting documentation to recreate.

The short version is: How can I cancel a proxy transformation that is in progress and have the normal routing continue. It seems that once a proxy request has started, it has to complete. Attempts to cancel it just result in http errors or a blank page being rendered.