-
Notifications
You must be signed in to change notification settings - Fork 106
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
Support for add_middleware() #179
Comments
@Kludex I think Starlette is doing the wrong thing here as per django/asgiref#343, what do you think? |
I did fix that on the last release: encode/starlette#2352. What Starlette version is being used here? Also, kind a related, it would be cool if you can check django/asgiref#424. 🙏 EDIT: I just saw there's FastAPI on the traceback - FastAPI still doesn't support the last Starlette version. |
0.27.0 |
Should be fixed now given enough time has passed for release updates. |
@pgjones well for me this still the case with hypercorn~=0.16
asgi-correlation-id~=4.3
starlette~=0.37.0
jinja2~=3.1 like: from asgi_correlation_id import CorrelationIdMiddleware, correlation_id
from hypercorn.middleware import ProxyFixMiddleware
from starlette.applications import Starlette
from starlette.middleware import Middleware
from starlette.middleware.gzip import GZipMiddleware
proxy_hops = int(os.getenv('PROXY_HOPS', '0'))
proxy_mode = os.getenv('PROXY_MODE', 'legacy')
middleware = [
Middleware(CorrelationIdMiddleware, header_name='X-Request-ID'),
Middleware(GZipMiddleware, minimum_size=1000)
]
if proxy_hops > 0:
middleware.append(Middleware(ProxyFixMiddleware, mode=proxy_mode, trusted_hops=proxy_hops))
app = Starlette(middleware=middleware)
app.mount('/static', StaticFiles(directory = 'statics'), name = 'static')
templates = Jinja2Templates(directory = 'templates')
...
@app.exception_handler(500)
async def server_error(request, exc):
"""
Return an HTTP 500 page.
"""
template = "500.html"
context = {
'request': request,
'title': 'Server Error',
'company': company
}
headers = {
'X-Request-ID': str(correlation_id.get() or '')
}
return templates.TemplateResponse(template, context, status_code = 500, headers=headers) Other middleware's works just fine, and if I would set
|
This is likely a bug with the |
Just rebuild with
|
Can you please re-open issue as it not yet solved? |
Thank you for making hypercorn.
As per the fastapi documentation the recommended way to add a middleware is to use
app.add_middleware(Middleware)
However, this does not work, at least for the ProxyFixMiddleware. When used this way, this is the exception stack when making a request:
Minimal example:
The text was updated successfully, but these errors were encountered: