class Async::HTTP::Protocol::HTTP2::Input

A writable body which requests window updates when data is read from it.

Public Class Methods

new(stream, length) click to toggle source
Calls superclass method Async::HTTP::Body::Writable::new
# File lib/async/http/protocol/http2/input.rb, line 31
def initialize(stream, length)
        super(length)
        
        @stream = stream
        @remaining = length
end

Public Instance Methods

read() click to toggle source
Calls superclass method Async::HTTP::Body::Writable#read
# File lib/async/http/protocol/http2/input.rb, line 38
def read
        if chunk = super
                # If we read a chunk fron the stream, we want to extend the window if required so more data will be provided.
                @stream.request_window_update
        end
        
        # We track the expected length and check we got what we were expecting.
        if @remaining
                if chunk
                        @remaining -= chunk.bytesize
                elsif @remaining > 0
                        raise EOFError, "Expected #{self.length} bytes, #{@remaining} bytes short!"
                elsif @remaining < 0
                        raise EOFError, "Expected #{self.length} bytes, #{@remaining} bytes over!"
                end
        end
        
        return chunk
end