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
-
#initialize(stream, frames = FRAMES) ⇒ Framer
constructor
DEBUG = !!ENV.
- #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
Constructor Details
Instance Method Details
#close ⇒ Object
62 63 64 |
# File 'lib/protocol/http2/framer.rb', line 62 def close @stream.close end |
#closed? ⇒ Boolean
66 67 68 |
# File 'lib/protocol/http2/framer.rb', line 66 def closed? @stream.closed? end |
#read_connection_preface ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'lib/protocol/http2/framer.rb', line 74 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) ⇒ Frame
Returns the frame that has been read from the underlying IO.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/protocol/http2/framer.rb', line 86 def read_frame(maximum_frame_size = MAXIMUM_ALLOWED_FRAME_SIZE) # Read the header: length, type, flags, stream_id = read_header # puts "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) # DEBUG and puts "read_frame: #{frame.inspect}" return frame end |
#read_header ⇒ Object
112 113 114 115 116 117 118 119 120 |
# File 'lib/protocol/http2/framer.rb', line 112 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
70 71 72 |
# File 'lib/protocol/http2/framer.rb', line 70 def write_connection_preface @stream.write(CONNECTION_PREFACE_MAGIC) end |
#write_frame(frame) ⇒ Object
103 104 105 106 107 108 109 110 |
# File 'lib/protocol/http2/framer.rb', line 103 def write_frame(frame) # DEBUG and puts "write_frame: #{frame.inspect}" frame.write(@stream) @stream.flush return frame end |