Gzip response is not being decompressed automatically
See original GitHub issueFirst Check
- I added a very descriptive title to this issue.
- I used the GitHub search to find a similar issue and didn’t find it.
- I searched the FastAPI documentation, with the integrated search.
- I already searched in Google “How to X in FastAPI” and didn’t find any information.
- I already read and followed all the tutorial in the docs and didn’t find an answer.
- I already checked if it is not related to FastAPI but to Pydantic.
- I already checked if it is not related to FastAPI but to Swagger UI.
- I already checked if it is not related to FastAPI but to ReDoc.
Commit to Help
- I commit to help with one of those options 👆
Example Code
from fastapi.middleware.gzip import GZipMiddleware
from fastapi import FastAPI
app = FastAPI(
title="xyz",
description="",
version="1.0.0",
)
app.add_middleware(GZipMiddleware)
@app.get("/status", status_code=200, tags=["Health Check"])
async def health_check(request: Request):
logger.info(f"health check was requested from {request.client.host}")
return
Description
Hi,
I am trying to compress the data given from our API, as it sometimes include very large JSON data sets. i was looking into the built-in GZIP middleware .
I am not sure if what i encounter is an issue with FastAPI or something that i’m doing wrong, because when using some other endpoints that have GZIP response (like https://postman-echo.com/gzip) the response is being decompressed automatically both from postman and the browser itself.
Also, when trying to look for it online I could not find anything, which makes me believe something i do is wrong.
when trying to access the health check endpoint, i get the following response (should be stringified null):
Same result is being received in the browser itself.
Am i missing something?
Thanks in advance.
Operating System
Linux, macOS
Operating System Details
No response
FastAPI Version
0.63.0
Python Version
3.8.0
Additional Context
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:17
Top GitHub Comments
Ah finally found the issue, I was using app.mount to mount the same app at the ‘/api’ endpoint.
Like this
app.mount('/api', app)
this might have messed up something removing this mount point fixed the issue, thanks!Yup, I see.
@JoshYuJump has fair point that if it doesn’t work and “something is no yes” with bundled Gzip Middleware or compression at all in FastAPI without clear reason (at least for three of us), then using custom based on build-in can be a nice alternative.
But it would be nice if we know that reason and create issue in this project or related one or document it if it is kind of expected and it actually works.
Have a nice day then! 😛