Class: Agoo::Request
- Inherits:
-
Object
- Object
- Agoo::Request
- Defined in:
- ext/agoo/request.c,
ext/agoo/request.c,
ext/agoo/request.c
Overview
A representation of an HTTP request that is used with a handler that responds to the on_request method. The request is a more efficient encapsulation of the rack environment.
Instance Method Summary collapse
-
#body ⇒ Object
call-seq: body().
-
#call ⇒ Object
call-seq: call().
-
#env ⇒ Object
call-seq: to_h().
-
#environment ⇒ Object
call-seq: to_h().
-
#headers ⇒ Object
call-seq: headers().
-
#path_info ⇒ Object
call-seq: path_info().
-
#query_string ⇒ Object
call-seq: query_string().
-
#rack_errors ⇒ Object
call-seq: rack_errors().
-
#rack_input ⇒ Object
call-seq: rack_input().
-
#rack_logger ⇒ Object
call-seq: rack_logger().
-
#rack_multiprocess ⇒ Object
call-seq: rack_multiprocess().
-
#rack_multithread ⇒ Object
call-seq: rack_multithread().
-
#rack_run_once ⇒ Object
call-seq: rack_run_once().
-
#rack_upgrade? ⇒ Boolean
call-seq: rack_upgrade?().
-
#rack_url_scheme ⇒ Object
call-seq: rack_url_scheme().
-
#rack_version ⇒ Object
call-seq: rack_version().
-
#request_method ⇒ Object
call-seq: request_method().
-
#script_name ⇒ Object
call-seq: script_name().
-
#server_name ⇒ Object
call-seq: server_name().
-
#server_port ⇒ Object
call-seq: server_port().
-
#to_h ⇒ Object
call-seq: to_h().
-
#to_s ⇒ Object
call-seq: to_s().
Instance Method Details
#body ⇒ Object
call-seq: body()
Returns the body of the request as a String. If there is no body then nil is returned.
515 516 517 518 519 520 521 522 523 524 525 526 |
# File 'ext/agoo/request.c', line 515
static VALUE
body(VALUE self) {
Req r = DATA_PTR(self);
if (NULL == r) {
rb_raise(rb_eArgError, "Request is no longer valid.");
}
if (NULL == r->body.start) {
return Qnil;
}
return rb_str_new(r->body.start, r->body.len);
}
|
#call ⇒ Object
call-seq: call()
Returns an IO like object and hijacks the connection.
630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 |
# File 'ext/agoo/request.c', line 630
static VALUE
call(VALUE self) {
Req r = DATA_PTR(self);
VALUE args[1];
volatile VALUE io;
if (NULL == r) {
rb_raise(rb_eArgError, "Request is no longer valid.");
}
r->res->con->hijacked = true;
// TBD try basic IO first. If that fails define a socket class
// is a mode needed?
args[0] = INT2NUM(r->res->con->sock);
io = rb_class_new_instance(1, args, rb_cIO);
rb_hash_aset(r->env, rack_hijack_io_val, io);
return io;
}
|
#env ⇒ Object
call-seq: to_h()
Returns a Hash representation of the request which is the same as a rack environment Hash.
601 602 603 604 605 606 607 608 609 |
# File 'ext/agoo/request.c', line 601
static VALUE
to_h(VALUE self) {
Req r = DATA_PTR(self);
if (NULL == r) {
rb_raise(rb_eArgError, "Request is no longer valid.");
}
return request_env(r, self);
}
|
#environment ⇒ Object
call-seq: to_h()
Returns a Hash representation of the request which is the same as a rack environment Hash.
601 602 603 604 605 606 607 608 609 |
# File 'ext/agoo/request.c', line 601
static VALUE
to_h(VALUE self) {
Req r = DATA_PTR(self);
if (NULL == r) {
rb_raise(rb_eArgError, "Request is no longer valid.");
}
return request_env(r, self);
}
|
#headers ⇒ Object
call-seq: headers()
Returns the header of the request as a Hash.
494 495 496 497 498 499 500 501 502 503 504 505 506 |
# File 'ext/agoo/request.c', line 494
static VALUE
headers(VALUE self) {
Req r = DATA_PTR(self);
volatile VALUE h;
if (NULL == r) {
rb_raise(rb_eArgError, "Request is no longer valid.");
}
h = rb_hash_new();
fill_headers(r, h);
return h;
}
|
#path_info ⇒ Object
call-seq: path_info()
Returns the script name which is assumed to be either ‘/’ or the empty according to the rack restrictions are followed on what the script name and path info should be.
157 158 159 160 |
# File 'ext/agoo/request.c', line 157
static VALUE
path_info(VALUE self) {
return req_path_info((Req)DATA_PTR(self));
}
|
#query_string ⇒ Object
call-seq: query_string()
Returns the query string of the request.
179 180 181 182 |
# File 'ext/agoo/request.c', line 179
static VALUE
query_string(VALUE self) {
return req_query_string((Req)DATA_PTR(self));
}
|
#rack_errors ⇒ Object
call-seq: rack_errors()
Returns an error stream for the request. This stream is used to write error log entries.
335 336 337 338 |
# File 'ext/agoo/request.c', line 335
static VALUE
rack_errors(VALUE self) {
return req_rack_errors((Req)DATA_PTR(self));
}
|
#rack_input ⇒ Object
call-seq: rack_input()
Returns an input stream for the request body. If no body is present then nil is returned.
318 319 320 321 |
# File 'ext/agoo/request.c', line 318
static VALUE
rack_input(VALUE self) {
return req_rack_input((Req)DATA_PTR(self));
}
|
#rack_logger ⇒ Object
call-seq: rack_logger()
Returns a RackLogger that can be used to log messages with the server logger. The methods supported are debug(), info(), warn(), error(), and fatal(). The signature is the same as the standard Ruby Logger of info(message, &block).
542 543 544 545 |
# File 'ext/agoo/request.c', line 542
static VALUE
rack_logger(VALUE self) {
return req_rack_logger((Req)DATA_PTR(self));
}
|
#rack_multiprocess ⇒ Object
call-seq: rack_multiprocess()
Returns false since the server is a single process.
368 369 370 371 |
# File 'ext/agoo/request.c', line 368 static VALUE rack_multiprocess(VALUE self) { return Qfalse; } |
#rack_multithread ⇒ Object
call-seq: rack_multithread()
Returns true is the server is using multiple handler worker threads.
357 358 359 360 |
# File 'ext/agoo/request.c', line 357
static VALUE
rack_multithread(VALUE self) {
return req_rack_multithread((Req)DATA_PTR(self));
}
|
#rack_run_once ⇒ Object
call-seq: rack_run_once()
Returns false.
379 380 381 382 |
# File 'ext/agoo/request.c', line 379 static VALUE rack_run_once(VALUE self) { return Qfalse; } |
#rack_upgrade? ⇒ Boolean
call-seq: rack_upgrade?()
Returns the URL scheme or either http or https as a string.
267 268 269 270 |
# File 'ext/agoo/request.c', line 267
static VALUE
rack_upgrade(VALUE self) {
return req_rack_upgrade((Req)DATA_PTR(self));
}
|
#rack_url_scheme ⇒ Object
call-seq: rack_url_scheme()
Returns the URL scheme or either http or https as a string.
295 296 297 298 |
# File 'ext/agoo/request.c', line 295
static VALUE
rack_url_scheme(VALUE self) {
return req_rack_url_scheme((Req)DATA_PTR(self));
}
|
#rack_version ⇒ Object
call-seq: rack_version()
Returns the rack version the request is compliant with.
278 279 280 281 |
# File 'ext/agoo/request.c', line 278 static VALUE rack_version(VALUE self) { return rack_version_val_val; } |
#request_method ⇒ Object
call-seq: request_method()
Returns the HTTP method of the request.
104 105 106 107 |
# File 'ext/agoo/request.c', line 104
static VALUE
method(VALUE self) {
return req_method((Req)DATA_PTR(self));
}
|
#script_name ⇒ Object
call-seq: script_name()
Returns the path info which is assumed to be the full path unless the root and then the rack restrictions are followed on what the script name and path info should be.
129 130 131 132 |
# File 'ext/agoo/request.c', line 129
static VALUE
script_name(VALUE self) {
return req_script_name((Req)DATA_PTR(self));
}
|
#server_name ⇒ Object
call-seq: server_name()
Returns the server or host name.
213 214 215 216 |
# File 'ext/agoo/request.c', line 213
static VALUE
server_name(VALUE self) {
return req_server_name((Req)DATA_PTR(self));
}
|
#server_port ⇒ Object
call-seq: server_port()
Returns the server or host port as a string.
247 248 249 250 |
# File 'ext/agoo/request.c', line 247
static VALUE
server_port(VALUE self) {
return req_server_port((Req)DATA_PTR(self));
}
|
#to_h ⇒ Object
call-seq: to_h()
Returns a Hash representation of the request which is the same as a rack environment Hash.
601 602 603 604 605 606 607 608 609 |
# File 'ext/agoo/request.c', line 601
static VALUE
to_h(VALUE self) {
Req r = DATA_PTR(self);
if (NULL == r) {
rb_raise(rb_eArgError, "Request is no longer valid.");
}
return request_env(r, self);
}
|
#to_s ⇒ Object
call-seq: to_s()
Returns a string representation of the request.
617 618 619 620 621 622 |
# File 'ext/agoo/request.c', line 617 static VALUE to_s(VALUE self) { volatile VALUE h = to_h(self); return rb_funcall(h, rb_intern("to_s"), 0); } |