Skip to content

Commit

Permalink
Remove on_headers_complete, add on_open.
Browse files Browse the repository at this point in the history
SYN_STREAM fires both of them now.
  • Loading branch information
jonasschneider committed Jan 4, 2012
1 parent 1b06fba commit 8ca91f4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
22 changes: 12 additions & 10 deletions lib/spdy/parser.rb
Expand Up @@ -14,11 +14,10 @@ def <<(data)
try_parse
end

def on_headers_complete(&blk)
@on_headers_complete = blk
def on_open(&blk)
@on_open = blk
end


def on_ping(&blk)
@on_ping = blk
end
Expand All @@ -43,12 +42,10 @@ def on_reset(&blk)

def unpack_control(pckt, data)
pckt.parse(data)

if @on_headers_complete
@on_headers_complete.call(pckt.header.stream_id.to_i,
(pckt.associated_to_stream_id.to_i rescue nil),
(pckt.pri.to_i rescue nil),
pckt.uncompressed_data.to_h)

if @on_headers && pckt.uncompressed_data.to_h != {}
@on_headers.call(pckt.header.stream_id.to_i,
pckt.uncompressed_data.to_h)
end
end

Expand All @@ -65,8 +62,13 @@ def try_parse
case pckt.type.to_i
when 1 then # SYN_STREAM
pckt = Control::SynStream.new({:zlib_session => @zlib_session})
if @on_open
@on_open.call(pckt.header.stream_id,
(pckt.associated_to_stream_id.to_i rescue nil),
(pckt.pri.to_i rescue nil))
end
unpack_control(pckt, @buffer)

@on_message_complete.call(pckt.header.stream_id) if @on_message_complete && fin?(pckt.header)

when 2 then # SYN_REPLY
Expand Down
20 changes: 13 additions & 7 deletions spec/parser_spec.rb
Expand Up @@ -6,7 +6,7 @@
context "callbacks" do
it "should accept header callback" do
lambda do
s.on_headers_complete {}
s.on_headers {}
end.should_not raise_error
end

Expand Down Expand Up @@ -38,7 +38,7 @@
data.should == 'This is SPDY.'

fired = false
s.on_headers_complete { fired = true }
s.on_open { fired = true }
s << SYN_STREAM

fired.should be_true
Expand All @@ -54,21 +54,27 @@
context "CONTROL" do
it "should parse SYN_STREAM packet" do
fired = false
s.on_headers_complete { fired = true }
s.on_open { fired = true }
s << SYN_STREAM

fired.should be_true
end

it "should return parsed headers for SYN_STREAM" do
sid, asid, pri, headers = nil
s.on_headers_complete do |stream, astream, priority, head|
sid = stream; asid = astream; pri = priority; headers = head
sid, sid2, asid, pri, headers = nil
order = []
s.on_open do |stream, astream, priority|
sid = stream; asid = astream; pri = priority;
end

s.on_headers do |stream, head|
sid2 = stream; headers = head
end

s << SYN_STREAM

sid.should == 1
sid2.should == 1
asid.should == 0
pri.should == 0

Expand Down Expand Up @@ -132,7 +138,7 @@
context "FIN" do
it "should invoke message_complete on FIN flag in CONTROL packet" do
f1, f2 = false
s.on_headers_complete { f1 = true }
s.on_open { f1 = true }
s.on_message_complete { |s| f2 = s }

sr = SPDY::Protocol::Control::SynStream.new
Expand Down

0 comments on commit 8ca91f4

Please sign in to comment.