-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing proxy-headers option like one in gunicorn #105
Comments
@pgjones Would you like me to work on this? I'm actually improving the I guess the idea here would be to populate the |
@dragoangel Is your problem happening when you implement a server with hypercorn only? Otherwise, is it still same though you use other frameworks such as Django or Flask? |
I don't use Flask or Django, so can't say. I used uvicorn (and gunicorn) with Starlette and now switched to hypercorn with Starlette. |
@dragoangel Does it mean that you cannot access the raw Proxy headers on your Starlette application? |
It's mean I not have options to get proper client ip, scheme, host on default variables while behind proxy and I don't have a way to set trusted proxy. Using proxy should be transparent for code when used with proxy milter, e.g.:
|
Is this something in the plans to get added? I am running behind a proxy with FastAPI and having issues with redirect URLs not using the x-forwarded-proto. |
I switched back to uvicorn because of the --proxy-headers being missing in hypercorn. I need to be able to get the request.client IP behind a proxy. |
You don't need to switch back. You can use the ProxyHeadersMiddleware from uvicorn, and continue to use use hypercorn. |
How can it be achieved when used as It truly works as: ...
from uvicorn.middleware.proxy_headers import ProxyHeadersMiddleware
...
proxy_hosts = os.getenv('PROXY_HOSTS', '127.0.0.1').split(",")
app = Starlette()
app.add_middleware(ProxyHeadersMiddleware, trusted_hosts=proxy_hosts)
... But I think importing another package is really bad just to get one basic middleware from it, right? |
Can we have documentation for that? |
I don't think this is an acceptable solution in the long term, it looks more like |
See the ProxyFixMiddleware added in 4fc0372 |
Hi @pgjones , thank you :) |
@pgjones in my setup it results in 500 and throws error in logs like:
I added it as: from hypercorn.middleware import ProxyFixMiddleware
from asgi_correlation_id import CorrelationIdMiddleware, correlation_id
from starlette.applications import Starlette
from starlette.middleware.gzip import GZipMiddleware
proxy_hops = int(os.getenv('PROXY_HOPS', '0'))
proxy_mode = os.getenv('PROXY_MODE', 'legacy')
app = Starlette()
app.add_middleware(ProxyFixMiddleware, mode=proxy_mode, trusted_hops=proxy_hops)
app.add_middleware(CorrelationIdMiddleware, header_name='X-Request-ID')
app.add_middleware(GZipMiddleware, minimum_size=1000) |
Currently, it's impossible to get a properly working service behind a proxy as headers like
x-forwarded-for
,x-forwarded-proto
,x-forwarded-host
,x-forwarded-port
andx-forwarded-prefix
isn't checked.for
andproto
most critically needed, as they used inlogging
, application behaviors (including critical one, f.e.:return metrics if trusted_ips(client)
) and URL generation (f.e.:url_for
).Can this be checked, please?
The text was updated successfully, but these errors were encountered: