http_parser.rb 0.7.0 → 0.8.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 +4 -4
- data/.github/workflows/linux.yml +2 -2
- data/.github/workflows/windows.yml +2 -2
- data/Rakefile +3 -2
- data/ext/ruby_http_parser/ext_help.h +6 -1
- data/ext/ruby_http_parser/org/ruby_http_parser/RubyHttpParser.java +9 -23
- data/ext/ruby_http_parser/ruby_http_parser.c +31 -3
- data/http_parser.rb.gemspec +2 -2
- data/tasks/compile.rake +1 -1
- metadata +3 -10
- data/spec/parser_spec.rb +0 -401
- data/spec/spec_helper.rb +0 -1
- data/spec/support/requests.json +0 -612
- data/spec/support/responses.json +0 -395
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7fb5f5d030bfee30671d56b87acf02da0839051af33452843cef949f11dc5f14
|
|
4
|
+
data.tar.gz: d232aab15c4758a799a6cf9c59d315ecbd814259aba71bcc609728b651841e1b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 263ea218dabc076ae0b10b8ed63d1383263a11d7c9d42539fd0e0349e78ffc9fb38a9e731f76d83367d1354e5b0c4d345d79b79be7d87327012d39a879a3f62d
|
|
7
|
+
data.tar.gz: b8118b7aa966b1be6b315c956afe8d55d633e5f5dfa8fc9a3f28e53b1b31d7d32624c905de208b29804336afe9f4ae64f52b29615c84846bbf44e326b6a60f66
|
data/.github/workflows/linux.yml
CHANGED
|
@@ -8,11 +8,11 @@ jobs:
|
|
|
8
8
|
strategy:
|
|
9
9
|
fail-fast: false
|
|
10
10
|
matrix:
|
|
11
|
-
ruby: [ '
|
|
11
|
+
ruby: [ '3.1', '3.2', '3.3', '3.4', 'head' ]
|
|
12
12
|
os: [ 'ubuntu-latest' ]
|
|
13
13
|
name: Ruby ${{ matrix.ruby }} unit testing on ${{ matrix.os }}
|
|
14
14
|
steps:
|
|
15
|
-
- uses: actions/checkout@
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
16
|
- uses: ruby/setup-ruby@v1
|
|
17
17
|
with:
|
|
18
18
|
ruby-version: ${{ matrix.ruby }}
|
|
@@ -8,11 +8,11 @@ jobs:
|
|
|
8
8
|
strategy:
|
|
9
9
|
fail-fast: false
|
|
10
10
|
matrix:
|
|
11
|
-
ruby: [ '
|
|
11
|
+
ruby: [ '3.1', '3.2', '3.3', '3.4', 'head' ]
|
|
12
12
|
os: [ 'windows-latest' ]
|
|
13
13
|
name: Ruby ${{ matrix.ruby }} unit testing on ${{ matrix.os }}
|
|
14
14
|
steps:
|
|
15
|
-
- uses: actions/checkout@
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
16
|
- uses: ruby/setup-ruby@v1
|
|
17
17
|
with:
|
|
18
18
|
ruby-version: ${{ matrix.ruby }}
|
data/Rakefile
CHANGED
|
@@ -2,7 +2,12 @@
|
|
|
2
2
|
#define ext_help_h
|
|
3
3
|
|
|
4
4
|
#define RAISE_NOT_NULL(T) if(T == NULL) rb_raise(rb_eArgError, "NULL found for " # T " when shouldn't be.");
|
|
5
|
-
#
|
|
5
|
+
#ifdef TypedData_Get_Struct
|
|
6
|
+
#define DATA_GET_STRUCT(from,type,name) TypedData_Get_Struct(from,type,&type##_type,name)
|
|
7
|
+
#else
|
|
8
|
+
#define DATA_GET_STRUCT(from,type,name) Data_Get_Struct(from,type,name)
|
|
9
|
+
#endif
|
|
10
|
+
#define DATA_GET(from,type,name) DATA_GET_STRUCT(from,type,name); RAISE_NOT_NULL(name);
|
|
6
11
|
#define REQUIRE_TYPE(V, T) if(TYPE(V) != T) rb_raise(rb_eTypeError, "Wrong argument type for " # V " required " # T);
|
|
7
12
|
|
|
8
13
|
/* for compatibility with Ruby 1.8.5, which doesn't declare RSTRING_PTR */
|
|
@@ -8,6 +8,9 @@ import http_parser.lolevel.HTTPDataCallback;
|
|
|
8
8
|
import http_parser.lolevel.ParserSettings;
|
|
9
9
|
|
|
10
10
|
import java.nio.ByteBuffer;
|
|
11
|
+
import java.util.Arrays;
|
|
12
|
+
import java.util.ArrayList;
|
|
13
|
+
import java.util.List;
|
|
11
14
|
|
|
12
15
|
import org.jcodings.Encoding;
|
|
13
16
|
import org.jcodings.specific.UTF8Encoding;
|
|
@@ -64,7 +67,6 @@ public class RubyHttpParser extends RubyObject {
|
|
|
64
67
|
private IRubyObject on_body;
|
|
65
68
|
private IRubyObject on_message_complete;
|
|
66
69
|
|
|
67
|
-
private IRubyObject status;
|
|
68
70
|
private IRubyObject requestUrl;
|
|
69
71
|
private IRubyObject requestPath;
|
|
70
72
|
private IRubyObject queryString;
|
|
@@ -82,6 +84,10 @@ public class RubyHttpParser extends RubyObject {
|
|
|
82
84
|
|
|
83
85
|
private static final Encoding UTF8 = UTF8Encoding.INSTANCE;
|
|
84
86
|
|
|
87
|
+
private static final List<String> VALUE_TYPES = new ArrayList<String>(
|
|
88
|
+
Arrays.asList("mixed", "arrays", "strings")
|
|
89
|
+
);
|
|
90
|
+
|
|
85
91
|
public RubyHttpParser(final Ruby runtime, RubyClass clazz) {
|
|
86
92
|
super(runtime, clazz);
|
|
87
93
|
|
|
@@ -107,18 +113,6 @@ public class RubyHttpParser extends RubyObject {
|
|
|
107
113
|
private void initSettings() {
|
|
108
114
|
this.settings = new ParserSettings();
|
|
109
115
|
|
|
110
|
-
this.settings.on_status = new HTTPDataCallback() {
|
|
111
|
-
public int cb(http_parser.lolevel.HTTPParser p, ByteBuffer buf, int pos, int len) {
|
|
112
|
-
byte[] data = fetchBytes(buf, pos, len);
|
|
113
|
-
if (runtime.is1_9() || runtime.is2_0()) {
|
|
114
|
-
((RubyString) status).cat(data, 0, data.length, UTF8);
|
|
115
|
-
} else {
|
|
116
|
-
((RubyString) status).cat(data);
|
|
117
|
-
}
|
|
118
|
-
return 0;
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
|
|
122
116
|
this.settings.on_url = new HTTPDataCallback() {
|
|
123
117
|
public int cb(http_parser.lolevel.HTTPParser p, ByteBuffer buf, int pos, int len) {
|
|
124
118
|
byte[] data = fetchBytes(buf, pos, len);
|
|
@@ -215,14 +209,12 @@ public class RubyHttpParser extends RubyObject {
|
|
|
215
209
|
headers = new RubyHash(runtime);
|
|
216
210
|
|
|
217
211
|
if (runtime.is1_9() || runtime.is2_0()) {
|
|
218
|
-
status = RubyString.newEmptyString(runtime, UTF8);
|
|
219
212
|
requestUrl = RubyString.newEmptyString(runtime, UTF8);
|
|
220
213
|
requestPath = RubyString.newEmptyString(runtime, UTF8);
|
|
221
214
|
queryString = RubyString.newEmptyString(runtime, UTF8);
|
|
222
215
|
fragment = RubyString.newEmptyString(runtime, UTF8);
|
|
223
216
|
upgradeData = RubyString.newEmptyString(runtime, UTF8);
|
|
224
217
|
} else {
|
|
225
|
-
status = RubyString.newEmptyString(runtime);
|
|
226
218
|
requestUrl = RubyString.newEmptyString(runtime);
|
|
227
219
|
requestPath = RubyString.newEmptyString(runtime);
|
|
228
220
|
queryString = RubyString.newEmptyString(runtime);
|
|
@@ -324,8 +316,7 @@ public class RubyHttpParser extends RubyObject {
|
|
|
324
316
|
this.parser = new HTTPParser();
|
|
325
317
|
this.parser.HTTP_PARSER_STRICT = true;
|
|
326
318
|
this.headers = null;
|
|
327
|
-
|
|
328
|
-
this.status = runtime.getNil();
|
|
319
|
+
|
|
329
320
|
this.requestUrl = runtime.getNil();
|
|
330
321
|
this.requestPath = runtime.getNil();
|
|
331
322
|
this.queryString = runtime.getNil();
|
|
@@ -462,11 +453,6 @@ public class RubyHttpParser extends RubyObject {
|
|
|
462
453
|
return headers == null ? runtime.getNil() : headers;
|
|
463
454
|
}
|
|
464
455
|
|
|
465
|
-
@JRubyMethod(name = "status")
|
|
466
|
-
public IRubyObject getStatus() {
|
|
467
|
-
return status == null ? runtime.getNil() : status;
|
|
468
|
-
}
|
|
469
|
-
|
|
470
456
|
@JRubyMethod(name = "request_url")
|
|
471
457
|
public IRubyObject getRequestUrl() {
|
|
472
458
|
return requestUrl == null ? runtime.getNil() : requestUrl;
|
|
@@ -495,7 +481,7 @@ public class RubyHttpParser extends RubyObject {
|
|
|
495
481
|
@JRubyMethod(name = "header_value_type=")
|
|
496
482
|
public IRubyObject set_header_value_type(IRubyObject val) {
|
|
497
483
|
String valString = val.toString();
|
|
498
|
-
if (valString
|
|
484
|
+
if (!VALUE_TYPES.contains(valString)) {
|
|
499
485
|
throw runtime.newArgumentError("Invalid header value type");
|
|
500
486
|
}
|
|
501
487
|
header_value_type = val;
|
|
@@ -81,6 +81,14 @@ void ParserWrapper_free(void *data) {
|
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
+
static const rb_data_type_t ParserWrapper_type = {
|
|
85
|
+
"ParserWrapper",
|
|
86
|
+
{
|
|
87
|
+
ParserWrapper_mark,
|
|
88
|
+
ParserWrapper_free,
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
|
|
84
92
|
static VALUE cParser;
|
|
85
93
|
static VALUE cRequestParser;
|
|
86
94
|
static VALUE cResponseParser;
|
|
@@ -293,7 +301,7 @@ VALUE Parser_alloc_by_type(VALUE klass, enum ryah_http_parser_type type) {
|
|
|
293
301
|
|
|
294
302
|
ParserWrapper_init(wrapper);
|
|
295
303
|
|
|
296
|
-
return
|
|
304
|
+
return TypedData_Wrap_Struct(klass, &ParserWrapper_type, wrapper);
|
|
297
305
|
}
|
|
298
306
|
|
|
299
307
|
VALUE Parser_alloc(VALUE klass) {
|
|
@@ -316,7 +324,17 @@ VALUE Parser_initialize(int argc, VALUE *argv, VALUE self) {
|
|
|
316
324
|
ParserWrapper *wrapper = NULL;
|
|
317
325
|
DATA_GET(self, ParserWrapper, wrapper);
|
|
318
326
|
|
|
319
|
-
|
|
327
|
+
VALUE default_header_value_type = Qnil;
|
|
328
|
+
|
|
329
|
+
if (argc > 0 && RB_TYPE_P(argv[argc-1], T_HASH)) {
|
|
330
|
+
ID keyword_ids[1];
|
|
331
|
+
keyword_ids[0] = rb_intern("default_header_value_type");
|
|
332
|
+
rb_get_kwargs(argv[argc-1], keyword_ids, 0, 1, &default_header_value_type);
|
|
333
|
+
if (default_header_value_type == Qundef) {
|
|
334
|
+
default_header_value_type = Qnil;
|
|
335
|
+
}
|
|
336
|
+
--argc;
|
|
337
|
+
}
|
|
320
338
|
|
|
321
339
|
if (argc == 1) {
|
|
322
340
|
wrapper->callback_object = argv[0];
|
|
@@ -324,7 +342,13 @@ VALUE Parser_initialize(int argc, VALUE *argv, VALUE self) {
|
|
|
324
342
|
|
|
325
343
|
if (argc == 2) {
|
|
326
344
|
wrapper->callback_object = argv[0];
|
|
327
|
-
|
|
345
|
+
default_header_value_type = argv[1];
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
if (default_header_value_type == Qnil) {
|
|
349
|
+
wrapper->header_value_type = rb_iv_get(CLASS_OF(self), "@default_header_value_type");
|
|
350
|
+
} else {
|
|
351
|
+
wrapper->header_value_type = default_header_value_type;
|
|
328
352
|
}
|
|
329
353
|
|
|
330
354
|
return self;
|
|
@@ -489,6 +513,10 @@ VALUE Parser_reset(VALUE self) {
|
|
|
489
513
|
}
|
|
490
514
|
|
|
491
515
|
void Init_ruby_http_parser() {
|
|
516
|
+
#ifdef HAVE_RB_EXT_RACTOR_SAFE
|
|
517
|
+
rb_ext_ractor_safe(true);
|
|
518
|
+
#endif
|
|
519
|
+
|
|
492
520
|
VALUE mHTTP = rb_define_module("HTTP");
|
|
493
521
|
cParser = rb_define_class_under(mHTTP, "Parser", rb_cObject);
|
|
494
522
|
cRequestParser = rb_define_class_under(mHTTP, "RequestParser", cParser);
|
data/http_parser.rb.gemspec
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Gem::Specification.new do |s|
|
|
2
2
|
s.name = "http_parser.rb"
|
|
3
|
-
s.version = "0.
|
|
3
|
+
s.version = "0.8.1"
|
|
4
4
|
s.summary = "Simple callback-based HTTP request/response parser"
|
|
5
5
|
s.description = "Ruby bindings to https://github.com/joyent/http-parser and https://github.com/http-parser/http-parser.java"
|
|
6
6
|
|
|
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
|
|
|
9
9
|
s.license = 'MIT'
|
|
10
10
|
|
|
11
11
|
s.homepage = "https://github.com/tmm1/http_parser.rb"
|
|
12
|
-
s.files = `git ls-files`.split("\n") + Dir['ext/ruby_http_parser/vendor/**/*']
|
|
12
|
+
s.files = `git ls-files`.split("\n").grep_v(%r{spec/}) + Dir['ext/ruby_http_parser/vendor/**/*']
|
|
13
13
|
|
|
14
14
|
s.require_paths = ["lib"]
|
|
15
15
|
s.extensions = ["ext/ruby_http_parser/extconf.rb"]
|
data/tasks/compile.rake
CHANGED
metadata
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: http_parser.rb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.8.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Marc-Andre Cournoyer
|
|
8
8
|
- Aman Gupta
|
|
9
|
-
autorequire:
|
|
10
9
|
bindir: bin
|
|
11
10
|
cert_chain: []
|
|
12
|
-
date:
|
|
11
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
13
12
|
dependencies:
|
|
14
13
|
- !ruby/object:Gem::Dependency
|
|
15
14
|
name: rake-compiler
|
|
@@ -182,10 +181,6 @@ files:
|
|
|
182
181
|
- http_parser.rb.gemspec
|
|
183
182
|
- lib/http/parser.rb
|
|
184
183
|
- lib/http_parser.rb
|
|
185
|
-
- spec/parser_spec.rb
|
|
186
|
-
- spec/spec_helper.rb
|
|
187
|
-
- spec/support/requests.json
|
|
188
|
-
- spec/support/responses.json
|
|
189
184
|
- tasks/compile.rake
|
|
190
185
|
- tasks/fixtures.rake
|
|
191
186
|
- tasks/spec.rake
|
|
@@ -194,7 +189,6 @@ homepage: https://github.com/tmm1/http_parser.rb
|
|
|
194
189
|
licenses:
|
|
195
190
|
- MIT
|
|
196
191
|
metadata: {}
|
|
197
|
-
post_install_message:
|
|
198
192
|
rdoc_options: []
|
|
199
193
|
require_paths:
|
|
200
194
|
- lib
|
|
@@ -209,8 +203,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
209
203
|
- !ruby/object:Gem::Version
|
|
210
204
|
version: '0'
|
|
211
205
|
requirements: []
|
|
212
|
-
rubygems_version: 3.
|
|
213
|
-
signing_key:
|
|
206
|
+
rubygems_version: 3.6.9
|
|
214
207
|
specification_version: 4
|
|
215
208
|
summary: Simple callback-based HTTP request/response parser
|
|
216
209
|
test_files: []
|