raptor 0.1.0
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 +7 -0
- data/.buildkite/pipeline.yml +36 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.txt +21 -0
- data/README.md +86 -0
- data/Rakefile +28 -0
- data/exe/raptor +8 -0
- data/ext/raptor_http/extconf.rb +7 -0
- data/ext/raptor_http/raptor_http.c +1248 -0
- data/ext/raptor_http2/extconf.rb +7 -0
- data/ext/raptor_http2/huffman_table.h +4888 -0
- data/ext/raptor_http2/raptor_http2.c +772 -0
- data/lib/raptor/binder.rb +249 -0
- data/lib/raptor/cli.rb +171 -0
- data/lib/raptor/cluster.rb +357 -0
- data/lib/raptor/http2.rb +416 -0
- data/lib/raptor/reactor.rb +411 -0
- data/lib/raptor/request.rb +992 -0
- data/lib/raptor/server.rb +167 -0
- data/lib/raptor/stats.rb +94 -0
- data/lib/raptor/version.rb +6 -0
- data/lib/raptor.rb +13 -0
- data/sig/generated/raptor/binder.rbs +162 -0
- data/sig/generated/raptor/cli.rbs +71 -0
- data/sig/generated/raptor/cluster.rbs +171 -0
- data/sig/generated/raptor/http2.rbs +145 -0
- data/sig/generated/raptor/reactor.rbs +251 -0
- data/sig/generated/raptor/request.rbs +477 -0
- data/sig/generated/raptor/server.rbs +88 -0
- data/sig/generated/raptor/stats.rbs +78 -0
- data/sig/generated/raptor/version.rbs +5 -0
- data/sig/generated/raptor.rbs +9 -0
- metadata +160 -0
|
@@ -0,0 +1,1248 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2005 Zed A. Shaw
|
|
3
|
+
* You can redistribute it and/or modify it under the same terms as Ruby.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
#include "ruby.h"
|
|
7
|
+
#include <assert.h>
|
|
8
|
+
#include <string.h>
|
|
9
|
+
#include <ctype.h>
|
|
10
|
+
|
|
11
|
+
#define MAX_HEADER_LENGTH (112 * 1024)
|
|
12
|
+
#define MAX_URI_LENGTH (12 * 1024)
|
|
13
|
+
#define MAX_FIELD_NAME 256
|
|
14
|
+
#define MAX_FIELD_VALUE (80 * 1024)
|
|
15
|
+
|
|
16
|
+
typedef struct raptor_parser {
|
|
17
|
+
int cs;
|
|
18
|
+
size_t mark;
|
|
19
|
+
size_t field_start;
|
|
20
|
+
size_t field_len;
|
|
21
|
+
size_t query_start;
|
|
22
|
+
size_t nread;
|
|
23
|
+
size_t body_start;
|
|
24
|
+
off_t content_len;
|
|
25
|
+
unsigned int flags;
|
|
26
|
+
VALUE request;
|
|
27
|
+
VALUE body;
|
|
28
|
+
char buf[MAX_FIELD_NAME + 6];
|
|
29
|
+
} raptor_parser;
|
|
30
|
+
|
|
31
|
+
#define MARK(M, P) (parser->M = (P) - buffer)
|
|
32
|
+
#define LEN(AT, P) ((P) - buffer - parser->AT)
|
|
33
|
+
#define PTR_TO(F) (buffer + parser->F)
|
|
34
|
+
|
|
35
|
+
#define FLAG_CHUNKED 0x1
|
|
36
|
+
#define FLAG_HAS_BODY 0x2
|
|
37
|
+
#define FLAG_FINISHED 0x4
|
|
38
|
+
|
|
39
|
+
static VALUE eHttpParserError;
|
|
40
|
+
static VALUE global_request_method;
|
|
41
|
+
static VALUE global_request_uri;
|
|
42
|
+
static VALUE global_query_string;
|
|
43
|
+
static VALUE global_server_protocol;
|
|
44
|
+
static VALUE global_request_path;
|
|
45
|
+
static VALUE global_fragment;
|
|
46
|
+
|
|
47
|
+
static inline void upcase_header_char(char *c) {
|
|
48
|
+
if (*c >= 'a' && *c <= 'z')
|
|
49
|
+
*c &= ~0x20;
|
|
50
|
+
else if (*c == '-')
|
|
51
|
+
*c = '_';
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static const int raptor_parser_start = 1;
|
|
55
|
+
static const int raptor_parser_first_final = 46;
|
|
56
|
+
static const int raptor_parser_error = 0;
|
|
57
|
+
|
|
58
|
+
size_t raptor_parser_execute(raptor_parser *parser, const char *buffer, size_t len) {
|
|
59
|
+
const char *p, *pe;
|
|
60
|
+
int cs = parser->cs;
|
|
61
|
+
|
|
62
|
+
p = buffer;
|
|
63
|
+
pe = buffer + len;
|
|
64
|
+
|
|
65
|
+
{
|
|
66
|
+
if ( p == pe )
|
|
67
|
+
goto _test_eof;
|
|
68
|
+
switch ( cs )
|
|
69
|
+
{
|
|
70
|
+
case 1:
|
|
71
|
+
switch( (*p) ) {
|
|
72
|
+
case 36: goto tr0;
|
|
73
|
+
case 95: goto tr0;
|
|
74
|
+
}
|
|
75
|
+
if ( (*p) < 48 ) {
|
|
76
|
+
if ( 45 <= (*p) && (*p) <= 46 )
|
|
77
|
+
goto tr0;
|
|
78
|
+
} else if ( (*p) > 57 ) {
|
|
79
|
+
if ( 65 <= (*p) && (*p) <= 90 )
|
|
80
|
+
goto tr0;
|
|
81
|
+
} else
|
|
82
|
+
goto tr0;
|
|
83
|
+
goto st0;
|
|
84
|
+
st0:
|
|
85
|
+
cs = 0;
|
|
86
|
+
goto _out;
|
|
87
|
+
tr0:
|
|
88
|
+
{ MARK(mark, p); }
|
|
89
|
+
goto st2;
|
|
90
|
+
st2:
|
|
91
|
+
if ( ++p == pe )
|
|
92
|
+
goto _test_eof2;
|
|
93
|
+
case 2:
|
|
94
|
+
switch( (*p) ) {
|
|
95
|
+
case 32: goto tr2;
|
|
96
|
+
case 36: goto st27;
|
|
97
|
+
case 95: goto st27;
|
|
98
|
+
}
|
|
99
|
+
if ( (*p) < 48 ) {
|
|
100
|
+
if ( 45 <= (*p) && (*p) <= 46 )
|
|
101
|
+
goto st27;
|
|
102
|
+
} else if ( (*p) > 57 ) {
|
|
103
|
+
if ( 65 <= (*p) && (*p) <= 90 )
|
|
104
|
+
goto st27;
|
|
105
|
+
} else
|
|
106
|
+
goto st27;
|
|
107
|
+
goto st0;
|
|
108
|
+
tr2:
|
|
109
|
+
{
|
|
110
|
+
VALUE method = rb_str_new(PTR_TO(mark), LEN(mark, p));
|
|
111
|
+
rb_hash_aset(parser->request, global_request_method, method);
|
|
112
|
+
}
|
|
113
|
+
goto st3;
|
|
114
|
+
st3:
|
|
115
|
+
if ( ++p == pe )
|
|
116
|
+
goto _test_eof3;
|
|
117
|
+
case 3:
|
|
118
|
+
switch( (*p) ) {
|
|
119
|
+
case 42: goto tr4;
|
|
120
|
+
case 43: goto tr5;
|
|
121
|
+
case 47: goto tr6;
|
|
122
|
+
case 58: goto tr7;
|
|
123
|
+
}
|
|
124
|
+
if ( (*p) < 65 ) {
|
|
125
|
+
if ( 45 <= (*p) && (*p) <= 57 )
|
|
126
|
+
goto tr5;
|
|
127
|
+
} else if ( (*p) > 90 ) {
|
|
128
|
+
if ( 97 <= (*p) && (*p) <= 122 )
|
|
129
|
+
goto tr5;
|
|
130
|
+
} else
|
|
131
|
+
goto tr5;
|
|
132
|
+
goto st0;
|
|
133
|
+
tr4:
|
|
134
|
+
{ MARK(mark, p); }
|
|
135
|
+
goto st4;
|
|
136
|
+
st4:
|
|
137
|
+
if ( ++p == pe )
|
|
138
|
+
goto _test_eof4;
|
|
139
|
+
case 4:
|
|
140
|
+
switch( (*p) ) {
|
|
141
|
+
case 32: goto tr8;
|
|
142
|
+
case 35: goto tr9;
|
|
143
|
+
}
|
|
144
|
+
goto st0;
|
|
145
|
+
tr8:
|
|
146
|
+
{
|
|
147
|
+
if (LEN(mark, p) > MAX_URI_LENGTH)
|
|
148
|
+
rb_raise(eHttpParserError, "URI too long");
|
|
149
|
+
VALUE uri = rb_str_new(PTR_TO(mark), LEN(mark, p));
|
|
150
|
+
rb_hash_aset(parser->request, global_request_uri, uri);
|
|
151
|
+
}
|
|
152
|
+
goto st5;
|
|
153
|
+
tr31:
|
|
154
|
+
{ MARK(mark, p); }
|
|
155
|
+
{
|
|
156
|
+
VALUE frag = rb_str_new(PTR_TO(mark), LEN(mark, p));
|
|
157
|
+
rb_hash_aset(parser->request, global_fragment, frag);
|
|
158
|
+
}
|
|
159
|
+
goto st5;
|
|
160
|
+
tr33:
|
|
161
|
+
{
|
|
162
|
+
VALUE frag = rb_str_new(PTR_TO(mark), LEN(mark, p));
|
|
163
|
+
rb_hash_aset(parser->request, global_fragment, frag);
|
|
164
|
+
}
|
|
165
|
+
goto st5;
|
|
166
|
+
tr37:
|
|
167
|
+
{
|
|
168
|
+
VALUE path = rb_str_new(PTR_TO(mark), LEN(mark,p));
|
|
169
|
+
rb_hash_aset(parser->request, global_request_path, path);
|
|
170
|
+
}
|
|
171
|
+
{
|
|
172
|
+
if (LEN(mark, p) > MAX_URI_LENGTH)
|
|
173
|
+
rb_raise(eHttpParserError, "URI too long");
|
|
174
|
+
VALUE uri = rb_str_new(PTR_TO(mark), LEN(mark, p));
|
|
175
|
+
rb_hash_aset(parser->request, global_request_uri, uri);
|
|
176
|
+
}
|
|
177
|
+
goto st5;
|
|
178
|
+
tr41:
|
|
179
|
+
{ MARK(query_start, p); }
|
|
180
|
+
{
|
|
181
|
+
VALUE query = rb_str_new(PTR_TO(query_start), LEN(query_start, p));
|
|
182
|
+
rb_hash_aset(parser->request, global_query_string, query);
|
|
183
|
+
}
|
|
184
|
+
{
|
|
185
|
+
if (LEN(mark, p) > MAX_URI_LENGTH)
|
|
186
|
+
rb_raise(eHttpParserError, "URI too long");
|
|
187
|
+
VALUE uri = rb_str_new(PTR_TO(mark), LEN(mark, p));
|
|
188
|
+
rb_hash_aset(parser->request, global_request_uri, uri);
|
|
189
|
+
}
|
|
190
|
+
goto st5;
|
|
191
|
+
tr44:
|
|
192
|
+
{
|
|
193
|
+
VALUE query = rb_str_new(PTR_TO(query_start), LEN(query_start, p));
|
|
194
|
+
rb_hash_aset(parser->request, global_query_string, query);
|
|
195
|
+
}
|
|
196
|
+
{
|
|
197
|
+
if (LEN(mark, p) > MAX_URI_LENGTH)
|
|
198
|
+
rb_raise(eHttpParserError, "URI too long");
|
|
199
|
+
VALUE uri = rb_str_new(PTR_TO(mark), LEN(mark, p));
|
|
200
|
+
rb_hash_aset(parser->request, global_request_uri, uri);
|
|
201
|
+
}
|
|
202
|
+
goto st5;
|
|
203
|
+
st5:
|
|
204
|
+
if ( ++p == pe )
|
|
205
|
+
goto _test_eof5;
|
|
206
|
+
case 5:
|
|
207
|
+
if ( (*p) == 72 )
|
|
208
|
+
goto tr10;
|
|
209
|
+
goto st0;
|
|
210
|
+
tr10:
|
|
211
|
+
{ MARK(mark, p); }
|
|
212
|
+
goto st6;
|
|
213
|
+
st6:
|
|
214
|
+
if ( ++p == pe )
|
|
215
|
+
goto _test_eof6;
|
|
216
|
+
case 6:
|
|
217
|
+
if ( (*p) == 84 )
|
|
218
|
+
goto st7;
|
|
219
|
+
goto st0;
|
|
220
|
+
st7:
|
|
221
|
+
if ( ++p == pe )
|
|
222
|
+
goto _test_eof7;
|
|
223
|
+
case 7:
|
|
224
|
+
if ( (*p) == 84 )
|
|
225
|
+
goto st8;
|
|
226
|
+
goto st0;
|
|
227
|
+
st8:
|
|
228
|
+
if ( ++p == pe )
|
|
229
|
+
goto _test_eof8;
|
|
230
|
+
case 8:
|
|
231
|
+
if ( (*p) == 80 )
|
|
232
|
+
goto st9;
|
|
233
|
+
goto st0;
|
|
234
|
+
st9:
|
|
235
|
+
if ( ++p == pe )
|
|
236
|
+
goto _test_eof9;
|
|
237
|
+
case 9:
|
|
238
|
+
if ( (*p) == 47 )
|
|
239
|
+
goto st10;
|
|
240
|
+
goto st0;
|
|
241
|
+
st10:
|
|
242
|
+
if ( ++p == pe )
|
|
243
|
+
goto _test_eof10;
|
|
244
|
+
case 10:
|
|
245
|
+
if ( 48 <= (*p) && (*p) <= 57 )
|
|
246
|
+
goto st11;
|
|
247
|
+
goto st0;
|
|
248
|
+
st11:
|
|
249
|
+
if ( ++p == pe )
|
|
250
|
+
goto _test_eof11;
|
|
251
|
+
case 11:
|
|
252
|
+
if ( (*p) == 46 )
|
|
253
|
+
goto st12;
|
|
254
|
+
if ( 48 <= (*p) && (*p) <= 57 )
|
|
255
|
+
goto st11;
|
|
256
|
+
goto st0;
|
|
257
|
+
st12:
|
|
258
|
+
if ( ++p == pe )
|
|
259
|
+
goto _test_eof12;
|
|
260
|
+
case 12:
|
|
261
|
+
if ( 48 <= (*p) && (*p) <= 57 )
|
|
262
|
+
goto st13;
|
|
263
|
+
goto st0;
|
|
264
|
+
st13:
|
|
265
|
+
if ( ++p == pe )
|
|
266
|
+
goto _test_eof13;
|
|
267
|
+
case 13:
|
|
268
|
+
if ( (*p) == 13 )
|
|
269
|
+
goto tr18;
|
|
270
|
+
if ( 48 <= (*p) && (*p) <= 57 )
|
|
271
|
+
goto st13;
|
|
272
|
+
goto st0;
|
|
273
|
+
tr18:
|
|
274
|
+
{
|
|
275
|
+
VALUE proto = rb_str_new(PTR_TO(mark), LEN(mark, p));
|
|
276
|
+
rb_hash_aset(parser->request, global_server_protocol, proto);
|
|
277
|
+
}
|
|
278
|
+
goto st14;
|
|
279
|
+
tr26:
|
|
280
|
+
{ MARK(mark, p); }
|
|
281
|
+
{
|
|
282
|
+
if (parser->field_len == 0 || parser->field_len > MAX_FIELD_NAME)
|
|
283
|
+
rb_raise(eHttpParserError, "invalid field name length");
|
|
284
|
+
|
|
285
|
+
size_t value_len = LEN(mark, p);
|
|
286
|
+
if (value_len > MAX_FIELD_VALUE)
|
|
287
|
+
rb_raise(eHttpParserError, "field value too long");
|
|
288
|
+
|
|
289
|
+
const char *field_ptr = PTR_TO(field_start);
|
|
290
|
+
|
|
291
|
+
int needs_http_prefix = 1;
|
|
292
|
+
if (parser->field_len == 14 && memcmp(field_ptr, "CONTENT_LENGTH", 14) == 0)
|
|
293
|
+
needs_http_prefix = 0;
|
|
294
|
+
else if (parser->field_len == 12 && memcmp(field_ptr, "CONTENT_TYPE", 12) == 0)
|
|
295
|
+
needs_http_prefix = 0;
|
|
296
|
+
|
|
297
|
+
if (needs_http_prefix) {
|
|
298
|
+
memcpy(parser->buf, "HTTP_", 5);
|
|
299
|
+
memcpy(parser->buf + 5, field_ptr, parser->field_len);
|
|
300
|
+
parser->buf[5 + parser->field_len] = '\0';
|
|
301
|
+
} else {
|
|
302
|
+
memcpy(parser->buf, field_ptr, parser->field_len);
|
|
303
|
+
parser->buf[parser->field_len] = '\0';
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
VALUE key = rb_str_new2(parser->buf);
|
|
307
|
+
VALUE value = rb_str_new(PTR_TO(mark), value_len);
|
|
308
|
+
|
|
309
|
+
char *value_ptr = RSTRING_PTR(value);
|
|
310
|
+
long value_real_len = RSTRING_LEN(value);
|
|
311
|
+
while (value_real_len > 0 && (value_ptr[value_real_len - 1] == ' ' ||
|
|
312
|
+
value_ptr[value_real_len - 1] == '\t'))
|
|
313
|
+
value_real_len--;
|
|
314
|
+
rb_str_set_len(value, value_real_len);
|
|
315
|
+
|
|
316
|
+
if (!needs_http_prefix && parser->field_len == 14) {
|
|
317
|
+
parser->content_len = strtoul(RSTRING_PTR(value), NULL, 10);
|
|
318
|
+
if (parser->content_len > 0)
|
|
319
|
+
parser->flags |= FLAG_HAS_BODY;
|
|
320
|
+
} else if (needs_http_prefix && parser->field_len == 17 &&
|
|
321
|
+
memcmp(field_ptr, "TRANSFER_ENCODING", 17) == 0) {
|
|
322
|
+
if (strstr(RSTRING_PTR(value), "chunked")) {
|
|
323
|
+
parser->flags |= FLAG_CHUNKED | FLAG_HAS_BODY;
|
|
324
|
+
parser->content_len = 0;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
VALUE existing = rb_hash_aref(parser->request, key);
|
|
329
|
+
if (!NIL_P(existing)) {
|
|
330
|
+
rb_str_cat2(existing, ", ");
|
|
331
|
+
rb_str_append(existing, value);
|
|
332
|
+
} else {
|
|
333
|
+
rb_hash_aset(parser->request, key, value);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
goto st14;
|
|
337
|
+
tr29:
|
|
338
|
+
{
|
|
339
|
+
if (parser->field_len == 0 || parser->field_len > MAX_FIELD_NAME)
|
|
340
|
+
rb_raise(eHttpParserError, "invalid field name length");
|
|
341
|
+
|
|
342
|
+
size_t value_len = LEN(mark, p);
|
|
343
|
+
if (value_len > MAX_FIELD_VALUE)
|
|
344
|
+
rb_raise(eHttpParserError, "field value too long");
|
|
345
|
+
|
|
346
|
+
const char *field_ptr = PTR_TO(field_start);
|
|
347
|
+
|
|
348
|
+
int needs_http_prefix = 1;
|
|
349
|
+
if (parser->field_len == 14 && memcmp(field_ptr, "CONTENT_LENGTH", 14) == 0)
|
|
350
|
+
needs_http_prefix = 0;
|
|
351
|
+
else if (parser->field_len == 12 && memcmp(field_ptr, "CONTENT_TYPE", 12) == 0)
|
|
352
|
+
needs_http_prefix = 0;
|
|
353
|
+
|
|
354
|
+
if (needs_http_prefix) {
|
|
355
|
+
memcpy(parser->buf, "HTTP_", 5);
|
|
356
|
+
memcpy(parser->buf + 5, field_ptr, parser->field_len);
|
|
357
|
+
parser->buf[5 + parser->field_len] = '\0';
|
|
358
|
+
} else {
|
|
359
|
+
memcpy(parser->buf, field_ptr, parser->field_len);
|
|
360
|
+
parser->buf[parser->field_len] = '\0';
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
VALUE key = rb_str_new2(parser->buf);
|
|
364
|
+
VALUE value = rb_str_new(PTR_TO(mark), value_len);
|
|
365
|
+
|
|
366
|
+
char *value_ptr = RSTRING_PTR(value);
|
|
367
|
+
long value_real_len = RSTRING_LEN(value);
|
|
368
|
+
while (value_real_len > 0 && (value_ptr[value_real_len - 1] == ' ' ||
|
|
369
|
+
value_ptr[value_real_len - 1] == '\t'))
|
|
370
|
+
value_real_len--;
|
|
371
|
+
rb_str_set_len(value, value_real_len);
|
|
372
|
+
|
|
373
|
+
if (!needs_http_prefix && parser->field_len == 14) {
|
|
374
|
+
parser->content_len = strtoul(RSTRING_PTR(value), NULL, 10);
|
|
375
|
+
if (parser->content_len > 0)
|
|
376
|
+
parser->flags |= FLAG_HAS_BODY;
|
|
377
|
+
} else if (needs_http_prefix && parser->field_len == 17 &&
|
|
378
|
+
memcmp(field_ptr, "TRANSFER_ENCODING", 17) == 0) {
|
|
379
|
+
if (strstr(RSTRING_PTR(value), "chunked")) {
|
|
380
|
+
parser->flags |= FLAG_CHUNKED | FLAG_HAS_BODY;
|
|
381
|
+
parser->content_len = 0;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
VALUE existing = rb_hash_aref(parser->request, key);
|
|
386
|
+
if (!NIL_P(existing)) {
|
|
387
|
+
rb_str_cat2(existing, ", ");
|
|
388
|
+
rb_str_append(existing, value);
|
|
389
|
+
} else {
|
|
390
|
+
rb_hash_aset(parser->request, key, value);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
goto st14;
|
|
394
|
+
st14:
|
|
395
|
+
if ( ++p == pe )
|
|
396
|
+
goto _test_eof14;
|
|
397
|
+
case 14:
|
|
398
|
+
if ( (*p) == 10 )
|
|
399
|
+
goto st15;
|
|
400
|
+
goto st0;
|
|
401
|
+
st15:
|
|
402
|
+
if ( ++p == pe )
|
|
403
|
+
goto _test_eof15;
|
|
404
|
+
case 15:
|
|
405
|
+
switch( (*p) ) {
|
|
406
|
+
case 13: goto st16;
|
|
407
|
+
case 33: goto tr21;
|
|
408
|
+
case 124: goto tr21;
|
|
409
|
+
case 126: goto tr21;
|
|
410
|
+
}
|
|
411
|
+
if ( (*p) < 45 ) {
|
|
412
|
+
if ( (*p) > 39 ) {
|
|
413
|
+
if ( 42 <= (*p) && (*p) <= 43 )
|
|
414
|
+
goto tr21;
|
|
415
|
+
} else if ( (*p) >= 35 )
|
|
416
|
+
goto tr21;
|
|
417
|
+
} else if ( (*p) > 46 ) {
|
|
418
|
+
if ( (*p) < 65 ) {
|
|
419
|
+
if ( 48 <= (*p) && (*p) <= 57 )
|
|
420
|
+
goto tr21;
|
|
421
|
+
} else if ( (*p) > 90 ) {
|
|
422
|
+
if ( 94 <= (*p) && (*p) <= 122 )
|
|
423
|
+
goto tr21;
|
|
424
|
+
} else
|
|
425
|
+
goto tr21;
|
|
426
|
+
} else
|
|
427
|
+
goto tr21;
|
|
428
|
+
goto st0;
|
|
429
|
+
st16:
|
|
430
|
+
if ( ++p == pe )
|
|
431
|
+
goto _test_eof16;
|
|
432
|
+
case 16:
|
|
433
|
+
if ( (*p) == 10 )
|
|
434
|
+
goto tr22;
|
|
435
|
+
goto st0;
|
|
436
|
+
tr22:
|
|
437
|
+
{
|
|
438
|
+
parser->body_start = p - buffer + 1;
|
|
439
|
+
parser->flags |= FLAG_FINISHED;
|
|
440
|
+
parser->nread = p - buffer + 1;
|
|
441
|
+
goto done;
|
|
442
|
+
}
|
|
443
|
+
goto st46;
|
|
444
|
+
st46:
|
|
445
|
+
if ( ++p == pe )
|
|
446
|
+
goto _test_eof46;
|
|
447
|
+
case 46:
|
|
448
|
+
goto st0;
|
|
449
|
+
tr21:
|
|
450
|
+
{ MARK(field_start, p); }
|
|
451
|
+
{ upcase_header_char((char *)p); }
|
|
452
|
+
goto st17;
|
|
453
|
+
tr23:
|
|
454
|
+
{ upcase_header_char((char *)p); }
|
|
455
|
+
goto st17;
|
|
456
|
+
st17:
|
|
457
|
+
if ( ++p == pe )
|
|
458
|
+
goto _test_eof17;
|
|
459
|
+
case 17:
|
|
460
|
+
switch( (*p) ) {
|
|
461
|
+
case 33: goto tr23;
|
|
462
|
+
case 58: goto tr24;
|
|
463
|
+
case 124: goto tr23;
|
|
464
|
+
case 126: goto tr23;
|
|
465
|
+
}
|
|
466
|
+
if ( (*p) < 45 ) {
|
|
467
|
+
if ( (*p) > 39 ) {
|
|
468
|
+
if ( 42 <= (*p) && (*p) <= 43 )
|
|
469
|
+
goto tr23;
|
|
470
|
+
} else if ( (*p) >= 35 )
|
|
471
|
+
goto tr23;
|
|
472
|
+
} else if ( (*p) > 46 ) {
|
|
473
|
+
if ( (*p) < 65 ) {
|
|
474
|
+
if ( 48 <= (*p) && (*p) <= 57 )
|
|
475
|
+
goto tr23;
|
|
476
|
+
} else if ( (*p) > 90 ) {
|
|
477
|
+
if ( 94 <= (*p) && (*p) <= 122 )
|
|
478
|
+
goto tr23;
|
|
479
|
+
} else
|
|
480
|
+
goto tr23;
|
|
481
|
+
} else
|
|
482
|
+
goto tr23;
|
|
483
|
+
goto st0;
|
|
484
|
+
tr24:
|
|
485
|
+
{
|
|
486
|
+
parser->field_len = LEN(field_start, p);
|
|
487
|
+
}
|
|
488
|
+
goto st18;
|
|
489
|
+
tr27:
|
|
490
|
+
{ MARK(mark, p); }
|
|
491
|
+
goto st18;
|
|
492
|
+
st18:
|
|
493
|
+
if ( ++p == pe )
|
|
494
|
+
goto _test_eof18;
|
|
495
|
+
case 18:
|
|
496
|
+
switch( (*p) ) {
|
|
497
|
+
case 13: goto tr26;
|
|
498
|
+
case 32: goto tr27;
|
|
499
|
+
case 127: goto st0;
|
|
500
|
+
}
|
|
501
|
+
if ( (*p) > 8 ) {
|
|
502
|
+
if ( 10 <= (*p) && (*p) <= 31 )
|
|
503
|
+
goto st0;
|
|
504
|
+
} else if ( (*p) >= 0 )
|
|
505
|
+
goto st0;
|
|
506
|
+
goto tr25;
|
|
507
|
+
tr25:
|
|
508
|
+
{ MARK(mark, p); }
|
|
509
|
+
goto st19;
|
|
510
|
+
st19:
|
|
511
|
+
if ( ++p == pe )
|
|
512
|
+
goto _test_eof19;
|
|
513
|
+
case 19:
|
|
514
|
+
switch( (*p) ) {
|
|
515
|
+
case 13: goto tr29;
|
|
516
|
+
case 127: goto st0;
|
|
517
|
+
}
|
|
518
|
+
if ( (*p) > 8 ) {
|
|
519
|
+
if ( 10 <= (*p) && (*p) <= 31 )
|
|
520
|
+
goto st0;
|
|
521
|
+
} else if ( (*p) >= 0 )
|
|
522
|
+
goto st0;
|
|
523
|
+
goto st19;
|
|
524
|
+
tr9:
|
|
525
|
+
{
|
|
526
|
+
if (LEN(mark, p) > MAX_URI_LENGTH)
|
|
527
|
+
rb_raise(eHttpParserError, "URI too long");
|
|
528
|
+
VALUE uri = rb_str_new(PTR_TO(mark), LEN(mark, p));
|
|
529
|
+
rb_hash_aset(parser->request, global_request_uri, uri);
|
|
530
|
+
}
|
|
531
|
+
goto st20;
|
|
532
|
+
tr38:
|
|
533
|
+
{
|
|
534
|
+
VALUE path = rb_str_new(PTR_TO(mark), LEN(mark,p));
|
|
535
|
+
rb_hash_aset(parser->request, global_request_path, path);
|
|
536
|
+
}
|
|
537
|
+
{
|
|
538
|
+
if (LEN(mark, p) > MAX_URI_LENGTH)
|
|
539
|
+
rb_raise(eHttpParserError, "URI too long");
|
|
540
|
+
VALUE uri = rb_str_new(PTR_TO(mark), LEN(mark, p));
|
|
541
|
+
rb_hash_aset(parser->request, global_request_uri, uri);
|
|
542
|
+
}
|
|
543
|
+
goto st20;
|
|
544
|
+
tr42:
|
|
545
|
+
{ MARK(query_start, p); }
|
|
546
|
+
{
|
|
547
|
+
VALUE query = rb_str_new(PTR_TO(query_start), LEN(query_start, p));
|
|
548
|
+
rb_hash_aset(parser->request, global_query_string, query);
|
|
549
|
+
}
|
|
550
|
+
{
|
|
551
|
+
if (LEN(mark, p) > MAX_URI_LENGTH)
|
|
552
|
+
rb_raise(eHttpParserError, "URI too long");
|
|
553
|
+
VALUE uri = rb_str_new(PTR_TO(mark), LEN(mark, p));
|
|
554
|
+
rb_hash_aset(parser->request, global_request_uri, uri);
|
|
555
|
+
}
|
|
556
|
+
goto st20;
|
|
557
|
+
tr45:
|
|
558
|
+
{
|
|
559
|
+
VALUE query = rb_str_new(PTR_TO(query_start), LEN(query_start, p));
|
|
560
|
+
rb_hash_aset(parser->request, global_query_string, query);
|
|
561
|
+
}
|
|
562
|
+
{
|
|
563
|
+
if (LEN(mark, p) > MAX_URI_LENGTH)
|
|
564
|
+
rb_raise(eHttpParserError, "URI too long");
|
|
565
|
+
VALUE uri = rb_str_new(PTR_TO(mark), LEN(mark, p));
|
|
566
|
+
rb_hash_aset(parser->request, global_request_uri, uri);
|
|
567
|
+
}
|
|
568
|
+
goto st20;
|
|
569
|
+
st20:
|
|
570
|
+
if ( ++p == pe )
|
|
571
|
+
goto _test_eof20;
|
|
572
|
+
case 20:
|
|
573
|
+
switch( (*p) ) {
|
|
574
|
+
case 32: goto tr31;
|
|
575
|
+
case 60: goto st0;
|
|
576
|
+
case 62: goto st0;
|
|
577
|
+
case 127: goto st0;
|
|
578
|
+
}
|
|
579
|
+
if ( (*p) > 31 ) {
|
|
580
|
+
if ( 34 <= (*p) && (*p) <= 35 )
|
|
581
|
+
goto st0;
|
|
582
|
+
} else if ( (*p) >= 0 )
|
|
583
|
+
goto st0;
|
|
584
|
+
goto tr30;
|
|
585
|
+
tr30:
|
|
586
|
+
{ MARK(mark, p); }
|
|
587
|
+
goto st21;
|
|
588
|
+
st21:
|
|
589
|
+
if ( ++p == pe )
|
|
590
|
+
goto _test_eof21;
|
|
591
|
+
case 21:
|
|
592
|
+
switch( (*p) ) {
|
|
593
|
+
case 32: goto tr33;
|
|
594
|
+
case 60: goto st0;
|
|
595
|
+
case 62: goto st0;
|
|
596
|
+
case 127: goto st0;
|
|
597
|
+
}
|
|
598
|
+
if ( (*p) > 31 ) {
|
|
599
|
+
if ( 34 <= (*p) && (*p) <= 35 )
|
|
600
|
+
goto st0;
|
|
601
|
+
} else if ( (*p) >= 0 )
|
|
602
|
+
goto st0;
|
|
603
|
+
goto st21;
|
|
604
|
+
tr5:
|
|
605
|
+
{ MARK(mark, p); }
|
|
606
|
+
goto st22;
|
|
607
|
+
st22:
|
|
608
|
+
if ( ++p == pe )
|
|
609
|
+
goto _test_eof22;
|
|
610
|
+
case 22:
|
|
611
|
+
switch( (*p) ) {
|
|
612
|
+
case 43: goto st22;
|
|
613
|
+
case 58: goto st23;
|
|
614
|
+
}
|
|
615
|
+
if ( (*p) < 48 ) {
|
|
616
|
+
if ( 45 <= (*p) && (*p) <= 46 )
|
|
617
|
+
goto st22;
|
|
618
|
+
} else if ( (*p) > 57 ) {
|
|
619
|
+
if ( (*p) > 90 ) {
|
|
620
|
+
if ( 97 <= (*p) && (*p) <= 122 )
|
|
621
|
+
goto st22;
|
|
622
|
+
} else if ( (*p) >= 65 )
|
|
623
|
+
goto st22;
|
|
624
|
+
} else
|
|
625
|
+
goto st22;
|
|
626
|
+
goto st0;
|
|
627
|
+
tr7:
|
|
628
|
+
{ MARK(mark, p); }
|
|
629
|
+
goto st23;
|
|
630
|
+
st23:
|
|
631
|
+
if ( ++p == pe )
|
|
632
|
+
goto _test_eof23;
|
|
633
|
+
case 23:
|
|
634
|
+
switch( (*p) ) {
|
|
635
|
+
case 32: goto tr8;
|
|
636
|
+
case 34: goto st0;
|
|
637
|
+
case 35: goto tr9;
|
|
638
|
+
case 60: goto st0;
|
|
639
|
+
case 62: goto st0;
|
|
640
|
+
case 127: goto st0;
|
|
641
|
+
}
|
|
642
|
+
if ( 0 <= (*p) && (*p) <= 31 )
|
|
643
|
+
goto st0;
|
|
644
|
+
goto st23;
|
|
645
|
+
tr6:
|
|
646
|
+
{ MARK(mark, p); }
|
|
647
|
+
goto st24;
|
|
648
|
+
st24:
|
|
649
|
+
if ( ++p == pe )
|
|
650
|
+
goto _test_eof24;
|
|
651
|
+
case 24:
|
|
652
|
+
switch( (*p) ) {
|
|
653
|
+
case 32: goto tr37;
|
|
654
|
+
case 34: goto st0;
|
|
655
|
+
case 35: goto tr38;
|
|
656
|
+
case 60: goto st0;
|
|
657
|
+
case 62: goto st0;
|
|
658
|
+
case 63: goto tr39;
|
|
659
|
+
case 127: goto st0;
|
|
660
|
+
}
|
|
661
|
+
if ( 0 <= (*p) && (*p) <= 31 )
|
|
662
|
+
goto st0;
|
|
663
|
+
goto st24;
|
|
664
|
+
tr39:
|
|
665
|
+
{
|
|
666
|
+
VALUE path = rb_str_new(PTR_TO(mark), LEN(mark,p));
|
|
667
|
+
rb_hash_aset(parser->request, global_request_path, path);
|
|
668
|
+
}
|
|
669
|
+
goto st25;
|
|
670
|
+
st25:
|
|
671
|
+
if ( ++p == pe )
|
|
672
|
+
goto _test_eof25;
|
|
673
|
+
case 25:
|
|
674
|
+
switch( (*p) ) {
|
|
675
|
+
case 32: goto tr41;
|
|
676
|
+
case 34: goto st0;
|
|
677
|
+
case 35: goto tr42;
|
|
678
|
+
case 60: goto st0;
|
|
679
|
+
case 62: goto st0;
|
|
680
|
+
case 127: goto st0;
|
|
681
|
+
}
|
|
682
|
+
if ( 0 <= (*p) && (*p) <= 31 )
|
|
683
|
+
goto st0;
|
|
684
|
+
goto tr40;
|
|
685
|
+
tr40:
|
|
686
|
+
{ MARK(query_start, p); }
|
|
687
|
+
goto st26;
|
|
688
|
+
st26:
|
|
689
|
+
if ( ++p == pe )
|
|
690
|
+
goto _test_eof26;
|
|
691
|
+
case 26:
|
|
692
|
+
switch( (*p) ) {
|
|
693
|
+
case 32: goto tr44;
|
|
694
|
+
case 34: goto st0;
|
|
695
|
+
case 35: goto tr45;
|
|
696
|
+
case 60: goto st0;
|
|
697
|
+
case 62: goto st0;
|
|
698
|
+
case 127: goto st0;
|
|
699
|
+
}
|
|
700
|
+
if ( 0 <= (*p) && (*p) <= 31 )
|
|
701
|
+
goto st0;
|
|
702
|
+
goto st26;
|
|
703
|
+
st27:
|
|
704
|
+
if ( ++p == pe )
|
|
705
|
+
goto _test_eof27;
|
|
706
|
+
case 27:
|
|
707
|
+
switch( (*p) ) {
|
|
708
|
+
case 32: goto tr2;
|
|
709
|
+
case 36: goto st28;
|
|
710
|
+
case 95: goto st28;
|
|
711
|
+
}
|
|
712
|
+
if ( (*p) < 48 ) {
|
|
713
|
+
if ( 45 <= (*p) && (*p) <= 46 )
|
|
714
|
+
goto st28;
|
|
715
|
+
} else if ( (*p) > 57 ) {
|
|
716
|
+
if ( 65 <= (*p) && (*p) <= 90 )
|
|
717
|
+
goto st28;
|
|
718
|
+
} else
|
|
719
|
+
goto st28;
|
|
720
|
+
goto st0;
|
|
721
|
+
st28:
|
|
722
|
+
if ( ++p == pe )
|
|
723
|
+
goto _test_eof28;
|
|
724
|
+
case 28:
|
|
725
|
+
switch( (*p) ) {
|
|
726
|
+
case 32: goto tr2;
|
|
727
|
+
case 36: goto st29;
|
|
728
|
+
case 95: goto st29;
|
|
729
|
+
}
|
|
730
|
+
if ( (*p) < 48 ) {
|
|
731
|
+
if ( 45 <= (*p) && (*p) <= 46 )
|
|
732
|
+
goto st29;
|
|
733
|
+
} else if ( (*p) > 57 ) {
|
|
734
|
+
if ( 65 <= (*p) && (*p) <= 90 )
|
|
735
|
+
goto st29;
|
|
736
|
+
} else
|
|
737
|
+
goto st29;
|
|
738
|
+
goto st0;
|
|
739
|
+
st29:
|
|
740
|
+
if ( ++p == pe )
|
|
741
|
+
goto _test_eof29;
|
|
742
|
+
case 29:
|
|
743
|
+
switch( (*p) ) {
|
|
744
|
+
case 32: goto tr2;
|
|
745
|
+
case 36: goto st30;
|
|
746
|
+
case 95: goto st30;
|
|
747
|
+
}
|
|
748
|
+
if ( (*p) < 48 ) {
|
|
749
|
+
if ( 45 <= (*p) && (*p) <= 46 )
|
|
750
|
+
goto st30;
|
|
751
|
+
} else if ( (*p) > 57 ) {
|
|
752
|
+
if ( 65 <= (*p) && (*p) <= 90 )
|
|
753
|
+
goto st30;
|
|
754
|
+
} else
|
|
755
|
+
goto st30;
|
|
756
|
+
goto st0;
|
|
757
|
+
st30:
|
|
758
|
+
if ( ++p == pe )
|
|
759
|
+
goto _test_eof30;
|
|
760
|
+
case 30:
|
|
761
|
+
switch( (*p) ) {
|
|
762
|
+
case 32: goto tr2;
|
|
763
|
+
case 36: goto st31;
|
|
764
|
+
case 95: goto st31;
|
|
765
|
+
}
|
|
766
|
+
if ( (*p) < 48 ) {
|
|
767
|
+
if ( 45 <= (*p) && (*p) <= 46 )
|
|
768
|
+
goto st31;
|
|
769
|
+
} else if ( (*p) > 57 ) {
|
|
770
|
+
if ( 65 <= (*p) && (*p) <= 90 )
|
|
771
|
+
goto st31;
|
|
772
|
+
} else
|
|
773
|
+
goto st31;
|
|
774
|
+
goto st0;
|
|
775
|
+
st31:
|
|
776
|
+
if ( ++p == pe )
|
|
777
|
+
goto _test_eof31;
|
|
778
|
+
case 31:
|
|
779
|
+
switch( (*p) ) {
|
|
780
|
+
case 32: goto tr2;
|
|
781
|
+
case 36: goto st32;
|
|
782
|
+
case 95: goto st32;
|
|
783
|
+
}
|
|
784
|
+
if ( (*p) < 48 ) {
|
|
785
|
+
if ( 45 <= (*p) && (*p) <= 46 )
|
|
786
|
+
goto st32;
|
|
787
|
+
} else if ( (*p) > 57 ) {
|
|
788
|
+
if ( 65 <= (*p) && (*p) <= 90 )
|
|
789
|
+
goto st32;
|
|
790
|
+
} else
|
|
791
|
+
goto st32;
|
|
792
|
+
goto st0;
|
|
793
|
+
st32:
|
|
794
|
+
if ( ++p == pe )
|
|
795
|
+
goto _test_eof32;
|
|
796
|
+
case 32:
|
|
797
|
+
switch( (*p) ) {
|
|
798
|
+
case 32: goto tr2;
|
|
799
|
+
case 36: goto st33;
|
|
800
|
+
case 95: goto st33;
|
|
801
|
+
}
|
|
802
|
+
if ( (*p) < 48 ) {
|
|
803
|
+
if ( 45 <= (*p) && (*p) <= 46 )
|
|
804
|
+
goto st33;
|
|
805
|
+
} else if ( (*p) > 57 ) {
|
|
806
|
+
if ( 65 <= (*p) && (*p) <= 90 )
|
|
807
|
+
goto st33;
|
|
808
|
+
} else
|
|
809
|
+
goto st33;
|
|
810
|
+
goto st0;
|
|
811
|
+
st33:
|
|
812
|
+
if ( ++p == pe )
|
|
813
|
+
goto _test_eof33;
|
|
814
|
+
case 33:
|
|
815
|
+
switch( (*p) ) {
|
|
816
|
+
case 32: goto tr2;
|
|
817
|
+
case 36: goto st34;
|
|
818
|
+
case 95: goto st34;
|
|
819
|
+
}
|
|
820
|
+
if ( (*p) < 48 ) {
|
|
821
|
+
if ( 45 <= (*p) && (*p) <= 46 )
|
|
822
|
+
goto st34;
|
|
823
|
+
} else if ( (*p) > 57 ) {
|
|
824
|
+
if ( 65 <= (*p) && (*p) <= 90 )
|
|
825
|
+
goto st34;
|
|
826
|
+
} else
|
|
827
|
+
goto st34;
|
|
828
|
+
goto st0;
|
|
829
|
+
st34:
|
|
830
|
+
if ( ++p == pe )
|
|
831
|
+
goto _test_eof34;
|
|
832
|
+
case 34:
|
|
833
|
+
switch( (*p) ) {
|
|
834
|
+
case 32: goto tr2;
|
|
835
|
+
case 36: goto st35;
|
|
836
|
+
case 95: goto st35;
|
|
837
|
+
}
|
|
838
|
+
if ( (*p) < 48 ) {
|
|
839
|
+
if ( 45 <= (*p) && (*p) <= 46 )
|
|
840
|
+
goto st35;
|
|
841
|
+
} else if ( (*p) > 57 ) {
|
|
842
|
+
if ( 65 <= (*p) && (*p) <= 90 )
|
|
843
|
+
goto st35;
|
|
844
|
+
} else
|
|
845
|
+
goto st35;
|
|
846
|
+
goto st0;
|
|
847
|
+
st35:
|
|
848
|
+
if ( ++p == pe )
|
|
849
|
+
goto _test_eof35;
|
|
850
|
+
case 35:
|
|
851
|
+
switch( (*p) ) {
|
|
852
|
+
case 32: goto tr2;
|
|
853
|
+
case 36: goto st36;
|
|
854
|
+
case 95: goto st36;
|
|
855
|
+
}
|
|
856
|
+
if ( (*p) < 48 ) {
|
|
857
|
+
if ( 45 <= (*p) && (*p) <= 46 )
|
|
858
|
+
goto st36;
|
|
859
|
+
} else if ( (*p) > 57 ) {
|
|
860
|
+
if ( 65 <= (*p) && (*p) <= 90 )
|
|
861
|
+
goto st36;
|
|
862
|
+
} else
|
|
863
|
+
goto st36;
|
|
864
|
+
goto st0;
|
|
865
|
+
st36:
|
|
866
|
+
if ( ++p == pe )
|
|
867
|
+
goto _test_eof36;
|
|
868
|
+
case 36:
|
|
869
|
+
switch( (*p) ) {
|
|
870
|
+
case 32: goto tr2;
|
|
871
|
+
case 36: goto st37;
|
|
872
|
+
case 95: goto st37;
|
|
873
|
+
}
|
|
874
|
+
if ( (*p) < 48 ) {
|
|
875
|
+
if ( 45 <= (*p) && (*p) <= 46 )
|
|
876
|
+
goto st37;
|
|
877
|
+
} else if ( (*p) > 57 ) {
|
|
878
|
+
if ( 65 <= (*p) && (*p) <= 90 )
|
|
879
|
+
goto st37;
|
|
880
|
+
} else
|
|
881
|
+
goto st37;
|
|
882
|
+
goto st0;
|
|
883
|
+
st37:
|
|
884
|
+
if ( ++p == pe )
|
|
885
|
+
goto _test_eof37;
|
|
886
|
+
case 37:
|
|
887
|
+
switch( (*p) ) {
|
|
888
|
+
case 32: goto tr2;
|
|
889
|
+
case 36: goto st38;
|
|
890
|
+
case 95: goto st38;
|
|
891
|
+
}
|
|
892
|
+
if ( (*p) < 48 ) {
|
|
893
|
+
if ( 45 <= (*p) && (*p) <= 46 )
|
|
894
|
+
goto st38;
|
|
895
|
+
} else if ( (*p) > 57 ) {
|
|
896
|
+
if ( 65 <= (*p) && (*p) <= 90 )
|
|
897
|
+
goto st38;
|
|
898
|
+
} else
|
|
899
|
+
goto st38;
|
|
900
|
+
goto st0;
|
|
901
|
+
st38:
|
|
902
|
+
if ( ++p == pe )
|
|
903
|
+
goto _test_eof38;
|
|
904
|
+
case 38:
|
|
905
|
+
switch( (*p) ) {
|
|
906
|
+
case 32: goto tr2;
|
|
907
|
+
case 36: goto st39;
|
|
908
|
+
case 95: goto st39;
|
|
909
|
+
}
|
|
910
|
+
if ( (*p) < 48 ) {
|
|
911
|
+
if ( 45 <= (*p) && (*p) <= 46 )
|
|
912
|
+
goto st39;
|
|
913
|
+
} else if ( (*p) > 57 ) {
|
|
914
|
+
if ( 65 <= (*p) && (*p) <= 90 )
|
|
915
|
+
goto st39;
|
|
916
|
+
} else
|
|
917
|
+
goto st39;
|
|
918
|
+
goto st0;
|
|
919
|
+
st39:
|
|
920
|
+
if ( ++p == pe )
|
|
921
|
+
goto _test_eof39;
|
|
922
|
+
case 39:
|
|
923
|
+
switch( (*p) ) {
|
|
924
|
+
case 32: goto tr2;
|
|
925
|
+
case 36: goto st40;
|
|
926
|
+
case 95: goto st40;
|
|
927
|
+
}
|
|
928
|
+
if ( (*p) < 48 ) {
|
|
929
|
+
if ( 45 <= (*p) && (*p) <= 46 )
|
|
930
|
+
goto st40;
|
|
931
|
+
} else if ( (*p) > 57 ) {
|
|
932
|
+
if ( 65 <= (*p) && (*p) <= 90 )
|
|
933
|
+
goto st40;
|
|
934
|
+
} else
|
|
935
|
+
goto st40;
|
|
936
|
+
goto st0;
|
|
937
|
+
st40:
|
|
938
|
+
if ( ++p == pe )
|
|
939
|
+
goto _test_eof40;
|
|
940
|
+
case 40:
|
|
941
|
+
switch( (*p) ) {
|
|
942
|
+
case 32: goto tr2;
|
|
943
|
+
case 36: goto st41;
|
|
944
|
+
case 95: goto st41;
|
|
945
|
+
}
|
|
946
|
+
if ( (*p) < 48 ) {
|
|
947
|
+
if ( 45 <= (*p) && (*p) <= 46 )
|
|
948
|
+
goto st41;
|
|
949
|
+
} else if ( (*p) > 57 ) {
|
|
950
|
+
if ( 65 <= (*p) && (*p) <= 90 )
|
|
951
|
+
goto st41;
|
|
952
|
+
} else
|
|
953
|
+
goto st41;
|
|
954
|
+
goto st0;
|
|
955
|
+
st41:
|
|
956
|
+
if ( ++p == pe )
|
|
957
|
+
goto _test_eof41;
|
|
958
|
+
case 41:
|
|
959
|
+
switch( (*p) ) {
|
|
960
|
+
case 32: goto tr2;
|
|
961
|
+
case 36: goto st42;
|
|
962
|
+
case 95: goto st42;
|
|
963
|
+
}
|
|
964
|
+
if ( (*p) < 48 ) {
|
|
965
|
+
if ( 45 <= (*p) && (*p) <= 46 )
|
|
966
|
+
goto st42;
|
|
967
|
+
} else if ( (*p) > 57 ) {
|
|
968
|
+
if ( 65 <= (*p) && (*p) <= 90 )
|
|
969
|
+
goto st42;
|
|
970
|
+
} else
|
|
971
|
+
goto st42;
|
|
972
|
+
goto st0;
|
|
973
|
+
st42:
|
|
974
|
+
if ( ++p == pe )
|
|
975
|
+
goto _test_eof42;
|
|
976
|
+
case 42:
|
|
977
|
+
switch( (*p) ) {
|
|
978
|
+
case 32: goto tr2;
|
|
979
|
+
case 36: goto st43;
|
|
980
|
+
case 95: goto st43;
|
|
981
|
+
}
|
|
982
|
+
if ( (*p) < 48 ) {
|
|
983
|
+
if ( 45 <= (*p) && (*p) <= 46 )
|
|
984
|
+
goto st43;
|
|
985
|
+
} else if ( (*p) > 57 ) {
|
|
986
|
+
if ( 65 <= (*p) && (*p) <= 90 )
|
|
987
|
+
goto st43;
|
|
988
|
+
} else
|
|
989
|
+
goto st43;
|
|
990
|
+
goto st0;
|
|
991
|
+
st43:
|
|
992
|
+
if ( ++p == pe )
|
|
993
|
+
goto _test_eof43;
|
|
994
|
+
case 43:
|
|
995
|
+
switch( (*p) ) {
|
|
996
|
+
case 32: goto tr2;
|
|
997
|
+
case 36: goto st44;
|
|
998
|
+
case 95: goto st44;
|
|
999
|
+
}
|
|
1000
|
+
if ( (*p) < 48 ) {
|
|
1001
|
+
if ( 45 <= (*p) && (*p) <= 46 )
|
|
1002
|
+
goto st44;
|
|
1003
|
+
} else if ( (*p) > 57 ) {
|
|
1004
|
+
if ( 65 <= (*p) && (*p) <= 90 )
|
|
1005
|
+
goto st44;
|
|
1006
|
+
} else
|
|
1007
|
+
goto st44;
|
|
1008
|
+
goto st0;
|
|
1009
|
+
st44:
|
|
1010
|
+
if ( ++p == pe )
|
|
1011
|
+
goto _test_eof44;
|
|
1012
|
+
case 44:
|
|
1013
|
+
switch( (*p) ) {
|
|
1014
|
+
case 32: goto tr2;
|
|
1015
|
+
case 36: goto st45;
|
|
1016
|
+
case 95: goto st45;
|
|
1017
|
+
}
|
|
1018
|
+
if ( (*p) < 48 ) {
|
|
1019
|
+
if ( 45 <= (*p) && (*p) <= 46 )
|
|
1020
|
+
goto st45;
|
|
1021
|
+
} else if ( (*p) > 57 ) {
|
|
1022
|
+
if ( 65 <= (*p) && (*p) <= 90 )
|
|
1023
|
+
goto st45;
|
|
1024
|
+
} else
|
|
1025
|
+
goto st45;
|
|
1026
|
+
goto st0;
|
|
1027
|
+
st45:
|
|
1028
|
+
if ( ++p == pe )
|
|
1029
|
+
goto _test_eof45;
|
|
1030
|
+
case 45:
|
|
1031
|
+
if ( (*p) == 32 )
|
|
1032
|
+
goto tr2;
|
|
1033
|
+
goto st0;
|
|
1034
|
+
}
|
|
1035
|
+
_test_eof2: cs = 2; goto _test_eof;
|
|
1036
|
+
_test_eof3: cs = 3; goto _test_eof;
|
|
1037
|
+
_test_eof4: cs = 4; goto _test_eof;
|
|
1038
|
+
_test_eof5: cs = 5; goto _test_eof;
|
|
1039
|
+
_test_eof6: cs = 6; goto _test_eof;
|
|
1040
|
+
_test_eof7: cs = 7; goto _test_eof;
|
|
1041
|
+
_test_eof8: cs = 8; goto _test_eof;
|
|
1042
|
+
_test_eof9: cs = 9; goto _test_eof;
|
|
1043
|
+
_test_eof10: cs = 10; goto _test_eof;
|
|
1044
|
+
_test_eof11: cs = 11; goto _test_eof;
|
|
1045
|
+
_test_eof12: cs = 12; goto _test_eof;
|
|
1046
|
+
_test_eof13: cs = 13; goto _test_eof;
|
|
1047
|
+
_test_eof14: cs = 14; goto _test_eof;
|
|
1048
|
+
_test_eof15: cs = 15; goto _test_eof;
|
|
1049
|
+
_test_eof16: cs = 16; goto _test_eof;
|
|
1050
|
+
_test_eof46: cs = 46; goto _test_eof;
|
|
1051
|
+
_test_eof17: cs = 17; goto _test_eof;
|
|
1052
|
+
_test_eof18: cs = 18; goto _test_eof;
|
|
1053
|
+
_test_eof19: cs = 19; goto _test_eof;
|
|
1054
|
+
_test_eof20: cs = 20; goto _test_eof;
|
|
1055
|
+
_test_eof21: cs = 21; goto _test_eof;
|
|
1056
|
+
_test_eof22: cs = 22; goto _test_eof;
|
|
1057
|
+
_test_eof23: cs = 23; goto _test_eof;
|
|
1058
|
+
_test_eof24: cs = 24; goto _test_eof;
|
|
1059
|
+
_test_eof25: cs = 25; goto _test_eof;
|
|
1060
|
+
_test_eof26: cs = 26; goto _test_eof;
|
|
1061
|
+
_test_eof27: cs = 27; goto _test_eof;
|
|
1062
|
+
_test_eof28: cs = 28; goto _test_eof;
|
|
1063
|
+
_test_eof29: cs = 29; goto _test_eof;
|
|
1064
|
+
_test_eof30: cs = 30; goto _test_eof;
|
|
1065
|
+
_test_eof31: cs = 31; goto _test_eof;
|
|
1066
|
+
_test_eof32: cs = 32; goto _test_eof;
|
|
1067
|
+
_test_eof33: cs = 33; goto _test_eof;
|
|
1068
|
+
_test_eof34: cs = 34; goto _test_eof;
|
|
1069
|
+
_test_eof35: cs = 35; goto _test_eof;
|
|
1070
|
+
_test_eof36: cs = 36; goto _test_eof;
|
|
1071
|
+
_test_eof37: cs = 37; goto _test_eof;
|
|
1072
|
+
_test_eof38: cs = 38; goto _test_eof;
|
|
1073
|
+
_test_eof39: cs = 39; goto _test_eof;
|
|
1074
|
+
_test_eof40: cs = 40; goto _test_eof;
|
|
1075
|
+
_test_eof41: cs = 41; goto _test_eof;
|
|
1076
|
+
_test_eof42: cs = 42; goto _test_eof;
|
|
1077
|
+
_test_eof43: cs = 43; goto _test_eof;
|
|
1078
|
+
_test_eof44: cs = 44; goto _test_eof;
|
|
1079
|
+
_test_eof45: cs = 45; goto _test_eof;
|
|
1080
|
+
|
|
1081
|
+
_test_eof: {}
|
|
1082
|
+
_out: {}
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
done:
|
|
1086
|
+
parser->cs = cs;
|
|
1087
|
+
parser->nread = p - buffer;
|
|
1088
|
+
|
|
1089
|
+
assert(p <= pe && "buffer overflow after parsing execute");
|
|
1090
|
+
assert(parser->nread <= len && "nread longer than length");
|
|
1091
|
+
assert(parser->body_start <= len && "body starts after buffer end");
|
|
1092
|
+
|
|
1093
|
+
return parser->nread;
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
int raptor_parser_finished(raptor_parser *parser) {
|
|
1097
|
+
return (parser->flags & FLAG_FINISHED) != 0;
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
int raptor_parser_has_body(raptor_parser *parser) {
|
|
1101
|
+
return (parser->flags & FLAG_HAS_BODY) != 0;
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
size_t raptor_parser_content_length(raptor_parser *parser) {
|
|
1105
|
+
return parser->content_len;
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
int raptor_parser_is_chunked(raptor_parser *parser) {
|
|
1109
|
+
return (parser->flags & FLAG_CHUNKED) != 0;
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
int raptor_parser_has_error(raptor_parser *parser) {
|
|
1113
|
+
return parser->cs == raptor_parser_error;
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
int raptor_parser_is_finished(raptor_parser *parser) {
|
|
1117
|
+
return parser->cs >= raptor_parser_first_final;
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
void raptor_parser_init(raptor_parser *parser) {
|
|
1121
|
+
parser->cs = raptor_parser_start;
|
|
1122
|
+
parser->mark = 0;
|
|
1123
|
+
parser->field_start = 0;
|
|
1124
|
+
parser->field_len = 0;
|
|
1125
|
+
parser->query_start = 0;
|
|
1126
|
+
parser->nread = 0;
|
|
1127
|
+
parser->body_start = 0;
|
|
1128
|
+
parser->content_len = 0;
|
|
1129
|
+
parser->flags = 0;
|
|
1130
|
+
parser->request = Qnil;
|
|
1131
|
+
parser->body = Qnil;
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1134
|
+
static VALUE cHttpParser;
|
|
1135
|
+
|
|
1136
|
+
static void parser_mark(void *ptr) {
|
|
1137
|
+
raptor_parser *parser = ptr;
|
|
1138
|
+
rb_gc_mark(parser->request);
|
|
1139
|
+
rb_gc_mark(parser->body);
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
static void parser_free(void *ptr) {
|
|
1143
|
+
xfree(ptr);
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
static size_t parser_memsize(const void *ptr) {
|
|
1147
|
+
return sizeof(raptor_parser);
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
static const rb_data_type_t parser_type = {
|
|
1151
|
+
"raptor_http_parser",
|
|
1152
|
+
{ parser_mark, parser_free, parser_memsize },
|
|
1153
|
+
0, 0, RUBY_TYPED_FREE_IMMEDIATELY
|
|
1154
|
+
};
|
|
1155
|
+
|
|
1156
|
+
static VALUE parser_alloc(VALUE klass) {
|
|
1157
|
+
raptor_parser *parser;
|
|
1158
|
+
VALUE obj = TypedData_Make_Struct(klass, raptor_parser, &parser_type, parser);
|
|
1159
|
+
raptor_parser_init(parser);
|
|
1160
|
+
return obj;
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
static VALUE parser_execute(VALUE self, VALUE req_hash, VALUE buffer, VALUE start) {
|
|
1164
|
+
raptor_parser *parser;
|
|
1165
|
+
TypedData_Get_Struct(self, raptor_parser, &parser_type, parser);
|
|
1166
|
+
|
|
1167
|
+
Check_Type(buffer, T_STRING);
|
|
1168
|
+
parser->request = req_hash;
|
|
1169
|
+
|
|
1170
|
+
size_t from = NUM2SIZET(start);
|
|
1171
|
+
const char *data = RSTRING_PTR(buffer);
|
|
1172
|
+
size_t len = RSTRING_LEN(buffer);
|
|
1173
|
+
|
|
1174
|
+
if (from >= len)
|
|
1175
|
+
rb_raise(eHttpParserError, "start is after buffer end");
|
|
1176
|
+
|
|
1177
|
+
raptor_parser_execute(parser, data + from, len - from);
|
|
1178
|
+
|
|
1179
|
+
return SIZET2NUM(parser->nread);
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
static VALUE parser_finished_p(VALUE self) {
|
|
1183
|
+
raptor_parser *parser;
|
|
1184
|
+
TypedData_Get_Struct(self, raptor_parser, &parser_type, parser);
|
|
1185
|
+
return raptor_parser_finished(parser) ? Qtrue : Qfalse;
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
static VALUE parser_has_body_p(VALUE self) {
|
|
1189
|
+
raptor_parser *parser;
|
|
1190
|
+
TypedData_Get_Struct(self, raptor_parser, &parser_type, parser);
|
|
1191
|
+
return raptor_parser_has_body(parser) ? Qtrue : Qfalse;
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
static VALUE parser_content_length(VALUE self) {
|
|
1195
|
+
raptor_parser *parser;
|
|
1196
|
+
TypedData_Get_Struct(self, raptor_parser, &parser_type, parser);
|
|
1197
|
+
return SIZET2NUM(raptor_parser_content_length(parser));
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
static VALUE parser_nread(VALUE self) {
|
|
1201
|
+
raptor_parser *parser;
|
|
1202
|
+
TypedData_Get_Struct(self, raptor_parser, &parser_type, parser);
|
|
1203
|
+
return SIZET2NUM(parser->nread);
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
static VALUE parser_reset(VALUE self) {
|
|
1207
|
+
raptor_parser *parser;
|
|
1208
|
+
TypedData_Get_Struct(self, raptor_parser, &parser_type, parser);
|
|
1209
|
+
raptor_parser_init(parser);
|
|
1210
|
+
return Qnil;
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1213
|
+
static VALUE parser_body(VALUE self) {
|
|
1214
|
+
raptor_parser *parser;
|
|
1215
|
+
TypedData_Get_Struct(self, raptor_parser, &parser_type, parser);
|
|
1216
|
+
return parser->body;
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
RUBY_FUNC_EXPORTED void Init_raptor_http(void) {
|
|
1220
|
+
rb_ext_ractor_safe(true);
|
|
1221
|
+
|
|
1222
|
+
VALUE mRaptor = rb_define_module("Raptor");
|
|
1223
|
+
cHttpParser = rb_define_class_under(mRaptor, "HttpParser", rb_cObject);
|
|
1224
|
+
eHttpParserError = rb_define_class_under(mRaptor, "HttpParserError", rb_eStandardError);
|
|
1225
|
+
|
|
1226
|
+
rb_global_variable(&global_request_method);
|
|
1227
|
+
rb_global_variable(&global_request_uri);
|
|
1228
|
+
rb_global_variable(&global_query_string);
|
|
1229
|
+
rb_global_variable(&global_server_protocol);
|
|
1230
|
+
rb_global_variable(&global_request_path);
|
|
1231
|
+
rb_global_variable(&global_fragment);
|
|
1232
|
+
|
|
1233
|
+
global_request_method = rb_str_new2("REQUEST_METHOD");
|
|
1234
|
+
global_request_uri = rb_str_new2("REQUEST_URI");
|
|
1235
|
+
global_query_string = rb_str_new2("QUERY_STRING");
|
|
1236
|
+
global_server_protocol = rb_str_new2("SERVER_PROTOCOL");
|
|
1237
|
+
global_request_path = rb_str_new2("PATH_INFO");
|
|
1238
|
+
global_fragment = rb_str_new2("FRAGMENT");
|
|
1239
|
+
|
|
1240
|
+
rb_define_alloc_func(cHttpParser, parser_alloc);
|
|
1241
|
+
rb_define_method(cHttpParser, "execute", parser_execute, 3);
|
|
1242
|
+
rb_define_method(cHttpParser, "finished?", parser_finished_p, 0);
|
|
1243
|
+
rb_define_method(cHttpParser, "has_body?", parser_has_body_p, 0);
|
|
1244
|
+
rb_define_method(cHttpParser, "content_length", parser_content_length, 0);
|
|
1245
|
+
rb_define_method(cHttpParser, "nread", parser_nread, 0);
|
|
1246
|
+
rb_define_method(cHttpParser, "reset", parser_reset, 0);
|
|
1247
|
+
rb_define_method(cHttpParser, "body", parser_body, 0);
|
|
1248
|
+
}
|