Class: H2::Stream
Constant Summary
collapse
- STREAM_EVENTS =
[
:close,
:headers,
:data
]
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from On
#on
Methods included from Blockable
#init_blocking, #unblock!
Constructor Details
#initialize(client:, stream:, push: false, parent: nil) {|_self| ... } ⇒ Stream
Returns a new instance of Stream.
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/h2/stream.rb', line 16
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 ⇒ Object
Returns the value of attribute body.
14
15
16
|
# File 'lib/h2/stream.rb', line 14
def body
@body
end
|
#client ⇒ Object
Returns the value of attribute client.
14
15
16
|
# File 'lib/h2/stream.rb', line 14
def client
@client
end
|
Returns the value of attribute headers.
14
15
16
|
# File 'lib/h2/stream.rb', line 14
def
@headers
end
|
#parent ⇒ Object
Returns the value of attribute parent.
14
15
16
|
# File 'lib/h2/stream.rb', line 14
def parent
@parent
end
|
#pushes ⇒ Object
Returns the value of attribute pushes.
14
15
16
|
# File 'lib/h2/stream.rb', line 14
def pushes
@pushes
end
|
#stream ⇒ Object
Returns the value of attribute stream.
14
15
16
|
# File 'lib/h2/stream.rb', line 14
def stream
@stream
end
|
Instance Method Details
#add_push(stream) ⇒ Object
47
48
49
|
# File 'lib/h2/stream.rb', line 47
def add_push stream
@pushes << stream
end
|
#bind_events ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/h2/stream.rb', line 71
def bind_events
@stream.on(:close) do
@parent.add_push self if @parent && push?
@client.last_stream = self
@closed = true
unblock!
on :close
end
@stream.on(:headers) do |h|
h = Hash[h]
on :headers, h
@headers.merge! h
end
@stream.on(:data) do |d|
on :data, d
@body << d
end
end
|
#block!(timeout = nil) ⇒ Object
56
57
58
59
|
# File 'lib/h2/stream.rb', line 56
def block! timeout = nil
@pushes.each {|p| p.block! timeout}
super
end
|
#cancel! ⇒ Object
51
52
53
54
|
# File 'lib/h2/stream.rb', line 51
def cancel!
@stream.cancel
unblock!
end
|
#closed? ⇒ Boolean
39
40
41
|
# File 'lib/h2/stream.rb', line 39
def closed?
@closed
end
|
#id ⇒ Object
31
32
33
|
# File 'lib/h2/stream.rb', line 31
def id
@stream.id
end
|
#ok? ⇒ Boolean
35
36
37
|
# File 'lib/h2/stream.rb', line 35
def ok?
[STATUS_KEY] == '200'
end
|
#push? ⇒ Boolean
43
44
45
|
# File 'lib/h2/stream.rb', line 43
def push?
@push
end
|
#to_h ⇒ Object
92
93
94
|
# File 'lib/h2/stream.rb', line 92
def to_h
{ headers: , body: body }
end
|