postmanlabs / httpbin

HTTP Request & Response Service, written in Python + Flask.
https://httpbin.org
ISC License
12.75k stars 1.81k forks source link

Feature request: "chunked" header in /drip #479

Open Lucretiel opened 6 years ago

Lucretiel commented 6 years ago

It'd be nice if the /drip endpoint accepted an additional header, called chunked, which (if given as true) would make it so that /drip doesn't use a content-length, and instead uses chunked encoding. This would be nice for testing clients that are designed to consume "live" data.

Lucretiel commented 6 years ago

If there's support for this I can put together a pull request

javabrett commented 6 years ago

Just checking that neither /range or /stream-bytes fill that need.

Lucretiel commented 6 years ago

The specific thing I'm trying to test is early termination— that is, cancelling a request that is in the middle of streaming a body. For that reason, it would be very helpful to have a request that streams over a duration, so that I can easily initiate termination halfway through it.

Lucretiel commented 6 years ago

They're both close, but not quite there. /range supports a duration parameter, but doesn't use the chunked transfer encoding. /stream-bytes does do chunked encoding, but doesn't have a tuneable duration.

georgir commented 6 years ago

A note for those still looking for such endpoint - /stream-bytes has an undocumented parameter chunk_size that can be helpful. By default it is 10k, making the endpoint appear non-streaming for smaller responses. The max response length it can return is 100k, making for just 10 chunks with the default chunk_size.

A chunk_size of 1 makes the endpoint considerably slow - around 1k/s, so it seems it could be useful for cases like what Lucretiel needed.

Also, from testing it seems even if you request a chunk_size of 1, you get quite a larger chunk size. I base this conclusion on the "transfer-size" field in browser dev tools - it should be 6 times higher than the content size if each chunk were a single byte, but it's barely higher in practice. My guess is that the reverse proxy ("vegur") in front of httpbin.org re-chunks the response.

dswitzer commented 9 months ago

I was very disappointed to discover that drip doesn't support chunked responses. That endpoint seems like you'd want chunked responses by default. So make me a +1 for wishing it supported chunked responses!

anonghuser commented 4 months ago

@dswitzer and others looking at this in the future i don't remember how things worked back in 2018 anymore, but now httpbin.org's servers use http/2 protocol where there is no such thing as explicit transfer-encoding: chunked header, and instead its functionality is supported by default. /drip endpoint works fine with it when i test. i would say this issue can be closed demo