Redirects through reverse proxy

I’m trying to build out some notifications when certain RStudio events happen using an mitmproxy add-on. RStudio itself only needs regular HTTP, but these directions also include making websockets work, as that is required by Shiny: https://support.rstudio.com/hc/en-us/articles/200552326-Running-RStudio-Server-with-a-Proxy

By default RStudio runs on port 8787, so I’m trying to reverse proxy as follows:

mitmdump -p 8888 --mode reverse:http://localhost:8787/

Right away, there’s a redirect and the port number is lost - so the redirect is to localhost/auth-sign-in (the port number is not properly re-written).

Based on my understanding of mitmproxy and the instructions I linked above, mitmproxy should by default properly rewrite redirect links, or am I missing something?

So, we can get to the point that we re-write ports by adding --setheader :~q:Host:localhost:8080. There is still no way we can find to re-write prefixes on the URL path.