lib/http/protocol/http2/connection.rb in http-protocol-0.3.1 vs lib/http/protocol/http2/connection.rb in http-protocol-0.3.2
- old
+ new
@@ -79,10 +79,16 @@
def closed?
@state == :closed
end
+ def close
+ send_goaway
+
+ @framer.close
+ end
+
def encode_headers(headers, buffer = String.new.b)
HPACK::Compressor.new(buffer, @encoder).encode(headers)
return buffer
end
@@ -101,21 +107,30 @@
end
attr :streams
def read_frame
- frame = @framer.read_frame
- # puts "#{self.class} #{@state} read_frame: #{frame.inspect}"
+ frame = @framer.read_frame(@local_settings.maximum_frame_size)
+ # puts "#{self.class} #{@state} read_frame: class=#{frame.class} flags=#{frame.flags} length=#{frame.length}"
yield frame if block_given?
frame.apply(self)
return frame
rescue ProtocolError => error
send_goaway(error.code || PROTOCOL_ERROR, error.message)
+
raise
+ rescue HTTP::HPACK::CompressionError => error
+ send_goaway(COMPRESSION_ERROR, error.message)
+
+ raise
+ rescue
+ send_goaway(PROTOCOL_ERROR, $!.message)
+
+ raise
end
def send_settings(changes)
@local_settings.append(changes)
@@ -134,15 +149,14 @@
@state = :closed
end
def receive_goaway(frame)
@state = :closed
- @framer.close
end
def write_frame(frame)
- # puts "#{self.class} #{@state} write_frame: #{frame.inspect}"
+ # puts "#{self.class} #{@state} write_frame: class=#{frame.class} flags=#{frame.flags} length=#{frame.length}"
@framer.write_frame(frame)
end
def send_ping(data)
if @state != :closed
@@ -244,9 +258,13 @@
def create_stream(stream_id = next_stream_id)
Stream.new(self, stream_id)
end
def receive_headers(frame)
+ if frame.stream_id == 0
+ raise ProtocolError, "Cannot receive headers for stream 0!"
+ end
+
if stream = @streams[frame.stream_id]
stream.receive_headers(frame)
if stream.closed?
@streams.delete(stream.id)