agoo 2.2.1 → 2.2.2

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: d44ba7a7229894d86dba33f2138fc300cf1885c20078709fda7ebe9264e4a6fe
4
- data.tar.gz: 411a5541b7d47bd2dd5dc68a45401206787b026599c33eff3544a71757cf8072
3
+ metadata.gz: 9ec3fe82e8d4833d543ce7389dbf2c184fefed6ceee8b6ede337dd99588a69c4
4
+ data.tar.gz: 9b65a945479295f9b3663dd443e96d3f1b053536cf1062d10b6096d4b58cd333
5
5
  SHA512:
6
- metadata.gz: 21ecc474d333acad22a54e781b135eb450273d0f6662c1566dd0b1949e9db3051db08264021b99fe01cd2fc819e7fab56abec3bbbb0dfd04b7fc6bc4a05f82e9
7
- data.tar.gz: b7f92457d97efd991b2a8e54bc1c0ae488482dcde217f32a2a2ea6d4f07536cab3b97341aebf0eadeaa514c03251a97e85510e3bf7b185aa43007f52a130bacc
6
+ metadata.gz: 335d419d49420ae7c091a2c89ba46830520be29041cdf18967a588c9bcf63383efbbddced7d65cab96d3d97f835b23b4c1f2a1749c2cb5591d3b66c89bb4af55
7
+ data.tar.gz: a25b384fcec18a72635a03c2f87218939adebcb3f18f63f912ab9c1e1fdbb04653cbb03f5598dfb3786113ad4496ee213d57d0971eeac254ca354a34253b45e7
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # CHANGELOG
2
2
 
3
+ ### 2.2.2 - 2018-06-05
4
+
5
+ - Fixed `bin/agoo` which had become out of date.
6
+
7
+ - Added optimization description in `misc/optimize.md`.
8
+
9
+ - Fixed static file asset page caching bug.
10
+
3
11
  ### 2.2.1 - 2018-05-31
4
12
 
5
13
  - Corrected header bug where a `:` in the value would cause an incorrect header key and value.
data/bin/agoo CHANGED
@@ -22,10 +22,17 @@ Usage: agoo [options] [<handler_class>@<path>]...
22
22
 
23
23
  version #{Agoo::VERSION}
24
24
 
25
- Agoo is a Ruby web server. It can be run as a standalone application using this
26
- application. The handler/class arguments must have the form of <class>@<path>
27
- where the class is the Ruby class where the new method takes not arguments and
28
- has either a call() method or a on_request() method.
25
+ Agoo is a Ruby web server. It can be run as a standalone application using
26
+ this application. The handler/class arguments must have the form of
27
+ <path>@<class> where the class is a Ruby class and the path is the URL path
28
+ that will be directed to the class or an instance of the class provided. If
29
+ the class implements a call() or on_request() method it will be used directly
30
+ otherwise an instance of the class will be created. The new method mut take no
31
+ arguments and have either a call() method or a on_request() method.
32
+
33
+ Example:
34
+
35
+ agoo -I example -r simple /simple@Simple
29
36
 
30
37
  }
31
38
 
@@ -36,47 +43,66 @@ has either a call() method or a on_request() method.
36
43
  @classic = true
37
44
  @console = true
38
45
  @colorize = true
46
+ @threads = 0
47
+ @workers = 0
48
+ @first = false
39
49
 
40
50
  @opts = OptionParser.new(usage)
41
- @opts.on('-h', '--help', 'Show this display.') { puts @opts.help; Process.exit!(0) }
42
- @opts.on('-s', '--silent', 'Silent.') { @verbose = 0 }
43
- @opts.on('-v', '--verbose', 'Increase verbosity.') { @verbose += 1 }
44
- @opts.on('-p', '--port PORT', Integer, 'Port to listen on.') { |p| @port = p }
45
- @opts.on('-d', '--dir DIR', String, 'Directory to serve static assets from.') { |d| @root = d }
46
- @opts.on('-r', '--require FILE', String, 'Ruby require.') { |r| require r }
47
- @opts.on('--log.dir DIR', String, 'Log file directory.') { |d| @log_dir = d }
48
- @opts.on('--[no-]log.classic', 'Classic log entries instead of JSON.') { |b| @classic = b }
49
- @opts.on('--[no-]log.console', 'Display log entries on the console.') { |b| @console = b }
50
- @opts.on('--[no-]log.colorize', 'Display log entries in color.') { |b| @colorize = b }
51
+ @opts.on('-h', '--help', 'Show this display.') { puts @opts.help; Process.exit!(0) }
52
+ @opts.on('-s', '--silent', 'Silent.') { @verbose = 0 }
53
+ @opts.on('-v', '--verbose', 'Increase verbosity.') { @verbose += 1 }
54
+ @opts.on('-f', '--root_first', 'Check the root directory before the handle paths.') { @first = true }
55
+ @opts.on('-p', '--port PORT', Integer, 'Port to listen on.') { |p| @port = p }
56
+ @opts.on('-d', '--dir DIR', String, 'Directory to serve static assets from.') { |d| @root = d }
57
+ @opts.on('-r', '--require FILE', String, 'Ruby require.') { |r| require r }
58
+ @opts.on('-t', '--threads COUNT', Integer, 'Number of threads to use.') { |t| @threads = t }
59
+ @opts.on('-w', '--workers COUNT', Integer, 'Number of workers to use.') { |w| @workers = w }
60
+ @opts.on('--log.dir DIR', String, 'Log file directory.') { |d| @log_dir = d }
61
+ @opts.on('--[no-]log.classic', 'Classic log entries instead of JSON.') { |b| @classic = b }
62
+ @opts.on('--[no-]log.console', 'Display log entries on the console.') { |b| @console = b }
63
+ @opts.on('--[no-]log.colorize', 'Display log entries in color.') { |b| @colorize = b }
51
64
 
52
65
  handler_paths = @opts.parse(ARGV)
53
66
 
54
- server = Agoo::Server.new(@port, @root,
55
- log_dir: @log_dir,
56
- thread_count: 0,
57
- log_console: @console,
58
- log_classic: @classic,
59
- log_colorize: @colorize,
60
- log_states: {
61
- INFO: 1 <= @verbose,
62
- DEBUG: 3 <= @verbose,
63
- connect: 2 <= @verbose,
64
- request: 2 <= @verbose,
65
- response: 2 <= @verbose,
66
- eval: 2 <= @verbose,
67
- })
67
+ @threads = 0 if @threads < 0
68
+ @workers = 1 if @workers < 1
69
+
70
+ Agoo::Log.configure(dir: @log_dir,
71
+ console: @console,
72
+ classic: @classic,
73
+ colorize: @colorize,
74
+ states: {
75
+ INFO: 1 <= @verbose,
76
+ DEBUG: 3 <= @verbose,
77
+ connect: 2 <= @verbose,
78
+ request: 2 <= @verbose,
79
+ response: 2 <= @verbose,
80
+ eval: 2 <= @verbose,
81
+ push: 2 <= @verbose,
82
+ })
83
+
84
+ Agoo::Server.init(@port, @root, thread_count: @threads, worker_count: @workers, root_first: @first)
85
+
68
86
  puts "Agoo #{Agoo::VERSION} is listening on port #{@port}. Path mappings are:" if 1 <= @verbose
69
87
 
70
88
  handler_paths.each { |hp|
71
- classname, path = hp.split('@')
89
+ path, classname = hp.split('@')
72
90
  if classname.nil? || path.nil? || classname.empty? || path.empty?
73
91
  raise "Invalid handler/path specification. Both a class and path must be present."
74
92
  end
75
93
  c = Object.const_get(classname)
76
- server.handle(nil, path, c.new)
94
+ if c.respond_to?(:call) || c.respond_to?(:on_request)
95
+ Agoo::Server.handle(nil, path, c)
96
+ else
97
+ Agoo::Server.handle(nil, path, c.new)
98
+ end
77
99
  if 1 <= @verbose
78
100
  puts " #{path} => #{classname}"
79
101
  end
80
102
  }
81
103
 
82
- server.start()
104
+ if handler_paths.empty?
105
+ puts "Agoo is only serving static files in '#{@root}'."
106
+ end
107
+
108
+ Agoo::Server.start()
data/ext/agoo/con.c CHANGED
@@ -272,15 +272,9 @@ con_header_read(Con c) {
272
272
  return bad_request(c, 500, __LINE__);
273
273
  }
274
274
  return -mlen;
275
-
276
- // TBD int hook_or_page(method, path, pend, &hook)
277
- // return http status
278
- // 0 is not handled
279
- // 200 means taken care of
280
- // default (over 200) call bad_request
281
275
  }
282
276
  if (GET == method && the_server.root_first &&
283
- NULL != (p = page_get(&err, &the_server.pages, path, (int)(pend - path)))) {
277
+ NULL != (p = page_get(&err, &the_server.pages, path, (int)(pend - path)))) {
284
278
  if (page_response(c, p, hend)) {
285
279
  return bad_request(c, 500, __LINE__);
286
280
  }
data/ext/agoo/hook.c CHANGED
@@ -62,6 +62,8 @@ hook_create(Method method, const char *pattern, VALUE handler) {
62
62
  hook->next = NULL;
63
63
  if (T_STRING == rb_type(handler)) {
64
64
  handler = resolve_classpath(StringValuePtr(handler), RSTRING_LEN(handler));
65
+ // TBD does class handle it or should an instance be made?
66
+ //
65
67
  }
66
68
  hook->handler = handler;
67
69
  rb_gc_register_address(&handler);
data/ext/agoo/page.c CHANGED
@@ -157,9 +157,9 @@ mime_set(Cache cache, const char *key, const char *value) {
157
157
  }
158
158
  for (s = *bucket; NULL != s; s = s->next) {
159
159
  if (h == (int64_t)s->hash && len == s->klen &&
160
- ((0 <= len && len <= MAX_KEY_UNIQ) || 0 == strcmp(s->key, key))) {
160
+ ((0 <= len && len <= MAX_KEY_UNIQ) || 0 == strncmp(s->key, key, len))) {
161
161
  if (h == (int64_t)s->hash && len == s->klen &&
162
- ((0 <= len && len <= MAX_KEY_UNIQ) || 0 == strcmp(s->key, key))) {
162
+ ((0 <= len && len <= MAX_KEY_UNIQ) || 0 == strncmp(s->key, key, len))) {
163
163
  DEBUG_FREE(mem_mime_slot, s->value)
164
164
  free(s->value);
165
165
  s->value = strdup(value);
@@ -196,9 +196,9 @@ cache_set(Cache cache, const char *key, int klen, Page value) {
196
196
  }
197
197
  for (s = *bucket; NULL != s; s = s->next) {
198
198
  if (h == (int64_t)s->hash && len == s->klen &&
199
- ((0 <= len && len <= MAX_KEY_UNIQ) || 0 == strcmp(s->key, key))) {
199
+ ((0 <= len && len <= MAX_KEY_UNIQ) || 0 == strncmp(s->key, key, len))) {
200
200
  if (h == (int64_t)s->hash && len == s->klen &&
201
- ((0 <= len && len <= MAX_KEY_UNIQ) || 0 == strcmp(s->key, key))) {
201
+ ((0 <= len && len <= MAX_KEY_UNIQ) || 0 == strncmp(s->key, key, len))) {
202
202
  old = s->value;
203
203
  // replace
204
204
  s->value = value;
@@ -216,7 +216,8 @@ cache_set(Cache cache, const char *key, int klen, Page value) {
216
216
  if (NULL == key) {
217
217
  *s->key = '\0';
218
218
  } else {
219
- strcpy(s->key, key);
219
+ strncpy(s->key, key, len);
220
+ s->key[len] = '\0';
220
221
  }
221
222
  s->value = value;
222
223
  s->next = *bucket;
@@ -318,6 +319,9 @@ update_contents(Cache cache, Page p) {
318
319
  break;
319
320
  }
320
321
  }
322
+ if (suffix <= p->path) {
323
+ suffix = NULL;
324
+ }
321
325
  if (NULL != suffix) {
322
326
  suffix++;
323
327
  if (NULL == (mime = mime_get(cache, suffix))) {
@@ -369,6 +373,7 @@ update_contents(Cache cache, Page p) {
369
373
  return false;
370
374
  }
371
375
  rewind(f);
376
+
372
377
  // Format size plus space for the length, the mime type, and some
373
378
  // padding. Then add the content length.
374
379
  msize = sizeof(page_fmt) + 60 + size;
data/lib/agoo/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Agoo
3
3
  # Agoo version.
4
- VERSION = '2.2.1'
4
+ VERSION = '2.2.2'
5
5
  end
@@ -1,5 +1,5 @@
1
1
 
2
- require 'agoo'
2
+ require 'agoo' unless defined?(Agoo)
3
3
 
4
4
  # Grand parent for the Agoo rack handler.
5
5
  module Rack
@@ -15,7 +15,7 @@ module Rack
15
15
  #
16
16
  # - *:port [_Integer_] port to listen on
17
17
  # - *:root [_String_] root or public directory for static assets
18
- # - *:rmux [_true_|_false_] if true look in the root directory first before calling Ruby hooks
18
+ # - *:root_first [_true_|_false_] if true look in the root directory first before calling Ruby hooks
19
19
  # - *:wc* [_Integer_] number of workers to fork. Defaults to one which is not to fork.
20
20
  # - */path=MyHandler* path and class name to handle requests on that path
21
21
  def self.run(handler, options={})
@@ -40,7 +40,7 @@ module Rack
40
40
  elsif :wc == k
41
41
  worker_count = v.to_i
42
42
  options.delete(k)
43
- elsif :rmux == k
43
+ elsif :rmux == k || :root_first == k || :f == k
44
44
  options[:root_first] = false
45
45
  elsif k.nil?
46
46
  not_found_handler = v
@@ -56,8 +56,8 @@ module Rack
56
56
  options[:thread_count] = 0
57
57
  options[:worker_count] = worker_count
58
58
  ::Agoo::Server.init(port, root, options)
59
- path_map.each { |path,handler|
60
- ::Agoo::Server.handle(nil, path, handler)
59
+ path_map.each { |path,h|
60
+ ::Agoo::Server.handle(nil, path, h)
61
61
  }
62
62
  begin
63
63
  # If Rails is loaded this should work else just ignore.
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: 2.2.1
4
+ version: 2.2.2
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-06-01 00:00:00.000000000 Z
11
+ date: 2018-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj