question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GZipMiddleware (unzipping encoded requests)

See original GitHub issue

Dear maintainers,

I am looking for the appropriate way to unzip clients requests which are gzip encoded. Looking at the GZipMiddleware it seems that it only zip responses but do not care about requests.

Thus I tried to do it at the dispatch level without success. I did something like:

@app.middleware("http")
async def dispatch(request, call_next):
    plain_body = gzip.decompress(request.body())
    request._body = plain_body  # I don't think it is the appropriate way
    response = await call_next(request)  # hangs here
    return response

I am not extremely familiar with the inner-working of starlette so I don’t know how to “push back in the queue” the decoded the request with the decoded body. If found no middlewares doing similar things.

Anyone can pinpoint me the appropriate way to do it ?

Thank you in advance for your help 😉

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:14 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
tomchristiecommented, Oct 20, 2021

We’re not preventing anyone from developing a GZipMiddleware that handles unzipping requests. You’re welcome to do so as a third party package, and we’d happily link to it from the docs.

1reaction
romanmarcommented, Nov 8, 2019
Read more comments on GitHub >

github_iconTop Results From Across the Web

Re: Proposal: add request decompression to gzip middleware
The idea behind this is simply to decompress the body of requests containing Content-Encoding: gzip header. I provided a working example on this...
Read more >
Accept gzipped body in FastAPI / Uvicorn - Stack Overflow
So far the following: added the GZipMiddleware, but it encodes responses, rather that decoding requests; added a 'Content-Encoding: gzip' to my ...
Read more >
Request decompression in ASP.NET Core - Microsoft Learn
Uses the Content-Encoding HTTP header to automatically identify and decompress requests which contain compressed content.
Read more >
Gzip Middleware recipe for FastAPI - DEV Community 👩‍💻👨‍💻
_receive() if "gzip" in request.headers.getlist("Content-Encoding"): print(receive_) data = gzip.decompress(receive_.get('body')) ...
Read more >
Python django.middleware.gzip.GZipMiddleware() Examples
assertEqual( self.decompress(b''.join(r)), b''.join(x.encode() for x in ... request = self.rf.get('/', HTTP_ACCEPT_ENCODING='gzip, deflate') response ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found