aio-libs / aiohttp

Asynchronous HTTP client/server framework for asyncio and Python
https://docs.aiohttp.org
Other
15.03k stars 2k forks source link

router.add_static() support customize gzip file #4546

Closed cole-dda closed 1 month ago

cole-dda commented 4 years ago

🐣 Is your feature request related to a problem? Please describe.

for static files, maybe store gz file on other location or dynamic generate

💡 Describe the solution you'd like

web_fileresponse.py

def my_gz_handler(request):
    filename = request.match_info['filename']
    return '/mygz/a.txt.gz'

app.router.add_static(prefix,path,gz_handler=my_gz_handler)

class FileResponse:
       def __init__(filepath,chunk_size,gz_handler=None):
               pass
       async def prepare(self,request):
                 ...
                if self.gz_handler:
                     gz_filename = self.gz_handler(request)

Describe alternatives you've considered

Now,I must copy web_fileresponse.py,and rewrite gzip part code

socketpair commented 4 years ago

I vote against. Serving static files is a nginx task.

Dreamsorcerer commented 1 month ago

It's not clear precisely what you're asking for, but maybe the changes in #8063 or similar do what you're looking for.