lib/http/2/stream.rb in http-2-0.8.1 vs lib/http/2/stream.rb in http-2-0.8.2

- old
+ new

@@ -95,12 +95,18 @@ def receive(frame) transition(frame, false) case frame[:type] when :data - @local_window -= frame[:payload].size + window_size = frame[:payload].bytesize + window_size += frame[:padding] || 0 + @local_window -= window_size emit(:data, frame[:payload]) unless frame[:ignore] + + # Automatically send WINDOW_UPDATE, + # assuming that emit(:data) can now receive next data + window_update(window_size) if window_size > 0 when :headers, :push_promise emit(:headers, frame[:payload]) unless frame[:ignore] when :priority process_priority(frame) when :window_update @@ -201,9 +207,20 @@ # Sends a RST_STREAM indicating that the stream has been refused prior # to performing any application processing. def refuse send(type: :rst_stream, error: :refused_stream) + end + + # Sends a WINDOW_UPDATE frame to the peer. + # + # @param increment [Integer] + def window_update(increment) + # always emit connection-level WINDOW_UPDATE + emit(:window_update, increment) + # emit stream-level WINDOW_UPDATE unless stream is closed + return if @state == :closed || @state == :remote_closed + send(type: :window_update, increment: increment) end private # HTTP 2.0 Stream States