agoo 1.2.2 → 2.0.0
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 +4 -4
- data/README.md +11 -9
- data/ext/agoo/agoo.c +45 -0
- data/ext/agoo/base64.c +107 -0
- data/ext/agoo/base64.h +15 -0
- data/ext/agoo/ccache.c +301 -0
- data/ext/agoo/ccache.h +53 -0
- data/ext/agoo/con.c +522 -82
- data/ext/agoo/con.h +7 -5
- data/ext/agoo/debug.c +121 -7
- data/ext/agoo/debug.h +11 -6
- data/ext/agoo/error_stream.c +5 -6
- data/ext/agoo/error_stream.h +1 -1
- data/ext/agoo/extconf.rb +2 -1
- data/ext/agoo/hook.c +4 -4
- data/ext/agoo/hook.h +1 -0
- data/ext/agoo/http.c +2 -2
- data/ext/agoo/http.h +2 -0
- data/ext/agoo/log.c +604 -219
- data/ext/agoo/log.h +20 -7
- data/ext/agoo/page.c +20 -23
- data/ext/agoo/page.h +2 -0
- data/ext/agoo/pub.c +111 -0
- data/ext/agoo/pub.h +40 -0
- data/ext/agoo/queue.c +2 -2
- data/ext/agoo/rack_logger.c +15 -71
- data/ext/agoo/rack_logger.h +1 -1
- data/ext/agoo/request.c +96 -21
- data/ext/agoo/request.h +23 -12
- data/ext/agoo/res.c +5 -2
- data/ext/agoo/res.h +4 -0
- data/ext/agoo/response.c +13 -12
- data/ext/agoo/response.h +1 -2
- data/ext/agoo/server.c +290 -428
- data/ext/agoo/server.h +10 -10
- data/ext/agoo/sha1.c +148 -0
- data/ext/agoo/sha1.h +10 -0
- data/ext/agoo/sse.c +26 -0
- data/ext/agoo/sse.h +12 -0
- data/ext/agoo/sub.c +111 -0
- data/ext/agoo/sub.h +36 -0
- data/ext/agoo/subscription.c +54 -0
- data/ext/agoo/subscription.h +18 -0
- data/ext/agoo/text.c +26 -4
- data/ext/agoo/text.h +2 -0
- data/ext/agoo/types.h +13 -0
- data/ext/agoo/upgraded.c +148 -0
- data/ext/agoo/upgraded.h +13 -0
- data/ext/agoo/websocket.c +248 -0
- data/ext/agoo/websocket.h +27 -0
- data/lib/agoo/version.rb +1 -1
- data/lib/rack/handler/agoo.rb +13 -6
- data/test/base_handler_test.rb +24 -22
- data/test/log_test.rb +146 -199
- data/test/rack_handler_test.rb +19 -20
- data/test/static_test.rb +30 -28
- metadata +23 -7
- data/test/rrr/test.rb +0 -26
- data/test/tests.rb +0 -8
@@ -0,0 +1,27 @@
|
|
1
|
+
// Copyright (c) 2018, Peter Ohler, All rights reserved.
|
2
|
+
|
3
|
+
#ifndef __AGOO_WEBSOCKET_H__
|
4
|
+
#define __AGOO_WEBSOCKET_H__
|
5
|
+
|
6
|
+
#define WS_OP_CONT 0x00
|
7
|
+
#define WS_OP_TEXT 0x01
|
8
|
+
#define WS_OP_BIN 0x02
|
9
|
+
#define WS_OP_CLOSE 0x08
|
10
|
+
#define WS_OP_PING 0x09
|
11
|
+
#define WS_OP_PONG 0x0A
|
12
|
+
|
13
|
+
struct _Req;
|
14
|
+
struct _Text;
|
15
|
+
|
16
|
+
extern struct _Text* ws_add_headers(struct _Req *req, struct _Text *t);
|
17
|
+
extern Text ws_expand(Text t);
|
18
|
+
extern size_t ws_decode(char *buf, size_t mlen);
|
19
|
+
|
20
|
+
extern long ws_calc_len(Con c, uint8_t *buf, size_t cnt);
|
21
|
+
extern bool ws_create_req(Con c, long mlen);
|
22
|
+
extern void ws_req_close(Con c);
|
23
|
+
|
24
|
+
extern void ws_ping(Con c);
|
25
|
+
extern void ws_pong(Con c);
|
26
|
+
|
27
|
+
#endif // __AGOO_WEBSOCKET_H__
|
data/lib/agoo/version.rb
CHANGED
data/lib/rack/handler/agoo.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
|
2
2
|
require 'agoo'
|
3
3
|
|
4
|
+
# Grand parent for the Agoo rack handler.
|
4
5
|
module Rack
|
6
|
+
|
7
|
+
# Parent for the Agoo rack handler.
|
5
8
|
module Handler
|
6
9
|
|
7
10
|
# The Rack::Handler::Agoo module is a handler for common rack config.rb files.
|
@@ -33,17 +36,21 @@ module Rack
|
|
33
36
|
end
|
34
37
|
}
|
35
38
|
options[:thread_count] = 0
|
36
|
-
|
39
|
+
::Agoo::Server.init(port, root, options)
|
37
40
|
path_map.each { |path,handler|
|
38
|
-
|
41
|
+
::Agoo::Server.handle(nil, path, handler)
|
39
42
|
}
|
40
43
|
unless default_handler.nil?
|
41
|
-
|
44
|
+
::Agoo::Server.handle(nil, '**', default_handler)
|
42
45
|
end
|
43
|
-
|
44
|
-
|
46
|
+
::Agoo::Server.handle_not_found(not_found_handler) unless not_found_handler.nil?
|
47
|
+
::Agoo::Server.start
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.shutdown
|
51
|
+
::Agoo::shutdown
|
45
52
|
end
|
46
|
-
|
53
|
+
|
47
54
|
end
|
48
55
|
end
|
49
56
|
end
|
data/test/base_handler_test.rb
CHANGED
@@ -44,28 +44,30 @@ class BaseHandlerTest < Minitest::Test
|
|
44
44
|
|
45
45
|
def test_base_handler
|
46
46
|
begin
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
47
|
+
Agoo::Log.configure(dir: '',
|
48
|
+
console: true,
|
49
|
+
classic: true,
|
50
|
+
colorize: true,
|
51
|
+
states: {
|
52
|
+
INFO: false,
|
53
|
+
DEBUG: false,
|
54
|
+
connect: false,
|
55
|
+
request: false,
|
56
|
+
response: false,
|
57
|
+
eval: true,
|
58
|
+
})
|
59
|
+
|
60
|
+
Agoo::Server.init(6470, 'root', thread_count: 1)
|
61
|
+
|
62
62
|
handler = TellMeHandler.new
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
63
|
+
|
64
|
+
Agoo::Server.handle(:GET, "/tellme", handler)
|
65
|
+
Agoo::Server.handle(:POST, "/makeme", handler)
|
66
|
+
Agoo::Server.handle(:PUT, "/makeme", handler)
|
67
|
+
Agoo::Server.handle(:GET, "/wild/*/one", WildHandler.new('one'))
|
68
|
+
Agoo::Server.handle(:GET, "/wild/all/**", WildHandler.new('all'))
|
69
|
+
|
70
|
+
Agoo::Server.start()
|
69
71
|
|
70
72
|
#sleep(100)
|
71
73
|
eval_test
|
@@ -74,7 +76,7 @@ class BaseHandlerTest < Minitest::Test
|
|
74
76
|
wild_one_test
|
75
77
|
wild_all_test
|
76
78
|
ensure
|
77
|
-
|
79
|
+
Agoo.shutdown
|
78
80
|
end
|
79
81
|
end
|
80
82
|
|
data/test/log_test.rb
CHANGED
@@ -11,271 +11,218 @@ require 'minitest/autorun'
|
|
11
11
|
|
12
12
|
require 'agoo'
|
13
13
|
|
14
|
-
class
|
14
|
+
class LogTest < Minitest::Test
|
15
15
|
|
16
|
-
def
|
16
|
+
def test_log
|
17
|
+
`rm -rf log`
|
17
18
|
begin
|
18
|
-
|
19
|
+
Agoo::Log.configure(dir: 'log',
|
20
|
+
max_files: 2,
|
21
|
+
max_size: 150,
|
22
|
+
console: false,
|
23
|
+
classic: true,
|
24
|
+
colorize: false,
|
25
|
+
states: {
|
26
|
+
INFO: true,
|
27
|
+
DEBUG: true,
|
28
|
+
eval: true,
|
29
|
+
})
|
30
|
+
|
31
|
+
10.times { |i|
|
32
|
+
Agoo::Log.info("my #{i} message")
|
33
|
+
}
|
34
|
+
Agoo::Log.flush(1.0)
|
35
|
+
sleep(0.05)
|
36
|
+
content = IO.read('log/agoo.log')
|
37
|
+
assert_match(/INFO: my 9 message/, content)
|
38
|
+
|
39
|
+
content = IO.read('log/agoo.log.1')
|
40
|
+
assert_match(/INFO: my 6 message/, content)
|
41
|
+
assert_match(/INFO: my 7 message/, content)
|
42
|
+
assert_match(/INFO: my 8 message/, content)
|
43
|
+
|
44
|
+
content = IO.read('log/agoo.log.2')
|
45
|
+
assert_match(/INFO: my 3 message/, content)
|
46
|
+
assert_match(/INFO: my 4 message/, content)
|
47
|
+
assert_match(/INFO: my 5 message/, content)
|
48
|
+
|
49
|
+
assert_raises() {
|
50
|
+
IO.read('log/agoo.log.3')
|
51
|
+
}
|
52
|
+
|
53
|
+
error_state_test()
|
54
|
+
warn_state_test()
|
55
|
+
info_state_test()
|
56
|
+
debug_state_test()
|
57
|
+
request_state_test()
|
58
|
+
|
59
|
+
Agoo::Log.max_size = 10000
|
60
|
+
|
61
|
+
Agoo::Log.classic
|
62
|
+
Agoo::Log.set_state('DEBUG', true)
|
63
|
+
Agoo::Log.set_state('eval', true)
|
64
|
+
classic_error_test()
|
65
|
+
classic_warn_test()
|
66
|
+
classic_info_test()
|
67
|
+
classic_debug_test()
|
68
|
+
classic_log_test()
|
69
|
+
|
70
|
+
Agoo::Log.json
|
71
|
+
json_error_test()
|
72
|
+
json_warn_test()
|
73
|
+
json_info_test()
|
74
|
+
json_debug_test()
|
75
|
+
json_log_test()
|
19
76
|
|
20
|
-
error_state_test(server)
|
21
|
-
warn_state_test(server)
|
22
|
-
info_state_test(server)
|
23
|
-
debug_state_test(server)
|
24
|
-
request_state_test(server)
|
25
|
-
response_state_test(server)
|
26
|
-
eval_state_test(server)
|
27
77
|
ensure
|
28
|
-
|
78
|
+
Agoo::Log.shutdown
|
29
79
|
end
|
30
80
|
end
|
31
|
-
|
32
|
-
def error_state_test(server)
|
33
|
-
assert(server.error?)
|
34
|
-
server.set_log_state('ERROR', false)
|
35
|
-
refute(server.error?)
|
36
|
-
server.set_log_state('ERROR', true)
|
37
|
-
end
|
38
81
|
|
39
|
-
def
|
40
|
-
assert(
|
41
|
-
|
42
|
-
refute(
|
43
|
-
|
82
|
+
def error_state_test()
|
83
|
+
assert(Agoo::Log.error?)
|
84
|
+
Agoo::Log.set_state('ERROR', false)
|
85
|
+
refute(Agoo::Log.error?)
|
86
|
+
Agoo::Log.set_state('ERROR', true)
|
44
87
|
end
|
45
88
|
|
46
|
-
def
|
47
|
-
assert(
|
48
|
-
|
49
|
-
refute(
|
50
|
-
|
89
|
+
def warn_state_test()
|
90
|
+
assert(Agoo::Log.warn?)
|
91
|
+
Agoo::Log.set_state('WARN', false)
|
92
|
+
refute(Agoo::Log.warn?)
|
93
|
+
Agoo::Log.set_state('WARN', true)
|
51
94
|
end
|
52
95
|
|
53
|
-
def
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
96
|
+
def info_state_test()
|
97
|
+
assert(Agoo::Log.info?)
|
98
|
+
Agoo::Log.set_state('INFO', false)
|
99
|
+
refute(Agoo::Log.info?)
|
100
|
+
Agoo::Log.set_state('INFO', true)
|
58
101
|
end
|
59
102
|
|
60
|
-
def
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
103
|
+
def debug_state_test()
|
104
|
+
Agoo::Log.set_state('DEBUG', false)
|
105
|
+
refute(Agoo::Log.debug?)
|
106
|
+
Agoo::Log.set_state('DEBUG', true)
|
107
|
+
assert(Agoo::Log.debug?)
|
108
|
+
Agoo::Log.set_state('DEBUG', false)
|
65
109
|
end
|
66
110
|
|
67
|
-
def
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
111
|
+
def request_state_test()
|
112
|
+
Agoo::Log.set_state('request', false)
|
113
|
+
refute(Agoo::Log.state('request'))
|
114
|
+
Agoo::Log.set_state('request', true)
|
115
|
+
assert(Agoo::Log.state('request'))
|
116
|
+
Agoo::Log.set_state('request', false)
|
72
117
|
end
|
73
118
|
|
74
|
-
def
|
75
|
-
refute(server.log_state('eval'))
|
76
|
-
server.set_log_state('eval', true)
|
77
|
-
assert(server.log_state('eval'))
|
78
|
-
server.set_log_state('eval', false)
|
79
|
-
end
|
80
|
-
|
81
|
-
def unknown_state_test(server)
|
119
|
+
def unknown_state_test()
|
82
120
|
assert_raises(ArgumentError) {
|
83
|
-
|
121
|
+
Agoo::Log.state('unknown')
|
84
122
|
}
|
85
123
|
assert_raises(ArgumentError) {
|
86
|
-
|
124
|
+
Agoo::Log.set_state('unknown', true)
|
87
125
|
}
|
88
126
|
end
|
89
127
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
`rm -rf log`
|
96
|
-
begin
|
97
|
-
server = Agoo::Server.new(6464, '.',
|
98
|
-
log_dir: 'log',
|
99
|
-
log_console: false,
|
100
|
-
log_classic: true,
|
101
|
-
log_colorize: false,
|
102
|
-
log_states: {
|
103
|
-
INFO: true,
|
104
|
-
DEBUG: true,
|
105
|
-
eval: true,
|
106
|
-
})
|
107
|
-
error_test(server)
|
108
|
-
warn_test(server)
|
109
|
-
info_test(server)
|
110
|
-
debug_test(server)
|
111
|
-
log_eval_test(server)
|
112
|
-
ensure
|
113
|
-
server.shutdown
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
def error_test(server)
|
118
|
-
server.error('my message')
|
119
|
-
server.log_flush(1.0)
|
120
|
-
sleep(0.01) # seems to be needed to assure writes actually happened even though flush was called.
|
128
|
+
def classic_error_test()
|
129
|
+
Agoo::Log.rotate
|
130
|
+
Agoo::Log.error('my message')
|
131
|
+
Agoo::Log.flush(1.0)
|
132
|
+
sleep(0.05) # seems to be needed to assure writes actually happened even though flush was called.
|
121
133
|
content = IO.read('log/agoo.log')
|
122
134
|
assert_match(/ERROR: my message/, content)
|
123
135
|
end
|
124
136
|
|
125
|
-
def
|
126
|
-
|
127
|
-
|
128
|
-
|
137
|
+
def classic_warn_test()
|
138
|
+
Agoo::Log.rotate
|
139
|
+
Agoo::Log.warn('my message')
|
140
|
+
Agoo::Log.flush(1.0)
|
141
|
+
sleep(0.05)
|
129
142
|
content = IO.read('log/agoo.log')
|
130
143
|
assert_match(/WARN: my message/, content)
|
131
144
|
end
|
132
145
|
|
133
|
-
def
|
134
|
-
|
135
|
-
|
136
|
-
|
146
|
+
def classic_info_test()
|
147
|
+
Agoo::Log.rotate
|
148
|
+
Agoo::Log.info('my message')
|
149
|
+
Agoo::Log.flush(1.0)
|
150
|
+
sleep(0.05)
|
137
151
|
content = IO.read('log/agoo.log')
|
138
152
|
assert_match(/INFO: my message/, content)
|
139
153
|
end
|
140
154
|
|
141
|
-
def
|
142
|
-
|
143
|
-
|
144
|
-
|
155
|
+
def classic_debug_test()
|
156
|
+
Agoo::Log.rotate
|
157
|
+
Agoo::Log.debug('my message')
|
158
|
+
Agoo::Log.flush(1.0)
|
159
|
+
sleep(0.05)
|
145
160
|
content = IO.read('log/agoo.log')
|
146
161
|
assert_match(/DEBUG: my message/, content)
|
147
162
|
end
|
148
163
|
|
149
|
-
def
|
150
|
-
|
151
|
-
|
152
|
-
|
164
|
+
def classic_log_test()
|
165
|
+
Agoo::Log.rotate
|
166
|
+
Agoo::Log.log('eval', 'my message')
|
167
|
+
Agoo::Log.flush(1.0)
|
168
|
+
sleep(0.05)
|
153
169
|
content = IO.read('log/agoo.log')
|
154
170
|
assert_match(/eval: my message/, content)
|
155
171
|
end
|
156
172
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
begin
|
164
|
-
server = Agoo::Server.new(6464, '.',
|
165
|
-
log_dir: 'log',
|
166
|
-
log_max_files: 2,
|
167
|
-
log_max_size: 10,
|
168
|
-
log_console: false,
|
169
|
-
log_classic: false,
|
170
|
-
log_colorize: false,
|
171
|
-
log_states: {
|
172
|
-
INFO: true,
|
173
|
-
DEBUG: true,
|
174
|
-
eval: true,
|
175
|
-
})
|
176
|
-
error_test(server)
|
177
|
-
warn_test(server)
|
178
|
-
info_test(server)
|
179
|
-
debug_test(server)
|
180
|
-
eval_test(server)
|
181
|
-
ensure
|
182
|
-
server.shutdown
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
def error_test(server)
|
187
|
-
server.error('my message')
|
188
|
-
server.log_flush(1.0)
|
189
|
-
sleep(0.01)
|
190
|
-
content = IO.read('log/agoo.log.1')
|
173
|
+
def json_error_test()
|
174
|
+
Agoo::Log.rotate
|
175
|
+
Agoo::Log.error('my message')
|
176
|
+
Agoo::Log.flush(1.0)
|
177
|
+
sleep(0.05)
|
178
|
+
content = IO.read('log/agoo.log')
|
191
179
|
assert_match(/"where":"ERROR"/, content)
|
192
180
|
assert_match(/"level":1/, content)
|
193
181
|
assert_match(/"what":"my message"/, content)
|
194
182
|
end
|
195
183
|
|
196
|
-
def
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
184
|
+
def json_warn_test()
|
185
|
+
Agoo::Log.rotate
|
186
|
+
Agoo::Log.warn('my message')
|
187
|
+
Agoo::Log.flush(1.0)
|
188
|
+
sleep(0.05)
|
189
|
+
content = IO.read('log/agoo.log')
|
201
190
|
assert_match(/"where":"WARN"/, content)
|
202
191
|
assert_match(/"level":2/, content)
|
203
192
|
assert_match(/"what":"my message"/, content)
|
204
193
|
end
|
205
194
|
|
206
|
-
def
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
195
|
+
def json_info_test()
|
196
|
+
Agoo::Log.rotate
|
197
|
+
Agoo::Log.info('my message')
|
198
|
+
Agoo::Log.flush(1.0)
|
199
|
+
sleep(0.05)
|
200
|
+
content = IO.read('log/agoo.log')
|
211
201
|
assert_match(/"where":"INFO"/, content)
|
212
202
|
assert_match(/"level":3/, content)
|
213
203
|
assert_match(/"what":"my message"/, content)
|
214
204
|
end
|
215
205
|
|
216
|
-
def
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
206
|
+
def json_debug_test()
|
207
|
+
Agoo::Log.rotate
|
208
|
+
Agoo::Log.debug('my message')
|
209
|
+
Agoo::Log.flush(1.0)
|
210
|
+
sleep(0.05)
|
211
|
+
content = IO.read('log/agoo.log')
|
221
212
|
assert_match(/"where":"DEBUG"/, content)
|
222
213
|
assert_match(/"level":4/, content)
|
223
214
|
assert_match(/"what":"my message"/, content)
|
224
215
|
end
|
225
216
|
|
226
|
-
def
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
217
|
+
def json_log_test()
|
218
|
+
Agoo::Log.rotate
|
219
|
+
Agoo::Log.log('eval', 'my message')
|
220
|
+
Agoo::Log.flush(1.0)
|
221
|
+
sleep(0.05)
|
222
|
+
content = IO.read('log/agoo.log')
|
231
223
|
assert_match(/"where":"eval"/, content)
|
232
224
|
assert_match(/"level":3/, content)
|
233
225
|
assert_match(/"what":"my message"/, content)
|
234
226
|
end
|
235
227
|
|
236
228
|
end
|
237
|
-
|
238
|
-
class LogRollTest < Minitest::Test
|
239
|
-
|
240
|
-
def setup
|
241
|
-
`rm -rf log`
|
242
|
-
begin
|
243
|
-
server = Agoo::Server.new(6464, '.',
|
244
|
-
log_dir: 'log',
|
245
|
-
log_max_files: 2,
|
246
|
-
log_max_size: 150,
|
247
|
-
log_console: false,
|
248
|
-
log_classic: true,
|
249
|
-
log_colorize: false,
|
250
|
-
log_states: {
|
251
|
-
INFO: true,
|
252
|
-
DEBUG: true,
|
253
|
-
eval: true,
|
254
|
-
})
|
255
|
-
10.times { |i|
|
256
|
-
@server.info("my #{i} message")
|
257
|
-
}
|
258
|
-
@server.log_flush(1.0)
|
259
|
-
sleep(0.01)
|
260
|
-
content = IO.read('log/agoo.log')
|
261
|
-
assert_match(/INFO: my 9 message/, content)
|
262
|
-
|
263
|
-
content = IO.read('log/agoo.log.1')
|
264
|
-
assert_match(/INFO: my 6 message/, content)
|
265
|
-
assert_match(/INFO: my 7 message/, content)
|
266
|
-
assert_match(/INFO: my 8 message/, content)
|
267
|
-
|
268
|
-
content = IO.read('log/agoo.log.2')
|
269
|
-
assert_match(/INFO: my 3 message/, content)
|
270
|
-
assert_match(/INFO: my 4 message/, content)
|
271
|
-
assert_match(/INFO: my 5 message/, content)
|
272
|
-
|
273
|
-
assert_raises() {
|
274
|
-
IO.read('log/agoo.log.3')
|
275
|
-
}
|
276
|
-
ensure
|
277
|
-
@server.shutdown
|
278
|
-
end
|
279
|
-
end
|
280
|
-
|
281
|
-
end
|