diff --git a/lib/protocol/http2/stream.rb b/lib/protocol/http2/stream.rb index 785e36f..d0f1718 100644 --- a/lib/protocol/http2/stream.rb +++ b/lib/protocol/http2/stream.rb @@ -124,10 +124,6 @@ def parent=(stream) @dependency.parent = stream.dependency end - # The stream is being closed because the connection is being closed. - def close(error = nil) - end - def maximum_frame_size @connection.available_frame_size end @@ -144,6 +140,15 @@ def closed? @state == :closed end + # Transition directly to closed state. Do not pass go, do not collect $200. + # This method should only be used by `Connection#close`. + def close(error = nil) + unless closed? + @state = :closed + self.closed(error) + end + end + def send_headers? @state == :idle or @state == :reserved_local or @state == :open or @state == :half_closed_remote end @@ -228,6 +233,10 @@ def send_data(*arguments, **options) end end + # The stream has been opened. + def opened(error = nil) + end + def open! if @state == :idle @state = :open @@ -235,9 +244,15 @@ def open! raise ProtocolError, "Cannot open stream in state: #{@state}" end + self.opened + return self end + # The stream has been closed. If closed due to a stream reset, the error will be set. + def closed(error = nil) + end + # Transition the stream into the closed state. # @param error_code [Integer] the error code if the stream was closed due to a stream reset. def close!(error_code = nil) @@ -248,7 +263,7 @@ def close!(error_code = nil) error = StreamError.new("Stream closed!", error_code) end - self.close(error) + self.closed(error) return self end