Permalink
Browse files

add reset! method to reset a parser's buffer and zlib

  • Loading branch information...
1 parent 98f44ca commit 6773e2bc97e5428d6e1b6ac1cdb39fb9e58f9341 @jonasschneider jonasschneider committed Jan 22, 2012
Showing with 30 additions and 0 deletions.
  1. +5 −0 lib/spdy/parser.rb
  2. +25 −0 spec/parser_spec.rb
View
@@ -38,6 +38,11 @@ def on_reset(&blk)
@on_reset = blk
end
+ def reset!
+ @buffer = ''
+ @zlib_session.reset
+ end
+
private
def handle_headers(pckt)
View
@@ -193,4 +193,29 @@
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

0 comments on commit 6773e2b

Please sign in to comment.