Can't implement proxy headers handling with a middleware #1835
Unanswered
wrzasa
asked this question in
Potential Issue
Replies: 1 comment
-
There seem to be more issues coming from the same piece of code: #1855 Is there a chance for an answer here? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey! I run into this issue when trying to implement handling standard proxy headers into my application and make starlette generate HTTP 307 to the correct URL in case of trailing slashes on the URL. I have a case with a stripped-path proxy that also changes HTTP host (communication with workers via network sockets) and protocol (proxy is a TLS terminator).
Some of the proxy-related headers seem to be handled correctly (e.g.
scheme
is changed toX-Forwarded-Proto
) but some are not.I tried to implement a middleware to handle the missing pieces. I was able to set
X-Forwarded-Prefix
to setroot_path
on the fly and this works. But I failed to handleX-Forwarded-Host
. That's because updatingserver
in the Starlette scope to does not change the host in the URL it redirects to. It seems to be caused by this line of code of the URL class:starlette/starlette/datastructures.py
Line 44 in b588ebe
server
attribute, goes directly to raw request headers to get it.I don't understand how this is an expected behavior, I'd expect
server
attribute to be used here. But before I provide a PR I prefer to ask if usingserver
is an expected fix here. If not, how can I implement handling theX-Forwarded-Host
correctly n my app?Beta Was this translation helpful? Give feedback.
All reactions