Class: H2::Stream
Constant Summary collapse
- STREAM_EVENTS =
[ :close, :headers, :data ]
Instance Attribute Summary collapse
-
#body ⇒ String
readonly
Response headers (blocks).
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#headers ⇒ Hash
readonly
Response headers (blocks).
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#pushes ⇒ Object
readonly
Returns the value of attribute pushes.
-
#stream ⇒ Object
readonly
Returns the value of attribute stream.
Instance Method Summary collapse
-
#add_headers(h) ⇒ Object
builds
Hash
from associative array, merges into response headers. -
#add_push(stream) ⇒ Object
add a push promise
Stream
to thisStream
‘s list of “child” pushes. -
#bind_events ⇒ Object
binds all stream events to their respective on_ handlers.
-
#block!(timeout = nil) ⇒ Object
block this stream until unblocked or timeout.
-
#cancel! ⇒ Object
call cancel and unblock this
Stream
. -
#closed? ⇒ Boolean
True if this
Stream
is closed. -
#id ⇒ Integer
Stream ID.
-
#initialize(client:, stream:, push: false, parent: nil) {|_self| ... } ⇒ H2::Stream
constructor
create a new h2 stream.
-
#ok? ⇒ Boolean
True if response status is 200.
-
#push? ⇒ Boolean
True if this
Stream
is a push promise. -
#to_h ⇒ Hash
A simple
Hash
with:headers
and:body
keys/values.
Methods included from On
Methods included from Blockable
Constructor Details
#initialize(client:, stream:, push: false, parent: nil) {|_self| ... } ⇒ H2::Stream
create a new h2 stream
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/h2/stream.rb', line 25 def initialize client:, stream:, push: false, parent: nil @body = '' @client = client @closed = false @headers = {} @parent = parent @push = push @pushes = Set.new @stream = stream init_blocking yield self if block_given? bind_events end |
Instance Attribute Details
#body ⇒ String (readonly)
Returns response headers (blocks).
93 94 95 |
# File 'lib/h2/stream.rb', line 93 def body @body end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
14 15 16 |
# File 'lib/h2/stream.rb', line 14 def client @client end |
#headers ⇒ Hash (readonly)
Returns response headers (blocks).
86 87 88 |
# File 'lib/h2/stream.rb', line 86 def headers @headers end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
14 15 16 |
# File 'lib/h2/stream.rb', line 14 def parent @parent end |
#pushes ⇒ Object (readonly)
Returns the value of attribute pushes.
14 15 16 |
# File 'lib/h2/stream.rb', line 14 def pushes @pushes end |
#stream ⇒ Object (readonly)
Returns the value of attribute stream.
14 15 16 |
# File 'lib/h2/stream.rb', line 14 def stream @stream end |
Instance Method Details
#add_headers(h) ⇒ Object
builds Hash
from associative array, merges into response headers
121 122 123 124 125 126 |
# File 'lib/h2/stream.rb', line 121 def add_headers h h = Hash[h] on :headers, h @headers.merge! h @headers end |
#add_push(stream) ⇒ Object
add a push promise Stream
to this Stream
‘s list of “child” pushes
66 67 68 |
# File 'lib/h2/stream.rb', line 66 def add_push stream @pushes << stream end |
#bind_events ⇒ Object
binds all stream events to their respective on_ handlers
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/h2/stream.rb', line 100 def bind_events @stream.on(:close) do @parent.add_push self if @parent && push? @client.last_stream = self @closed = true unblock! on :close end ah = method :add_headers @stream.on :promise_headers, &ah @stream.on :headers, &ah @stream.on(:data) do |d| on :data, d @body << d end end |
#block!(timeout = nil) ⇒ Object
block this stream until unblocked or timeout
79 80 81 82 |
# File 'lib/h2/stream.rb', line 79 def block! timeout = nil @pushes.each {|p| p.block! timeout} super end |
#cancel! ⇒ Object
call cancel and unblock this Stream
72 73 74 75 |
# File 'lib/h2/stream.rb', line 72 def cancel! @stream.cancel unblock! end |
#closed? ⇒ Boolean
Returns true if this Stream
is closed.
54 55 56 |
# File 'lib/h2/stream.rb', line 54 def closed? @closed end |
#id ⇒ Integer
Returns stream ID.
42 43 44 |
# File 'lib/h2/stream.rb', line 42 def id @stream.id end |
#ok? ⇒ Boolean
Returns true if response status is 200.
48 49 50 |
# File 'lib/h2/stream.rb', line 48 def ok? headers[STATUS_KEY] == '200' end |
#push? ⇒ Boolean
Returns true if this Stream
is a push promise.
60 61 62 |
# File 'lib/h2/stream.rb', line 60 def push? @push end |
#to_h ⇒ Hash
Returns a simple Hash
with :headers
and :body
keys/values.
130 131 132 |
# File 'lib/h2/stream.rb', line 130 def to_h { headers: headers, body: body } end |