http_parser.rb 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  [submodule "ext/ruby_http_parser/vendor/http-parser"]
2
2
  path = ext/ruby_http_parser/vendor/http-parser
3
- url = git://github.com/ry/http-parser.git
3
+ url = git://github.com/joyent/http-parser.git
4
4
  [submodule "ext/ruby_http_parser/vendor/http-parser-java"]
5
5
  path = ext/ruby_http_parser/vendor/http-parser-java
6
6
  url = git://github.com/a2800276/http-parser.java.git
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  A simple callback-based HTTP request/response parser for writing http
4
4
  servers, clients and proxies.
5
5
 
6
- This gem is built on top of [ry/http-parser](http://github.com/ry/http-parser) and its java port [a2800276/http-parser.java](http://github.com/a2800276/http-parser.java).
6
+ This gem is built on top of [joyent/http-parser](http://github.com/joyent/http-parser) and its java port [a2800276/http-parser.java](http://github.com/a2800276/http-parser.java).
7
7
 
8
8
  ## Supported Platforms
9
9
 
@@ -100,6 +100,7 @@ static ID Ion_body;
100
100
  static ID Ion_message_complete;
101
101
 
102
102
  static VALUE Sstop;
103
+ static VALUE Sreset;
103
104
  static VALUE Sarrays;
104
105
  static VALUE Sstrings;
105
106
  static VALUE Smixed;
@@ -229,6 +230,8 @@ int on_headers_complete(ryah_http_parser *parser) {
229
230
  if (ret == Sstop) {
230
231
  wrapper->stopped = Qtrue;
231
232
  return -1;
233
+ } else if (ret == Sreset){
234
+ return 1;
232
235
  } else {
233
236
  return 0;
234
237
  }
@@ -348,7 +351,7 @@ VALUE Parser_execute(VALUE self, VALUE data) {
348
351
  if (wrapper->parser.upgrade) {
349
352
  rb_str_cat(wrapper->upgrade_data, ptr + nparsed + 1, len - nparsed - 1);
350
353
 
351
- } else if (nparsed != len) {
354
+ } else if (nparsed != (size_t)len) {
352
355
  if (!RTEST(wrapper->stopped) && !RTEST(wrapper->completed))
353
356
  rb_raise(eParserError, "Could not parse data entirely");
354
357
  else
@@ -401,7 +404,7 @@ VALUE Parser_upgrade_p(VALUE self) {
401
404
  ParserWrapper *wrapper = NULL;
402
405
  DATA_GET(self, ParserWrapper, wrapper);
403
406
 
404
- return wrapper->parser.upgrade == 1 ? Qtrue : Qfalse;
407
+ return wrapper->parser.upgrade ? Qtrue : Qfalse;
405
408
  }
406
409
 
407
410
  VALUE Parser_http_version(VALUE self) {
@@ -502,6 +505,7 @@ void Init_ruby_http_parser() {
502
505
  Ion_body = rb_intern("on_body");
503
506
  Ion_message_complete = rb_intern("on_message_complete");
504
507
  Sstop = ID2SYM(rb_intern("stop"));
508
+ Sreset = ID2SYM(rb_intern("reset"));
505
509
 
506
510
  Sarrays = ID2SYM(rb_intern("arrays"));
507
511
  Sstrings = ID2SYM(rb_intern("strings"));
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "http_parser.rb"
3
- s.version = "0.5.2"
3
+ s.version = "0.5.3"
4
4
  s.summary = "Simple callback-based HTTP request/response parser"
5
5
  s.description = "Ruby bindings to http://github.com/ry/http-parser and http://github.com/a2800276/http-parser.java"
6
6
 
@@ -53,11 +53,11 @@ describe HTTP::Parser do
53
53
  it "should throw an Argument Error if header value type is invalid" do
54
54
  proc{ @parser.header_value_type = 'bob' }.should raise_error(ArgumentError)
55
55
  end
56
-
56
+
57
57
  it "should throw an Argument Error if default header value type is invalid" do
58
58
  proc{ HTTP::Parser.default_header_value_type = 'bob' }.should raise_error(ArgumentError)
59
59
  end
60
-
60
+
61
61
  it "should implement basic api" do
62
62
  @parser <<
63
63
  "GET /test?ok=1 HTTP/1.1\r\n" +
@@ -135,6 +135,25 @@ describe HTTP::Parser do
135
135
  @parser.fragment.should be_nil
136
136
  end
137
137
 
138
+ it "should optionally reset parser state on no-body responses" do
139
+ @parser.reset!.should be_true
140
+
141
+ @head, @complete = 0, 0
142
+ @parser.on_headers_complete = proc {|h| @head += 1; :reset }
143
+ @parser.on_message_complete = proc { @complete += 1 }
144
+ @parser.on_body = proc {|b| fail }
145
+
146
+ head_response = "HTTP/1.1 200 OK\r\nContent-Length:10\r\n\r\n"
147
+
148
+ @parser << head_response
149
+ @head.should == 1
150
+ @complete.should == 1
151
+
152
+ @parser << head_response
153
+ @head.should == 2
154
+ @complete.should == 2
155
+ end
156
+
138
157
  it "should retain callbacks after reset" do
139
158
  @parser.reset!.should be_true
140
159
 
@@ -15,7 +15,7 @@ task :fixtures => :submodules do
15
15
  tmp.gsub!('FALSE', 'false')
16
16
 
17
17
  # remove macros and comments
18
- tmp.gsub!(/^#define.+$/,'')
18
+ tmp.gsub!(/^#(if|elif|endif|define).+$/,'')
19
19
  tmp.gsub!(/\/\*(.+?)\*\/$/,'')
20
20
 
21
21
  # HTTP_* enums become strings
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http_parser.rb
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 2
10
- version: 0.5.2
9
+ - 3
10
+ version: 0.5.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Marc-Andre Cournoyer
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-08-27 00:00:00 -07:00
19
+ date: 2011-10-01 00:00:00 -05:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency