Skip to content

Instantly share code, notes, and snippets.

@igrigorik igrigorik/parser-reset.rb Secret
Created Apr 10, 2011

Embed
What would you like to do?
require 'http/parser' # http_parser.rb
@p = Http::Parser.new
@p.on_headers_complete = proc {|h| p [:headers, h]; @p.reset! }
@p.on_body = proc {|b| p [:on_body, b, :SHOULD_NOT_FIRE] }
@p.on_message_complete = proc { p [:complete, :SHOULD_NOT_FIRE] }
s = <<STR
HTTP/1.1 200 OK
Content-Length: 10
STR
@p << s
@p << s
# [:headers, {"Content-Length"=>"10"}]
# [:on_body, "HTTP/1.1 2", :SHOULD_NOT_FIRE]
# [:complete, :SHOULD_NOT_FIRE]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.