llhttp 0.4.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +32 -22
- data/ext/llhttp/api.c +95 -25
- data/ext/llhttp/http.c +2 -24
- data/ext/llhttp/llhttp.c +5453 -2170
- data/ext/llhttp/llhttp.h +266 -38
- data/ext/llhttp/llhttp_ext.c +106 -69
- data/lib/llhttp/version.rb +1 -1
- metadata +5 -5
data/ext/llhttp/llhttp_ext.c
CHANGED
@@ -10,34 +10,43 @@
|
|
10
10
|
|
11
11
|
static VALUE mLLHttp, cParser, eError;
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
13
|
+
typedef struct {
|
14
|
+
VALUE delegate;
|
15
|
+
ID on_message_begin;
|
16
|
+
ID on_url;
|
17
|
+
ID on_status;
|
18
|
+
ID on_header_field;
|
19
|
+
ID on_header_value;
|
20
|
+
ID on_headers_complete;
|
21
|
+
ID on_body;
|
22
|
+
ID on_message_complete;
|
23
|
+
ID on_chunk_header;
|
24
|
+
ID on_chunk_complete;
|
25
|
+
ID on_url_complete;
|
26
|
+
ID on_status_complete;
|
27
|
+
ID on_header_field_complete;
|
28
|
+
ID on_header_value_complete;
|
29
|
+
} rb_llhttp_parser_data;
|
27
30
|
|
28
31
|
static void rb_llhttp_free(llhttp_t *parser) {
|
29
|
-
|
32
|
+
rb_llhttp_parser_data *parserData = (rb_llhttp_parser_data*) parser->data;
|
33
|
+
|
34
|
+
// If `parserData` is not `0`, it (and settings) were initialized.
|
35
|
+
//
|
36
|
+
if (parserData != 0) {
|
37
|
+
free(parserData);
|
30
38
|
free(parser->settings);
|
31
|
-
free(parser);
|
32
39
|
}
|
40
|
+
|
41
|
+
free(parser);
|
33
42
|
}
|
34
43
|
|
35
44
|
VALUE rb_llhttp_allocate(VALUE klass) {
|
36
45
|
llhttp_t *parser = (llhttp_t *)malloc(sizeof(llhttp_t));
|
37
|
-
llhttp_settings_t *settings = (llhttp_settings_t *)malloc(sizeof(llhttp_settings_t));
|
38
46
|
|
39
|
-
|
40
|
-
|
47
|
+
// Set data to false so we know when the parser has been initialized.
|
48
|
+
//
|
49
|
+
parser->data = 0;
|
41
50
|
|
42
51
|
return Data_Wrap_Struct(klass, 0, rb_llhttp_free, parser);
|
43
52
|
}
|
@@ -51,77 +60,105 @@ void rb_llhttp_data_callback_call(VALUE delegate, ID method, char *data, size_t
|
|
51
60
|
}
|
52
61
|
|
53
62
|
int rb_llhttp_on_message_begin(llhttp_t *parser) {
|
54
|
-
|
63
|
+
rb_llhttp_parser_data *parserData = (rb_llhttp_parser_data*) parser->data;
|
64
|
+
|
65
|
+
return NUM2INT(rb_llhttp_callback_call(parserData->delegate, parserData->on_message_begin));
|
55
66
|
}
|
56
67
|
|
57
68
|
int rb_llhttp_on_headers_complete(llhttp_t *parser) {
|
58
|
-
|
69
|
+
rb_llhttp_parser_data *parserData = (rb_llhttp_parser_data*) parser->data;
|
70
|
+
|
71
|
+
return NUM2INT(rb_llhttp_callback_call(parserData->delegate, parserData->on_headers_complete));
|
59
72
|
}
|
60
73
|
|
61
74
|
int rb_llhttp_on_message_complete(llhttp_t *parser) {
|
62
|
-
|
75
|
+
rb_llhttp_parser_data *parserData = (rb_llhttp_parser_data*) parser->data;
|
76
|
+
|
77
|
+
return NUM2INT(rb_llhttp_callback_call(parserData->delegate, parserData->on_message_complete));
|
63
78
|
}
|
64
79
|
|
65
80
|
int rb_llhttp_on_chunk_header(llhttp_t *parser) {
|
66
|
-
|
81
|
+
rb_llhttp_parser_data *parserData = (rb_llhttp_parser_data*) parser->data;
|
82
|
+
|
83
|
+
return NUM2INT(rb_llhttp_callback_call(parserData->delegate, parserData->on_chunk_header));
|
67
84
|
}
|
68
85
|
|
69
86
|
int rb_llhttp_on_url(llhttp_t *parser, char *data, size_t length) {
|
70
|
-
|
87
|
+
rb_llhttp_parser_data *parserData = (rb_llhttp_parser_data*) parser->data;
|
88
|
+
|
89
|
+
rb_llhttp_data_callback_call(parserData->delegate, parserData->on_url, data, length);
|
71
90
|
|
72
91
|
return 0;
|
73
92
|
}
|
74
93
|
|
75
94
|
int rb_llhttp_on_status(llhttp_t *parser, char *data, size_t length) {
|
76
|
-
|
95
|
+
rb_llhttp_parser_data *parserData = (rb_llhttp_parser_data*) parser->data;
|
96
|
+
|
97
|
+
rb_llhttp_data_callback_call(parserData->delegate, parserData->on_status, data, length);
|
77
98
|
|
78
99
|
return 0;
|
79
100
|
}
|
80
101
|
|
81
102
|
int rb_llhttp_on_header_field(llhttp_t *parser, char *data, size_t length) {
|
82
|
-
|
103
|
+
rb_llhttp_parser_data *parserData = (rb_llhttp_parser_data*) parser->data;
|
104
|
+
|
105
|
+
rb_llhttp_data_callback_call(parserData->delegate, parserData->on_header_field, data, length);
|
83
106
|
|
84
107
|
return 0;
|
85
108
|
}
|
86
109
|
|
87
110
|
int rb_llhttp_on_header_value(llhttp_t *parser, char *data, size_t length) {
|
88
|
-
|
111
|
+
rb_llhttp_parser_data *parserData = (rb_llhttp_parser_data*) parser->data;
|
112
|
+
|
113
|
+
rb_llhttp_data_callback_call(parserData->delegate, parserData->on_header_value, data, length);
|
89
114
|
|
90
115
|
return 0;
|
91
116
|
}
|
92
117
|
|
93
118
|
int rb_llhttp_on_body(llhttp_t *parser, char *data, size_t length) {
|
94
|
-
|
119
|
+
rb_llhttp_parser_data *parserData = (rb_llhttp_parser_data*) parser->data;
|
120
|
+
|
121
|
+
rb_llhttp_data_callback_call(parserData->delegate, parserData->on_body, data, length);
|
95
122
|
|
96
123
|
return 0;
|
97
124
|
}
|
98
125
|
|
99
126
|
int rb_llhttp_on_chunk_complete(llhttp_t *parser) {
|
100
|
-
|
127
|
+
rb_llhttp_parser_data *parserData = (rb_llhttp_parser_data*) parser->data;
|
128
|
+
|
129
|
+
rb_llhttp_callback_call(parserData->delegate, parserData->on_chunk_complete);
|
101
130
|
|
102
131
|
return 0;
|
103
132
|
}
|
104
133
|
|
105
134
|
int rb_llhttp_on_url_complete(llhttp_t *parser) {
|
106
|
-
|
135
|
+
rb_llhttp_parser_data *parserData = (rb_llhttp_parser_data*) parser->data;
|
136
|
+
|
137
|
+
rb_llhttp_callback_call(parserData->delegate, parserData->on_url_complete);
|
107
138
|
|
108
139
|
return 0;
|
109
140
|
}
|
110
141
|
|
111
142
|
int rb_llhttp_on_status_complete(llhttp_t *parser) {
|
112
|
-
|
143
|
+
rb_llhttp_parser_data *parserData = (rb_llhttp_parser_data*) parser->data;
|
144
|
+
|
145
|
+
rb_llhttp_callback_call(parserData->delegate, parserData->on_status_complete);
|
113
146
|
|
114
147
|
return 0;
|
115
148
|
}
|
116
149
|
|
117
150
|
int rb_llhttp_on_header_field_complete(llhttp_t *parser) {
|
118
|
-
|
151
|
+
rb_llhttp_parser_data *parserData = (rb_llhttp_parser_data*) parser->data;
|
152
|
+
|
153
|
+
rb_llhttp_callback_call(parserData->delegate, parserData->on_header_field_complete);
|
119
154
|
|
120
155
|
return 0;
|
121
156
|
}
|
122
157
|
|
123
158
|
int rb_llhttp_on_header_value_complete(llhttp_t *parser) {
|
124
|
-
|
159
|
+
rb_llhttp_parser_data *parserData = (rb_llhttp_parser_data*) parser->data;
|
160
|
+
|
161
|
+
rb_llhttp_callback_call(parserData->delegate, parserData->on_header_value_complete);
|
125
162
|
|
126
163
|
return 0;
|
127
164
|
}
|
@@ -159,8 +196,6 @@ VALUE rb_llhttp_reset(VALUE self) {
|
|
159
196
|
|
160
197
|
Data_Get_Struct(self, llhttp_t, parser);
|
161
198
|
|
162
|
-
llhttp_settings_t *settings = parser->settings;
|
163
|
-
|
164
199
|
llhttp_reset(parser);
|
165
200
|
|
166
201
|
return Qtrue;
|
@@ -221,84 +256,86 @@ static VALUE rb_llhttp_init(VALUE self, VALUE type) {
|
|
221
256
|
|
222
257
|
Data_Get_Struct(self, llhttp_t, parser);
|
223
258
|
|
224
|
-
llhttp_settings_t *settings =
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
259
|
+
llhttp_settings_t *settings = (llhttp_settings_t *)malloc(sizeof(llhttp_settings_t));
|
260
|
+
llhttp_settings_init(settings);
|
261
|
+
|
262
|
+
rb_llhttp_parser_data *parserData = malloc(sizeof(rb_llhttp_parser_data));
|
263
|
+
parserData->delegate = rb_iv_get(self, "@delegate");
|
264
|
+
|
265
|
+
parserData->on_message_begin = rb_intern("internal_on_message_begin");
|
266
|
+
parserData->on_headers_complete = rb_intern("internal_on_headers_complete");
|
267
|
+
parserData->on_message_complete = rb_intern("internal_on_message_complete");
|
268
|
+
parserData->on_chunk_header = rb_intern("internal_on_chunk_header");
|
269
|
+
parserData->on_url = rb_intern("on_url");
|
270
|
+
parserData->on_status = rb_intern("on_status");
|
271
|
+
parserData->on_header_field = rb_intern("on_header_field");
|
272
|
+
parserData->on_header_value = rb_intern("on_header_value");
|
273
|
+
parserData->on_body = rb_intern("on_body");
|
274
|
+
parserData->on_chunk_complete = rb_intern("on_chunk_complete");
|
275
|
+
parserData->on_url_complete = rb_intern("on_url_complete");
|
276
|
+
parserData->on_status_complete = rb_intern("on_status_complete");
|
277
|
+
parserData->on_header_field_complete = rb_intern("on_header_field_complete");
|
278
|
+
parserData->on_header_value_complete = rb_intern("on_header_value_complete");
|
279
|
+
|
280
|
+
if (rb_respond_to(parserData->delegate, rb_intern("on_message_begin"))) {
|
244
281
|
settings->on_message_begin = (llhttp_cb)rb_llhttp_on_message_begin;
|
245
282
|
}
|
246
283
|
|
247
|
-
if (rb_respond_to(delegate, rb_intern("on_headers_complete"))) {
|
284
|
+
if (rb_respond_to(parserData->delegate, rb_intern("on_headers_complete"))) {
|
248
285
|
settings->on_headers_complete = (llhttp_cb)rb_llhttp_on_headers_complete;
|
249
286
|
}
|
250
287
|
|
251
|
-
if (rb_respond_to(delegate, rb_intern("on_message_complete"))) {
|
288
|
+
if (rb_respond_to(parserData->delegate, rb_intern("on_message_complete"))) {
|
252
289
|
settings->on_message_complete = (llhttp_cb)rb_llhttp_on_message_complete;
|
253
290
|
}
|
254
291
|
|
255
|
-
if (rb_respond_to(delegate, rb_intern("on_chunk_header"))) {
|
292
|
+
if (rb_respond_to(parserData->delegate, rb_intern("on_chunk_header"))) {
|
256
293
|
settings->on_chunk_header = (llhttp_cb)rb_llhttp_on_chunk_header;
|
257
294
|
}
|
258
295
|
|
259
|
-
if (rb_respond_to(delegate,
|
296
|
+
if (rb_respond_to(parserData->delegate, parserData->on_url)) {
|
260
297
|
settings->on_url = (llhttp_data_cb)rb_llhttp_on_url;
|
261
298
|
}
|
262
299
|
|
263
|
-
if (rb_respond_to(delegate,
|
300
|
+
if (rb_respond_to(parserData->delegate, parserData->on_status)) {
|
264
301
|
settings->on_status = (llhttp_data_cb)rb_llhttp_on_status;
|
265
302
|
}
|
266
303
|
|
267
|
-
if (rb_respond_to(delegate,
|
304
|
+
if (rb_respond_to(parserData->delegate, parserData->on_header_field)) {
|
268
305
|
settings->on_header_field = (llhttp_data_cb)rb_llhttp_on_header_field;
|
269
306
|
}
|
270
307
|
|
271
|
-
if (rb_respond_to(delegate,
|
308
|
+
if (rb_respond_to(parserData->delegate, parserData->on_header_value)) {
|
272
309
|
settings->on_header_value = (llhttp_data_cb)rb_llhttp_on_header_value;
|
273
310
|
}
|
274
311
|
|
275
|
-
if (rb_respond_to(delegate,
|
312
|
+
if (rb_respond_to(parserData->delegate, parserData->on_body)) {
|
276
313
|
settings->on_body = (llhttp_data_cb)rb_llhttp_on_body;
|
277
314
|
}
|
278
315
|
|
279
|
-
if (rb_respond_to(delegate,
|
316
|
+
if (rb_respond_to(parserData->delegate, parserData->on_chunk_complete)) {
|
280
317
|
settings->on_chunk_complete = (llhttp_cb)rb_llhttp_on_chunk_complete;
|
281
318
|
}
|
282
319
|
|
283
|
-
if (rb_respond_to(delegate,
|
320
|
+
if (rb_respond_to(parserData->delegate, parserData->on_url_complete)) {
|
284
321
|
settings->on_url_complete = (llhttp_cb)rb_llhttp_on_url_complete;
|
285
322
|
}
|
286
323
|
|
287
|
-
if (rb_respond_to(delegate,
|
324
|
+
if (rb_respond_to(parserData->delegate, parserData->on_status_complete)) {
|
288
325
|
settings->on_status_complete = (llhttp_cb)rb_llhttp_on_status_complete;
|
289
326
|
}
|
290
327
|
|
291
|
-
if (rb_respond_to(delegate,
|
328
|
+
if (rb_respond_to(parserData->delegate, parserData->on_header_field_complete)) {
|
292
329
|
settings->on_header_field_complete = (llhttp_cb)rb_llhttp_on_header_field_complete;
|
293
330
|
}
|
294
331
|
|
295
|
-
if (rb_respond_to(delegate,
|
332
|
+
if (rb_respond_to(parserData->delegate, parserData->on_header_value_complete)) {
|
296
333
|
settings->on_header_value_complete = (llhttp_cb)rb_llhttp_on_header_value_complete;
|
297
334
|
}
|
298
335
|
|
299
336
|
llhttp_init(parser, FIX2INT(type), settings);
|
300
337
|
|
301
|
-
parser->data = (void*)
|
338
|
+
parser->data = (void*)parserData;
|
302
339
|
|
303
340
|
return Qtrue;
|
304
341
|
}
|
data/lib/llhttp/version.rb
CHANGED
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: llhttp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Powell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Ruby bindings for llhttp.
|
14
|
-
email: bryan@
|
14
|
+
email: bryan@bryanp.org
|
15
15
|
executables: []
|
16
16
|
extensions:
|
17
17
|
- ext/llhttp/extconf.rb
|
@@ -31,7 +31,7 @@ files:
|
|
31
31
|
- lib/llhttp/error.rb
|
32
32
|
- lib/llhttp/parser.rb
|
33
33
|
- lib/llhttp/version.rb
|
34
|
-
homepage: https://github.com/
|
34
|
+
homepage: https://github.com/bryanp/llhttp/
|
35
35
|
licenses:
|
36
36
|
- MPL-2.0
|
37
37
|
metadata: {}
|
@@ -50,7 +50,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
50
50
|
- !ruby/object:Gem::Version
|
51
51
|
version: '0'
|
52
52
|
requirements: []
|
53
|
-
rubygems_version: 3.
|
53
|
+
rubygems_version: 3.4.9
|
54
54
|
signing_key:
|
55
55
|
specification_version: 4
|
56
56
|
summary: Ruby bindings for llhttp.
|