Class: HTTP::Protocol::HTTP2::Framer
- Inherits:
-
Object
- Object
- HTTP::Protocol::HTTP2::Framer
- Defined in:
- lib/http/protocol/http2/framer.rb
Instance Method Summary collapse
- #close ⇒ 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) ⇒ Object
- #read_header ⇒ Object
- #write_connection_preface ⇒ Object
- #write_frame(frame) ⇒ Object
Constructor Details
Instance Method Details
#close ⇒ Object
61 62 63 |
# File 'lib/http/protocol/http2/framer.rb', line 61 def close @stream.close end |
#read_connection_preface ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/http/protocol/http2/framer.rb', line 69 def read_connection_preface string = @stream.read(CONNECTION_PREFACE_MAGIC.bytesize) unless string == CONNECTION_PREFACE_MAGIC raise ProtocolError, "Invalid connection preface: #{string.inspect}" end return string end |
#read_frame(maximum_frame_size = MAXIMUM_ALLOWED_FRAME_SIZE) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/http/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 # 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(@stream, maximum_frame_size) return frame end |
#read_header ⇒ Object
104 105 106 107 108 109 110 111 |
# File 'lib/http/protocol/http2/framer.rb', line 104 def read_header if buffer = @stream.read(9) return Frame.parse_header(buffer) else # TODO: Is this necessary? I thought the IO would throw this. raise EOFError end end |
#write_connection_preface ⇒ Object
65 66 67 |
# File 'lib/http/protocol/http2/framer.rb', line 65 def write_connection_preface @stream.write(CONNECTION_PREFACE_MAGIC) end |
#write_frame(frame) ⇒ Object
95 96 97 98 99 100 101 102 |
# File 'lib/http/protocol/http2/framer.rb', line 95 def write_frame(frame) # puts "framer: write_frame #{frame.inspect}" frame.write(@stream) @stream.flush return frame end |