Skip to content

Solution to set stream response with aiohttp #2012

Answered by vytas7
icebearrrr asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @icebearrrr !
One way is to use an HTTP client library's functionality that is not based on context managers, if the library in question supports such (I'm not sure if this is possible with aiohttp though). The following Gist demonstrates how to manually close a connection using another popular client, httpx: Proxying a website with Falcon ASGI + httpx.

As to your aiohttp snippet, maybe you could simply wrap it in another async generator, and assign that to resp.stream?
Something along the lines of (not tested in depth!)

import aiohttp
import falcon.asgi


class StreamDownload:
    LOGO = 'https://falcon.readthedocs.io/en/stable/_static/img/logo.svg'

    async def aiohttp_stream(self, u…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@icebearrrr
Comment options

Answer selected by icebearrrr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants