Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/event with flags #150

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Metrics/LineLength:

Metrics/BlockLength:
Max: 700
Exclude:
- spec/**/*

Layout/EndAlignment:
EnforcedStyleAlignWith: variable
Expand Down
6 changes: 3 additions & 3 deletions lib/http/2/stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ def receive(frame)
when :data
update_local_window(frame)
# Emit DATA frame
emit(:data, frame[:payload]) unless frame[:ignore]
emit(:data, frame[:payload], frame[:flags]) unless frame[:ignore]
calculate_window_update(@local_window_max_size)
when :headers
emit(:headers, frame[:payload]) unless frame[:ignore]
emit(:headers, frame[:payload], frame[:flags]) unless frame[:ignore]
when :push_promise
emit(:promise_headers, frame[:payload]) unless frame[:ignore]
emit(:promise_headers, frame[:payload], frame[:flags]) unless frame[:ignore]
when :priority
process_priority(frame)
when :window_update
Expand Down
27 changes: 19 additions & 8 deletions spec/stream_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -751,20 +751,25 @@
end

it 'should emit received headers via on(:headers)' do
headers, recv = REQUEST_HEADERS, nil
headers, recv, flags = REQUEST_HEADERS, nil, []
@srv.on(:stream) do |stream|
stream.on(:headers) { |h| recv = h }
stream.on(:headers) do |h, f|
recv = h
flags << f
end
end

@client_stream.headers(headers)
expect(recv).to eq headers
expect(flags).to eq [[:end_headers]]
end

it 'should emit received payload via on(:data)' do
it 'should emit received payload & flags via on(:data)' do
payload = 'some-payload'
@srv.on(:stream) do |stream|
stream.on(:data) do |recv|
stream.on(:data) do |recv, flags|
expect(recv).to eq payload
expect(flags).to eq [:end_stream]
end
end

Expand Down Expand Up @@ -834,22 +839,27 @@
end

it 'client: promise_headers > active > headers > .. > data > close' do
order, headers, promise_headers = [], [], []
order, headers, promise_headers, flags = [], [], [], []
@client.on(:promise) do |push|
order << :reserved

push.on(:active) { order << :active }
push.on(:data) { order << :data }
push.on(:half_close) { order << :half_close }
push.on(:close) { order << :close }

push.on(:promise_headers) do |h|
push.on(:promise_headers) do |h, f|
order << :promise_headers
promise_headers += h
flags << f
end
push.on(:headers) do |h|
push.on(:headers) do |h, f|
order << :headers
headers += h
flags << f
end
push.on(:data) do |_d, f|
order << :data
flags << f
end

expect(push.id).to be_even
Expand All @@ -871,6 +881,7 @@
:data,
:close,
]
expect(flags).to eql([[:end_headers], [:end_headers], [:end_stream]])
end
end
end
Expand Down