Class: Protocol::HTTP2::Framer
- Inherits:
-
Object
- Object
- Protocol::HTTP2::Framer
- Defined in:
- lib/protocol/http2/framer.rb
Instance Method Summary collapse
- #close ⇒ Object
- #closed? ⇒ Boolean
- #flush ⇒ Object
-
#initialize(stream, frames = FRAMES) ⇒ Framer
constructor
A new instance of Framer.
- #read_connection_preface ⇒ Object
-
#read_frame(maximum_frame_size = MAXIMUM_ALLOWED_FRAME_SIZE) ⇒ Frame
The frame that has been read from the underlying IO.
- #read_header ⇒ Object
- #write_connection_preface ⇒ Object
-
#write_frame(frame) ⇒ Object
Write a frame to the underlying IO.
Constructor Details
Instance Method Details
#close ⇒ Object
55 56 57 |
# File 'lib/protocol/http2/framer.rb', line 55 def close @stream.close end |
#closed? ⇒ Boolean
59 60 61 |
# File 'lib/protocol/http2/framer.rb', line 59 def closed? @stream.closed? end |
#flush ⇒ Object
51 52 53 |
# File 'lib/protocol/http2/framer.rb', line 51 def flush @stream.flush end |
#read_connection_preface ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/protocol/http2/framer.rb', line 67 def read_connection_preface string = @stream.read(CONNECTION_PREFACE.bytesize) unless string == CONNECTION_PREFACE raise HandshakeError, "Invalid connection preface: #{string.inspect}" end return string end |
#read_frame(maximum_frame_size = MAXIMUM_ALLOWED_FRAME_SIZE) ⇒ Frame
Returns the frame that has been read from the underlying IO.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/protocol/http2/framer.rb', line 79 def read_frame(maximum_frame_size = MAXIMUM_ALLOWED_FRAME_SIZE) # Read the header: length, type, flags, stream_id = read_header # Console.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) # Console.debug(self, name: "read") {frame.inspect} return frame end |
#read_header ⇒ Object
108 109 110 111 112 113 114 115 116 |
# File 'lib/protocol/http2/framer.rb', line 108 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 ⇒ Object
63 64 65 |
# File 'lib/protocol/http2/framer.rb', line 63 def write_connection_preface @stream.write(CONNECTION_PREFACE) end |
#write_frame(frame) ⇒ Object
Write a frame to the underlying IO. After writing one or more frames, you should call flush to ensure the frames are sent to the remote peer.
100 101 102 103 104 105 106 |
# File 'lib/protocol/http2/framer.rb', line 100 def write_frame(frame) # Console.debug(self, name: "write") {frame.inspect} frame.write(@stream) return frame end |