Add support for streaming bodies.#2740
Conversation
|
@nateberkopec if you have some time, do you think you can give me your feedback on making bi-directional streaming a non-optional feature of Rack? It's semantically identical to |
|
Looks like there's been some movement on the proposal so we'll need to rebase/update. |
|
Yes sure I will update. |
6b2bba4 to
eeba3c3
Compare
|
I think the conditional EDIT: maybe something like: if !res_info[:response_hijack] && res_body.respond_to?(:call)
response_hijack = res_body
else
response_hijack = res_info[:response_hijack]
endNot sure what I think of additions that make it easy for Puma to have all its threads kept busy? |
eeba3c3 to
e876244
Compare
23146a4 to
4942b32
Compare
@MSP-Greg check the spec, you can't do that. If body responds to |
|
@nateberkopec Good morning. Sorry, I posted the message and later came to the realization that it was totally wrong. Meant to edit/update but having fun with Actions code... |
|
Awesome, thanks for merging this! |
* Add support for streaming bodies. * Added a test Co-authored-by: Nate Berkopec <nate.berkopec@gmail.com>
Uses "callable body" - rack/rack#1745 - puma/puma#2740 This doesn't work in Puma 5, it will error like this 2022-10-28 08:35:53 +0200 Read: #<NoMethodError: undefined method `each' for #<Proc:0x00000001050b2fd8 /Users/dentarg/local_code/testssl.web/app.rb:44 (lambda)> res_body.each do |part| ^^^^^>
Uses "callable body" - rack/rack#1745 - puma/puma#2740 This doesn't work in Puma 5, it will error like this 2022-10-28 08:35:53 +0200 Read: #<NoMethodError: undefined method `each' for #<Proc:0x00000001050b2fd8 /Users/dentarg/local_code/testssl.web/app.rb:44 (lambda)> res_body.each do |part| ^^^^^>
|
Good day. This PR's test used HTTP/1.0. But, when most people here the term 'streaming', it implies more than one body segment. The old HTTP/1.0 spec seems to state that 'content-length' must always be specified. Kind of a conflict here. Was there a reason you used HTTTP/1.0 instead of HTTTP/1.1? |
|
Sorry for the Sinatra question. IIRC, there were some changes to Puma related to Sinatra and 'streaming'. Can't recall. WIll Sinatra send a 'streaming' response (or an Enum body) to an HTTP/1.0 client? If so, that kind of conflicts with the HTTP/1.0 spec, which states that the content length must always be specified, since HTTP/1.0 doesn't support chunked. And, yes, this is a pita, since I doubt there's much HTTP/1.0 use anymore... |
You can use |
|
Thanks for the response. I'll see what curl does tomorrow... |
|
@MSP-Greg let me know how it goes. Don't forget to use |
|
@MSP-Greg to my knowledge Sinatra does not take the HTTP version into account for anything (but feel free to double check me) also: sinatra/sinatra#1892 |
|
This recent problem came about when revising the Puma test suite. I don't recall the last time I looked at HTTP/1.0, and I was busy with some other family things. I believe you're correct. I incorrectly read the 'spec' (https://www.w3.org/Protocols/HTTP/1.0/spec.html). Sorry. I found the following in section 7.2.2:
The next paragraph essentially explains why that won't work for a request, so 'content-length' must be specified for request bodies, which is also mentioned here, with the phrase:
|
|
In theory, it's possible to |
Proof of concept streaming bodies without using
rack.hijack.