Skip to content

Commit

Permalink
add reset! method to reset a parser's buffer and zlib
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasschneider committed Jan 22, 2012
1 parent 98f44ca commit 6773e2b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/spdy/parser.rb
Expand Up @@ -38,6 +38,11 @@ def on_reset(&blk)
@on_reset = blk @on_reset = blk
end end


def reset!
@buffer = ''
@zlib_session.reset
end

private private


def handle_headers(pckt) def handle_headers(pckt)
Expand Down
25 changes: 25 additions & 0 deletions spec/parser_spec.rb
Expand Up @@ -193,4 +193,29 @@


end end


context "#reset!" do
# because the zlib session is stateful
it "should raise when trying to inflate the same thing twice" do
s << SYN_STREAM
lambda {
s << SYN_STREAM
}.should raise_error
end

it "should not raise when resetting the parser after each frame" do
s << SYN_STREAM
s.reset!
lambda {
s << SYN_STREAM
}.should_not raise_error
end

it "should clear the buffer" do
s << SYN_STREAM[0..30]
s.reset!
lambda {
s << SYN_STREAM
}.should_not raise_error
end
end
end end

0 comments on commit 6773e2b

Please sign in to comment.