Module: Plum::FrameFactory
- Included in:
- Frame
- Defined in:
- lib/plum/frame_factory.rb
Instance Method Summary collapse
-
#continuation(stream_id, payload, end_headers: false) ⇒ Object
Creates a CONTINUATION frame.
-
#data(stream_id, payload = "", end_stream: false) ⇒ Object
Creates a DATA frame.
-
#goaway(last_id, error_type, message = "") ⇒ Object
Creates a GOAWAY frame.
-
#headers(stream_id, encoded, end_stream: false, end_headers: false) ⇒ Object
Creates a HEADERS frame.
-
#ping(arg1 = "plum\x00\x00\x00\x00".b, arg2 = nil) ⇒ Object
Creates a PING frame.
-
#push_promise(stream_id, new_id, encoded, end_headers: false) ⇒ Object
Creates a PUSH_PROMISE frame.
-
#rst_stream(stream_id, error_type) ⇒ Object
Creates a RST_STREAM frame.
-
#settings(ack = nil, **args) ⇒ Object
Creates a SETTINGS frame.
Instance Method Details
#continuation(stream_id, payload, end_headers: false) ⇒ Object
Creates a CONTINUATION frame.
91 92 93 |
# File 'lib/plum/frame_factory.rb', line 91 def continuation(stream_id, payload, end_headers: false) Frame.new(type: :continuation, stream_id: stream_id, flags_value: (end_headers ? 4 : 0), payload: payload) end |
#data(stream_id, payload = "", end_stream: false) ⇒ Object
Creates a DATA frame.
58 59 60 61 62 |
# File 'lib/plum/frame_factory.rb', line 58 def data(stream_id, payload = "", end_stream: false) payload = payload.b if payload&.encoding != Encoding::BINARY fval = end_stream ? 1 : 0 Frame.new(type_value: 0, stream_id: stream_id, flags_value: fval, payload: payload) end |
#goaway(last_id, error_type, message = "") ⇒ Object
Creates a GOAWAY frame.
19 20 21 22 23 24 |
# File 'lib/plum/frame_factory.rb', line 19 def goaway(last_id, error_type, = "") payload = String.new.push_uint32(last_id) .push_uint32(HTTPError::ERROR_CODES[error_type]) .push() Frame.new(type: :goaway, stream_id: 0, payload: payload) end |
#headers(stream_id, encoded, end_stream: false, end_headers: false) ⇒ Object
Creates a HEADERS frame.
69 70 71 72 73 |
# File 'lib/plum/frame_factory.rb', line 69 def headers(stream_id, encoded, end_stream: false, end_headers: false) fval = end_stream ? 1 : 0 fval += 4 if end_headers Frame.new(type_value: 1, stream_id: stream_id, flags_value: fval, payload: encoded) end |
#ping(ack, payload) ⇒ Object #ping(payload = "plum\x00\x00\x00\x00") ⇒ Object
Creates a PING frame.
44 45 46 47 48 49 50 51 52 |
# File 'lib/plum/frame_factory.rb', line 44 def ping(arg1 = "plum\x00\x00\x00\x00".b, arg2 = nil) if !arg2 raise ArgumentError.new("data must be 8 octets") if arg1.bytesize != 8 arg1 = arg1.b if arg1.encoding != Encoding::BINARY Frame.new(type: :ping, stream_id: 0, payload: arg1) else Frame.new(type: :ping, stream_id: 0, flags: [:ack], payload: arg2) end end |
#push_promise(stream_id, new_id, encoded, end_headers: false) ⇒ Object
Creates a PUSH_PROMISE frame.
80 81 82 83 84 85 |
# File 'lib/plum/frame_factory.rb', line 80 def push_promise(stream_id, new_id, encoded, end_headers: false) payload = String.new.push_uint32(new_id) .push(encoded) fval = end_headers ? 4 : 0 Frame.new(type: :push_promise, stream_id: stream_id, flags_value: fval, payload: payload) end |
#rst_stream(stream_id, error_type) ⇒ Object
Creates a RST_STREAM frame.
9 10 11 12 |
# File 'lib/plum/frame_factory.rb', line 9 def rst_stream(stream_id, error_type) payload = String.new.push_uint32(HTTPError::ERROR_CODES[error_type]) Frame.new(type: :rst_stream, stream_id: stream_id, payload: payload) end |
#settings(ack = nil, **args) ⇒ Object
Creates a SETTINGS frame.
29 30 31 32 33 34 35 36 |
# File 'lib/plum/frame_factory.rb', line 29 def settings(ack = nil, **args) payload = args.inject(String.new) {|payload, (key, value)| id = Frame::SETTINGS_TYPE[key] or raise ArgumentError.new("invalid settings type") payload.push_uint16(id) payload.push_uint32(value) } Frame.new(type: :settings, stream_id: 0, flags: [ack], payload: payload) end |