http_parser.rb 0.5.1-java → 0.5.2-java

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.
Files changed (47) hide show
  1. data/Gemfile.lock +6 -6
  2. data/LICENSE-MIT +20 -0
  3. data/ext/ruby_http_parser/org/ruby_http_parser/RubyHttpParser.java +68 -11
  4. data/ext/ruby_http_parser/ruby_http_parser.c +74 -6
  5. data/ext/ruby_http_parser/vendor/http-parser-java/LICENSE-MIT +26 -1
  6. data/ext/ruby_http_parser/vendor/http-parser-java/README.md +23 -143
  7. data/ext/ruby_http_parser/vendor/http-parser-java/TODO +3 -0
  8. data/ext/ruby_http_parser/vendor/http-parser-java/build.xml +74 -0
  9. data/ext/ruby_http_parser/vendor/http-parser-java/http_parser.c +115 -61
  10. data/ext/ruby_http_parser/vendor/http-parser-java/http_parser.h +19 -3
  11. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPCallback.java +8 -0
  12. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPDataCallback.java +34 -0
  13. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPErrorCallback.java +12 -0
  14. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPException.java +4 -2
  15. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPMethod.java +64 -52
  16. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPParser.java +5 -0
  17. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/ParserSettings.java +323 -0
  18. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/{lolevel/Util.java → Util.java} +27 -28
  19. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/lolevel/HTTPParser.java +259 -85
  20. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/lolevel/ParserSettings.java +1 -0
  21. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Message.java +324 -0
  22. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Requests.java +69 -0
  23. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Responses.java +51 -0
  24. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Test.java +15 -0
  25. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/TestHeaderOverflowError.java +47 -0
  26. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/TestLoaderNG.java +183 -447
  27. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/TestNoOverflowLongBody.java +61 -0
  28. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/UnitTest.java +2 -1
  29. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Upgrade.java +26 -0
  30. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Util.java +165 -0
  31. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/WrongContentLength.java +58 -0
  32. data/ext/ruby_http_parser/vendor/http-parser-java/test.c +232 -29
  33. data/ext/ruby_http_parser/vendor/http-parser-java/test_permutations +1 -1
  34. data/ext/ruby_http_parser/vendor/http-parser-java/test_unit +1 -1
  35. data/ext/ruby_http_parser/vendor/http-parser-java/test_utf8 +1 -0
  36. data/ext/ruby_http_parser/vendor/http-parser-java/tests.dumped +154 -7
  37. data/ext/ruby_http_parser/vendor/http-parser-java/tests.utf8 +17 -0
  38. data/ext/ruby_http_parser/vendor/http-parser/LICENSE-MIT +1 -1
  39. data/ext/ruby_http_parser/vendor/http-parser/http_parser.c +52 -10
  40. data/ext/ruby_http_parser/vendor/http-parser/http_parser.h +3 -1
  41. data/ext/ruby_http_parser/vendor/http-parser/test.c +89 -3
  42. data/http_parser.rb.gemspec +8 -2
  43. data/lib/http_parser.rb +17 -0
  44. data/spec/parser_spec.rb +97 -6
  45. data/tasks/compile.rake +3 -1
  46. metadata +40 -27
  47. data/ext/ruby_http_parser/vendor/http-parser-java/CONTRIBUTIONS +0 -4
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "http_parser.rb"
3
- s.version = "0.5.1"
3
+ s.version = "0.5.2"
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
 
@@ -13,7 +13,13 @@ Gem::Specification.new do |s|
13
13
  s.require_paths = ["lib"]
14
14
  s.extensions = ["ext/ruby_http_parser/extconf.rb"]
15
15
 
16
- s.add_development_dependency 'rake-compiler', '>= 0.7.5'
16
+ s.add_development_dependency 'rake-compiler', '>= 0.7.9'
17
17
  s.add_development_dependency 'rspec', '>= 2.0.1'
18
18
  s.add_development_dependency 'json', '>= 1.4.6'
19
+
20
+ if RUBY_PLATFORM =~ /java/
21
+ s.add_development_dependency 'jruby-openssl'
22
+ else
23
+ s.add_development_dependency 'yajl-ruby', '>= 0.8.1'
24
+ end
19
25
  end
data/lib/http_parser.rb CHANGED
@@ -2,3 +2,20 @@ $:.unshift File.expand_path('../', __FILE__)
2
2
  require 'ruby_http_parser'
3
3
 
4
4
  Http = HTTP
5
+
6
+ module HTTP
7
+ class Parser
8
+ class << self
9
+ attr_reader :default_header_value_type
10
+
11
+ def default_header_value_type=(val)
12
+ if (val != :mixed && val != :strings && val != :arrays)
13
+ raise ArgumentError, "Invalid header value type"
14
+ end
15
+ @default_header_value_type = val
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ HTTP::Parser.default_header_value_type = :mixed
data/spec/parser_spec.rb CHANGED
@@ -27,8 +27,37 @@ describe HTTP::Parser do
27
27
  @parser.request_path.should be_nil
28
28
  @parser.query_string.should be_nil
29
29
  @parser.fragment.should be_nil
30
+
31
+ @parser.header_value_type.should == :mixed
32
+ end
33
+
34
+ it "should allow us to set the header value type" do
35
+ [:mixed, :arrays, :strings].each do |type|
36
+ @parser.header_value_type = type
37
+ @parser.header_value_type.should == type
38
+
39
+ parser_tmp = HTTP::Parser.new(nil, type)
40
+ parser_tmp.header_value_type.should == type
41
+ end
30
42
  end
31
43
 
44
+ it "should allow us to set the default header value type" do
45
+ [:mixed, :arrays, :strings].each do |type|
46
+ HTTP::Parser.default_header_value_type = type
47
+
48
+ parser = HTTP::Parser.new
49
+ parser.header_value_type.should == type
50
+ end
51
+ end
52
+
53
+ it "should throw an Argument Error if header value type is invalid" do
54
+ proc{ @parser.header_value_type = 'bob' }.should raise_error(ArgumentError)
55
+ end
56
+
57
+ it "should throw an Argument Error if default header value type is invalid" do
58
+ proc{ HTTP::Parser.default_header_value_type = 'bob' }.should raise_error(ArgumentError)
59
+ end
60
+
32
61
  it "should implement basic api" do
33
62
  @parser <<
34
63
  "GET /test?ok=1 HTTP/1.1\r\n" +
@@ -132,16 +161,57 @@ describe HTTP::Parser do
132
161
  }
133
162
  end
134
163
 
135
- it "should handle multiple headers" do
164
+ it "should handle multiple headers using strings" do
165
+ @parser.header_value_type = :strings
166
+
136
167
  @parser <<
137
168
  "GET / HTTP/1.0\r\n" +
138
- "Header: value 1\r\n" +
139
- "Header: value 2\r\n" +
169
+ "Set-Cookie: PREF=ID=a7d2c98; expires=Fri, 05-Apr-2013 05:00:45 GMT; path=/; domain=.bob.com\r\n" +
170
+ "Set-Cookie: NID=46jSHxPM; path=/; domain=.bob.com; HttpOnly\r\n" +
140
171
  "\r\n"
141
172
 
142
- @parser.headers.should == {
143
- 'Header' => 'value 1, value 2'
144
- }
173
+ @parser.headers["Set-Cookie"].should == "PREF=ID=a7d2c98; expires=Fri, 05-Apr-2013 05:00:45 GMT; path=/; domain=.bob.com, NID=46jSHxPM; path=/; domain=.bob.com; HttpOnly"
174
+ end
175
+
176
+ it "should handle multiple headers using strings" do
177
+ @parser.header_value_type = :arrays
178
+
179
+ @parser <<
180
+ "GET / HTTP/1.0\r\n" +
181
+ "Set-Cookie: PREF=ID=a7d2c98; expires=Fri, 05-Apr-2013 05:00:45 GMT; path=/; domain=.bob.com\r\n" +
182
+ "Set-Cookie: NID=46jSHxPM; path=/; domain=.bob.com; HttpOnly\r\n" +
183
+ "\r\n"
184
+
185
+ @parser.headers["Set-Cookie"].should == [
186
+ "PREF=ID=a7d2c98; expires=Fri, 05-Apr-2013 05:00:45 GMT; path=/; domain=.bob.com",
187
+ "NID=46jSHxPM; path=/; domain=.bob.com; HttpOnly"
188
+ ]
189
+ end
190
+
191
+ it "should handle multiple headers using mixed" do
192
+ @parser.header_value_type = :mixed
193
+
194
+ @parser <<
195
+ "GET / HTTP/1.0\r\n" +
196
+ "Set-Cookie: PREF=ID=a7d2c98; expires=Fri, 05-Apr-2013 05:00:45 GMT; path=/; domain=.bob.com\r\n" +
197
+ "Set-Cookie: NID=46jSHxPM; path=/; domain=.bob.com; HttpOnly\r\n" +
198
+ "\r\n"
199
+
200
+ @parser.headers["Set-Cookie"].should == [
201
+ "PREF=ID=a7d2c98; expires=Fri, 05-Apr-2013 05:00:45 GMT; path=/; domain=.bob.com",
202
+ "NID=46jSHxPM; path=/; domain=.bob.com; HttpOnly"
203
+ ]
204
+ end
205
+
206
+ it "should handle a single cookie using mixed" do
207
+ @parser.header_value_type = :mixed
208
+
209
+ @parser <<
210
+ "GET / HTTP/1.0\r\n" +
211
+ "Set-Cookie: PREF=ID=a7d2c98; expires=Fri, 05-Apr-2013 05:00:45 GMT; path=/; domain=.bob.com\r\n" +
212
+ "\r\n"
213
+
214
+ @parser.headers["Set-Cookie"].should == "PREF=ID=a7d2c98; expires=Fri, 05-Apr-2013 05:00:45 GMT; path=/; domain=.bob.com"
145
215
  end
146
216
 
147
217
  it "should support alternative api" do
@@ -172,6 +242,27 @@ describe HTTP::Parser do
172
242
  @done.should be_true
173
243
  end
174
244
 
245
+ it 'sets upgrade_data if available' do
246
+ @parser <<
247
+ "GET /demo HTTP/1.1\r\n" +
248
+ "Connection: Upgrade\r\n" +
249
+ "Upgrade: WebSocket\r\n\r\n" +
250
+ "third key data"
251
+
252
+ @parser.upgrade?.should be_true
253
+ @parser.upgrade_data.should == 'third key data'
254
+ end
255
+
256
+ it 'sets upgrade_data to blank if un-available' do
257
+ @parser <<
258
+ "GET /demo HTTP/1.1\r\n" +
259
+ "Connection: Upgrade\r\n" +
260
+ "Upgrade: WebSocket\r\n\r\n"
261
+
262
+ @parser.upgrade?.should be_true
263
+ @parser.upgrade_data.should == ''
264
+ end
265
+
175
266
  %w[ request response ].each do |type|
176
267
  JSON.parse(File.read(File.expand_path("../support/#{type}s.json", __FILE__))).each do |test|
177
268
  test['headers'] ||= {}
data/tasks/compile.rake CHANGED
@@ -10,7 +10,9 @@ Rake::GemPackageTask.new(gemspec) do |pkg|
10
10
  end
11
11
 
12
12
  if RUBY_PLATFORM =~ /java/
13
- Rake::JavaExtensionTask.new("ruby_http_parser", gemspec)
13
+ Rake::JavaExtensionTask.new("ruby_http_parser", gemspec) do |ext|
14
+ ext.classpath = File.expand_path('../../ext/ruby_http_parser/vendor/http-parser-java/ext/primitives.jar', __FILE__)
15
+ end
14
16
  else
15
17
  Rake::ExtensionTask.new("ruby_http_parser", gemspec) do |ext|
16
18
  unless RUBY_PLATFORM =~ /mswin|mingw/
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http_parser.rb
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 5
8
- - 1
9
- version: 0.5.1
4
+ prerelease:
5
+ version: 0.5.2
10
6
  platform: java
11
7
  authors:
12
8
  - Marc-Andre Cournoyer
@@ -15,34 +11,28 @@ autorequire:
15
11
  bindir: bin
16
12
  cert_chain: []
17
13
 
18
- date: 2011-01-25 00:00:00 -08:00
14
+ date: 2011-08-27 00:00:00 -07:00
19
15
  default_executable:
20
16
  dependencies:
21
17
  - !ruby/object:Gem::Dependency
22
18
  name: rake-compiler
23
19
  prerelease: false
24
20
  requirement: &id001 !ruby/object:Gem::Requirement
21
+ none: false
25
22
  requirements:
26
23
  - - ">="
27
24
  - !ruby/object:Gem::Version
28
- segments:
29
- - 0
30
- - 7
31
- - 5
32
- version: 0.7.5
25
+ version: 0.7.9
33
26
  type: :development
34
27
  version_requirements: *id001
35
28
  - !ruby/object:Gem::Dependency
36
29
  name: rspec
37
30
  prerelease: false
38
31
  requirement: &id002 !ruby/object:Gem::Requirement
32
+ none: false
39
33
  requirements:
40
34
  - - ">="
41
35
  - !ruby/object:Gem::Version
42
- segments:
43
- - 2
44
- - 0
45
- - 1
46
36
  version: 2.0.1
47
37
  type: :development
48
38
  version_requirements: *id002
@@ -50,16 +40,24 @@ dependencies:
50
40
  name: json
51
41
  prerelease: false
52
42
  requirement: &id003 !ruby/object:Gem::Requirement
43
+ none: false
53
44
  requirements:
54
45
  - - ">="
55
46
  - !ruby/object:Gem::Version
56
- segments:
57
- - 1
58
- - 4
59
- - 6
60
47
  version: 1.4.6
61
48
  type: :development
62
49
  version_requirements: *id003
50
+ - !ruby/object:Gem::Dependency
51
+ name: jruby-openssl
52
+ prerelease: false
53
+ requirement: &id004 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ type: :development
60
+ version_requirements: *id004
63
61
  description: Ruby bindings to http://github.com/ry/http-parser and http://github.com/a2800276/http-parser.java
64
62
  email:
65
63
  - macournoyer@gmail.com
@@ -75,6 +73,7 @@ files:
75
73
  - .gitmodules
76
74
  - Gemfile
77
75
  - Gemfile.lock
76
+ - LICENSE-MIT
78
77
  - README.md
79
78
  - Rakefile
80
79
  - bench/thin.rb
@@ -103,8 +102,8 @@ files:
103
102
  - ext/ruby_http_parser/vendor/http-parser/Makefile
104
103
  - ext/ruby_http_parser/vendor/http-parser/README.md
105
104
  - ext/ruby_http_parser/vendor/http-parser/test.c
105
+ - ext/ruby_http_parser/vendor/http-parser-java/build.xml
106
106
  - ext/ruby_http_parser/vendor/http-parser-java/compile
107
- - ext/ruby_http_parser/vendor/http-parser-java/CONTRIBUTIONS
108
107
  - ext/ruby_http_parser/vendor/http-parser-java/http_parser.c
109
108
  - ext/ruby_http_parser/vendor/http-parser-java/http_parser.h
110
109
  - ext/ruby_http_parser/vendor/http-parser-java/LICENSE-MIT
@@ -113,20 +112,36 @@ files:
113
112
  - ext/ruby_http_parser/vendor/http-parser-java/test.c
114
113
  - ext/ruby_http_parser/vendor/http-parser-java/test_permutations
115
114
  - ext/ruby_http_parser/vendor/http-parser-java/test_unit
115
+ - ext/ruby_http_parser/vendor/http-parser-java/test_utf8
116
116
  - ext/ruby_http_parser/vendor/http-parser-java/tests.dumped
117
+ - ext/ruby_http_parser/vendor/http-parser-java/tests.utf8
117
118
  - ext/ruby_http_parser/vendor/http-parser-java/TODO
119
+ - ext/ruby_http_parser/vendor/http-parser-java/ext/primitives.jar
120
+ - ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPCallback.java
121
+ - ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPDataCallback.java
122
+ - ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPErrorCallback.java
118
123
  - ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPException.java
119
124
  - ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPMethod.java
120
125
  - ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPParser.java
126
+ - ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/ParserSettings.java
121
127
  - ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/ParserType.java
128
+ - ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/Util.java
122
129
  - ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/lolevel/HTTPCallback.java
123
130
  - ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/lolevel/HTTPDataCallback.java
124
131
  - ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/lolevel/HTTPErrorCallback.java
125
132
  - ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/lolevel/HTTPParser.java
126
133
  - ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/lolevel/ParserSettings.java
127
- - ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/lolevel/Util.java
134
+ - ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Message.java
135
+ - ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Requests.java
136
+ - ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Responses.java
137
+ - ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Test.java
138
+ - ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/TestHeaderOverflowError.java
128
139
  - ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/TestLoaderNG.java
140
+ - ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/TestNoOverflowLongBody.java
129
141
  - ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/UnitTest.java
142
+ - ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Upgrade.java
143
+ - ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Util.java
144
+ - ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/WrongContentLength.java
130
145
  - ext/ruby_http_parser/vendor/http-parser-java/tools/byte_constants.rb
131
146
  - ext/ruby_http_parser/vendor/http-parser-java/tools/const_char.rb
132
147
  - ext/ruby_http_parser/vendor/http-parser-java/tools/lowcase.rb
@@ -142,23 +157,21 @@ rdoc_options: []
142
157
  require_paths:
143
158
  - lib
144
159
  required_ruby_version: !ruby/object:Gem::Requirement
160
+ none: false
145
161
  requirements:
146
162
  - - ">="
147
163
  - !ruby/object:Gem::Version
148
- segments:
149
- - 0
150
164
  version: "0"
151
165
  required_rubygems_version: !ruby/object:Gem::Requirement
166
+ none: false
152
167
  requirements:
153
168
  - - ">="
154
169
  - !ruby/object:Gem::Version
155
- segments:
156
- - 0
157
170
  version: "0"
158
171
  requirements: []
159
172
 
160
173
  rubyforge_project:
161
- rubygems_version: 1.3.6
174
+ rubygems_version: 1.5.1
162
175
  signing_key:
163
176
  specification_version: 3
164
177
  summary: Simple callback-based HTTP request/response parser
@@ -1,4 +0,0 @@
1
- Contributors must agree to the Contributor License Agreement before patches
2
- can be accepted.
3
-
4
- http://spreadsheets2.google.com/viewform?hl=en&formkey=dDJXOGUwbzlYaWM4cHN1MERwQS1CSnc6MQ