Skip to content

Instantly share code, notes, and snippets.

@igrigorik
Created April 10, 2011 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igrigorik/05bf5df49899d45446bd to your computer and use it in GitHub Desktop.
Save igrigorik/05bf5df49899d45446bd to your computer and use it in GitHub Desktop.
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