Skip to content

Commit

Permalink
Merge 45b7456 into d52934f
Browse files Browse the repository at this point in the history
  • Loading branch information
xiejiangzhi committed Apr 1, 2019
2 parents d52934f + 45b7456 commit c7ba98f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .rubocop.yml
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
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
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

0 comments on commit c7ba98f

Please sign in to comment.