agoo 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of agoo might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8a18f59a226cbfe061c8b645fadeab626f7ba7eb7f8af017032192bf276db749
4
- data.tar.gz: d10ec4a0c5ba7676e2298e14cee626db4794465f6b987e02b6a8c2f341eaedb5
3
+ metadata.gz: 1210b704838b2b955043a6898f84de5314c807c2557310f4e1eb2049c4b92dc6
4
+ data.tar.gz: cb5d9a00fd52a2bad258e3ec946597ae2ebb76a6c8ee1a1f13f33fadd06bd200
5
5
  SHA512:
6
- metadata.gz: f8fa258e15e65f91ed6d9586c0cf951dca2038c13a52e4727a94bd79bb0794574f8cb306cd7f75188a435063f19016e7b32e754ee304fc53be75ff63ab045464
7
- data.tar.gz: 14be184ac912ff59aaf1d097a612d8cf4228d00840b7e2410b76682909a776db5c4ce6e4f3769eb34410e42e9df8eba90d1d2b5275c6fbfe0eee6593ae2a77fb
6
+ metadata.gz: 6139683e96c96440854aad33d252036942e020a0a38cd619802033c5ee3523306ee2ce356af4c0abf294b510bf2320dfb3544aa87b5d449d5a0b14ece8ea9b37
7
+ data.tar.gz: e1d8735be9d8036b6274dcd18baeb5e678ae47a9118d35ee4aca1b3b5ee9145d7836f51e72d82643a8a409a0164acfa5be2d4da8fa04563eb9378626c8be5356
data/ext/agoo/con.c CHANGED
@@ -328,7 +328,11 @@ con_read(Con c) {
328
328
  // Terminate with \0 for debug and strstr() check
329
329
  c->buf[c->bcnt] = '\0';
330
330
  if (0 > (mlen = con_header_read(c))) {
331
- if (-mlen < (long)c->bcnt) {
331
+ if (-1 == mlen) {
332
+ c->bcnt = 0;
333
+ *c->buf = '\0';
334
+ return false;
335
+ } else if (-mlen < (long)c->bcnt) {
332
336
  mlen = -mlen;
333
337
  memmove(c->buf, c->buf + mlen, c->bcnt - mlen);
334
338
  c->bcnt -= mlen;
data/ext/agoo/request.c CHANGED
@@ -555,6 +555,11 @@ request_init(VALUE mod) {
555
555
 
556
556
  new_id = rb_intern("new");
557
557
 
558
+ rack_version_val_val = rb_ary_new();
559
+ rb_ary_push(rack_version_val_val, INT2NUM(1));
560
+ rb_ary_push(rack_version_val_val, INT2NUM(3));
561
+ rb_gc_register_address(&rack_version_val_val);
562
+
558
563
  stringio_class = rb_const_get(rb_cObject, rb_intern("StringIO"));
559
564
 
560
565
  connect_val = rb_str_new_cstr("CONNECT"); rb_gc_register_address(&connect_val);
@@ -578,7 +583,6 @@ request_init(VALUE mod) {
578
583
  rack_run_once_val = rb_str_new_cstr("rack.run_once"); rb_gc_register_address(&rack_run_once_val);
579
584
  rack_url_scheme_val = rb_str_new_cstr("rack.url_scheme"); rb_gc_register_address(&rack_url_scheme_val);
580
585
  rack_version_val = rb_str_new_cstr("rack.version"); rb_gc_register_address(&rack_version_val);
581
- rack_version_val_val = rb_str_new_cstr("1.3"); rb_gc_register_address(&rack_version_val_val);
582
586
  request_method_val = rb_str_new_cstr("REQUEST_METHOD"); rb_gc_register_address(&request_method_val);
583
587
  script_name_val = rb_str_new_cstr("SCRIPT_NAME"); rb_gc_register_address(&script_name_val);
584
588
  server_name_val = rb_str_new_cstr("SERVER_NAME"); rb_gc_register_address(&server_name_val);
data/ext/agoo/server.c CHANGED
@@ -119,7 +119,7 @@ configure(Err err, Server s, int port, const char *root, VALUE options) {
119
119
  s->log.cats = NULL;
120
120
  log_cat_reg(&s->log, &s->error_cat, "ERROR", ERROR, RED, true);
121
121
  log_cat_reg(&s->log, &s->warn_cat, "WARN", WARN, YELLOW, true);
122
- log_cat_reg(&s->log, &s->info_cat, "INFO", INFO, GREEN, false);
122
+ log_cat_reg(&s->log, &s->info_cat, "INFO", INFO, GREEN, true);
123
123
  log_cat_reg(&s->log, &s->debug_cat, "DEBUG", DEBUG, GRAY, false);
124
124
  log_cat_reg(&s->log, &s->con_cat, "connect", INFO, GREEN, false);
125
125
  log_cat_reg(&s->log, &s->req_cat, "request", INFO, CYAN, false);
@@ -144,6 +144,39 @@ configure(Err err, Server s, int port, const char *root, VALUE options) {
144
144
  if (Qnil != (v = rb_hash_lookup(options, ID2SYM(rb_intern("pedantic"))))) {
145
145
  s->pedantic = (Qtrue == v);
146
146
  }
147
+ if (Qnil != (v = rb_hash_lookup(options, ID2SYM(rb_intern("Port"))))) {
148
+ if (rb_cInteger == rb_obj_class(v)) {
149
+ s->port = NUM2INT(v);
150
+ } else {
151
+ switch (rb_type(v)) {
152
+ case T_STRING:
153
+ s->port = atoi(StringValuePtr(v));
154
+ break;
155
+ case T_FIXNUM:
156
+ s->port = NUM2INT(v);
157
+ break;
158
+ default:
159
+ break;
160
+ }
161
+ }
162
+ }
163
+ if (Qnil != (v = rb_hash_lookup(options, ID2SYM(rb_intern("quiet"))))) {
164
+ if (Qtrue == v) {
165
+ s->info_cat.on = false;
166
+ }
167
+ }
168
+ if (Qnil != (v = rb_hash_lookup(options, ID2SYM(rb_intern("debug"))))) {
169
+ if (Qtrue == v) {
170
+ s->error_cat.on = true;
171
+ s->warn_cat.on = true;
172
+ s->info_cat.on = true;
173
+ s->debug_cat.on = true;
174
+ s->con_cat.on = true;
175
+ s->req_cat.on = true;
176
+ s->resp_cat.on = true;
177
+ s->eval_cat.on = true;
178
+ }
179
+ }
147
180
  }
148
181
  return ERR_OK;
149
182
  }
@@ -400,7 +433,7 @@ handle_rack_inner(void *x) {
400
433
  int code;
401
434
  const char *status_msg;
402
435
  int bsize = 0;
403
-
436
+
404
437
  rb_check_type(res, T_ARRAY);
405
438
  if (3 != RARRAY_LEN(res)) {
406
439
  rb_raise(rb_eArgError, "a rack call() response must be an array of 3 members.");
@@ -426,15 +459,38 @@ handle_rack_inner(void *x) {
426
459
  if (NULL == (t = text_allocate(1024))) {
427
460
  rb_raise(rb_eArgError, "failed to allocate response.");
428
461
  }
429
- if (T_ARRAY != rb_type(bv)) {
462
+ if (T_ARRAY == rb_type(bv)) {
430
463
  int i;
431
464
  int bcnt = (int)RARRAY_LEN(bv);
432
-
465
+
433
466
  for (i = 0; i < bcnt; i++) {
434
467
  bsize += (int)RSTRING_LEN(rb_ary_entry(bv, i));
435
468
  }
436
469
  } else {
437
- rb_iterate(rb_each, bv, body_len_cb, (VALUE)&bsize);
470
+ if (HEAD == req->method) {
471
+ // Rack wraps the response in two layers, Rack::Lint and
472
+ // Rack::BodyProxy. It each is called on either with the HEAD
473
+ // method an exception is raised so the length can not be
474
+ // determined. This digs down to get the actual response so the
475
+ // length can be calculated. A very special case.
476
+ if (0 == strcmp("Rack::BodyProxy", rb_obj_classname(bv))) {
477
+ volatile VALUE body = rb_ivar_get(bv, rb_intern("@body"));
478
+
479
+ if (Qnil != body) {
480
+ body = rb_ivar_get(body, rb_intern("@body"));
481
+ }
482
+ if (Qnil != body) {
483
+ body = rb_ivar_get(body, rb_intern("@body"));
484
+ }
485
+ if (rb_respond_to(body, rb_intern("each"))) {
486
+ rb_iterate(rb_each, body, body_len_cb, (VALUE)&bsize);
487
+ }
488
+ } else {
489
+ rb_iterate(rb_each, bv, body_len_cb, (VALUE)&bsize);
490
+ }
491
+ } else {
492
+ rb_iterate(rb_each, bv, body_len_cb, (VALUE)&bsize);
493
+ }
438
494
  }
439
495
  switch (code) {
440
496
  case 100:
@@ -443,7 +499,7 @@ handle_rack_inner(void *x) {
443
499
  case 204:
444
500
  case 205:
445
501
  case 304:
446
- // TBD Content-Type and Content-Length can not be present
502
+ // Content-Type and Content-Length can not be present
447
503
  t->len = snprintf(t->text, 1024, "HTTP/1.1 %d %s\r\n", code, status_msg);
448
504
  break;
449
505
  default:
@@ -451,10 +507,14 @@ handle_rack_inner(void *x) {
451
507
  t->len = snprintf(t->text, 1024, "HTTP/1.1 %d %s\r\nContent-Length: %d\r\n", code, status_msg, bsize);
452
508
  break;
453
509
  }
454
- if (T_HASH == rb_type(hv)) {
455
- rb_hash_foreach(hv, header_cb, (VALUE)&t);
510
+ if (HEAD == req->method) {
511
+ bsize = 0;
456
512
  } else {
457
- rb_iterate (rb_each, hv, header_each_cb, (VALUE)&t);
513
+ if (T_HASH == rb_type(hv)) {
514
+ rb_hash_foreach(hv, header_cb, (VALUE)&t);
515
+ } else {
516
+ rb_iterate (rb_each, hv, header_each_cb, (VALUE)&t);
517
+ }
458
518
  }
459
519
  t = text_append(t, "\r\n", 2);
460
520
  if (0 < bsize) {
data/lib/agoo.rb CHANGED
@@ -5,3 +5,5 @@ end
5
5
  require 'agoo/version'
6
6
  require 'rack/handler/agoo'
7
7
  require 'agoo/agoo' # C extension
8
+
9
+ ENV['RACK_HANDLER'] = 'Agoo'
data/lib/agoo/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Agoo
3
3
  # Agoo version.
4
- VERSION = '1.2.0'
4
+ VERSION = '1.2.1'
5
5
  end
@@ -38,8 +38,7 @@ module Rack
38
38
  server.handle(nil, path, handler)
39
39
  }
40
40
  unless default_handler.nil?
41
- server.handle(nil, '/', default_handler)
42
- server.handle(nil, '/**', default_handler)
41
+ server.handle(nil, '**', default_handler)
43
42
  end
44
43
  server.handle_not_found(not_found_handler) unless not_found_handler.nil?
45
44
  server.start
@@ -108,7 +108,7 @@ class BaseHandlerTest < Minitest::Test
108
108
  "rack.multithread" => false,
109
109
  "rack.run_once" => false,
110
110
  "rack.url_scheme" => "http",
111
- "rack.version" => "1.3",
111
+ "rack.version" => [1, 3],
112
112
  "rack.logger" => nil,
113
113
  }
114
114
  expect.each_pair { |k,v|
data/test/log_test.rb CHANGED
@@ -44,9 +44,10 @@ class LogStateTest < Minitest::Test
44
44
  end
45
45
 
46
46
  def info_state_test(server)
47
+ assert(server.info?)
48
+ server.set_log_state('INFO', false)
47
49
  refute(server.info?)
48
50
  server.set_log_state('INFO', true)
49
- assert(server.info?)
50
51
  end
51
52
 
52
53
  def debug_state_test(server)
@@ -103,7 +103,7 @@ class RackHandlerTest < Minitest::Test
103
103
  "rack.multithread" => false,
104
104
  "rack.run_once" => false,
105
105
  "rack.url_scheme" => "http",
106
- "rack.version" => "1.3",
106
+ "rack.version" => [1, 3],
107
107
  }
108
108
  expect.each_pair { |k,v|
109
109
  if v.nil?
data/test/rrr/test.rb ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ require "agoo"
5
+
6
+ server = Agoo::Server.new(6464, "root", thread_count: 0)
7
+
8
+ class MyHandler
9
+ def call(_req)
10
+ [200, {}, ["hello world"]]
11
+ end
12
+ end
13
+
14
+ handler = MyHandler.new
15
+ #server.handle(:GET, "/hello", handler)
16
+ server.handle(nil, "**", handler)
17
+ server.start
18
+
19
+ # $ bundle exec ruby test.rb
20
+ # waits for connections, nothing is logged.
21
+
22
+ # on a separated shell:
23
+ # ➜ curl -I http://localhost:6464
24
+ # HTTP/1.1 500 Internal Error
25
+ # Connection: Close
26
+ # Content-Length: 0
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: agoo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Ohler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-01 00:00:00.000000000 Z
11
+ date: 2018-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj
@@ -82,6 +82,7 @@ files:
82
82
  - test/base_handler_test.rb
83
83
  - test/log_test.rb
84
84
  - test/rack_handler_test.rb
85
+ - test/rrr/test.rb
85
86
  - test/static_test.rb
86
87
  - test/tests.rb
87
88
  homepage: https://github.com/ohler55/agoo
@@ -121,5 +122,6 @@ test_files:
121
122
  - test/tests.rb
122
123
  - test/rack_handler_test.rb
123
124
  - test/base_handler_test.rb
125
+ - test/rrr/test.rb
124
126
  - test/static_test.rb
125
127
  - test/log_test.rb