Class: Agoo::Request

Inherits:
Object
  • Object
show all
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

Instance Method Details

#bodyObject

call-seq: body()

Returns the body of the request as a String. If there is no body then nil is returned.



498
499
500
501
502
503
504
505
506
507
508
509
# File 'ext/agoo/request.c', line 498

static VALUE
body(VALUE self) {
    agooReq	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);
}

#callObject

call-seq: call()

Returns an IO like object and hijack the connection.



618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
# File 'ext/agoo/request.c', line 618

static VALUE
call(VALUE self) {
    agooReq		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((VALUE)r->env, rack_hijack_io_val, io);

    return io;
}

#envObject

call-seq: to_h()

Returns a Hash representation of the request which is the same as a rack environment Hash.



589
590
591
592
593
594
595
596
597
# File 'ext/agoo/request.c', line 589

static VALUE
to_h(VALUE self) {
    agooReq	r = DATA_PTR(self);

    if (NULL == r) {
	rb_raise(rb_eArgError, "Request is no longer valid.");
    }
    return request_env(r, self);
}

#environmentObject

call-seq: to_h()

Returns a Hash representation of the request which is the same as a rack environment Hash.



589
590
591
592
593
594
595
596
597
# File 'ext/agoo/request.c', line 589

static VALUE
to_h(VALUE self) {
    agooReq	r = DATA_PTR(self);

    if (NULL == r) {
	rb_raise(rb_eArgError, "Request is no longer valid.");
    }
    return request_env(r, self);
}

#headersObject

call-seq: headers()

Returns the header of the request as a Hash.



477
478
479
480
481
482
483
484
485
486
487
488
489
# File 'ext/agoo/request.c', line 477

static VALUE
headers(VALUE self) {
    agooReq		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_infoObject

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.



147
148
149
150
# File 'ext/agoo/request.c', line 147

static VALUE
path_info(VALUE self) {
    return req_path_info((agooReq)DATA_PTR(self));
}

#query_stringObject

call-seq: query_string()

Returns the query string of the request.



169
170
171
172
# File 'ext/agoo/request.c', line 169

static VALUE
query_string(VALUE self) {
    return req_query_string((agooReq)DATA_PTR(self));
}

#rack_errorsObject

call-seq: rack_errors()

Returns an error stream for the request. This stream is used to write error log entries.



318
319
320
321
# File 'ext/agoo/request.c', line 318

static VALUE
rack_errors(VALUE self) {
    return req_rack_errors((agooReq)DATA_PTR(self));
}

#rack_inputObject

call-seq: rack_input()

Returns an input stream for the request body. If no body is present then nil is returned.



301
302
303
304
# File 'ext/agoo/request.c', line 301

static VALUE
rack_input(VALUE self) {
    return req_rack_input((agooReq)DATA_PTR(self));
}

#rack_loggerObject

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).



525
526
527
528
# File 'ext/agoo/request.c', line 525

static VALUE
rack_logger(VALUE self) {
    return req_rack_logger((agooReq)DATA_PTR(self));
}

#rack_multiprocessObject

call-seq: rack_multiprocess()

Returns false since the server is a single process.



351
352
353
354
# File 'ext/agoo/request.c', line 351

static VALUE
rack_multiprocess(VALUE self) {
    return Qfalse;
}

#rack_multithreadObject

call-seq: rack_multithread()

Returns true is the server is using multiple handler worker threads.



340
341
342
343
# File 'ext/agoo/request.c', line 340

static VALUE
rack_multithread(VALUE self) {
    return req_rack_multithread((agooReq)DATA_PTR(self));
}

#rack_run_onceObject

call-seq: rack_run_once()

Returns false.



362
363
364
365
# File 'ext/agoo/request.c', line 362

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.

Returns:

  • (Boolean)


248
249
250
251
# File 'ext/agoo/request.c', line 248

static VALUE
rack_upgrade(VALUE self) {
    return req_rack_upgrade((agooReq)DATA_PTR(self));
}

#rack_url_schemeObject

call-seq: rack_url_scheme()

Returns the URL scheme or either http or https as a string.



278
279
280
281
# File 'ext/agoo/request.c', line 278

static VALUE
rack_url_scheme(VALUE self) {
    return req_rack_url_scheme((agooReq)DATA_PTR(self));
}

#rack_versionObject

call-seq: rack_version()

Returns the rack version the request is compliant with.



259
260
261
262
# File 'ext/agoo/request.c', line 259

static VALUE
rack_version(VALUE self) {
    return rack_version_val_val;
}

#request_methodObject

call-seq: request_method()

Returns the HTTP method of the request.



94
95
96
97
# File 'ext/agoo/request.c', line 94

static VALUE
method(VALUE self) {
    return req_method((agooReq)DATA_PTR(self));
}

#script_nameObject

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.



119
120
121
122
# File 'ext/agoo/request.c', line 119

static VALUE
script_name(VALUE self) {
    return req_script_name((agooReq)DATA_PTR(self));
}

#server_nameObject

call-seq: server_name()

Returns the server or host name.



194
195
196
197
# File 'ext/agoo/request.c', line 194

static VALUE
server_name(VALUE self) {
    return req_server_name((agooReq)DATA_PTR(self));
}

#server_portObject

call-seq: server_port()

Returns the server or host port as a string.



228
229
230
231
# File 'ext/agoo/request.c', line 228

static VALUE
server_port(VALUE self) {
    return req_server_port((agooReq)DATA_PTR(self));
}

#to_hObject

call-seq: to_h()

Returns a Hash representation of the request which is the same as a rack environment Hash.



589
590
591
592
593
594
595
596
597
# File 'ext/agoo/request.c', line 589

static VALUE
to_h(VALUE self) {
    agooReq	r = DATA_PTR(self);

    if (NULL == r) {
	rb_raise(rb_eArgError, "Request is no longer valid.");
    }
    return request_env(r, self);
}

#to_sObject

call-seq: to_s()

Returns a string representation of the request.



605
606
607
608
609
610
# File 'ext/agoo/request.c', line 605

static VALUE
to_s(VALUE self) {
    volatile VALUE	h = to_h(self);

    return rb_funcall(h, rb_intern("to_s"), 0);
}