puma 2.16.0 → 3.11.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/{History.txt → History.md} +489 -70
- data/README.md +143 -174
- data/docs/architecture.md +36 -0
- data/{DEPLOYMENT.md → docs/deployment.md} +1 -1
- data/docs/images/puma-connection-flow-no-reactor.png +0 -0
- data/docs/images/puma-connection-flow.png +0 -0
- data/docs/images/puma-general-arch.png +0 -0
- data/docs/nginx.md +2 -2
- data/docs/plugins.md +28 -0
- data/docs/restart.md +39 -0
- data/docs/signals.md +56 -3
- data/docs/systemd.md +272 -0
- data/ext/puma_http11/extconf.rb +2 -0
- data/ext/puma_http11/http11_parser.c +291 -447
- data/ext/puma_http11/http11_parser.h +1 -0
- data/ext/puma_http11/http11_parser.java.rl +5 -5
- data/ext/puma_http11/http11_parser.rl +10 -9
- data/ext/puma_http11/http11_parser_common.rl +1 -1
- data/ext/puma_http11/io_buffer.c +8 -8
- data/ext/puma_http11/mini_ssl.c +64 -6
- data/ext/puma_http11/org/jruby/puma/Http11Parser.java +113 -131
- data/ext/puma_http11/org/jruby/puma/MiniSSL.java +9 -2
- data/ext/puma_http11/puma_http11.c +1 -0
- data/lib/puma/app/status.rb +9 -1
- data/lib/puma/binder.rb +90 -38
- data/lib/puma/cli.rb +134 -491
- data/lib/puma/client.rb +142 -4
- data/lib/puma/cluster.rb +132 -76
- data/lib/puma/commonlogger.rb +19 -20
- data/lib/puma/compat.rb +3 -7
- data/lib/puma/configuration.rb +206 -67
- data/lib/puma/const.rb +21 -31
- data/lib/puma/control_cli.rb +92 -103
- data/lib/puma/convenient.rb +23 -0
- data/lib/puma/daemon_ext.rb +6 -0
- data/lib/puma/detect.rb +10 -1
- data/lib/puma/dsl.rb +203 -45
- data/lib/puma/events.rb +22 -13
- data/lib/puma/io_buffer.rb +1 -1
- data/lib/puma/jruby_restart.rb +1 -2
- data/lib/puma/launcher.rb +431 -0
- data/lib/puma/minissl.rb +83 -4
- data/lib/puma/null_io.rb +19 -11
- data/lib/puma/plugin/tmp_restart.rb +34 -0
- data/lib/puma/plugin.rb +115 -0
- data/lib/puma/rack/backports/uri/common_193.rb +17 -13
- data/lib/puma/rack/builder.rb +3 -0
- data/lib/puma/rack/urlmap.rb +9 -8
- data/lib/puma/reactor.rb +18 -0
- data/lib/puma/runner.rb +43 -15
- data/lib/puma/server.rb +141 -35
- data/lib/puma/single.rb +16 -6
- data/lib/puma/state_file.rb +29 -0
- data/lib/puma/tcp_logger.rb +8 -1
- data/lib/puma/thread_pool.rb +60 -10
- data/lib/puma/util.rb +1 -5
- data/lib/puma.rb +13 -4
- data/lib/rack/handler/puma.rb +76 -29
- data/tools/jungle/README.md +12 -2
- data/tools/jungle/init.d/README.md +9 -2
- data/tools/jungle/init.d/puma +86 -59
- data/tools/jungle/init.d/run-puma +16 -1
- data/tools/jungle/rc.d/README.md +74 -0
- data/tools/jungle/rc.d/puma +61 -0
- data/tools/jungle/rc.d/puma.conf +10 -0
- data/tools/jungle/upstart/puma.conf +1 -1
- data/tools/trickletest.rb +1 -1
- metadata +28 -95
- data/COPYING +0 -55
- data/Gemfile +0 -13
- data/Manifest.txt +0 -74
- data/Rakefile +0 -158
- data/docs/config.md +0 -0
- data/lib/puma/capistrano.rb +0 -94
- data/lib/puma/rack/backports/uri/common_18.rb +0 -56
- data/lib/puma/rack/backports/uri/common_192.rb +0 -52
- data/puma.gemspec +0 -52
|
@@ -7,8 +7,8 @@ public class Http11Parser {
|
|
|
7
7
|
/** Machine **/
|
|
8
8
|
|
|
9
9
|
%%{
|
|
10
|
-
|
|
11
|
-
machine
|
|
10
|
+
|
|
11
|
+
machine puma_parser;
|
|
12
12
|
|
|
13
13
|
action mark {parser.mark = fpc; }
|
|
14
14
|
|
|
@@ -60,7 +60,7 @@ public class Http11Parser {
|
|
|
60
60
|
fbreak;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
include
|
|
63
|
+
include puma_parser_common "http11_parser_common.rl";
|
|
64
64
|
|
|
65
65
|
}%%
|
|
66
66
|
|
|
@@ -152,10 +152,10 @@ public class Http11Parser {
|
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
public boolean has_error() {
|
|
155
|
-
return parser.cs ==
|
|
155
|
+
return parser.cs == puma_parser_error;
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
public boolean is_finished() {
|
|
159
|
-
return parser.cs ==
|
|
159
|
+
return parser.cs == puma_parser_first_final;
|
|
160
160
|
}
|
|
161
161
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright (c) 2005 Zed A. Shaw
|
|
3
3
|
* You can redistribute it and/or modify it under the same terms as Ruby.
|
|
4
|
+
* License 3-clause BSD
|
|
4
5
|
*/
|
|
5
6
|
#include "http11_parser.h"
|
|
6
7
|
#include <stdio.h>
|
|
@@ -28,7 +29,7 @@ static void snake_upcase_char(char *c)
|
|
|
28
29
|
/** Machine **/
|
|
29
30
|
|
|
30
31
|
%%{
|
|
31
|
-
|
|
32
|
+
|
|
32
33
|
machine puma_parser;
|
|
33
34
|
|
|
34
35
|
action mark { MARK(mark, fpc); }
|
|
@@ -36,7 +37,7 @@ static void snake_upcase_char(char *c)
|
|
|
36
37
|
|
|
37
38
|
action start_field { MARK(field_start, fpc); }
|
|
38
39
|
action snake_upcase_field { snake_upcase_char((char *)fpc); }
|
|
39
|
-
action write_field {
|
|
40
|
+
action write_field {
|
|
40
41
|
parser->field_len = LEN(field_start, fpc);
|
|
41
42
|
}
|
|
42
43
|
|
|
@@ -44,10 +45,10 @@ static void snake_upcase_char(char *c)
|
|
|
44
45
|
action write_value {
|
|
45
46
|
parser->http_field(parser, PTR_TO(field_start), parser->field_len, PTR_TO(mark), LEN(mark, fpc));
|
|
46
47
|
}
|
|
47
|
-
action request_method {
|
|
48
|
+
action request_method {
|
|
48
49
|
parser->request_method(parser, PTR_TO(mark), LEN(mark, fpc));
|
|
49
50
|
}
|
|
50
|
-
action request_uri {
|
|
51
|
+
action request_uri {
|
|
51
52
|
parser->request_uri(parser, PTR_TO(mark), LEN(mark, fpc));
|
|
52
53
|
}
|
|
53
54
|
action fragment {
|
|
@@ -55,11 +56,11 @@ static void snake_upcase_char(char *c)
|
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
action start_query { MARK(query_start, fpc); }
|
|
58
|
-
action query_string {
|
|
59
|
+
action query_string {
|
|
59
60
|
parser->query_string(parser, PTR_TO(query_start), LEN(query_start, fpc));
|
|
60
61
|
}
|
|
61
62
|
|
|
62
|
-
action http_version {
|
|
63
|
+
action http_version {
|
|
63
64
|
parser->http_version(parser, PTR_TO(mark), LEN(mark, fpc));
|
|
64
65
|
}
|
|
65
66
|
|
|
@@ -67,8 +68,8 @@ static void snake_upcase_char(char *c)
|
|
|
67
68
|
parser->request_path(parser, PTR_TO(mark), LEN(mark,fpc));
|
|
68
69
|
}
|
|
69
70
|
|
|
70
|
-
action done {
|
|
71
|
-
parser->body_start = fpc - buffer + 1;
|
|
71
|
+
action done {
|
|
72
|
+
parser->body_start = fpc - buffer + 1;
|
|
72
73
|
parser->header_done(parser, fpc + 1, pe - fpc - 1);
|
|
73
74
|
fbreak;
|
|
74
75
|
}
|
|
@@ -108,7 +109,7 @@ size_t puma_parser_execute(puma_parser *parser, const char *buffer, size_t len,
|
|
|
108
109
|
pe = buffer+len;
|
|
109
110
|
|
|
110
111
|
/* assert(*pe == '\0' && "pointer does not end on NUL"); */
|
|
111
|
-
assert(pe - p == len - off && "pointers aren't same distance");
|
|
112
|
+
assert((size_t) (pe - p) == len - off && "pointers aren't same distance");
|
|
112
113
|
|
|
113
114
|
%% write exec;
|
|
114
115
|
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
national = any -- (alpha | digit | reserved | extra | safe | unsafe);
|
|
16
16
|
unreserved = (alpha | digit | safe | extra | national);
|
|
17
17
|
escape = ("%" xdigit xdigit);
|
|
18
|
-
uchar = (unreserved | escape);
|
|
18
|
+
uchar = (unreserved | escape | "%");
|
|
19
19
|
pchar = (uchar | ":" | "@" | "&" | "=" | "+");
|
|
20
20
|
tspecials = ("(" | ")" | "<" | ">" | "@" | "," | ";" | ":" | "\\" | "\"" | "/" | "[" | "]" | "?" | "=" | "{" | "}" | " " | "\t");
|
|
21
21
|
|
data/ext/puma_http11/io_buffer.c
CHANGED
|
@@ -14,8 +14,8 @@ struct buf_int {
|
|
|
14
14
|
#define BUF_TOLERANCE 32
|
|
15
15
|
|
|
16
16
|
static void buf_free(struct buf_int* internal) {
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
xfree(internal->top);
|
|
18
|
+
xfree(internal);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
static VALUE buf_alloc(VALUE self) {
|
|
@@ -25,7 +25,7 @@ static VALUE buf_alloc(VALUE self) {
|
|
|
25
25
|
buf = Data_Make_Struct(self, struct buf_int, 0, buf_free, internal);
|
|
26
26
|
|
|
27
27
|
internal->size = BUF_DEFAULT_SIZE;
|
|
28
|
-
internal->top =
|
|
28
|
+
internal->top = ALLOC_N(uint8_t, BUF_DEFAULT_SIZE);
|
|
29
29
|
internal->cur = internal->top;
|
|
30
30
|
|
|
31
31
|
return buf;
|
|
@@ -51,13 +51,13 @@ static VALUE buf_append(VALUE self, VALUE str) {
|
|
|
51
51
|
|
|
52
52
|
new_size = (n > new_size ? n : new_size + BUF_TOLERANCE);
|
|
53
53
|
|
|
54
|
-
top =
|
|
54
|
+
top = ALLOC_N(uint8_t, new_size);
|
|
55
55
|
old = b->top;
|
|
56
56
|
memcpy(top, old, used);
|
|
57
57
|
b->top = top;
|
|
58
58
|
b->cur = top + used;
|
|
59
59
|
b->size = new_size;
|
|
60
|
-
|
|
60
|
+
xfree(old);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
memcpy(b->cur, RSTRING_PTR(str), str_len);
|
|
@@ -92,13 +92,13 @@ static VALUE buf_append2(int argc, VALUE* argv, VALUE self) {
|
|
|
92
92
|
|
|
93
93
|
new_size = (n > new_size ? n : new_size + BUF_TOLERANCE);
|
|
94
94
|
|
|
95
|
-
top =
|
|
95
|
+
top = ALLOC_N(uint8_t, new_size);
|
|
96
96
|
old = b->top;
|
|
97
97
|
memcpy(top, old, used);
|
|
98
98
|
b->top = top;
|
|
99
99
|
b->cur = top + used;
|
|
100
100
|
b->size = new_size;
|
|
101
|
-
|
|
101
|
+
xfree(old);
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
for(i = 0; i < argc; i++) {
|
|
@@ -116,7 +116,7 @@ static VALUE buf_to_str(VALUE self) {
|
|
|
116
116
|
struct buf_int* b;
|
|
117
117
|
Data_Get_Struct(self, struct buf_int, b);
|
|
118
118
|
|
|
119
|
-
return rb_str_new(b->top, b->cur - b->top);
|
|
119
|
+
return rb_str_new((const char*)(b->top), b->cur - b->top);
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
static VALUE buf_used(VALUE self) {
|
data/ext/puma_http11/mini_ssl.c
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
#define RSTRING_NOT_MODIFIED 1
|
|
2
2
|
|
|
3
3
|
#include <ruby.h>
|
|
4
|
+
#include <ruby/version.h>
|
|
5
|
+
|
|
6
|
+
#if RUBY_API_VERSION_MAJOR == 1
|
|
4
7
|
#include <rubyio.h>
|
|
8
|
+
#else
|
|
9
|
+
#include <ruby/io.h>
|
|
10
|
+
#endif
|
|
5
11
|
|
|
6
12
|
#ifdef HAVE_OPENSSL_BIO_H
|
|
7
13
|
|
|
@@ -81,6 +87,8 @@ DH *get_dh1024() {
|
|
|
81
87
|
|
|
82
88
|
DH *dh;
|
|
83
89
|
dh = DH_new();
|
|
90
|
+
|
|
91
|
+
#if OPENSSL_VERSION_NUMBER < 0x10100005L || defined(LIBRESSL_VERSION_NUMBER)
|
|
84
92
|
dh->p = BN_bin2bn(dh1024_p, sizeof(dh1024_p), NULL);
|
|
85
93
|
dh->g = BN_bin2bn(dh1024_g, sizeof(dh1024_g), NULL);
|
|
86
94
|
|
|
@@ -88,6 +96,18 @@ DH *get_dh1024() {
|
|
|
88
96
|
DH_free(dh);
|
|
89
97
|
return NULL;
|
|
90
98
|
}
|
|
99
|
+
#else
|
|
100
|
+
BIGNUM *p, *g;
|
|
101
|
+
p = BN_bin2bn(dh1024_p, sizeof(dh1024_p), NULL);
|
|
102
|
+
g = BN_bin2bn(dh1024_g, sizeof(dh1024_g), NULL);
|
|
103
|
+
|
|
104
|
+
if (p == NULL || g == NULL || !DH_set0_pqg(dh, p, NULL, g)) {
|
|
105
|
+
DH_free(dh);
|
|
106
|
+
BN_free(p);
|
|
107
|
+
BN_free(g);
|
|
108
|
+
return NULL;
|
|
109
|
+
}
|
|
110
|
+
#endif
|
|
91
111
|
|
|
92
112
|
return dh;
|
|
93
113
|
}
|
|
@@ -128,9 +148,13 @@ VALUE engine_init_server(VALUE self, VALUE mini_ssl_ctx) {
|
|
|
128
148
|
ID sym_key = rb_intern("key");
|
|
129
149
|
VALUE key = rb_funcall(mini_ssl_ctx, sym_key, 0);
|
|
130
150
|
|
|
151
|
+
StringValue(key);
|
|
152
|
+
|
|
131
153
|
ID sym_cert = rb_intern("cert");
|
|
132
154
|
VALUE cert = rb_funcall(mini_ssl_ctx, sym_cert, 0);
|
|
133
155
|
|
|
156
|
+
StringValue(cert);
|
|
157
|
+
|
|
134
158
|
ID sym_ca = rb_intern("ca");
|
|
135
159
|
VALUE ca = rb_funcall(mini_ssl_ctx, sym_ca, 0);
|
|
136
160
|
|
|
@@ -144,9 +168,10 @@ VALUE engine_init_server(VALUE self, VALUE mini_ssl_ctx) {
|
|
|
144
168
|
SSL_CTX_use_PrivateKey_file(ctx, RSTRING_PTR(key), SSL_FILETYPE_PEM);
|
|
145
169
|
|
|
146
170
|
if (!NIL_P(ca)) {
|
|
171
|
+
StringValue(ca);
|
|
147
172
|
SSL_CTX_load_verify_locations(ctx, RSTRING_PTR(ca), NULL);
|
|
148
173
|
}
|
|
149
|
-
|
|
174
|
+
|
|
150
175
|
SSL_CTX_set_options(ctx, SSL_OP_CIPHER_SERVER_PREFERENCE | SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 | SSL_OP_SINGLE_DH_USE | SSL_OP_SINGLE_ECDH_USE | SSL_OP_NO_COMPRESSION);
|
|
151
176
|
SSL_CTX_set_session_cache_mode(ctx, SSL_SESS_CACHE_OFF);
|
|
152
177
|
|
|
@@ -219,7 +244,7 @@ void raise_error(SSL* ssl, int result) {
|
|
|
219
244
|
const char* err_str;
|
|
220
245
|
int err = errno;
|
|
221
246
|
int ssl_err = SSL_get_error(ssl, result);
|
|
222
|
-
int verify_err = SSL_get_verify_result(ssl);
|
|
247
|
+
int verify_err = (int) SSL_get_verify_result(ssl);
|
|
223
248
|
|
|
224
249
|
if(SSL_ERROR_SYSCALL == ssl_err) {
|
|
225
250
|
snprintf(msg, sizeof(msg), "System error: %s - %d", strerror(err), err);
|
|
@@ -232,7 +257,7 @@ void raise_error(SSL* ssl, int result) {
|
|
|
232
257
|
err_str, verify_err);
|
|
233
258
|
|
|
234
259
|
} else {
|
|
235
|
-
err = ERR_get_error();
|
|
260
|
+
err = (int) ERR_get_error();
|
|
236
261
|
ERR_error_string_n(err, buf, sizeof(buf));
|
|
237
262
|
snprintf(msg, sizeof(msg), "OpenSSL error: %s - %d", buf, err);
|
|
238
263
|
|
|
@@ -316,6 +341,30 @@ VALUE engine_extract(VALUE self) {
|
|
|
316
341
|
return Qnil;
|
|
317
342
|
}
|
|
318
343
|
|
|
344
|
+
VALUE engine_shutdown(VALUE self) {
|
|
345
|
+
ms_conn* conn;
|
|
346
|
+
int ok;
|
|
347
|
+
|
|
348
|
+
Data_Get_Struct(self, ms_conn, conn);
|
|
349
|
+
|
|
350
|
+
ERR_clear_error();
|
|
351
|
+
|
|
352
|
+
ok = SSL_shutdown(conn->ssl);
|
|
353
|
+
if (ok == 0) {
|
|
354
|
+
return Qfalse;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
return Qtrue;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
VALUE engine_init(VALUE self) {
|
|
361
|
+
ms_conn* conn;
|
|
362
|
+
|
|
363
|
+
Data_Get_Struct(self, ms_conn, conn);
|
|
364
|
+
|
|
365
|
+
return SSL_in_init(conn->ssl) ? Qtrue : Qfalse;
|
|
366
|
+
}
|
|
367
|
+
|
|
319
368
|
VALUE engine_peercert(VALUE self) {
|
|
320
369
|
ms_conn* conn;
|
|
321
370
|
X509* cert;
|
|
@@ -347,7 +396,7 @@ VALUE engine_peercert(VALUE self) {
|
|
|
347
396
|
}
|
|
348
397
|
}
|
|
349
398
|
|
|
350
|
-
rb_cert_buf = rb_str_new(buf, bytes);
|
|
399
|
+
rb_cert_buf = rb_str_new((const char*)(buf), bytes);
|
|
351
400
|
if(!cert_buf) {
|
|
352
401
|
OPENSSL_free(buf);
|
|
353
402
|
}
|
|
@@ -362,11 +411,16 @@ VALUE noop(VALUE self) {
|
|
|
362
411
|
void Init_mini_ssl(VALUE puma) {
|
|
363
412
|
VALUE mod, eng;
|
|
364
413
|
|
|
414
|
+
/* Fake operation for documentation (RDoc, YARD) */
|
|
415
|
+
#if 0 == 1
|
|
416
|
+
puma = rb_define_module("Puma");
|
|
417
|
+
#endif
|
|
418
|
+
|
|
365
419
|
SSL_library_init();
|
|
366
420
|
OpenSSL_add_ssl_algorithms();
|
|
367
421
|
SSL_load_error_strings();
|
|
368
422
|
ERR_load_crypto_strings();
|
|
369
|
-
|
|
423
|
+
|
|
370
424
|
mod = rb_define_module_under(puma, "MiniSSL");
|
|
371
425
|
eng = rb_define_class_under(mod, "Engine", rb_cObject);
|
|
372
426
|
|
|
@@ -383,6 +437,10 @@ void Init_mini_ssl(VALUE puma) {
|
|
|
383
437
|
rb_define_method(eng, "write", engine_write, 1);
|
|
384
438
|
rb_define_method(eng, "extract", engine_extract, 0);
|
|
385
439
|
|
|
440
|
+
rb_define_method(eng, "shutdown", engine_shutdown, 0);
|
|
441
|
+
|
|
442
|
+
rb_define_method(eng, "init?", engine_init, 0);
|
|
443
|
+
|
|
386
444
|
rb_define_method(eng, "peercert", engine_peercert, 0);
|
|
387
445
|
}
|
|
388
446
|
|
|
@@ -394,7 +452,7 @@ VALUE raise_error(VALUE self) {
|
|
|
394
452
|
}
|
|
395
453
|
|
|
396
454
|
void Init_mini_ssl(VALUE puma) {
|
|
397
|
-
VALUE mod
|
|
455
|
+
VALUE mod;
|
|
398
456
|
|
|
399
457
|
mod = rb_define_module_under(puma, "MiniSSL");
|
|
400
458
|
rb_define_class_under(mod, "SSLError", rb_eStandardError);
|