Well, this is the implementation for the link you provided:

@chunked = "chunked" == @header['Transfer-Encoding']

This would be equivalent for the Rack middleware to check for this particular header. But this is highly dependent on whether the Rails action will set this header or some other middleware present in the application's stack. For my particular action this header is not present for instance. If all streamed responses are supposed to set this header, than Rails should include it for all controller's actions where ActionController::Live is included.


On 16-07-2014 09:07, ismaSan wrote:
Oh I totally agree that a proper API in Rack would be better for this. But I thought the problem is precisely that there isn't one?

I can see that Rack already knows whether the response is "chunked" or not (which I think is what "streaming" means in Rails, as opposed to Server Sent Events, Websockets and other ways of streaming data over HTTP).

https://github.com/rack/rack/blob/master/lib/rack/response.rb#L27

So maybe the only thing that needs to be added is:

    def streaming?
      @chunked
    end

On Tuesday, 15 July 2014 13:38:21 UTC+1, Rodrigo Rosenfeld Rosas wrote:

    This would depend if Content-Length would be set by another
    middleware, so depending on the order of the middlewares it might
    work or not.

    This is just as brittle in my opinion. The proper way of handling
    this is through some new API in the Rack library itself to let the
    middlewares know whether it's a streamed response or not.

    Such API would also be useful in this issue:

    https://github.com/rails/rails/issues/14358
    <https://github.com/rails/rails/issues/14358>

    By the way, I can't find it by searching on GitHub. Any ideas why?
    I can only access it because I had the link stored in some e-mail
    of my inbox...

    On 15-07-2014 08:58, ismaSan wrote:
    I haven't tested this but an HTTP streaming response should *not*
    have a Content-Length header. Maybe that's enough to detect
    whether it's streaming or not? So you look at the properties of
    the HTTP response itself instead of the Ruby wrapper, which as
    you say might change in the future.


    On Monday, 14 July 2014 22:14:31 UTC+1, Jason Clark wrote:

        I'm curious if there's a good way to detect from a Rack
        middleware whether a response is streaming or not.

        From what I can see, my options are:

        * In the Controller note we've included
        `ActionController::Live` somewhere the middleware can access it
        * Look at the response object coming back to Rack to see if
        its class is `ActionController::Live::Response`
        * Look at the `stream` (if available) on the response object
        returned to Rack to check if it's a
        `ActionController::Live::Buffer`

        All of these ideas seem pretty brittle and liable to break
        across new versions of Rails and/or new streaming mechanisms
        that might come along. Is there something I'm missing?

        Thanks!

        Jason Clark
        @jasonrclark
        New Relic, Ruby Agent engineer

-- You received this message because you are subscribed to the
    Google Groups "Ruby on Rails: Core" group.
    To unsubscribe from this group and stop receiving emails from it,
    send an email to [email protected] <javascript:>.
    To post to this group, send email to [email protected]
    <javascript:>.
    Visit this group at
    http://groups.google.com/group/rubyonrails-core
    <http://groups.google.com/group/rubyonrails-core>.
    For more options, visit https://groups.google.com/d/optout
    <https://groups.google.com/d/optout>.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected] <mailto:[email protected]>. To post to this group, send email to [email protected] <mailto:[email protected]>.
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on 
Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Reply via email to