http-parser 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4294a329a0339635dbcafcf057d23f832b80c8ec
4
- data.tar.gz: 23d181a796fd7d9aaec50b32aa525fdb03ce2e86
3
+ metadata.gz: ef7dd40436524e48ef90904d871caed3ba2754d6
4
+ data.tar.gz: d1eebb668464073456f155757c4d34d06c3ebd1d
5
5
  SHA512:
6
- metadata.gz: af8092393a33fa87bb0b0182f34ace79e593b6f1672cd4dee0c2a8fa8d8161b3984071c684054451f926c82ce5ee4de29052c899f560a5ea83c8aef1b7044027
7
- data.tar.gz: dec2187b798145b8f2c670048a8c885d13d27d874c404ce9f9feb391a61336d9516c9e86ed85604887ab6e03f7f19b48b5be3a6f2752a013ad666883b19d6cde
6
+ metadata.gz: 477ec97207cb8c602db5279f4e1ef315cb896d3d79e2669c712d0c4a950c36b941a8d1aa5ba490813e6bd5a6befcbd5947f00dd1d1e28acaeb340d20c789f111
7
+ data.tar.gz: e5b18b9ddd5bc2befbd6b334834bc9cd16f5428c2d0413bb791a0ede0141ca9f6dbed49daddc42177dcf96b5e51610fcdc92bc5ea5753b66f15e2cccb5d31cbf
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # http-parser
2
2
 
3
- Ruby FFI bindings to [http-parser](https://github.com/joyent/http-parser)
3
+ Ruby FFI bindings to [http-parser](https://github.com/joyent/http-parser) [![Build Status](https://travis-ci.org/cotag/http-parser.png)](https://travis-ci.org/cotag/http-parser)
4
4
 
5
5
  ## Install
6
6
 
data/Rakefile CHANGED
@@ -0,0 +1,19 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rspec/core/rake_task'
4
+
5
+ task :default => [:compile, :test]
6
+
7
+ task :compile do
8
+ protect = ['http_parser.c', 'http_parser.h']
9
+ Dir["ext/http-parser/**/*"].each do |file|
10
+ begin
11
+ next if protect.include? File.basename(file)
12
+ FileUtils.rm file
13
+ rescue
14
+ end
15
+ end
16
+ system 'cd ext && rake'
17
+ end
18
+
19
+ RSpec::Core::RakeTask.new(:test)
data/ext/Rakefile CHANGED
@@ -5,5 +5,4 @@ FFI::Compiler::CompileTask.new('http-parser-ext') do |t|
5
5
  t.cflags << "-D_GNU_SOURCE=1" if RbConfig::CONFIG["host_os"].downcase =~ /mingw/
6
6
  t.cflags << "-arch x86_64 -arch i386" if t.platform.mac?
7
7
  t.ldflags << "-arch x86_64 -arch i386" if t.platform.mac?
8
- t.export '../lib/http-parser/ext.rb'
9
8
  end
@@ -929,6 +929,7 @@ size_t http_parser_execute (http_parser *parser,
929
929
  } else if (parser->index == 2 && ch == 'P') {
930
930
  parser->method = HTTP_COPY;
931
931
  } else {
932
+ SET_ERRNO(HPE_INVALID_METHOD);
932
933
  goto error;
933
934
  }
934
935
  } else if (parser->method == HTTP_MKCOL) {
@@ -941,12 +942,14 @@ size_t http_parser_execute (http_parser *parser,
941
942
  } else if (parser->index == 2 && ch == 'A') {
942
943
  parser->method = HTTP_MKACTIVITY;
943
944
  } else {
945
+ SET_ERRNO(HPE_INVALID_METHOD);
944
946
  goto error;
945
947
  }
946
948
  } else if (parser->method == HTTP_SUBSCRIBE) {
947
949
  if (parser->index == 1 && ch == 'E') {
948
950
  parser->method = HTTP_SEARCH;
949
951
  } else {
952
+ SET_ERRNO(HPE_INVALID_METHOD);
950
953
  goto error;
951
954
  }
952
955
  } else if (parser->index == 1 && parser->method == HTTP_POST) {
@@ -957,13 +960,27 @@ size_t http_parser_execute (http_parser *parser,
957
960
  } else if (ch == 'A') {
958
961
  parser->method = HTTP_PATCH;
959
962
  } else {
963
+ SET_ERRNO(HPE_INVALID_METHOD);
960
964
  goto error;
961
965
  }
962
966
  } else if (parser->index == 2) {
963
967
  if (parser->method == HTTP_PUT) {
964
- if (ch == 'R') parser->method = HTTP_PURGE;
968
+ if (ch == 'R') {
969
+ parser->method = HTTP_PURGE;
970
+ } else {
971
+ SET_ERRNO(HPE_INVALID_METHOD);
972
+ goto error;
973
+ }
965
974
  } else if (parser->method == HTTP_UNLOCK) {
966
- if (ch == 'S') parser->method = HTTP_UNSUBSCRIBE;
975
+ if (ch == 'S') {
976
+ parser->method = HTTP_UNSUBSCRIBE;
977
+ } else {
978
+ SET_ERRNO(HPE_INVALID_METHOD);
979
+ goto error;
980
+ }
981
+ } else {
982
+ SET_ERRNO(HPE_INVALID_METHOD);
983
+ goto error;
967
984
  }
968
985
  } else if (parser->index == 4 && parser->method == HTTP_PROPFIND && ch == 'P') {
969
986
  parser->method = HTTP_PROPPATCH;
@@ -2173,3 +2190,10 @@ int
2173
2190
  http_body_is_final(const struct http_parser *parser) {
2174
2191
  return parser->state == s_message_done;
2175
2192
  }
2193
+
2194
+ unsigned long
2195
+ http_parser_version(void) {
2196
+ return HTTP_PARSER_VERSION_MAJOR * 0x10000 |
2197
+ HTTP_PARSER_VERSION_MINOR * 0x00100 |
2198
+ HTTP_PARSER_VERSION_PATCH * 0x00001;
2199
+ }
@@ -27,6 +27,7 @@ extern "C" {
27
27
  /* Also update SONAME in the Makefile whenever you change these. */
28
28
  #define HTTP_PARSER_VERSION_MAJOR 2
29
29
  #define HTTP_PARSER_VERSION_MINOR 1
30
+ #define HTTP_PARSER_VERSION_PATCH 0
30
31
 
31
32
  #include <sys/types.h>
32
33
  #if defined(_WIN32) && !defined(__MINGW32__) && (!defined(_MSC_VER) || _MSC_VER<1600)
@@ -68,7 +69,7 @@ typedef struct http_parser_settings http_parser_settings;
68
69
  * HEAD request which may contain 'Content-Length' or 'Transfer-Encoding:
69
70
  * chunked' headers that indicate the presence of a body.
70
71
  *
71
- * http_data_cb does not return data chunks. It will be call arbitrarily
72
+ * http_data_cb does not return data chunks. It will be call arbitrarally
72
73
  * many times for each string. E.G. you might get 10 callbacks for "on_url"
73
74
  * each providing just a few characters more data.
74
75
  */
@@ -262,6 +263,18 @@ struct http_parser_url {
262
263
  };
263
264
 
264
265
 
266
+ /* Returns the library version. Bits 16-23 contain the major version number,
267
+ * bits 8-15 the minor version number and bits 0-7 the patch level.
268
+ * Usage example:
269
+ *
270
+ * unsigned long version = http_parser_version();
271
+ * unsigned major = (version >> 16) & 255;
272
+ * unsigned minor = (version >> 8) & 255;
273
+ * unsigned patch = version & 255;
274
+ * printf("http_parser v%u.%u.%u\n", major, minor, version);
275
+ */
276
+ unsigned long http_parser_version(void);
277
+
265
278
  void http_parser_init(http_parser *parser, enum http_parser_type type);
266
279
 
267
280
 
data/http-parser.gemspec CHANGED
@@ -7,6 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.version = HttpParser::VERSION
8
8
  s.authors = ["Stephen von Takach"]
9
9
  s.email = ["steve@cotag.me"]
10
+ s.license = 'MIT'
10
11
  s.homepage = "https://github.com/cotag/http-parser"
11
12
  s.summary = "Ruby bindings to joyent/http-parser"
12
13
  s.description = <<-EOF
@@ -160,7 +160,7 @@ module HttpParser
160
160
  #
161
161
  def parse(inst, data)
162
162
  ::HttpParser.http_parser_execute(inst, @settings, data, data.length)
163
- return !inst.error?
163
+ return inst.error?
164
164
  end
165
165
 
166
166
 
@@ -1,3 +1,3 @@
1
1
  module HttpParser
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
data/spec/error_spec.rb CHANGED
@@ -5,24 +5,24 @@ describe HttpParser::Parser, "#initialize" do
5
5
  @inst = HttpParser::Parser.new_instance
6
6
  end
7
7
 
8
- it "should return true when no error" do
9
- subject.parse(@inst, "GET / HTTP/1.1\r\n").should be_true
10
- @inst.error?.should be_false
8
+ it "should return true when error" do
9
+ subject.parse(@inst, "GETS / HTTP/1.1\r\n").should be_true
10
+ @inst.error?.should be_true
11
11
  end
12
12
 
13
- it "should return false on error" do
14
- subject.parse(@inst, "GETS / HTTP/1.1\r\n").should be_false
15
- @inst.error?.should be_true
13
+ it "should return false on success" do
14
+ subject.parse(@inst, "GET / HTTP/1.1\r\n").should be_false
15
+ @inst.error?.should be_false
16
16
  end
17
17
 
18
18
  it "the error should be inspectable" do
19
- subject.parse(@inst, "GETS / HTTP/1.1\r\n").should be_false
19
+ subject.parse(@inst, "GETS / HTTP/1.1\r\n").should be_true
20
20
  @inst.error.should be_kind_of(::HttpParser::Error::INVALID_METHOD)
21
21
  @inst.error?.should be_true
22
22
  end
23
23
 
24
24
  it "raises different error types depending on the error" do
25
- subject.parse(@inst, "GET / HTTP/23\r\n").should be_false
25
+ subject.parse(@inst, "GET / HTTP/23\r\n").should be_true
26
26
  @inst.error.should be_kind_of(::HttpParser::Error::INVALID_VERSION)
27
27
  @inst.error?.should be_true
28
28
  end
@@ -35,7 +35,7 @@ describe HttpParser::Parser, "#initialize" do
35
35
  end
36
36
 
37
37
  it "should handle unhandled errors gracefully" do
38
- subject.parse(@inst, "GET /foo?q=1 HTTP/1.1").should be_false
38
+ subject.parse(@inst, "GET /foo?q=1 HTTP/1.1").should be_true
39
39
 
40
40
  @inst.error?.should be_true
41
41
  @inst.error.should be_kind_of(::HttpParser::Error::CALLBACK)
data/spec/parser_spec.rb CHANGED
@@ -270,5 +270,19 @@ describe HttpParser::Parser, "#initialize" do
270
270
  @inst.upgrade?.should be_true
271
271
  end
272
272
  end
273
+
274
+ describe "pipelined requests" do
275
+ subject do
276
+ @begun = 0
277
+ described_class.new do |parser|
278
+ parser.on_message_begin { @begun += 1 }
279
+ end
280
+ end
281
+
282
+ it "should trigger on a new request" do
283
+ subject.parse @inst, "GET /demo HTTP/1.1\r\n\r\nGET /demo HTTP/1.1\r\n\r\n"
284
+ @begun.should == 2
285
+ end
286
+ end
273
287
  end
274
288
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http-parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen von Takach
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-05 00:00:00.000000000 Z
11
+ date: 2013-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi-compiler
@@ -94,7 +94,8 @@ files:
94
94
  - spec/parser_spec.rb
95
95
  - ext/Rakefile
96
96
  homepage: https://github.com/cotag/http-parser
97
- licenses: []
97
+ licenses:
98
+ - MIT
98
99
  metadata: {}
99
100
  post_install_message:
100
101
  rdoc_options: []