Class: HTTP::Protocol::HTTP2::Framer
- Inherits:
-
Object
- Object
- HTTP::Protocol::HTTP2::Framer
- Defined in:
- lib/http/protocol/http2/framer.rb
Instance Method Summary collapse
-
#initialize(io, frames = FRAMES) ⇒ Framer
constructor
A new instance of Framer.
- #read_connection_preface ⇒ Object
- #read_frame ⇒ Object
- #read_header ⇒ Object
- #write_connection_preface ⇒ Object
- #write_frame(frame) ⇒ Object
Constructor Details
Instance Method Details
#read_connection_preface ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/http/protocol/http2/framer.rb', line 67 def read_connection_preface string = @io.read(CONNECTION_PREFACE_MAGIC.bytesize) unless string == CONNECTION_PREFACE_MAGIC raise ProtocolError, "Invalid connection preface: #{string.inspect}" end return string end |
#read_frame ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/http/protocol/http2/framer.rb', line 77 def read_frame # Read the header: length, type, flags, stream_id = read_header # puts "framer: read_frame #{type} #{length}" # Allocate the frame: klass = @frames[type] || Frame frame = klass.new(stream_id, flags, type, length) # Read the payload: frame.read(@io) return frame end |
#read_header ⇒ Object
99 100 101 |
# File 'lib/http/protocol/http2/framer.rb', line 99 def read_header return Frame.parse_header(@io.read(9)) end |
#write_connection_preface ⇒ Object
63 64 65 |
# File 'lib/http/protocol/http2/framer.rb', line 63 def write_connection_preface @io.write(CONNECTION_PREFACE_MAGIC) end |
#write_frame(frame) ⇒ Object
93 94 95 96 97 |
# File 'lib/http/protocol/http2/framer.rb', line 93 def write_frame(frame) # puts "framer: write_frame #{frame.inspect}" frame.write(@io) @io.flush end |