midori_http_parser 0.6.1.3 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.gitmodules +0 -3
- data/.travis.yml +12 -17
- data/Gemfile +5 -0
- data/{LICENSE-MIT → LICENSE} +5 -2
- data/midori_http_parser.gemspec +3 -9
- data/spec/spec_helper.rb +8 -1
- data/tasks/compile.rake +7 -13
- metadata +5 -74
- data/ext/ruby_http_parser/RubyHttpParserService.java +0 -18
- data/ext/ruby_http_parser/org/ruby_http_parser/RubyHttpParser.java +0 -495
- data/ext/ruby_http_parser/vendor/http-parser-java/AUTHORS +0 -32
- data/ext/ruby_http_parser/vendor/http-parser-java/LICENSE-MIT +0 -48
- data/ext/ruby_http_parser/vendor/http-parser-java/README.md +0 -183
- data/ext/ruby_http_parser/vendor/http-parser-java/TODO +0 -28
- data/ext/ruby_http_parser/vendor/http-parser-java/build.xml +0 -74
- data/ext/ruby_http_parser/vendor/http-parser-java/http_parser.c +0 -2175
- data/ext/ruby_http_parser/vendor/http-parser-java/http_parser.gyp +0 -79
- data/ext/ruby_http_parser/vendor/http-parser-java/http_parser.h +0 -304
- data/ext/ruby_http_parser/vendor/http-parser-java/src/Http-parser.java.iml +0 -22
- data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/FieldData.java +0 -41
- data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPCallback.java +0 -8
- data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPDataCallback.java +0 -34
- data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPErrorCallback.java +0 -12
- data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPException.java +0 -9
- data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPMethod.java +0 -113
- data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPParser.java +0 -36
- data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPParserUrl.java +0 -76
- data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/ParserSettings.java +0 -256
- data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/ParserType.java +0 -13
- data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/Util.java +0 -111
- data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/lolevel/HTTPCallback.java +0 -5
- data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/lolevel/HTTPDataCallback.java +0 -25
- data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/lolevel/HTTPErrorCallback.java +0 -7
- data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/lolevel/HTTPParser.java +0 -2171
- data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/lolevel/ParserSettings.java +0 -83
- data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Message.java +0 -374
- data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/ParseUrl.java +0 -51
- data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Requests.java +0 -69
- data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Responses.java +0 -52
- data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Test.java +0 -16
- data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/TestHeaderOverflowError.java +0 -48
- data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/TestLoaderNG.java +0 -212
- data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/TestNoOverflowLongBody.java +0 -62
- data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/UnitTest.java +0 -117
- data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Upgrade.java +0 -27
- data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Url.java +0 -127
- data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Util.java +0 -236
- data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/WrongContentLength.java +0 -59
- data/ext/ruby_http_parser/vendor/http-parser-java/test.c +0 -3425
- data/ext/ruby_http_parser/vendor/http-parser-java/tests.dumped +0 -845
- data/ext/ruby_http_parser/vendor/http-parser-java/tests.utf8 +0 -17
- data/ext/ruby_http_parser/vendor/http-parser-java/tools/byte_constants.rb +0 -6
- data/ext/ruby_http_parser/vendor/http-parser-java/tools/const_char.rb +0 -13
- data/ext/ruby_http_parser/vendor/http-parser-java/tools/lowcase.rb +0 -15
- data/ext/ruby_http_parser/vendor/http-parser-java/tools/parse_tests.rb +0 -33
- data/ext/ruby_http_parser/vendor/http-parser/test_fast +0 -0
- data/ext/ruby_http_parser/vendor/http-parser/test_g +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 918559e2736b0cbdc13ba89b146f8bff7c9d66fd
|
4
|
+
data.tar.gz: 264a262e190a94ee1a5bb02834ded5cdfbce3370
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf77f2ffa1783e63da4de402431949630a0ccb5c28f477301deb758ddf5d24a40a32b3eccb4a18a824d162e245aa50f14a08f459d01e2fe7bcaae08abc66f814
|
7
|
+
data.tar.gz: 3103073e0a0678399357e9463cfa93974509ece403699839fe05f7ac2ff912c81d6e63453e38d851e9b275d21ea21973dccbf91b7209ca995b90f4eabc48fe3f
|
data/.gitignore
CHANGED
data/.gitmodules
CHANGED
data/.travis.yml
CHANGED
@@ -1,27 +1,15 @@
|
|
1
1
|
language: ruby
|
2
|
-
rvm: 2.
|
2
|
+
rvm: 2.2.7
|
3
3
|
sudo: false
|
4
4
|
matrix:
|
5
5
|
include:
|
6
|
-
- rvm: 2.2.
|
7
|
-
- rvm: 2.3.
|
8
|
-
- rvm: 2.4.
|
6
|
+
- rvm: 2.2.8
|
7
|
+
- rvm: 2.3.5
|
8
|
+
- rvm: 2.4.2
|
9
9
|
- rvm: ruby-head
|
10
|
-
- rvm: jruby-9.0.4.0
|
11
|
-
jdk: oraclejdk7
|
12
|
-
- rvm: jruby-9.0.4.0
|
13
|
-
jdk: oraclejdk8
|
14
|
-
- rvm: jruby-9.0.4.0
|
15
|
-
jdk: openjdk7
|
16
|
-
- rvm: jruby-head
|
17
|
-
jdk: oraclejdk7
|
18
|
-
- rvm: jruby-head
|
19
|
-
jdk: oraclejdk8
|
20
|
-
- rvm: jruby-head
|
21
|
-
jdk: openjdk7
|
22
10
|
allow_failures:
|
23
|
-
- rvm: jruby-head
|
24
11
|
- rvm: ruby-head
|
12
|
+
fast_finish: true
|
25
13
|
|
26
14
|
os:
|
27
15
|
- linux
|
@@ -29,5 +17,12 @@ os:
|
|
29
17
|
before_install:
|
30
18
|
- gem install bundler
|
31
19
|
|
20
|
+
script:
|
21
|
+
- gem list -l
|
22
|
+
- bundle exec rake compile
|
23
|
+
- bundle exec rake
|
24
|
+
- bundle exec codeclimate-test-reporter
|
25
|
+
- gem build ./midori_http_parser.gemspec
|
26
|
+
|
32
27
|
notifications:
|
33
28
|
email: false
|
data/Gemfile
CHANGED
data/{LICENSE-MIT → LICENSE}
RENAMED
@@ -1,5 +1,8 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2009-2010 Marc-André Cournoyer <macournoyer@gmail.com>
|
4
|
+
Copyright (c) 2010-2011 Aman Gupta <aman@tmm1.net>
|
5
|
+
Copyright (c) 2016-2017 Delton Ding <dsh0416@gmail.com>
|
3
6
|
|
4
7
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
8
|
of this software and associated documentation files (the "Software"), to
|
data/midori_http_parser.gemspec
CHANGED
@@ -1,18 +1,14 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "midori_http_parser"
|
3
|
-
s.version = "0.6.
|
3
|
+
s.version = "0.6.2"
|
4
4
|
s.summary = "Simple callback-based HTTP request/response parser"
|
5
5
|
s.description = "Fast Ruby Parser inpired by Node"
|
6
|
-
|
7
|
-
s.platform = 'java'
|
8
|
-
else
|
9
|
-
s.platform = 'ruby'
|
10
|
-
end
|
6
|
+
s.platform = 'ruby'
|
11
7
|
s.authors = ["Delton Ding"]
|
12
8
|
s.email = ["delton@heckpsi.com"]
|
13
9
|
s.license = 'MIT'
|
14
10
|
|
15
|
-
s.homepage = "https://github.com/
|
11
|
+
s.homepage = "https://github.com/midori-rb/http_parser.rb"
|
16
12
|
s.files = `git ls-files`.split("\n") + Dir['ext/ruby_http_parser/vendor/**/*']
|
17
13
|
|
18
14
|
s.require_paths = ["lib"]
|
@@ -23,6 +19,4 @@ Gem::Specification.new do |s|
|
|
23
19
|
s.add_development_dependency 'json', '>= 1.4.6'
|
24
20
|
s.add_development_dependency 'benchmark_suite'
|
25
21
|
s.add_development_dependency 'ffi'
|
26
|
-
|
27
|
-
s.add_development_dependency 'yajl-ruby', '>= 0.8.1' unless RUBY_PLATFORM =~ /java/
|
28
22
|
end
|
data/spec/spec_helper.rb
CHANGED
data/tasks/compile.rake
CHANGED
@@ -9,20 +9,14 @@ end
|
|
9
9
|
Gem::PackageTask.new(gemspec) do |pkg|
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
ext.
|
15
|
-
|
16
|
-
else
|
17
|
-
Rake::ExtensionTask.new("ruby_http_parser", gemspec) do |ext|
|
18
|
-
unless RUBY_PLATFORM =~ /mswin|mingw/
|
19
|
-
ext.cross_compile = true
|
20
|
-
ext.cross_platform = ['x86-mingw32', 'x86-mswin32-60']
|
12
|
+
Rake::ExtensionTask.new("ruby_http_parser", gemspec) do |ext|
|
13
|
+
unless RUBY_PLATFORM =~ /mswin|mingw/
|
14
|
+
ext.cross_compile = true
|
15
|
+
ext.cross_platform = ['x86-mingw32', 'x86-mswin32-60']
|
21
16
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
17
|
+
# inject 1.8/1.9 pure-ruby entry point
|
18
|
+
ext.cross_compiling do |spec|
|
19
|
+
spec.files += ['lib/ruby_http_parser.rb']
|
26
20
|
end
|
27
21
|
end
|
28
22
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: midori_http_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Delton Ding
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|
@@ -80,20 +80,6 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: yajl-ruby
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: 0.8.1
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: 0.8.1
|
97
83
|
description: Fast Ruby Parser inpired by Node
|
98
84
|
email:
|
99
85
|
- delton@heckpsi.com
|
@@ -106,65 +92,16 @@ files:
|
|
106
92
|
- ".gitmodules"
|
107
93
|
- ".travis.yml"
|
108
94
|
- Gemfile
|
109
|
-
- LICENSE
|
95
|
+
- LICENSE
|
110
96
|
- README.md
|
111
97
|
- Rakefile
|
112
98
|
- bench/standalone.rb
|
113
99
|
- bench/thin.rb
|
114
100
|
- ext/ruby_http_parser/.gitignore
|
115
|
-
- ext/ruby_http_parser/RubyHttpParserService.java
|
116
101
|
- ext/ruby_http_parser/ext_help.h
|
117
102
|
- ext/ruby_http_parser/extconf.rb
|
118
|
-
- ext/ruby_http_parser/org/ruby_http_parser/RubyHttpParser.java
|
119
103
|
- ext/ruby_http_parser/ruby_http_parser.c
|
120
104
|
- ext/ruby_http_parser/vendor/.gitkeep
|
121
|
-
- ext/ruby_http_parser/vendor/http-parser-java/AUTHORS
|
122
|
-
- ext/ruby_http_parser/vendor/http-parser-java/LICENSE-MIT
|
123
|
-
- ext/ruby_http_parser/vendor/http-parser-java/Makefile
|
124
|
-
- ext/ruby_http_parser/vendor/http-parser-java/README.md
|
125
|
-
- ext/ruby_http_parser/vendor/http-parser-java/TODO
|
126
|
-
- ext/ruby_http_parser/vendor/http-parser-java/build.xml
|
127
|
-
- ext/ruby_http_parser/vendor/http-parser-java/ext/primitives.jar
|
128
|
-
- ext/ruby_http_parser/vendor/http-parser-java/http_parser.c
|
129
|
-
- ext/ruby_http_parser/vendor/http-parser-java/http_parser.gyp
|
130
|
-
- ext/ruby_http_parser/vendor/http-parser-java/http_parser.h
|
131
|
-
- ext/ruby_http_parser/vendor/http-parser-java/src/Http-parser.java.iml
|
132
|
-
- ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/FieldData.java
|
133
|
-
- ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPCallback.java
|
134
|
-
- ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPDataCallback.java
|
135
|
-
- ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPErrorCallback.java
|
136
|
-
- ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPException.java
|
137
|
-
- ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPMethod.java
|
138
|
-
- ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPParser.java
|
139
|
-
- ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPParserUrl.java
|
140
|
-
- ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/ParserSettings.java
|
141
|
-
- ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/ParserType.java
|
142
|
-
- ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/Util.java
|
143
|
-
- ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/lolevel/HTTPCallback.java
|
144
|
-
- ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/lolevel/HTTPDataCallback.java
|
145
|
-
- ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/lolevel/HTTPErrorCallback.java
|
146
|
-
- ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/lolevel/HTTPParser.java
|
147
|
-
- ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/lolevel/ParserSettings.java
|
148
|
-
- ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Message.java
|
149
|
-
- ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/ParseUrl.java
|
150
|
-
- ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Requests.java
|
151
|
-
- ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Responses.java
|
152
|
-
- ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Test.java
|
153
|
-
- ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/TestHeaderOverflowError.java
|
154
|
-
- ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/TestLoaderNG.java
|
155
|
-
- ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/TestNoOverflowLongBody.java
|
156
|
-
- ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/UnitTest.java
|
157
|
-
- ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Upgrade.java
|
158
|
-
- ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Url.java
|
159
|
-
- ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Util.java
|
160
|
-
- ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/WrongContentLength.java
|
161
|
-
- ext/ruby_http_parser/vendor/http-parser-java/test.c
|
162
|
-
- ext/ruby_http_parser/vendor/http-parser-java/tests.dumped
|
163
|
-
- ext/ruby_http_parser/vendor/http-parser-java/tests.utf8
|
164
|
-
- ext/ruby_http_parser/vendor/http-parser-java/tools/byte_constants.rb
|
165
|
-
- ext/ruby_http_parser/vendor/http-parser-java/tools/const_char.rb
|
166
|
-
- ext/ruby_http_parser/vendor/http-parser-java/tools/lowcase.rb
|
167
|
-
- ext/ruby_http_parser/vendor/http-parser-java/tools/parse_tests.rb
|
168
105
|
- ext/ruby_http_parser/vendor/http-parser/AUTHORS
|
169
106
|
- ext/ruby_http_parser/vendor/http-parser/LICENSE-MIT
|
170
107
|
- ext/ruby_http_parser/vendor/http-parser/Makefile
|
@@ -175,13 +112,7 @@ files:
|
|
175
112
|
- ext/ruby_http_parser/vendor/http-parser/http_parser.c
|
176
113
|
- ext/ruby_http_parser/vendor/http-parser/http_parser.gyp
|
177
114
|
- ext/ruby_http_parser/vendor/http-parser/http_parser.h
|
178
|
-
- ext/ruby_http_parser/vendor/http-parser/http_parser.o
|
179
|
-
- ext/ruby_http_parser/vendor/http-parser/http_parser_g.o
|
180
115
|
- ext/ruby_http_parser/vendor/http-parser/test.c
|
181
|
-
- ext/ruby_http_parser/vendor/http-parser/test.o
|
182
|
-
- ext/ruby_http_parser/vendor/http-parser/test_fast
|
183
|
-
- ext/ruby_http_parser/vendor/http-parser/test_g
|
184
|
-
- ext/ruby_http_parser/vendor/http-parser/test_g.o
|
185
116
|
- lib/http/parser.rb
|
186
117
|
- lib/http_parser.rb
|
187
118
|
- midori_http_parser.gemspec
|
@@ -193,7 +124,7 @@ files:
|
|
193
124
|
- tasks/fixtures.rake
|
194
125
|
- tasks/spec.rake
|
195
126
|
- tasks/submodules.rake
|
196
|
-
homepage: https://github.com/
|
127
|
+
homepage: https://github.com/midori-rb/http_parser.rb
|
197
128
|
licenses:
|
198
129
|
- MIT
|
199
130
|
metadata: {}
|
@@ -213,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
213
144
|
version: '0'
|
214
145
|
requirements: []
|
215
146
|
rubyforge_project:
|
216
|
-
rubygems_version: 2.6.
|
147
|
+
rubygems_version: 2.6.10
|
217
148
|
signing_key:
|
218
149
|
specification_version: 4
|
219
150
|
summary: Simple callback-based HTTP request/response parser
|
@@ -1,18 +0,0 @@
|
|
1
|
-
import java.io.IOException;
|
2
|
-
|
3
|
-
import org.jruby.Ruby;
|
4
|
-
import org.jruby.RubyClass;
|
5
|
-
import org.jruby.RubyModule;
|
6
|
-
import org.jruby.runtime.load.BasicLibraryService;
|
7
|
-
|
8
|
-
import org.ruby_http_parser.*;
|
9
|
-
|
10
|
-
public class RubyHttpParserService implements BasicLibraryService {
|
11
|
-
public boolean basicLoad(final Ruby runtime) throws IOException {
|
12
|
-
RubyModule mHTTP = runtime.defineModule("HTTP");
|
13
|
-
RubyClass cParser = mHTTP.defineClassUnder("Parser", runtime.getObject(), RubyHttpParser.ALLOCATOR);
|
14
|
-
cParser.defineAnnotatedMethods(RubyHttpParser.class);
|
15
|
-
cParser.defineClassUnder("Error", runtime.getClass("IOError"),runtime.getClass("IOError").getAllocator());
|
16
|
-
return true;
|
17
|
-
}
|
18
|
-
}
|
@@ -1,495 +0,0 @@
|
|
1
|
-
package org.ruby_http_parser;
|
2
|
-
|
3
|
-
import http_parser.HTTPException;
|
4
|
-
import http_parser.HTTPMethod;
|
5
|
-
import http_parser.HTTPParser;
|
6
|
-
import http_parser.lolevel.HTTPCallback;
|
7
|
-
import http_parser.lolevel.HTTPDataCallback;
|
8
|
-
import http_parser.lolevel.ParserSettings;
|
9
|
-
|
10
|
-
import java.nio.ByteBuffer;
|
11
|
-
|
12
|
-
import org.jcodings.Encoding;
|
13
|
-
import org.jcodings.specific.UTF8Encoding;
|
14
|
-
import org.jruby.Ruby;
|
15
|
-
import org.jruby.RubyArray;
|
16
|
-
import org.jruby.RubyClass;
|
17
|
-
import org.jruby.RubyHash;
|
18
|
-
import org.jruby.RubyNumeric;
|
19
|
-
import org.jruby.RubyObject;
|
20
|
-
import org.jruby.RubyString;
|
21
|
-
import org.jruby.RubySymbol;
|
22
|
-
import org.jruby.anno.JRubyMethod;
|
23
|
-
import org.jruby.exceptions.RaiseException;
|
24
|
-
import org.jruby.runtime.ObjectAllocator;
|
25
|
-
import org.jruby.runtime.ThreadContext;
|
26
|
-
import org.jruby.runtime.builtin.IRubyObject;
|
27
|
-
import org.jruby.util.ByteList;
|
28
|
-
|
29
|
-
public class RubyHttpParser extends RubyObject {
|
30
|
-
|
31
|
-
@JRubyMethod(name = "strict?", module = true)
|
32
|
-
public static IRubyObject strict(IRubyObject recv) {
|
33
|
-
return recv.getRuntime().newBoolean(true);
|
34
|
-
}
|
35
|
-
|
36
|
-
public static ObjectAllocator ALLOCATOR = new ObjectAllocator() {
|
37
|
-
public IRubyObject allocate(Ruby runtime, RubyClass klass) {
|
38
|
-
return new RubyHttpParser(runtime, klass);
|
39
|
-
}
|
40
|
-
};
|
41
|
-
|
42
|
-
byte[] fetchBytes(ByteBuffer b, int pos, int len) {
|
43
|
-
byte[] by = new byte[len];
|
44
|
-
int saved = b.position();
|
45
|
-
b.position(pos);
|
46
|
-
b.get(by);
|
47
|
-
b.position(saved);
|
48
|
-
return by;
|
49
|
-
}
|
50
|
-
|
51
|
-
public class StopException extends RuntimeException {
|
52
|
-
}
|
53
|
-
|
54
|
-
private Ruby runtime;
|
55
|
-
private HTTPParser parser;
|
56
|
-
private ParserSettings settings;
|
57
|
-
|
58
|
-
private RubyClass eParserError;
|
59
|
-
|
60
|
-
private RubyHash headers;
|
61
|
-
|
62
|
-
private IRubyObject on_message_begin;
|
63
|
-
private IRubyObject on_headers_complete;
|
64
|
-
private IRubyObject on_body;
|
65
|
-
private IRubyObject on_message_complete;
|
66
|
-
|
67
|
-
private IRubyObject requestUrl;
|
68
|
-
private IRubyObject requestPath;
|
69
|
-
private IRubyObject queryString;
|
70
|
-
private IRubyObject fragment;
|
71
|
-
|
72
|
-
private IRubyObject header_value_type;
|
73
|
-
private IRubyObject upgradeData;
|
74
|
-
|
75
|
-
private IRubyObject callback_object;
|
76
|
-
|
77
|
-
private boolean completed;
|
78
|
-
|
79
|
-
private byte[] _current_header;
|
80
|
-
private byte[] _last_header;
|
81
|
-
|
82
|
-
private static final Encoding UTF8 = UTF8Encoding.INSTANCE;
|
83
|
-
|
84
|
-
public RubyHttpParser(final Ruby runtime, RubyClass clazz) {
|
85
|
-
super(runtime, clazz);
|
86
|
-
|
87
|
-
this.runtime = runtime;
|
88
|
-
this.eParserError = (RubyClass) runtime.getModule("HTTP").getClass("Parser").getConstant("Error");
|
89
|
-
|
90
|
-
this.on_message_begin = null;
|
91
|
-
this.on_headers_complete = null;
|
92
|
-
this.on_body = null;
|
93
|
-
this.on_message_complete = null;
|
94
|
-
|
95
|
-
this.callback_object = null;
|
96
|
-
|
97
|
-
this.completed = false;
|
98
|
-
|
99
|
-
this.header_value_type = runtime.getModule("HTTP").getClass("Parser")
|
100
|
-
.getInstanceVariable("@default_header_value_type");
|
101
|
-
|
102
|
-
initSettings();
|
103
|
-
init();
|
104
|
-
}
|
105
|
-
|
106
|
-
private void initSettings() {
|
107
|
-
this.settings = new ParserSettings();
|
108
|
-
|
109
|
-
this.settings.on_url = new HTTPDataCallback() {
|
110
|
-
public int cb(http_parser.lolevel.HTTPParser p, ByteBuffer buf, int pos, int len) {
|
111
|
-
byte[] data = fetchBytes(buf, pos, len);
|
112
|
-
if (runtime.is1_9() || runtime.is2_0()) {
|
113
|
-
((RubyString) requestUrl).cat(data, 0, data.length, UTF8);
|
114
|
-
} else {
|
115
|
-
((RubyString) requestUrl).cat(data);
|
116
|
-
}
|
117
|
-
return 0;
|
118
|
-
}
|
119
|
-
};
|
120
|
-
|
121
|
-
this.settings.on_header_field = new HTTPDataCallback() {
|
122
|
-
public int cb(http_parser.lolevel.HTTPParser p, ByteBuffer buf, int pos, int len) {
|
123
|
-
byte[] data = fetchBytes(buf, pos, len);
|
124
|
-
|
125
|
-
if (_current_header == null)
|
126
|
-
_current_header = data;
|
127
|
-
else {
|
128
|
-
byte[] tmp = new byte[_current_header.length + data.length];
|
129
|
-
System.arraycopy(_current_header, 0, tmp, 0, _current_header.length);
|
130
|
-
System.arraycopy(data, 0, tmp, _current_header.length, data.length);
|
131
|
-
_current_header = tmp;
|
132
|
-
}
|
133
|
-
|
134
|
-
return 0;
|
135
|
-
}
|
136
|
-
};
|
137
|
-
final RubySymbol arraysSym = runtime.newSymbol("arrays");
|
138
|
-
final RubySymbol mixedSym = runtime.newSymbol("mixed");
|
139
|
-
final RubySymbol stopSym = runtime.newSymbol("stop");
|
140
|
-
final RubySymbol resetSym = runtime.newSymbol("reset");
|
141
|
-
this.settings.on_header_value = new HTTPDataCallback() {
|
142
|
-
public int cb(http_parser.lolevel.HTTPParser p, ByteBuffer buf, int pos, int len) {
|
143
|
-
byte[] data = fetchBytes(buf, pos, len);
|
144
|
-
ThreadContext context = headers.getRuntime().getCurrentContext();
|
145
|
-
IRubyObject key, val;
|
146
|
-
int new_field = 0;
|
147
|
-
|
148
|
-
if (_current_header != null) {
|
149
|
-
new_field = 1;
|
150
|
-
_last_header = _current_header;
|
151
|
-
_current_header = null;
|
152
|
-
}
|
153
|
-
|
154
|
-
key = RubyString.newString(runtime, new ByteList(_last_header, UTF8, false));
|
155
|
-
val = headers.op_aref(context, key);
|
156
|
-
|
157
|
-
if (new_field == 1) {
|
158
|
-
if (val.isNil()) {
|
159
|
-
if (header_value_type == arraysSym) {
|
160
|
-
headers.op_aset(context, key,
|
161
|
-
RubyArray.newArrayLight(runtime, RubyString.newStringLight(runtime, 10, UTF8)));
|
162
|
-
} else {
|
163
|
-
headers.op_aset(context, key, RubyString.newStringLight(runtime, 10, UTF8));
|
164
|
-
}
|
165
|
-
} else {
|
166
|
-
if (header_value_type == mixedSym) {
|
167
|
-
if (val instanceof RubyString) {
|
168
|
-
headers.op_aset(context, key,
|
169
|
-
RubyArray.newArrayLight(runtime, val, RubyString.newStringLight(runtime, 10, UTF8)));
|
170
|
-
} else {
|
171
|
-
((RubyArray) val).add(RubyString.newStringLight(runtime, 10, UTF8));
|
172
|
-
}
|
173
|
-
} else if (header_value_type == arraysSym) {
|
174
|
-
((RubyArray) val).add(RubyString.newStringLight(runtime, 10, UTF8));
|
175
|
-
} else {
|
176
|
-
if (runtime.is1_9() || runtime.is2_0()) {
|
177
|
-
((RubyString) val).cat(',', UTF8).cat(' ', UTF8);
|
178
|
-
} else {
|
179
|
-
((RubyString) val).cat(',').cat(' ');
|
180
|
-
}
|
181
|
-
}
|
182
|
-
}
|
183
|
-
val = headers.op_aref(context, key);
|
184
|
-
}
|
185
|
-
|
186
|
-
if (val instanceof RubyArray) {
|
187
|
-
val = ((RubyArray) val).entry(-1);
|
188
|
-
}
|
189
|
-
|
190
|
-
if (runtime.is1_9() || runtime.is2_0()) {
|
191
|
-
((RubyString) val).cat(data, 0, data.length, UTF8);
|
192
|
-
} else {
|
193
|
-
((RubyString) val).cat(data);
|
194
|
-
}
|
195
|
-
|
196
|
-
return 0;
|
197
|
-
}
|
198
|
-
};
|
199
|
-
|
200
|
-
this.settings.on_message_begin = new HTTPCallback() {
|
201
|
-
public int cb(http_parser.lolevel.HTTPParser p) {
|
202
|
-
headers = new RubyHash(runtime);
|
203
|
-
|
204
|
-
if (runtime.is1_9() || runtime.is2_0()) {
|
205
|
-
requestUrl = RubyString.newEmptyString(runtime, UTF8);
|
206
|
-
requestPath = RubyString.newEmptyString(runtime, UTF8);
|
207
|
-
queryString = RubyString.newEmptyString(runtime, UTF8);
|
208
|
-
fragment = RubyString.newEmptyString(runtime, UTF8);
|
209
|
-
upgradeData = RubyString.newEmptyString(runtime, UTF8);
|
210
|
-
} else {
|
211
|
-
requestUrl = RubyString.newEmptyString(runtime);
|
212
|
-
requestPath = RubyString.newEmptyString(runtime);
|
213
|
-
queryString = RubyString.newEmptyString(runtime);
|
214
|
-
fragment = RubyString.newEmptyString(runtime);
|
215
|
-
upgradeData = RubyString.newEmptyString(runtime);
|
216
|
-
}
|
217
|
-
|
218
|
-
IRubyObject ret = runtime.getNil();
|
219
|
-
|
220
|
-
if (callback_object != null) {
|
221
|
-
if (((RubyObject) callback_object).respondsTo("on_message_begin")) {
|
222
|
-
ThreadContext context = callback_object.getRuntime().getCurrentContext();
|
223
|
-
ret = callback_object.callMethod(context, "on_message_begin");
|
224
|
-
}
|
225
|
-
} else if (on_message_begin != null) {
|
226
|
-
ThreadContext context = on_message_begin.getRuntime().getCurrentContext();
|
227
|
-
ret = on_message_begin.callMethod(context, "call");
|
228
|
-
}
|
229
|
-
|
230
|
-
if (ret == stopSym) {
|
231
|
-
throw new StopException();
|
232
|
-
} else {
|
233
|
-
return 0;
|
234
|
-
}
|
235
|
-
}
|
236
|
-
};
|
237
|
-
this.settings.on_message_complete = new HTTPCallback() {
|
238
|
-
public int cb(http_parser.lolevel.HTTPParser p) {
|
239
|
-
IRubyObject ret = runtime.getNil();
|
240
|
-
|
241
|
-
completed = true;
|
242
|
-
|
243
|
-
if (callback_object != null) {
|
244
|
-
if (((RubyObject) callback_object).respondsTo("on_message_complete")) {
|
245
|
-
ThreadContext context = callback_object.getRuntime().getCurrentContext();
|
246
|
-
ret = callback_object.callMethod(context, "on_message_complete");
|
247
|
-
}
|
248
|
-
} else if (on_message_complete != null) {
|
249
|
-
ThreadContext context = on_message_complete.getRuntime().getCurrentContext();
|
250
|
-
ret = on_message_complete.callMethod(context, "call");
|
251
|
-
}
|
252
|
-
|
253
|
-
if (ret == stopSym) {
|
254
|
-
throw new StopException();
|
255
|
-
} else {
|
256
|
-
return 0;
|
257
|
-
}
|
258
|
-
}
|
259
|
-
};
|
260
|
-
this.settings.on_headers_complete = new HTTPCallback() {
|
261
|
-
public int cb(http_parser.lolevel.HTTPParser p) {
|
262
|
-
IRubyObject ret = runtime.getNil();
|
263
|
-
|
264
|
-
if (callback_object != null) {
|
265
|
-
if (((RubyObject) callback_object).respondsTo("on_headers_complete")) {
|
266
|
-
ThreadContext context = callback_object.getRuntime().getCurrentContext();
|
267
|
-
ret = callback_object.callMethod(context, "on_headers_complete", headers);
|
268
|
-
}
|
269
|
-
} else if (on_headers_complete != null) {
|
270
|
-
ThreadContext context = on_headers_complete.getRuntime().getCurrentContext();
|
271
|
-
ret = on_headers_complete.callMethod(context, "call", headers);
|
272
|
-
}
|
273
|
-
|
274
|
-
if (ret == stopSym) {
|
275
|
-
throw new StopException();
|
276
|
-
} else if (ret == resetSym) {
|
277
|
-
return 1;
|
278
|
-
} else {
|
279
|
-
return 0;
|
280
|
-
}
|
281
|
-
}
|
282
|
-
};
|
283
|
-
this.settings.on_body = new HTTPDataCallback() {
|
284
|
-
public int cb(http_parser.lolevel.HTTPParser p, ByteBuffer buf, int pos, int len) {
|
285
|
-
IRubyObject ret = runtime.getNil();
|
286
|
-
byte[] data = fetchBytes(buf, pos, len);
|
287
|
-
|
288
|
-
if (callback_object != null) {
|
289
|
-
if (((RubyObject) callback_object).respondsTo("on_body")) {
|
290
|
-
ThreadContext context = callback_object.getRuntime().getCurrentContext();
|
291
|
-
ret = callback_object.callMethod(context, "on_body",
|
292
|
-
RubyString.newString(runtime, new ByteList(data, UTF8, false)));
|
293
|
-
}
|
294
|
-
} else if (on_body != null) {
|
295
|
-
ThreadContext context = on_body.getRuntime().getCurrentContext();
|
296
|
-
ret = on_body.callMethod(context, "call", RubyString.newString(runtime, new ByteList(data, UTF8, false)));
|
297
|
-
}
|
298
|
-
|
299
|
-
if (ret == stopSym) {
|
300
|
-
throw new StopException();
|
301
|
-
} else {
|
302
|
-
return 0;
|
303
|
-
}
|
304
|
-
}
|
305
|
-
};
|
306
|
-
}
|
307
|
-
|
308
|
-
private void init() {
|
309
|
-
this.parser = new HTTPParser();
|
310
|
-
this.parser.HTTP_PARSER_STRICT = true;
|
311
|
-
this.headers = null;
|
312
|
-
|
313
|
-
this.requestUrl = runtime.getNil();
|
314
|
-
this.requestPath = runtime.getNil();
|
315
|
-
this.queryString = runtime.getNil();
|
316
|
-
this.fragment = runtime.getNil();
|
317
|
-
|
318
|
-
this.upgradeData = runtime.getNil();
|
319
|
-
}
|
320
|
-
|
321
|
-
@JRubyMethod(name = "initialize")
|
322
|
-
public IRubyObject initialize() {
|
323
|
-
return this;
|
324
|
-
}
|
325
|
-
|
326
|
-
@JRubyMethod(name = "initialize")
|
327
|
-
public IRubyObject initialize(IRubyObject arg) {
|
328
|
-
callback_object = arg;
|
329
|
-
return initialize();
|
330
|
-
}
|
331
|
-
|
332
|
-
@JRubyMethod(name = "initialize")
|
333
|
-
public IRubyObject initialize(IRubyObject arg, IRubyObject arg2) {
|
334
|
-
header_value_type = arg2;
|
335
|
-
return initialize(arg);
|
336
|
-
}
|
337
|
-
|
338
|
-
@JRubyMethod(name = "on_message_begin=")
|
339
|
-
public IRubyObject set_on_message_begin(IRubyObject cb) {
|
340
|
-
on_message_begin = cb;
|
341
|
-
return cb;
|
342
|
-
}
|
343
|
-
|
344
|
-
@JRubyMethod(name = "on_headers_complete=")
|
345
|
-
public IRubyObject set_on_headers_complete(IRubyObject cb) {
|
346
|
-
on_headers_complete = cb;
|
347
|
-
return cb;
|
348
|
-
}
|
349
|
-
|
350
|
-
@JRubyMethod(name = "on_body=")
|
351
|
-
public IRubyObject set_on_body(IRubyObject cb) {
|
352
|
-
on_body = cb;
|
353
|
-
return cb;
|
354
|
-
}
|
355
|
-
|
356
|
-
@JRubyMethod(name = "on_message_complete=")
|
357
|
-
public IRubyObject set_on_message_complete(IRubyObject cb) {
|
358
|
-
on_message_complete = cb;
|
359
|
-
return cb;
|
360
|
-
}
|
361
|
-
|
362
|
-
@JRubyMethod(name = "<<")
|
363
|
-
public IRubyObject execute(IRubyObject data) {
|
364
|
-
RubyString str = (RubyString) data;
|
365
|
-
ByteList byteList = str.getByteList();
|
366
|
-
ByteBuffer buf = ByteBuffer.wrap(byteList.getUnsafeBytes(), byteList.getBegin(), byteList.getRealSize());
|
367
|
-
boolean stopped = false;
|
368
|
-
|
369
|
-
try {
|
370
|
-
this.parser.execute(this.settings, buf);
|
371
|
-
} catch (HTTPException e) {
|
372
|
-
throw new RaiseException(runtime, eParserError, e.getMessage(), true);
|
373
|
-
} catch (StopException e) {
|
374
|
-
stopped = true;
|
375
|
-
}
|
376
|
-
|
377
|
-
if (parser.getUpgrade()) {
|
378
|
-
byte[] upData = fetchBytes(buf, buf.position(), buf.limit() - buf.position());
|
379
|
-
if (runtime.is1_9() || runtime.is2_0()) {
|
380
|
-
((RubyString) upgradeData).cat(upData, 0, upData.length, UTF8);
|
381
|
-
} else {
|
382
|
-
((RubyString) upgradeData).cat(upData);
|
383
|
-
}
|
384
|
-
} else if (buf.hasRemaining() && !completed) {
|
385
|
-
if (!stopped)
|
386
|
-
throw new RaiseException(runtime, eParserError, "Could not parse data entirely", true);
|
387
|
-
}
|
388
|
-
|
389
|
-
return RubyNumeric.int2fix(runtime, buf.position());
|
390
|
-
}
|
391
|
-
|
392
|
-
@JRubyMethod(name = "keep_alive?")
|
393
|
-
public IRubyObject shouldKeepAlive() {
|
394
|
-
return runtime.newBoolean(parser.shouldKeepAlive());
|
395
|
-
}
|
396
|
-
|
397
|
-
@JRubyMethod(name = "upgrade?")
|
398
|
-
public IRubyObject shouldUpgrade() {
|
399
|
-
return runtime.newBoolean(parser.getUpgrade());
|
400
|
-
}
|
401
|
-
|
402
|
-
@JRubyMethod(name = "http_major")
|
403
|
-
public IRubyObject httpMajor() {
|
404
|
-
if (parser.getMajor() == 0 && parser.getMinor() == 0)
|
405
|
-
return runtime.getNil();
|
406
|
-
else
|
407
|
-
return RubyNumeric.int2fix(runtime, parser.getMajor());
|
408
|
-
}
|
409
|
-
|
410
|
-
@JRubyMethod(name = "http_minor")
|
411
|
-
public IRubyObject httpMinor() {
|
412
|
-
if (parser.getMajor() == 0 && parser.getMinor() == 0)
|
413
|
-
return runtime.getNil();
|
414
|
-
else
|
415
|
-
return RubyNumeric.int2fix(runtime, parser.getMinor());
|
416
|
-
}
|
417
|
-
|
418
|
-
@JRubyMethod(name = "http_version")
|
419
|
-
public IRubyObject httpVersion() {
|
420
|
-
if (parser.getMajor() == 0 && parser.getMinor() == 0)
|
421
|
-
return runtime.getNil();
|
422
|
-
else
|
423
|
-
return runtime.newArray(httpMajor(), httpMinor());
|
424
|
-
}
|
425
|
-
|
426
|
-
@JRubyMethod(name = "http_method")
|
427
|
-
public IRubyObject httpMethod() {
|
428
|
-
HTTPMethod method = parser.getHTTPMethod();
|
429
|
-
if (method != null)
|
430
|
-
return runtime.newString(new String(method.bytes));
|
431
|
-
else
|
432
|
-
return runtime.getNil();
|
433
|
-
}
|
434
|
-
|
435
|
-
@JRubyMethod(name = "status_code")
|
436
|
-
public IRubyObject statusCode() {
|
437
|
-
int code = parser.getStatusCode();
|
438
|
-
if (code != 0)
|
439
|
-
return RubyNumeric.int2fix(runtime, code);
|
440
|
-
else
|
441
|
-
return runtime.getNil();
|
442
|
-
}
|
443
|
-
|
444
|
-
@JRubyMethod(name = "headers")
|
445
|
-
public IRubyObject getHeaders() {
|
446
|
-
return headers == null ? runtime.getNil() : headers;
|
447
|
-
}
|
448
|
-
|
449
|
-
@JRubyMethod(name = "request_url")
|
450
|
-
public IRubyObject getRequestUrl() {
|
451
|
-
return requestUrl == null ? runtime.getNil() : requestUrl;
|
452
|
-
}
|
453
|
-
|
454
|
-
@JRubyMethod(name = "request_path")
|
455
|
-
public IRubyObject getRequestPath() {
|
456
|
-
return requestPath == null ? runtime.getNil() : requestPath;
|
457
|
-
}
|
458
|
-
|
459
|
-
@JRubyMethod(name = "query_string")
|
460
|
-
public IRubyObject getQueryString() {
|
461
|
-
return queryString == null ? runtime.getNil() : queryString;
|
462
|
-
}
|
463
|
-
|
464
|
-
@JRubyMethod(name = "fragment")
|
465
|
-
public IRubyObject getFragment() {
|
466
|
-
return fragment == null ? runtime.getNil() : fragment;
|
467
|
-
}
|
468
|
-
|
469
|
-
@JRubyMethod(name = "header_value_type")
|
470
|
-
public IRubyObject getHeaderValueType() {
|
471
|
-
return header_value_type == null ? runtime.getNil() : header_value_type;
|
472
|
-
}
|
473
|
-
|
474
|
-
@JRubyMethod(name = "header_value_type=")
|
475
|
-
public IRubyObject set_header_value_type(IRubyObject val) {
|
476
|
-
String valString = val.toString();
|
477
|
-
if (valString != "mixed" && valString != "arrays" && valString != "strings") {
|
478
|
-
throw runtime.newArgumentError("Invalid header value type");
|
479
|
-
}
|
480
|
-
header_value_type = val;
|
481
|
-
return val;
|
482
|
-
}
|
483
|
-
|
484
|
-
@JRubyMethod(name = "upgrade_data")
|
485
|
-
public IRubyObject upgradeData() {
|
486
|
-
return upgradeData == null ? runtime.getNil() : upgradeData;
|
487
|
-
}
|
488
|
-
|
489
|
-
@JRubyMethod(name = "reset!")
|
490
|
-
public IRubyObject reset() {
|
491
|
-
init();
|
492
|
-
return runtime.getTrue();
|
493
|
-
}
|
494
|
-
|
495
|
-
}
|