agoo 1.1.1 → 1.1.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 +4 -4
- data/ext/agoo/con.c +71 -48
- data/ext/agoo/con.h +0 -2
- data/ext/agoo/queue.c +2 -0
- data/ext/agoo/server.c +1 -1
- data/lib/agoo/version.rb +1 -1
- data/test/base_handler_test.rb +7 -7
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 017722eeae76195c26f2282976788f75f4104499603f00c3644383ea366071a5
|
4
|
+
data.tar.gz: e89000afbdc9a9727a68461b493b729977475b1f497811f35aa44d6910d62064
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf56a6b3e9bcdc8f35093f7a7119b2f07bf5b673986e97710918f62d002ba4d02b5de1fc75b1725cb663d14bb85ae7b2d538ffe2d285579052620b2a754f42db
|
7
|
+
data.tar.gz: 1f49fe3e014610b5c77ac96edf500dbf68fa2bf9678051e74c227246e2c9f054431479f4d599aee72eb0d74749e1cc5519fb4060a380b452be7a5ed0e7dcdd12
|
data/ext/agoo/con.c
CHANGED
@@ -76,7 +76,7 @@ con_header_value(const char *header, int hlen, const char *key, int *vlen) {
|
|
76
76
|
return NULL;
|
77
77
|
}
|
78
78
|
|
79
|
-
static
|
79
|
+
static long
|
80
80
|
bad_request(Con c, int status, int line) {
|
81
81
|
Res res;
|
82
82
|
const char *msg = http_code_message(status);
|
@@ -97,7 +97,7 @@ bad_request(Con c, int status, int line) {
|
|
97
97
|
res->close = true;
|
98
98
|
res_set_message(res, message);
|
99
99
|
}
|
100
|
-
return
|
100
|
+
return -1;
|
101
101
|
}
|
102
102
|
|
103
103
|
static bool
|
@@ -111,8 +111,12 @@ should_close(const char *header, int hlen) {
|
|
111
111
|
return false;
|
112
112
|
}
|
113
113
|
|
114
|
-
// Returns
|
115
|
-
|
114
|
+
// Returns:
|
115
|
+
// 0 - when header has not been read
|
116
|
+
// message length - when length can be determined
|
117
|
+
// -1 on a bad request
|
118
|
+
// negative of message length - when message is handled here.
|
119
|
+
static long
|
116
120
|
con_header_read(Con c) {
|
117
121
|
Server server = c->server;
|
118
122
|
char *hend = strstr(c->buf, "\r\n\r\n");
|
@@ -123,14 +127,14 @@ con_header_read(Con c) {
|
|
123
127
|
char *qend;
|
124
128
|
char *b;
|
125
129
|
size_t clen = 0;
|
126
|
-
|
130
|
+
long mlen;
|
127
131
|
Hook hook = NULL;
|
128
132
|
|
129
133
|
if (NULL == hend) {
|
130
134
|
if (sizeof(c->buf) - 1 <= c->bcnt) {
|
131
135
|
return bad_request(c, 431, __LINE__);
|
132
136
|
}
|
133
|
-
return
|
137
|
+
return 0;
|
134
138
|
}
|
135
139
|
if (server->req_cat.on) {
|
136
140
|
*hend = '\0';
|
@@ -222,6 +226,7 @@ con_header_read(Con c) {
|
|
222
226
|
} else {
|
223
227
|
qend = b;
|
224
228
|
}
|
229
|
+
mlen = hend - c->buf + 4 + clen;
|
225
230
|
if (NULL == (hook = hook_find(server->hooks, method, path, pend))) {
|
226
231
|
if (GET == method) {
|
227
232
|
struct _Err err = ERR_INIT;
|
@@ -253,19 +258,23 @@ con_header_read(Con c) {
|
|
253
258
|
text_ref(p->resp);
|
254
259
|
res_set_message(res, p->resp);
|
255
260
|
|
256
|
-
return
|
261
|
+
return -mlen;
|
257
262
|
}
|
258
263
|
}
|
259
264
|
HOOKED:
|
260
265
|
// Create request and populate.
|
261
|
-
mlen = hend - c->buf + 4 + clen;
|
262
266
|
if (NULL == (c->req = (Req)malloc(mlen + sizeof(struct _Req) - 8 + 1))) {
|
263
267
|
return bad_request(c, 413, __LINE__);
|
264
268
|
}
|
265
|
-
|
266
|
-
|
267
|
-
|
269
|
+
if ((long)c->bcnt <= mlen) {
|
270
|
+
memcpy(c->req->msg, c->buf, c->bcnt);
|
271
|
+
if ((long)c->bcnt < mlen) {
|
272
|
+
memset(c->req->msg + c->bcnt, 0, mlen - c->bcnt);
|
273
|
+
}
|
274
|
+
} else {
|
275
|
+
memcpy(c->req->msg, c->buf, mlen);
|
268
276
|
}
|
277
|
+
c->req->msg[mlen] = '\0';
|
269
278
|
c->req->server = server;
|
270
279
|
c->req->method = method;
|
271
280
|
c->req->path.start = c->req->msg + (path - c->buf);
|
@@ -286,14 +295,14 @@ HOOKED:
|
|
286
295
|
c->req->handler = Qnil;
|
287
296
|
c->req->handler_type = NO_HOOK;
|
288
297
|
}
|
289
|
-
return
|
298
|
+
return mlen;
|
290
299
|
}
|
291
300
|
|
292
301
|
// return true to remove/close connection
|
293
302
|
static bool
|
294
303
|
con_read(Con c) {
|
295
304
|
ssize_t cnt;
|
296
|
-
|
305
|
+
|
297
306
|
if (NULL != c->req) {
|
298
307
|
cnt = recv(c->sock, c->req->msg + c->bcnt, c->req->mlen - c->bcnt, 0);
|
299
308
|
} else {
|
@@ -312,47 +321,61 @@ con_read(Con c) {
|
|
312
321
|
return true;
|
313
322
|
}
|
314
323
|
c->bcnt += cnt;
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
+
while (true) {
|
325
|
+
if (NULL == c->req) {
|
326
|
+
long mlen;
|
327
|
+
|
328
|
+
// Terminate with \0 for debug and strstr() check
|
329
|
+
c->buf[c->bcnt] = '\0';
|
330
|
+
if (0 > (mlen = con_header_read(c))) {
|
331
|
+
if (-mlen < (long)c->bcnt) {
|
332
|
+
mlen = -mlen;
|
333
|
+
memmove(c->buf, c->buf + mlen, c->bcnt - mlen);
|
334
|
+
c->bcnt -= mlen;
|
335
|
+
} else {
|
336
|
+
c->bcnt = 0;
|
337
|
+
*c->buf = '\0';
|
338
|
+
return false;
|
339
|
+
}
|
340
|
+
continue;
|
341
|
+
}
|
324
342
|
}
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
if (c->req->mlen <= c->bcnt) {
|
329
|
-
Res res;
|
343
|
+
if (NULL != c->req) {
|
344
|
+
if (c->req->mlen <= c->bcnt) {
|
345
|
+
Res res;
|
330
346
|
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
} else {
|
339
|
-
if (NULL == c->res_tail) {
|
340
|
-
c->res_head = res;
|
347
|
+
if (c->server->debug_cat.on && NULL != c->req && NULL != c->req->body.start) {
|
348
|
+
log_cat(&c->server->debug_cat, "request on %llu: %s", c->iid, c->req->body.start);
|
349
|
+
}
|
350
|
+
if (NULL == (res = res_create())) {
|
351
|
+
c->req = NULL;
|
352
|
+
log_cat(&c->server->error_cat, "memory allocation of response failed on connection %llu.", c->iid);
|
353
|
+
return bad_request(c, 500, __LINE__);
|
341
354
|
} else {
|
342
|
-
c->res_tail
|
355
|
+
if (NULL == c->res_tail) {
|
356
|
+
c->res_head = res;
|
357
|
+
} else {
|
358
|
+
c->res_tail->next = res;
|
359
|
+
}
|
360
|
+
c->res_tail = res;
|
361
|
+
res->close = should_close(c->req->header.start, c->req->header.len);
|
343
362
|
}
|
344
|
-
c->
|
345
|
-
|
363
|
+
c->req->res = res;
|
364
|
+
queue_push(&c->server->eval_queue, (void*)c->req);
|
365
|
+
if (c->req->mlen < c->bcnt) {
|
366
|
+
memmove(c->buf, c->buf + c->req->mlen, c->bcnt - c->req->mlen);
|
367
|
+
c->bcnt -= c->req->mlen;
|
368
|
+
} else {
|
369
|
+
c->bcnt = 0;
|
370
|
+
*c->buf = '\0';
|
371
|
+
c->req = NULL;
|
372
|
+
break;
|
373
|
+
}
|
374
|
+
c->req = NULL;
|
375
|
+
continue;
|
346
376
|
}
|
347
|
-
c->req->res = res;
|
348
|
-
queue_push(&c->server->eval_queue, (void*)c->req);
|
349
|
-
c->req = NULL;
|
350
|
-
c->bcnt = 0;
|
351
|
-
*c->buf = '\0';
|
352
|
-
// TBD handle extra data in buf
|
353
|
-
|
354
|
-
return false;
|
355
377
|
}
|
378
|
+
break;
|
356
379
|
}
|
357
380
|
return false;
|
358
381
|
}
|
data/ext/agoo/con.h
CHANGED
data/ext/agoo/queue.c
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
// Copyright 2015, 2016, 2018 by Peter Ohler, All Rights Reserved
|
2
2
|
|
3
3
|
#include <fcntl.h>
|
4
|
+
#include <stdio.h>
|
4
5
|
#include <stdlib.h>
|
5
6
|
#include <string.h>
|
6
7
|
#include <sys/socket.h>
|
7
8
|
#include <unistd.h>
|
9
|
+
#include <pthread.h>
|
8
10
|
|
9
11
|
#include "dtime.h"
|
10
12
|
#include "queue.h"
|
data/ext/agoo/server.c
CHANGED
@@ -208,6 +208,7 @@ server_new(int argc, VALUE *argv, VALUE self) {
|
|
208
208
|
}
|
209
209
|
queue_multi_init(&s->con_queue, 256, false, false);
|
210
210
|
queue_multi_init(&s->eval_queue, 1024, false, true);
|
211
|
+
|
211
212
|
cache_init(&s->pages);
|
212
213
|
the_server = s;
|
213
214
|
|
@@ -512,7 +513,6 @@ handle_wab(void *x) {
|
|
512
513
|
}
|
513
514
|
static void
|
514
515
|
handle_protected(Req req) {
|
515
|
-
|
516
516
|
switch (req->handler_type) {
|
517
517
|
case BASE_HOOK:
|
518
518
|
rb_thread_call_with_gvl(handle_base, req);
|
data/lib/agoo/version.rb
CHANGED
data/test/base_handler_test.rb
CHANGED
@@ -44,7 +44,7 @@ class BaseHandlerTest < Minitest::Test
|
|
44
44
|
|
45
45
|
def test_base_handler
|
46
46
|
begin
|
47
|
-
server = Agoo::Server.new(
|
47
|
+
server = Agoo::Server.new(6470, 'root',
|
48
48
|
pedantic: false,
|
49
49
|
log_dir: '',
|
50
50
|
thread_count: 1,
|
@@ -79,7 +79,7 @@ class BaseHandlerTest < Minitest::Test
|
|
79
79
|
end
|
80
80
|
|
81
81
|
def eval_test
|
82
|
-
uri = URI('http://localhost:
|
82
|
+
uri = URI('http://localhost:6470/tellme?a=1')
|
83
83
|
req = Net::HTTP::Get.new(uri)
|
84
84
|
# Set the headers the way we want them.
|
85
85
|
req['Accept-Encoding'] = '*'
|
@@ -101,7 +101,7 @@ class BaseHandlerTest < Minitest::Test
|
|
101
101
|
"REQUEST_METHOD" => "GET",
|
102
102
|
"SCRIPT_NAME" => "/tellme",
|
103
103
|
"SERVER_NAME" => "localhost",
|
104
|
-
"SERVER_PORT" => "
|
104
|
+
"SERVER_PORT" => "6470",
|
105
105
|
"rack.errors" => nil,
|
106
106
|
"rack.input" => nil,
|
107
107
|
"rack.multiprocess" => false,
|
@@ -121,7 +121,7 @@ class BaseHandlerTest < Minitest::Test
|
|
121
121
|
end
|
122
122
|
|
123
123
|
def post_test
|
124
|
-
uri = URI('http://localhost:
|
124
|
+
uri = URI('http://localhost:6470/makeme')
|
125
125
|
req = Net::HTTP::Post.new(uri)
|
126
126
|
# Set the headers the way we want them.
|
127
127
|
req['Accept-Encoding'] = '*'
|
@@ -135,7 +135,7 @@ class BaseHandlerTest < Minitest::Test
|
|
135
135
|
end
|
136
136
|
|
137
137
|
def put_test
|
138
|
-
uri = URI('http://localhost:
|
138
|
+
uri = URI('http://localhost:6470/makeme')
|
139
139
|
req = Net::HTTP::Put.new(uri)
|
140
140
|
# Set the headers the way we want them.
|
141
141
|
req['Accept-Encoding'] = '*'
|
@@ -151,7 +151,7 @@ class BaseHandlerTest < Minitest::Test
|
|
151
151
|
end
|
152
152
|
|
153
153
|
def wild_one_test
|
154
|
-
uri = URI('http://localhost:
|
154
|
+
uri = URI('http://localhost:6470/wild/abc/one')
|
155
155
|
req = Net::HTTP::Get.new(uri)
|
156
156
|
res = Net::HTTP.start(uri.hostname, uri.port) { |h|
|
157
157
|
h.request(req)
|
@@ -160,7 +160,7 @@ class BaseHandlerTest < Minitest::Test
|
|
160
160
|
end
|
161
161
|
|
162
162
|
def wild_all_test
|
163
|
-
uri = URI('http://localhost:
|
163
|
+
uri = URI('http://localhost:6470/wild/all/x/y')
|
164
164
|
req = Net::HTTP::Get.new(uri)
|
165
165
|
res = Net::HTTP.start(uri.hostname, uri.port) { |h|
|
166
166
|
h.request(req)
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: agoo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.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-02-
|
12
|
-
dependencies:
|
11
|
+
date: 2018-02-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: oj
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.4.0
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.4.0
|
13
27
|
description: A fast HTTP server supporting rack.
|
14
28
|
email: peter@ohler.com
|
15
29
|
executables:
|