New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When should a server add chunked encoding? #2032
Comments
A server has two options when
The advantage of 2 is that the connection is not closed afterwards, and the connection has more integrity as the final zero length chunk communicates the end of the stream, vs closing the connection which could happen if the stream drops out, in other words you don't know if the data has completed successfully or the connection just dropped out. With respect to streaming, there is no other advantage or disadvantage. Rack applications should never generate a
A server should always prefer chunked encoding because (1) it is more robust and (2) it allows connection reuse. Even when using This is different from def call(env)
[200, {}, {|stream| ...}]
end Depending on the situation, Coming back to your original question - it would be entirely plausible for most servers to end up double encoding the chunked response if there is application-side chunked encoding. Chunked encoding has nothing to do with streaming, streaming and chunked encoding are entirely orthogonal. The correct way to achieve this is to use Rack 3 streaming bodies or in Rack 2, partial hijack has very similar semantics, while full hijack is completely broken w.r.t. HTTP compatibility - how would it work with HTTP/2+? You'd have to implement a full HTTP/1 <-> HTTP/2 proxy. Hope that helps. |
Yes, but from a practical standpoint, Rails, with at least versions 4 thru current 7, is doing so in I guess things are somewhat dependent on what Rails does with If it removes both 'Transfer-Encoding' and 'Content-Length' and the body responds to You've mentioned hijacking (callable and I have seen code that seems to use a partial hijack for writing an http compliant body. If the app is closing the stream (which would often be the actual socket), doesn't this force an HTTP/1.1 connection to close when it could remain open? |
Practically speaking none of this matters if it's never worked correctly.
Given the assumption that no server ever supported it correctly except perhaps
Sure, but this won't work with
Yes, |
I haven't mentioned streaming, why Rails uses the term, not sure. I would call it chunked, in that (as they describe it) determining 'Content-length' is difficult. So, chunked. When I hear the term 'streaming', I think of a flow of data/content that will take a measurable amount of time, as in seconds...
Maybe I'd say 'interesting to work with'. I assume it's been around a while, and a lot has changed. |
As I said earlier, you can use |
I assume I'm missing something, but...
See https://msp-greg.github.io/rails_master/ActionController/Streaming.html, which currently uses
Rack::Chunked
, and setsTransfer-Encoding: chunked
.When Rails upgrades to Rack 3,
Rack::Chunked
will be removed, and it's unclear what happens then.So, how is a server to decide whether it needs to apply chunked info, or whether the app is doing so? Obviously, by querying the body's properties, one may be able to guess, but that may not be correct...
I couldn't find the terms 'transfer-encoding' or 'chunked' anywhere in the spec.
A lot of things are mentioned in RFC 9112 and RFC 9110 regarding when and if particular headers are either required or not allowed.
Given that the app is passing most important headers to the server, who is responsible for their accuracy? One example from RFC 9112 6.1:
A server MUST NOT send a Transfer-Encoding header field in any response with a status code of 1xx (Informational) or 204 (No Content). A server MUST NOT send a Transfer-Encoding header field in any 2xx (Successful) response to a CONNECT request (Section 9.3.6 of [HTTP]).
The text was updated successfully, but these errors were encountered: