Class: HTTP::Parser
- Inherits:
-
Object
show all
- Defined in:
- ext/ruby_http_parser/ruby_http_parser.c
Defined Under Namespace
Classes: Error
Instance Method Summary
collapse
Constructor Details
#initialize(*args) ⇒ Object
279
280
281
282
283
284
285
286
287
|
# File 'ext/ruby_http_parser/ruby_http_parser.c', line 279
VALUE Parser_initialize(int argc, VALUE *argv, VALUE self) {
ParserWrapper *wrapper = NULL;
DATA_GET(self, ParserWrapper, wrapper);
if (argc == 1)
wrapper->callback_object = argv[0];
return self;
}
|
Instance Method Details
#<<(data) ⇒ Object
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
|
# File 'ext/ruby_http_parser/ruby_http_parser.c', line 289
VALUE Parser_execute(VALUE self, VALUE data) {
ParserWrapper *wrapper = NULL;
Check_Type(data, T_STRING);
char *ptr = RSTRING_PTR(data);
long len = RSTRING_LEN(data);
DATA_GET(self, ParserWrapper, wrapper);
wrapper->stopped = Qfalse;
size_t nparsed = ryah_http_parser_execute(&wrapper->parser, &settings, ptr, len);
if (wrapper->parser.upgrade) {
// upgrade request
} else if (nparsed != len) {
if (!RTEST(wrapper->stopped) && !RTEST(wrapper->completed))
rb_raise(eParserError, "Could not parse data entirely");
else
nparsed += 1; // error states fail on the current character
}
return INT2FIX(nparsed);
}
|
#fragment ⇒ Object
#http_major ⇒ Object
369
370
371
372
373
374
375
376
377
|
# File 'ext/ruby_http_parser/ruby_http_parser.c', line 369
VALUE Parser_http_major(VALUE self) {
ParserWrapper *wrapper = NULL;
DATA_GET(self, ParserWrapper, wrapper);
if (wrapper->parser.http_major == 0 && wrapper->parser.http_minor == 0)
return Qnil;
else
return INT2FIX(wrapper->parser.http_major);
}
|
#http_method ⇒ Object
389
390
391
392
393
394
395
396
397
|
# File 'ext/ruby_http_parser/ruby_http_parser.c', line 389
VALUE Parser_http_method(VALUE self) {
ParserWrapper *wrapper = NULL;
DATA_GET(self, ParserWrapper, wrapper);
if (wrapper->parser.type == HTTP_REQUEST)
return rb_str_new2(http_method_str(wrapper->parser.method));
else
return Qnil;
}
|
#http_minor ⇒ Object
379
380
381
382
383
384
385
386
387
|
# File 'ext/ruby_http_parser/ruby_http_parser.c', line 379
VALUE Parser_http_minor(VALUE self) {
ParserWrapper *wrapper = NULL;
DATA_GET(self, ParserWrapper, wrapper);
if (wrapper->parser.http_major == 0 && wrapper->parser.http_minor == 0)
return Qnil;
else
return INT2FIX(wrapper->parser.http_minor);
}
|
#http_version ⇒ Object
359
360
361
362
363
364
365
366
367
|
# File 'ext/ruby_http_parser/ruby_http_parser.c', line 359
VALUE Parser_http_version(VALUE self) {
ParserWrapper *wrapper = NULL;
DATA_GET(self, ParserWrapper, wrapper);
if (wrapper->parser.http_major == 0 && wrapper->parser.http_minor == 0)
return Qnil;
else
return rb_ary_new3(2, INT2FIX(wrapper->parser.http_major), INT2FIX(wrapper->parser.http_minor));
}
|
#keep_alive? ⇒ Boolean
345
346
347
348
349
350
|
# File 'ext/ruby_http_parser/ruby_http_parser.c', line 345
VALUE Parser_keep_alive_p(VALUE self) {
ParserWrapper *wrapper = NULL;
DATA_GET(self, ParserWrapper, wrapper);
return http_should_keep_alive(&wrapper->parser) == 1 ? Qtrue : Qfalse;
}
|
#on_body=(callback) ⇒ Object
329
330
331
332
333
334
335
|
# File 'ext/ruby_http_parser/ruby_http_parser.c', line 329
VALUE Parser_set_on_body(VALUE self, VALUE callback) {
ParserWrapper *wrapper = NULL;
DATA_GET(self, ParserWrapper, wrapper);
wrapper->on_body = callback;
return callback;
}
|
321
322
323
324
325
326
327
|
# File 'ext/ruby_http_parser/ruby_http_parser.c', line 321
VALUE Parser_set_on_headers_complete(VALUE self, VALUE callback) {
ParserWrapper *wrapper = NULL;
DATA_GET(self, ParserWrapper, wrapper);
wrapper->on_headers_complete = callback;
return callback;
}
|
#on_message_begin=(callback) ⇒ Object
313
314
315
316
317
318
319
|
# File 'ext/ruby_http_parser/ruby_http_parser.c', line 313
VALUE Parser_set_on_message_begin(VALUE self, VALUE callback) {
ParserWrapper *wrapper = NULL;
DATA_GET(self, ParserWrapper, wrapper);
wrapper->on_message_begin = callback;
return callback;
}
|
#on_message_complete=(callback) ⇒ Object
337
338
339
340
341
342
343
|
# File 'ext/ruby_http_parser/ruby_http_parser.c', line 337
VALUE Parser_set_on_message_complete(VALUE self, VALUE callback) {
ParserWrapper *wrapper = NULL;
DATA_GET(self, ParserWrapper, wrapper);
wrapper->on_message_complete = callback;
return callback;
}
|
#query_string ⇒ Object
#request_path ⇒ Object
#request_url ⇒ Object
#reset! ⇒ Object
422
423
424
425
426
427
428
429
|
# File 'ext/ruby_http_parser/ruby_http_parser.c', line 422
VALUE Parser_reset(VALUE self) {
ParserWrapper *wrapper = NULL;
DATA_GET(self, ParserWrapper, wrapper);
ParserWrapper_init(wrapper);
return Qtrue;
}
|
#status_code ⇒ Object
399
400
401
402
403
404
405
406
407
|
# File 'ext/ruby_http_parser/ruby_http_parser.c', line 399
VALUE Parser_status_code(VALUE self) {
ParserWrapper *wrapper = NULL;
DATA_GET(self, ParserWrapper, wrapper);
if (wrapper->parser.status_code)
return INT2FIX(wrapper->parser.status_code);
else
return Qnil;
}
|
#upgrade? ⇒ Boolean
352
353
354
355
356
357
|
# File 'ext/ruby_http_parser/ruby_http_parser.c', line 352
VALUE Parser_upgrade_p(VALUE self) {
ParserWrapper *wrapper = NULL;
DATA_GET(self, ParserWrapper, wrapper);
return wrapper->parser.upgrade == 1 ? Qtrue : Qfalse;
}
|