Skip to content
Browse files

added missing on_headers_complete callback

  • Loading branch information...
1 parent 64552f6 commit 39359ecd90468a64b15566d74c3b17ad340713e0 @deepfryed committed Jun 30, 2012
Showing with 22 additions and 5 deletions.
  1. +4 −0 CHANGELOG
  2. +5 −0 README.md
  3. +1 −1 Rakefile
  4. +7 −0 ext/http-parser/ruby_http_parser.c
  5. +2 −2 http-parser-lite.gemspec
  6. +1 −1 lib/http-parser.rb
  7. +2 −1 test/test_http_parser.rb
View
4 CHANGELOG
@@ -1,3 +1,7 @@
+== 0.4.0 (2012-06-30)
+
+* added missing on_headers_complete callback.
+
== 0.3.0 (2012-06-27)
* Added optional type argument to Parser#initialize and Parser#reset
View
5 README.md
@@ -21,6 +21,10 @@ parser.on_message_complete do
puts "message complete"
end
+parser.on_headers_complete do
+ puts "value: #{value}"
+end
+
parser.on_url do |url|
puts "url: #{url}"
end
@@ -63,6 +67,7 @@ HTTP::Parser
#on_url(&block)
#on_header_field(&block)
#on_header_value(&block)
+ #on_headers_complete(&block)
#on_body(&block)
#http_status
View
2 Rakefile
@@ -7,7 +7,7 @@ require 'rake/testtask'
$rootdir = Pathname.new(__FILE__).dirname
$gemspec = Gem::Specification.new do |s|
s.name = 'http-parser-lite'
- s.version = '0.3.0'
+ s.version = '0.4.0'
s.date = Date.today
s.authors = ['Bharanee Rathna']
s.email = ['deepfryed@gmail.com']
View
7 ext/http-parser/ruby_http_parser.c
@@ -53,6 +53,12 @@ int rb_parser_on_header_value(http_parser *parser, char *data, size_t length) {
return 0;
}
+int rb_parser_on_headers_complete(http_parser *parser) {
+ VALUE self = (VALUE)parser->data;
+ rb_parser_callback_call(self, "on_headers_complete", 0, 0);
+ return 0;
+}
+
int rb_parser_on_body(http_parser *parser, char *data, size_t length) {
VALUE self = (VALUE)parser->data;
rb_parser_callback_call(self, "on_body", data, length);
@@ -77,6 +83,7 @@ VALUE rb_parser_parse(VALUE self, VALUE data) {
.on_url = (http_data_cb)rb_parser_on_url,
.on_header_field = (http_data_cb)rb_parser_on_header_field,
.on_header_value = (http_data_cb)rb_parser_on_header_value,
+ .on_headers_complete = (http_cb)rb_parser_on_headers_complete,
.on_body = (http_data_cb)rb_parser_on_body,
.on_message_begin = (http_cb)rb_parser_on_message_begin,
.on_message_complete = (http_cb)rb_parser_on_message_complete
View
4 http-parser-lite.gemspec
@@ -2,11 +2,11 @@
Gem::Specification.new do |s|
s.name = "http-parser-lite"
- s.version = "0.3.0"
+ s.version = "0.4.0"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Bharanee Rathna"]
- s.date = "2012-06-27"
+ s.date = "2012-06-30"
s.description = "A lite ruby wrapper around Joyent http-parser"
s.email = ["deepfryed@gmail.com"]
s.extensions = ["ext/http-parser/extconf.rb"]
View
2 lib/http-parser.rb
@@ -5,7 +5,7 @@ class Parser
TYPE_REQUEST = 0
TYPE_RESPONSE = 1
TYPE_BOTH = 2
- CALLBACKS = %w(on_url on_header_field on_header_value on_body on_message_begin on_message_complete)
+ CALLBACKS = %w(on_url on_header_field on_header_value on_headers_complete on_body on_message_begin on_message_complete)
CALLBACKS.each do |name|
define_method(name) do |&block|
View
3 test/test_http_parser.rb
@@ -40,10 +40,11 @@
parser.on_url {got << 'u'}
parser.on_header_field {got << 'f'}
parser.on_header_value {got << 'v'}
+ parser.on_headers_complete {got << 'h'}
parser.on_body {got << 'b'}
parser << "POST / HTTP/1.0\r\nContent-Type: text/plain\r\nContent-Length: 5\r\n\r\nhello"
- assert_equal %w(s u f v f v b e), got
+ assert_equal %w(s u f v f v h b e), got
end
it 'should parse chunked response' do

0 comments on commit 39359ec

Please sign in to comment.
Something went wrong with that request. Please try again.