puma 3.11.4 → 4.2.0

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

Potentially problematic release.


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

Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +130 -1
  3. data/README.md +100 -44
  4. data/docs/architecture.md +1 -0
  5. data/docs/deployment.md +24 -4
  6. data/docs/restart.md +4 -2
  7. data/docs/systemd.md +27 -9
  8. data/ext/puma_http11/PumaHttp11Service.java +2 -0
  9. data/ext/puma_http11/extconf.rb +8 -0
  10. data/ext/puma_http11/http11_parser.c +37 -62
  11. data/ext/puma_http11/http11_parser_common.rl +3 -3
  12. data/ext/puma_http11/mini_ssl.c +96 -5
  13. data/ext/puma_http11/org/jruby/puma/IOBuffer.java +72 -0
  14. data/ext/puma_http11/org/jruby/puma/MiniSSL.java +21 -4
  15. data/lib/puma/accept_nonblock.rb +7 -1
  16. data/lib/puma/app/status.rb +35 -29
  17. data/lib/puma/binder.rb +47 -11
  18. data/lib/puma/cli.rb +21 -7
  19. data/lib/puma/client.rb +227 -191
  20. data/lib/puma/cluster.rb +70 -31
  21. data/lib/puma/commonlogger.rb +2 -0
  22. data/lib/puma/configuration.rb +6 -3
  23. data/lib/puma/const.rb +24 -18
  24. data/lib/puma/control_cli.rb +33 -14
  25. data/lib/puma/convenient.rb +2 -0
  26. data/lib/puma/delegation.rb +2 -0
  27. data/lib/puma/detect.rb +2 -0
  28. data/lib/puma/dsl.rb +308 -76
  29. data/lib/puma/events.rb +6 -1
  30. data/lib/puma/io_buffer.rb +3 -6
  31. data/lib/puma/jruby_restart.rb +2 -0
  32. data/lib/puma/launcher.rb +102 -55
  33. data/lib/puma/minissl.rb +41 -19
  34. data/lib/puma/null_io.rb +2 -0
  35. data/lib/puma/plugin/tmp_restart.rb +2 -0
  36. data/lib/puma/plugin.rb +7 -2
  37. data/lib/puma/rack/builder.rb +4 -1
  38. data/lib/puma/rack/urlmap.rb +2 -0
  39. data/lib/puma/rack_default.rb +2 -0
  40. data/lib/puma/reactor.rb +220 -34
  41. data/lib/puma/runner.rb +14 -4
  42. data/lib/puma/server.rb +82 -40
  43. data/lib/puma/single.rb +15 -3
  44. data/lib/puma/state_file.rb +2 -0
  45. data/lib/puma/tcp_logger.rb +2 -0
  46. data/lib/puma/thread_pool.rb +59 -36
  47. data/lib/puma/util.rb +2 -6
  48. data/lib/puma.rb +8 -0
  49. data/lib/rack/handler/puma.rb +6 -3
  50. data/tools/docker/Dockerfile +16 -0
  51. data/tools/jungle/init.d/puma +6 -6
  52. data/tools/trickletest.rb +0 -1
  53. metadata +22 -10
  54. data/lib/puma/compat.rb +0 -14
  55. data/lib/puma/daemon_ext.rb +0 -31
  56. data/lib/puma/java_io_buffer.rb +0 -45
  57. data/lib/puma/rack/backports/uri/common_193.rb +0 -33
@@ -38,7 +38,7 @@ static void snake_upcase_char(char *c)
38
38
 
39
39
  #line 40 "ext/puma_http11/http11_parser.c"
40
40
  static const int puma_parser_start = 1;
41
- static const int puma_parser_first_final = 47;
41
+ static const int puma_parser_first_final = 46;
42
42
  static const int puma_parser_error = 0;
43
43
 
44
44
  static const int puma_parser_en_main = 1;
@@ -117,17 +117,17 @@ case 2:
117
117
  #line 118 "ext/puma_http11/http11_parser.c"
118
118
  switch( (*p) ) {
119
119
  case 32: goto tr2;
120
- case 36: goto st28;
121
- case 95: goto st28;
120
+ case 36: goto st27;
121
+ case 95: goto st27;
122
122
  }
123
123
  if ( (*p) < 48 ) {
124
124
  if ( 45 <= (*p) && (*p) <= 46 )
125
- goto st28;
125
+ goto st27;
126
126
  } else if ( (*p) > 57 ) {
127
127
  if ( 65 <= (*p) && (*p) <= 90 )
128
- goto st28;
128
+ goto st27;
129
129
  } else
130
- goto st28;
130
+ goto st27;
131
131
  goto st0;
132
132
  tr2:
133
133
  #line 48 "ext/puma_http11/http11_parser.rl"
@@ -199,7 +199,7 @@ tr37:
199
199
  parser->request_uri(parser, PTR_TO(mark), LEN(mark, p));
200
200
  }
201
201
  goto st5;
202
- tr44:
202
+ tr41:
203
203
  #line 58 "ext/puma_http11/http11_parser.rl"
204
204
  { MARK(query_start, p); }
205
205
  #line 59 "ext/puma_http11/http11_parser.rl"
@@ -211,7 +211,7 @@ tr44:
211
211
  parser->request_uri(parser, PTR_TO(mark), LEN(mark, p));
212
212
  }
213
213
  goto st5;
214
- tr47:
214
+ tr44:
215
215
  #line 59 "ext/puma_http11/http11_parser.rl"
216
216
  {
217
217
  parser->query_string(parser, PTR_TO(query_start), LEN(query_start, p));
@@ -362,13 +362,13 @@ tr22:
362
362
  {
363
363
  parser->body_start = p - buffer + 1;
364
364
  parser->header_done(parser, p + 1, pe - p - 1);
365
- {p++; cs = 47; goto _out;}
365
+ {p++; cs = 46; goto _out;}
366
366
  }
367
- goto st47;
368
- st47:
367
+ goto st46;
368
+ st46:
369
369
  if ( ++p == pe )
370
- goto _test_eof47;
371
- case 47:
370
+ goto _test_eof46;
371
+ case 46:
372
372
  #line 373 "ext/puma_http11/http11_parser.c"
373
373
  goto st0;
374
374
  tr21:
@@ -458,7 +458,7 @@ tr38:
458
458
  parser->request_uri(parser, PTR_TO(mark), LEN(mark, p));
459
459
  }
460
460
  goto st20;
461
- tr45:
461
+ tr42:
462
462
  #line 58 "ext/puma_http11/http11_parser.rl"
463
463
  { MARK(query_start, p); }
464
464
  #line 59 "ext/puma_http11/http11_parser.rl"
@@ -470,7 +470,7 @@ tr45:
470
470
  parser->request_uri(parser, PTR_TO(mark), LEN(mark, p));
471
471
  }
472
472
  goto st20;
473
- tr48:
473
+ tr45:
474
474
  #line 59 "ext/puma_http11/http11_parser.rl"
475
475
  {
476
476
  parser->query_string(parser, PTR_TO(query_start), LEN(query_start, p));
@@ -576,10 +576,9 @@ case 24:
576
576
  case 32: goto tr37;
577
577
  case 34: goto st0;
578
578
  case 35: goto tr38;
579
- case 59: goto tr39;
580
579
  case 60: goto st0;
581
580
  case 62: goto st0;
582
- case 63: goto tr40;
581
+ case 63: goto tr39;
583
582
  case 127: goto st0;
584
583
  }
585
584
  if ( 0 <= (*p) && (*p) <= 31 )
@@ -595,30 +594,27 @@ st25:
595
594
  if ( ++p == pe )
596
595
  goto _test_eof25;
597
596
  case 25:
598
- #line 599 "ext/puma_http11/http11_parser.c"
597
+ #line 598 "ext/puma_http11/http11_parser.c"
599
598
  switch( (*p) ) {
600
- case 32: goto tr8;
599
+ case 32: goto tr41;
601
600
  case 34: goto st0;
602
- case 35: goto tr9;
601
+ case 35: goto tr42;
603
602
  case 60: goto st0;
604
603
  case 62: goto st0;
605
- case 63: goto st26;
606
604
  case 127: goto st0;
607
605
  }
608
606
  if ( 0 <= (*p) && (*p) <= 31 )
609
607
  goto st0;
610
- goto st25;
608
+ goto tr40;
611
609
  tr40:
612
- #line 67 "ext/puma_http11/http11_parser.rl"
613
- {
614
- parser->request_path(parser, PTR_TO(mark), LEN(mark,p));
615
- }
610
+ #line 58 "ext/puma_http11/http11_parser.rl"
611
+ { MARK(query_start, p); }
616
612
  goto st26;
617
613
  st26:
618
614
  if ( ++p == pe )
619
615
  goto _test_eof26;
620
616
  case 26:
621
- #line 622 "ext/puma_http11/http11_parser.c"
617
+ #line 618 "ext/puma_http11/http11_parser.c"
622
618
  switch( (*p) ) {
623
619
  case 32: goto tr44;
624
620
  case 34: goto st0;
@@ -629,27 +625,25 @@ case 26:
629
625
  }
630
626
  if ( 0 <= (*p) && (*p) <= 31 )
631
627
  goto st0;
632
- goto tr43;
633
- tr43:
634
- #line 58 "ext/puma_http11/http11_parser.rl"
635
- { MARK(query_start, p); }
636
- goto st27;
628
+ goto st26;
637
629
  st27:
638
630
  if ( ++p == pe )
639
631
  goto _test_eof27;
640
632
  case 27:
641
- #line 642 "ext/puma_http11/http11_parser.c"
642
633
  switch( (*p) ) {
643
- case 32: goto tr47;
644
- case 34: goto st0;
645
- case 35: goto tr48;
646
- case 60: goto st0;
647
- case 62: goto st0;
648
- case 127: goto st0;
634
+ case 32: goto tr2;
635
+ case 36: goto st28;
636
+ case 95: goto st28;
649
637
  }
650
- if ( 0 <= (*p) && (*p) <= 31 )
651
- goto st0;
652
- goto st27;
638
+ if ( (*p) < 48 ) {
639
+ if ( 45 <= (*p) && (*p) <= 46 )
640
+ goto st28;
641
+ } else if ( (*p) > 57 ) {
642
+ if ( 65 <= (*p) && (*p) <= 90 )
643
+ goto st28;
644
+ } else
645
+ goto st28;
646
+ goto st0;
653
647
  st28:
654
648
  if ( ++p == pe )
655
649
  goto _test_eof28;
@@ -960,24 +954,6 @@ st45:
960
954
  if ( ++p == pe )
961
955
  goto _test_eof45;
962
956
  case 45:
963
- switch( (*p) ) {
964
- case 32: goto tr2;
965
- case 36: goto st46;
966
- case 95: goto st46;
967
- }
968
- if ( (*p) < 48 ) {
969
- if ( 45 <= (*p) && (*p) <= 46 )
970
- goto st46;
971
- } else if ( (*p) > 57 ) {
972
- if ( 65 <= (*p) && (*p) <= 90 )
973
- goto st46;
974
- } else
975
- goto st46;
976
- goto st0;
977
- st46:
978
- if ( ++p == pe )
979
- goto _test_eof46;
980
- case 46:
981
957
  if ( (*p) == 32 )
982
958
  goto tr2;
983
959
  goto st0;
@@ -997,7 +973,7 @@ case 46:
997
973
  _test_eof14: cs = 14; goto _test_eof;
998
974
  _test_eof15: cs = 15; goto _test_eof;
999
975
  _test_eof16: cs = 16; goto _test_eof;
1000
- _test_eof47: cs = 47; goto _test_eof;
976
+ _test_eof46: cs = 46; goto _test_eof;
1001
977
  _test_eof17: cs = 17; goto _test_eof;
1002
978
  _test_eof18: cs = 18; goto _test_eof;
1003
979
  _test_eof19: cs = 19; goto _test_eof;
@@ -1027,7 +1003,6 @@ case 46:
1027
1003
  _test_eof43: cs = 43; goto _test_eof;
1028
1004
  _test_eof44: cs = 44; goto _test_eof;
1029
1005
  _test_eof45: cs = 45; goto _test_eof;
1030
- _test_eof46: cs = 46; goto _test_eof;
1031
1006
 
1032
1007
  _test_eof: {}
1033
1008
  _out: {}
@@ -1,5 +1,5 @@
1
1
  %%{
2
-
2
+
3
3
  machine puma_parser_common;
4
4
 
5
5
  #### HTTP PROTOCOL GRAMMAR
@@ -16,7 +16,7 @@
16
16
  unreserved = (alpha | digit | safe | extra | national);
17
17
  escape = ("%" xdigit xdigit);
18
18
  uchar = (unreserved | escape | "%");
19
- pchar = (uchar | ":" | "@" | "&" | "=" | "+");
19
+ pchar = (uchar | ":" | "@" | "&" | "=" | "+" | ";");
20
20
  tspecials = ("(" | ")" | "<" | ">" | "@" | "," | ";" | ":" | "\\" | "\"" | "/" | "[" | "]" | "?" | "=" | "{" | "}" | " " | "\t");
21
21
 
22
22
  # elements
@@ -30,7 +30,7 @@
30
30
  query = ( uchar | reserved )* %query_string ;
31
31
  param = ( pchar | "/" )* ;
32
32
  params = ( param ( ";" param )* ) ;
33
- rel_path = ( path? %request_path (";" params)? ) ("?" %start_query query)?;
33
+ rel_path = ( path? %request_path ) ("?" %start_query query)?;
34
34
  absolute_path = ( "/"+ rel_path );
35
35
 
36
36
  Request_URI = ( "*" | absolute_uri | absolute_path ) >mark %request_uri;
@@ -142,6 +142,7 @@ VALUE engine_init_server(VALUE self, VALUE mini_ssl_ctx) {
142
142
  VALUE obj;
143
143
  SSL_CTX* ctx;
144
144
  SSL* ssl;
145
+ int min, ssl_options;
145
146
 
146
147
  ms_conn* conn = engine_alloc(self, &obj);
147
148
 
@@ -161,7 +162,20 @@ VALUE engine_init_server(VALUE self, VALUE mini_ssl_ctx) {
161
162
  ID sym_verify_mode = rb_intern("verify_mode");
162
163
  VALUE verify_mode = rb_funcall(mini_ssl_ctx, sym_verify_mode, 0);
163
164
 
165
+ ID sym_ssl_cipher_filter = rb_intern("ssl_cipher_filter");
166
+ VALUE ssl_cipher_filter = rb_funcall(mini_ssl_ctx, sym_ssl_cipher_filter, 0);
167
+
168
+ ID sym_no_tlsv1 = rb_intern("no_tlsv1");
169
+ VALUE no_tlsv1 = rb_funcall(mini_ssl_ctx, sym_no_tlsv1, 0);
170
+
171
+ ID sym_no_tlsv1_1 = rb_intern("no_tlsv1_1");
172
+ VALUE no_tlsv1_1 = rb_funcall(mini_ssl_ctx, sym_no_tlsv1_1, 0);
173
+
174
+ #ifdef HAVE_TLS_SERVER_METHOD
175
+ ctx = SSL_CTX_new(TLS_server_method());
176
+ #else
164
177
  ctx = SSL_CTX_new(SSLv23_server_method());
178
+ #endif
165
179
  conn->ctx = ctx;
166
180
 
167
181
  SSL_CTX_use_certificate_chain_file(ctx, RSTRING_PTR(cert));
@@ -172,20 +186,61 @@ VALUE engine_init_server(VALUE self, VALUE mini_ssl_ctx) {
172
186
  SSL_CTX_load_verify_locations(ctx, RSTRING_PTR(ca), NULL);
173
187
  }
174
188
 
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);
189
+ ssl_options = SSL_OP_CIPHER_SERVER_PREFERENCE | SSL_OP_SINGLE_ECDH_USE | SSL_OP_NO_COMPRESSION;
190
+
191
+ #ifdef HAVE_SSL_CTX_SET_MIN_PROTO_VERSION
192
+ if (RTEST(no_tlsv1_1)) {
193
+ min = TLS1_2_VERSION;
194
+ }
195
+ else if (RTEST(no_tlsv1)) {
196
+ min = TLS1_1_VERSION;
197
+ }
198
+ else {
199
+ min = TLS1_VERSION;
200
+ }
201
+
202
+ SSL_CTX_set_min_proto_version(ctx, min);
203
+
204
+ SSL_CTX_set_options(ctx, ssl_options);
205
+
206
+ #else
207
+ /* As of 1.0.2f, SSL_OP_SINGLE_DH_USE key use is always on */
208
+ ssl_options |= SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 | SSL_OP_SINGLE_DH_USE;
209
+
210
+ if (RTEST(no_tlsv1)) {
211
+ ssl_options |= SSL_OP_NO_TLSv1;
212
+ }
213
+ if(RTEST(no_tlsv1_1)) {
214
+ ssl_options |= SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1;
215
+ }
216
+ SSL_CTX_set_options(ctx, ssl_options);
217
+ #endif
218
+
176
219
  SSL_CTX_set_session_cache_mode(ctx, SSL_SESS_CACHE_OFF);
177
220
 
178
- SSL_CTX_set_cipher_list(ctx, "HIGH:!aNULL@STRENGTH");
221
+ if (!NIL_P(ssl_cipher_filter)) {
222
+ StringValue(ssl_cipher_filter);
223
+ SSL_CTX_set_cipher_list(ctx, RSTRING_PTR(ssl_cipher_filter));
224
+ }
225
+ else {
226
+ SSL_CTX_set_cipher_list(ctx, "HIGH:!aNULL@STRENGTH");
227
+ }
179
228
 
180
229
  DH *dh = get_dh1024();
181
230
  SSL_CTX_set_tmp_dh(ctx, dh);
182
231
 
183
- #ifndef OPENSSL_NO_ECDH
184
- EC_KEY *ecdh = EC_KEY_new_by_curve_name(NID_secp521r1);
232
+ #if OPENSSL_VERSION_NUMBER < 0x10002000L
233
+ // Remove this case if OpenSSL 1.0.1 (now EOL) support is no
234
+ // longer needed.
235
+ EC_KEY *ecdh = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
185
236
  if (ecdh) {
186
237
  SSL_CTX_set_tmp_ecdh(ctx, ecdh);
187
238
  EC_KEY_free(ecdh);
188
239
  }
240
+ #elif OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
241
+ // Prior to OpenSSL 1.1.0, servers must manually enable server-side ECDH
242
+ // negotiation.
243
+ SSL_CTX_set_ecdh_auto(ctx, 1);
189
244
  #endif
190
245
 
191
246
  ssl = SSL_new(ctx);
@@ -207,8 +262,11 @@ VALUE engine_init_server(VALUE self, VALUE mini_ssl_ctx) {
207
262
  VALUE engine_init_client(VALUE klass) {
208
263
  VALUE obj;
209
264
  ms_conn* conn = engine_alloc(klass, &obj);
210
-
265
+ #ifdef HAVE_DTLS_METHOD
266
+ conn->ctx = SSL_CTX_new(DTLS_method());
267
+ #else
211
268
  conn->ctx = SSL_CTX_new(DTLSv1_method());
269
+ #endif
212
270
  conn->ssl = SSL_new(conn->ctx);
213
271
  SSL_set_app_data(conn->ssl, NULL);
214
272
  SSL_set_verify(conn->ssl, SSL_VERIFY_NONE, NULL);
@@ -424,6 +482,39 @@ void Init_mini_ssl(VALUE puma) {
424
482
  mod = rb_define_module_under(puma, "MiniSSL");
425
483
  eng = rb_define_class_under(mod, "Engine", rb_cObject);
426
484
 
485
+ // OpenSSL Build / Runtime/Load versions
486
+
487
+ /* Version of OpenSSL that Puma was compiled with */
488
+ rb_define_const(mod, "OPENSSL_VERSION", rb_str_new2(OPENSSL_VERSION_TEXT));
489
+
490
+ #if !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000
491
+ /* Version of OpenSSL that Puma loaded with */
492
+ rb_define_const(mod, "OPENSSL_LIBRARY_VERSION", rb_str_new2(OpenSSL_version(OPENSSL_VERSION)));
493
+ #else
494
+ rb_define_const(mod, "OPENSSL_LIBRARY_VERSION", rb_str_new2(SSLeay_version(SSLEAY_VERSION)));
495
+ #endif
496
+
497
+ #if defined(OPENSSL_NO_SSL3) || defined(OPENSSL_NO_SSL3_METHOD)
498
+ /* True if SSL3 is not available */
499
+ rb_define_const(mod, "OPENSSL_NO_SSL3", Qtrue);
500
+ #else
501
+ rb_define_const(mod, "OPENSSL_NO_SSL3", Qfalse);
502
+ #endif
503
+
504
+ #if defined(OPENSSL_NO_TLS1) || defined(OPENSSL_NO_TLS1_METHOD)
505
+ /* True if TLS1 is not available */
506
+ rb_define_const(mod, "OPENSSL_NO_TLS1", Qtrue);
507
+ #else
508
+ rb_define_const(mod, "OPENSSL_NO_TLS1", Qfalse);
509
+ #endif
510
+
511
+ #if defined(OPENSSL_NO_TLS1_1) || defined(OPENSSL_NO_TLS1_1_METHOD)
512
+ /* True if TLS1_1 is not available */
513
+ rb_define_const(mod, "OPENSSL_NO_TLS1_1", Qtrue);
514
+ #else
515
+ rb_define_const(mod, "OPENSSL_NO_TLS1_1", Qfalse);
516
+ #endif
517
+
427
518
  rb_define_singleton_method(mod, "check", noop, 0);
428
519
 
429
520
  eError = rb_define_class_under(mod, "SSLError", rb_eStandardError);
@@ -0,0 +1,72 @@
1
+ package org.jruby.puma;
2
+
3
+ import org.jruby.*;
4
+ import org.jruby.anno.JRubyMethod;
5
+ import org.jruby.runtime.ObjectAllocator;
6
+ import org.jruby.runtime.ThreadContext;
7
+ import org.jruby.runtime.builtin.IRubyObject;
8
+ import org.jruby.util.ByteList;
9
+
10
+ /**
11
+ * @author kares
12
+ */
13
+ public class IOBuffer extends RubyObject {
14
+
15
+ private static final ObjectAllocator ALLOCATOR = new ObjectAllocator() {
16
+ public IRubyObject allocate(Ruby runtime, RubyClass klass) {
17
+ return new IOBuffer(runtime, klass);
18
+ }
19
+ };
20
+
21
+ public static void createIOBuffer(Ruby runtime) {
22
+ RubyModule mPuma = runtime.defineModule("Puma");
23
+ RubyClass cIOBuffer = mPuma.defineClassUnder("IOBuffer", runtime.getObject(), ALLOCATOR);
24
+ cIOBuffer.defineAnnotatedMethods(IOBuffer.class);
25
+ }
26
+
27
+ private static final int DEFAULT_SIZE = 4096;
28
+
29
+ final ByteList buffer = new ByteList(DEFAULT_SIZE);
30
+
31
+ IOBuffer(Ruby runtime, RubyClass klass) {
32
+ super(runtime, klass);
33
+ }
34
+
35
+ @JRubyMethod
36
+ public RubyInteger used(ThreadContext context) {
37
+ return context.runtime.newFixnum(buffer.getRealSize());
38
+ }
39
+
40
+ @JRubyMethod
41
+ public RubyInteger capacity(ThreadContext context) {
42
+ return context.runtime.newFixnum(buffer.unsafeBytes().length);
43
+ }
44
+
45
+ @JRubyMethod
46
+ public IRubyObject reset() {
47
+ buffer.setRealSize(0);
48
+ return this;
49
+ }
50
+
51
+ @JRubyMethod(name = { "to_s", "to_str" })
52
+ public RubyString to_s(ThreadContext context) {
53
+ return RubyString.newStringShared(context.runtime, buffer.unsafeBytes(), 0, buffer.getRealSize());
54
+ }
55
+
56
+ @JRubyMethod(name = "<<")
57
+ public IRubyObject add(IRubyObject str) {
58
+ addImpl(str.convertToString());
59
+ return this;
60
+ }
61
+
62
+ @JRubyMethod(rest = true)
63
+ public IRubyObject append(IRubyObject[] strs) {
64
+ for (IRubyObject str : strs) addImpl(str.convertToString());
65
+ return this;
66
+ }
67
+
68
+ private void addImpl(RubyString str) {
69
+ buffer.append(str.getByteList());
70
+ }
71
+
72
+ }
@@ -23,6 +23,7 @@ import javax.net.ssl.SSLPeerUnverifiedException;
23
23
  import javax.net.ssl.SSLSession;
24
24
  import java.io.FileInputStream;
25
25
  import java.io.IOException;
26
+ import java.nio.Buffer;
26
27
  import java.nio.ByteBuffer;
27
28
  import java.security.KeyManagementException;
28
29
  import java.security.KeyStore;
@@ -65,7 +66,7 @@ public class MiniSSL extends RubyObject {
65
66
 
66
67
  public void clear() { buffer.clear(); }
67
68
  public void compact() { buffer.compact(); }
68
- public void flip() { buffer.flip(); }
69
+ public void flip() { ((Buffer) buffer).flip(); }
69
70
  public boolean hasRemaining() { return buffer.hasRemaining(); }
70
71
  public int position() { return buffer.position(); }
71
72
 
@@ -89,7 +90,7 @@ public class MiniSSL extends RubyObject {
89
90
  public void resize(int newCapacity) {
90
91
  if (newCapacity > buffer.capacity()) {
91
92
  ByteBuffer dstTmp = ByteBuffer.allocate(newCapacity);
92
- buffer.flip();
93
+ flip();
93
94
  dstTmp.put(buffer);
94
95
  buffer = dstTmp;
95
96
  } else {
@@ -101,7 +102,7 @@ public class MiniSSL extends RubyObject {
101
102
  * Drains the buffer to a ByteList, or returns null for an empty buffer
102
103
  */
103
104
  public ByteList asByteList() {
104
- buffer.flip();
105
+ flip();
105
106
  if (!buffer.hasRemaining()) {
106
107
  buffer.clear();
107
108
  return null;
@@ -158,7 +159,17 @@ public class MiniSSL extends RubyObject {
158
159
  sslCtx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
159
160
  engine = sslCtx.createSSLEngine();
160
161
 
161
- String[] protocols = new String[] { "TLSv1", "TLSv1.1", "TLSv1.2" };
162
+ String[] protocols;
163
+ if(miniSSLContext.callMethod(threadContext, "no_tlsv1").isTrue()) {
164
+ protocols = new String[] { "TLSv1.1", "TLSv1.2" };
165
+ } else {
166
+ protocols = new String[] { "TLSv1", "TLSv1.1", "TLSv1.2" };
167
+ }
168
+
169
+ if(miniSSLContext.callMethod(threadContext, "no_tlsv1_1").isTrue()) {
170
+ protocols = new String[] { "TLSv1.2" };
171
+ }
172
+
162
173
  engine.setEnabledProtocols(protocols);
163
174
  engine.setUseClientMode(false);
164
175
 
@@ -170,6 +181,12 @@ public class MiniSSL extends RubyObject {
170
181
  engine.setNeedClientAuth(true);
171
182
  }
172
183
 
184
+ IRubyObject sslCipherListObject = miniSSLContext.callMethod(threadContext, "ssl_cipher_list");
185
+ if (!sslCipherListObject.isNil()) {
186
+ String[] sslCipherList = sslCipherListObject.convertToString().asJavaString().split(",");
187
+ engine.setEnabledCipherSuites(sslCipherList);
188
+ }
189
+
173
190
  SSLSession session = engine.getSession();
174
191
  inboundNetData = new MiniSSLBuffer(session.getPacketBufferSize());
175
192
  outboundAppData = new MiniSSLBuffer(session.getApplicationBufferSize());
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'openssl'
2
4
 
3
5
  module OpenSSL
@@ -13,7 +15,11 @@ module OpenSSL
13
15
  ssl.accept if @start_immediately
14
16
  ssl
15
17
  rescue SSLError => ex
16
- sock.close
18
+ if ssl
19
+ ssl.close
20
+ else
21
+ sock.close
22
+ end
17
23
  raise ex
18
24
  end
19
25
  end
@@ -1,26 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+
1
5
  module Puma
2
6
  module App
7
+ # Check out {#call}'s source code to see what actions this web application
8
+ # can respond to.
3
9
  class Status
4
- def initialize(cli)
5
- @cli = cli
6
- @auth_token = nil
7
- end
8
10
  OK_STATUS = '{ "status": "ok" }'.freeze
9
11
 
10
- attr_accessor :auth_token
11
-
12
- def authenticate(env)
13
- return true unless @auth_token
14
- env['QUERY_STRING'].to_s.split(/&;/).include?("token=#{@auth_token}")
15
- end
16
-
17
- def rack_response(status, body, content_type='application/json')
18
- headers = {
19
- 'Content-Type' => content_type,
20
- 'Content-Length' => body.bytesize.to_s
21
- }
22
-
23
- [status, headers, [body]]
12
+ def initialize(cli, token = nil)
13
+ @cli = cli
14
+ @auth_token = token
24
15
  end
25
16
 
26
17
  def call(env)
@@ -31,44 +22,59 @@ module Puma
31
22
  case env['PATH_INFO']
32
23
  when /\/stop$/
33
24
  @cli.stop
34
- return rack_response(200, OK_STATUS)
25
+ rack_response(200, OK_STATUS)
35
26
 
36
27
  when /\/halt$/
37
28
  @cli.halt
38
- return rack_response(200, OK_STATUS)
29
+ rack_response(200, OK_STATUS)
39
30
 
40
31
  when /\/restart$/
41
32
  @cli.restart
42
- return rack_response(200, OK_STATUS)
33
+ rack_response(200, OK_STATUS)
43
34
 
44
35
  when /\/phased-restart$/
45
36
  if !@cli.phased_restart
46
- return rack_response(404, '{ "error": "phased restart not available" }')
37
+ rack_response(404, '{ "error": "phased restart not available" }')
47
38
  else
48
- return rack_response(200, OK_STATUS)
39
+ rack_response(200, OK_STATUS)
49
40
  end
50
41
 
51
42
  when /\/reload-worker-directory$/
52
43
  if !@cli.send(:reload_worker_directory)
53
- return rack_response(404, '{ "error": "reload_worker_directory not available" }')
44
+ rack_response(404, '{ "error": "reload_worker_directory not available" }')
54
45
  else
55
- return rack_response(200, OK_STATUS)
46
+ rack_response(200, OK_STATUS)
56
47
  end
57
48
 
58
49
  when /\/gc$/
59
50
  GC.start
60
- return rack_response(200, OK_STATUS)
51
+ rack_response(200, OK_STATUS)
61
52
 
62
53
  when /\/gc-stats$/
63
- json = "{" + GC.stat.map { |k, v| "\"#{k}\": #{v}" }.join(",") + "}"
64
- return rack_response(200, json)
54
+ rack_response(200, GC.stat.to_json)
65
55
 
66
56
  when /\/stats$/
67
- return rack_response(200, @cli.stats)
57
+ rack_response(200, @cli.stats)
68
58
  else
69
59
  rack_response 404, "Unsupported action", 'text/plain'
70
60
  end
71
61
  end
62
+
63
+ private
64
+
65
+ def authenticate(env)
66
+ return true unless @auth_token
67
+ env['QUERY_STRING'].to_s.split(/&;/).include?("token=#{@auth_token}")
68
+ end
69
+
70
+ def rack_response(status, body, content_type='application/json')
71
+ headers = {
72
+ 'Content-Type' => content_type,
73
+ 'Content-Length' => body.bytesize.to_s
74
+ }
75
+
76
+ [status, headers, [body]]
77
+ end
72
78
  end
73
79
  end
74
80
  end