-
-
Notifications
You must be signed in to change notification settings - Fork 933
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
GZIP content length mismatch fix #1579
Conversation
Is this still an issue on fastapi/fastapi#4488 ? |
This comment was marked as spam.
This comment was marked as spam.
Also, I going to update my pull request, found another corner case. I am not handling. |
How can I reproduce the issue here? |
This issues seems to occur on a serving static files and this case from the linked issues from FastApi [4050]. However, I need to find time to translate my specific case into a smaller test case.
|
I'm able to reproduce this with: from typing import Awaitable, Callable
from starlette.middleware.base import BaseHTTPMiddleware
from starlette.middleware.gzip import GZipMiddleware
from starlette.routing import Route
from starlette.middleware import Middleware
from starlette.applications import Starlette
from starlette.responses import Response
from starlette.requests import Request
class NoopMiddleware(BaseHTTPMiddleware):
async def dispatch(self, request: Request, call_next: Callable[[Request], Awaitable]):
return await call_next(request)
def endpoint(request: Request):
return Response(status_code=304)
app2 = Starlette(
routes=[Route("/", endpoint=endpoint)],
middleware=[Middleware(GZipMiddleware), Middleware(NoopMiddleware)]
) This is more as a self note. I'll continue to check this later on. |
This PR did solve the problem, but that |
These seem to be linting rules coming from https://wemake-python-stylegui.de/en/latest/ |
This PR doesn't solve the issue for me... I've tried with both examples above, and I still have the same issues. |
This addresses concerns raised by the following discussions:
We encountered this problem when developing our internal application, when we implemented both Brotli and GZIP compression. We tested the following fix using several use cases.
The solution tries to address the problem using two(2) approaches:
Setting the respond body if NULL bytes are detected
Not writing the message body when its empty or contains NULL byte char
Initially raised as discussion Gzip Middleware content-length is incorrect #803