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.



570
571
572
573
574
575
576
577
578
579
580
581
# File 'ext/agoo/request.c', line 570

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.



692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
# File 'ext/agoo/request.c', line 692

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.



663
664
665
666
667
668
669
670
671
# File 'ext/agoo/request.c', line 663

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.



663
664
665
666
667
668
669
670
671
# File 'ext/agoo/request.c', line 663

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.



549
550
551
552
553
554
555
556
557
558
559
560
561
# File 'ext/agoo/request.c', line 549

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.



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

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.



192
193
194
195
# File 'ext/agoo/request.c', line 192

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.



366
367
368
369
# File 'ext/agoo/request.c', line 366

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.



349
350
351
352
# File 'ext/agoo/request.c', line 349

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



597
598
599
600
# File 'ext/agoo/request.c', line 597

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.



399
400
401
402
# File 'ext/agoo/request.c', line 399

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.



388
389
390
391
# File 'ext/agoo/request.c', line 388

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

#rack_run_onceObject

call-seq: rack_run_once()

Returns false.



410
411
412
413
# File 'ext/agoo/request.c', line 410

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)


296
297
298
299
# File 'ext/agoo/request.c', line 296

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.



326
327
328
329
# File 'ext/agoo/request.c', line 326

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.



307
308
309
310
# File 'ext/agoo/request.c', line 307

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

#remote_addrObject

call-seq: remote_addr()

Returns the remote address.



116
117
118
119
# File 'ext/agoo/request.c', line 116

static VALUE
remote_addr(VALUE self) {
    return req_remote_addr((agooReq)DATA_PTR(self));
}

#request_methodObject

call-seq: request_method()

Returns the HTTP method of the request.



96
97
98
99
# File 'ext/agoo/request.c', line 96

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.



142
143
144
145
# File 'ext/agoo/request.c', line 142

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.



217
218
219
220
# File 'ext/agoo/request.c', line 217

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.



276
277
278
279
# File 'ext/agoo/request.c', line 276

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

#server_protocolObject

call-seq: server_protocol()

Returns the server or host protocol.



242
243
244
245
# File 'ext/agoo/request.c', line 242

static VALUE
server_protocol(VALUE self) {
    return req_server_protocol((agooReq)DATA_PTR(self));
}

#set(key, val) ⇒ Object

call-seq: set()

Sets an key value pair to the environment of the request.



720
721
722
723
724
725
726
727
728
729
730
731
# File 'ext/agoo/request.c', line 720

static VALUE
set(VALUE self, VALUE key, VALUE val) {
    agooReq	r = DATA_PTR(self);

    if (NULL == r) {
	rb_raise(rb_eArgError, "Request is no longer valid.");
    }
    request_env(r, self);
    rb_hash_aset((VALUE)r->env, key, val);

    return Qnil;
}

#to_hObject

call-seq: to_h()

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



663
664
665
666
667
668
669
670
671
# File 'ext/agoo/request.c', line 663

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.



679
680
681
682
683
684
# File 'ext/agoo/request.c', line 679

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

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