class Protocol::HTTP2::Framer
Public Class Methods
new(stream, frames = FRAMES)
click to toggle source
# File lib/protocol/http2/framer.rb, line 55 def initialize(stream, frames = FRAMES) @stream = stream @frames = frames end
Public Instance Methods
close()
click to toggle source
# File lib/protocol/http2/framer.rb, line 60 def close @stream.close end
closed?()
click to toggle source
# File lib/protocol/http2/framer.rb, line 64 def closed? @stream.closed? end
read_connection_preface()
click to toggle source
# File lib/protocol/http2/framer.rb, line 72 def read_connection_preface string = @stream.read(CONNECTION_PREFACE_MAGIC.bytesize) unless string == CONNECTION_PREFACE_MAGIC raise HandshakeError, "Invalid connection preface: #{string.inspect}" end return string end
read_frame(maximum_frame_size = MAXIMUM_ALLOWED_FRAME_SIZE)
click to toggle source
@return [Frame] the frame that has been read from the underlying IO. @raise if the underlying IO fails for some reason.
# File lib/protocol/http2/framer.rb, line 84 def read_frame(maximum_frame_size = MAXIMUM_ALLOWED_FRAME_SIZE) # Read the header: length, type, flags, stream_id = read_header # Async.logger.debug(self) {"read_frame: length=#{length} type=#{type} flags=#{flags} stream_id=#{stream_id} -> klass=#{@frames[type].inspect}"} # Allocate the frame: klass = @frames[type] || Frame frame = klass.new(stream_id, flags, type, length) # Read the payload: frame.read(@stream, maximum_frame_size) # Async.logger.debug(self, name: "read") {frame.inspect} return frame end
read_header()
click to toggle source
# File lib/protocol/http2/framer.rb, line 113 def read_header if buffer = @stream.read(9) if buffer.bytesize == 9 return Frame.parse_header(buffer) end end raise EOFError, "Could not read frame header!" end
write_connection_preface()
click to toggle source
# File lib/protocol/http2/framer.rb, line 68 def write_connection_preface @stream.write(CONNECTION_PREFACE_MAGIC) end
write_frame(frame)
click to toggle source
# File lib/protocol/http2/framer.rb, line 102 def write_frame(frame) # Async.logger.debug(self, name: "write") {frame.inspect} frame.write(@stream) # Don't call @stream.flush here because it can cause significant contention if there is a semaphore around this method. # @stream.flush return frame end