pytest-httpserver icon indicating copy to clipboard operation
pytest-httpserver copied to clipboard

Support streaming API

Open hemandev opened this issue 1 year ago • 1 comments

Hi, first of all, let me say this is a great library, and I've loved using it so far.

I have a use-case where I need to test a streaming API from ChatGPT. Does this library support streaming responses?

I couldn't find anything in the docs, so just checking here. Thanks!

hemandev avatar Sep 29 '24 18:09 hemandev

hi @hemandev ,

Thanks! 🙏

For the first sight, you could try using implementing your own response handler, which is a function accepting a request object and returning a response object.

https://pytest-httpserver.readthedocs.io/en/latest/howto.html#using-custom-request-handler

Here, the Response object is provided by werkzeug: https://werkzeug.palletsprojects.com/en/3.0.x/wrappers/#werkzeug.wrappers.Response

...which allows you to specify an iterable object as response body.

I haven't made a PoC for this for this yet, but I'd suggest trying this.

Hope it helps,

Zsolt

csernazs avatar Sep 29 '24 19:09 csernazs