puma 7.2.4 → 8.0.0

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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +38 -37
  3. data/README.md +1 -2
  4. data/docs/5.0-Upgrade.md +98 -0
  5. data/docs/6.0-Upgrade.md +56 -0
  6. data/docs/7.0-Upgrade.md +52 -0
  7. data/docs/8.0-Upgrade.md +100 -0
  8. data/docs/grpc.md +62 -0
  9. data/docs/images/favicon.svg +1 -0
  10. data/docs/images/running-puma.svg +1 -0
  11. data/docs/images/standard-logo.svg +1 -0
  12. data/docs/signals.md +1 -1
  13. data/ext/puma_http11/http11_parser.java.rl +51 -65
  14. data/ext/puma_http11/mini_ssl.c +3 -10
  15. data/ext/puma_http11/org/jruby/puma/EnvKey.java +241 -0
  16. data/ext/puma_http11/org/jruby/puma/Http11.java +168 -104
  17. data/ext/puma_http11/org/jruby/puma/Http11Parser.java +71 -85
  18. data/ext/puma_http11/org/jruby/puma/MiniSSL.java +34 -44
  19. data/ext/puma_http11/puma_http11.c +3 -4
  20. data/lib/puma/binder.rb +3 -4
  21. data/lib/puma/cli.rb +1 -1
  22. data/lib/puma/client.rb +114 -196
  23. data/lib/puma/client_env.rb +171 -0
  24. data/lib/puma/cluster.rb +1 -1
  25. data/lib/puma/commonlogger.rb +0 -3
  26. data/lib/puma/configuration.rb +69 -8
  27. data/lib/puma/const.rb +3 -7
  28. data/lib/puma/control_cli.rb +4 -15
  29. data/lib/puma/detect.rb +11 -0
  30. data/lib/puma/dsl.rb +75 -22
  31. data/lib/puma/error_logger.rb +1 -2
  32. data/lib/puma/launcher.rb +3 -4
  33. data/lib/puma/minissl.rb +56 -101
  34. data/lib/puma/reactor.rb +3 -35
  35. data/lib/puma/{request.rb → response.rb} +16 -201
  36. data/lib/puma/runner.rb +1 -2
  37. data/lib/puma/server.rb +84 -120
  38. data/lib/puma/server_plugin_control.rb +32 -0
  39. data/lib/puma/thread_pool.rb +129 -23
  40. data/lib/puma/util.rb +4 -8
  41. data/lib/rack/handler/puma.rb +1 -1
  42. metadata +15 -4
@@ -383,41 +383,36 @@ public class MiniSSL extends RubyObject { // MiniSSL::Engine
383
383
  }
384
384
 
385
385
  MiniSSLBuffer inboundAppData = new MiniSSLBuffer(engine.getSession().getApplicationBufferSize());
386
- int consumedTo;
387
- do {
388
- consumedTo = inboundNetData.position();
389
- doOp(SSLOperation.UNWRAP, inboundNetData, inboundAppData);
390
-
391
- HandshakeStatus handshakeStatus = engine.getHandshakeStatus();
392
- boolean done = false;
393
- while (!done) {
394
- SSLEngineResult res;
395
- switch (handshakeStatus) {
396
- case NEED_WRAP:
397
- res = doOp(SSLOperation.WRAP, inboundAppData, outboundNetData);
398
- handshakeStatus = res.getHandshakeStatus();
399
- break;
400
- case NEED_UNWRAP:
401
- res = doOp(SSLOperation.UNWRAP, inboundNetData, inboundAppData);
402
- if (res.getStatus() == Status.BUFFER_UNDERFLOW) {
403
- // need more data before we can shake more hands
404
- done = true;
405
- }
406
- handshakeStatus = res.getHandshakeStatus();
407
- break;
408
- case NEED_TASK:
409
- Runnable runnable;
410
- while ((runnable = engine.getDelegatedTask()) != null) {
411
- runnable.run();
412
- }
413
- handshakeStatus = engine.getHandshakeStatus();
414
- break;
415
- default:
386
+ doOp(SSLOperation.UNWRAP, inboundNetData, inboundAppData);
387
+
388
+ HandshakeStatus handshakeStatus = engine.getHandshakeStatus();
389
+ boolean done = false;
390
+ while (!done) {
391
+ SSLEngineResult res;
392
+ switch (handshakeStatus) {
393
+ case NEED_WRAP:
394
+ res = doOp(SSLOperation.WRAP, inboundAppData, outboundNetData);
395
+ handshakeStatus = res.getHandshakeStatus();
396
+ break;
397
+ case NEED_UNWRAP:
398
+ res = doOp(SSLOperation.UNWRAP, inboundNetData, inboundAppData);
399
+ if (res.getStatus() == Status.BUFFER_UNDERFLOW) {
400
+ // need more data before we can shake more hands
416
401
  done = true;
417
- }
402
+ }
403
+ handshakeStatus = res.getHandshakeStatus();
404
+ break;
405
+ case NEED_TASK:
406
+ Runnable runnable;
407
+ while ((runnable = engine.getDelegatedTask()) != null) {
408
+ runnable.run();
409
+ }
410
+ handshakeStatus = engine.getHandshakeStatus();
411
+ break;
412
+ default:
413
+ done = true;
418
414
  }
419
- } while (inboundAppData.position() == 0 && !closed &&
420
- inboundNetData.hasRemaining() && inboundNetData.position() > consumedTo);
415
+ }
421
416
 
422
417
  if (inboundNetData.hasRemaining()) {
423
418
  inboundNetData.compact();
@@ -487,19 +482,14 @@ public class MiniSSL extends RubyObject { // MiniSSL::Engine
487
482
 
488
483
  @JRubyMethod
489
484
  public IRubyObject shutdown() {
490
- // The peer may be speaking plain HTTP if the handshake did not finish.
491
- if (closed || !handshake || engine.isInboundDone() && engine.isOutboundDone()) {
492
- return getRuntime().getTrue();
493
- }
494
-
495
- // Generate close_notify for MiniSSL::Socket#close to send.
496
- engine.closeOutbound();
497
- try {
498
- doOp(SSLOperation.WRAP, outboundAppData, outboundNetData);
499
- } catch (SSLException e) {
485
+ if (closed || engine.isInboundDone() && engine.isOutboundDone()) {
486
+ if (engine.isOutboundDone()) {
487
+ engine.closeOutbound();
488
+ }
500
489
  return getRuntime().getTrue();
490
+ } else {
491
+ return getRuntime().getFalse();
501
492
  }
502
- return getRuntime().getFalse();
503
493
  }
504
494
 
505
495
  private static RubyClass getSSLError(Ruby runtime) {
@@ -385,8 +385,7 @@ static VALUE HttpParser_execute(VALUE self, VALUE req_hash, VALUE data, VALUE st
385
385
  long dlen = 0;
386
386
 
387
387
  from = FIX2INT(start);
388
- dptr = RSTRING_PTR(data);
389
- dlen = (long)RSTRING_LEN(data);
388
+ RSTRING_GETMEM(data, dptr, dlen);
390
389
 
391
390
  if(from >= dlen) {
392
391
  rb_raise(eHttpParserError, "%s", "Requested start is after data buffer end.");
@@ -399,7 +398,7 @@ static VALUE HttpParser_execute(VALUE self, VALUE req_hash, VALUE data, VALUE st
399
398
  if(puma_parser_has_error(http)) {
400
399
  rb_raise(eHttpParserError, "%s", "Invalid HTTP format, parsing fails. Are you trying to open an SSL connection to a non-SSL Puma?");
401
400
  } else {
402
- return SIZET2NUM(puma_parser_nread(http));
401
+ return INT2FIX(puma_parser_nread(http));
403
402
  }
404
403
  }
405
404
  }
@@ -445,7 +444,7 @@ static VALUE HttpParser_nread(VALUE self)
445
444
  {
446
445
  puma_parser *http = HttpParser_unwrap(self);
447
446
 
448
- return SIZET2NUM(http->nread);
447
+ return INT2FIX(http->nread);
449
448
  }
450
449
 
451
450
  /**
data/lib/puma/binder.rb CHANGED
@@ -236,7 +236,7 @@ module Puma
236
236
  # Load localhost authority if not loaded.
237
237
  # Ruby 3 `values_at` accepts an array, earlier do not
238
238
  if params.values_at(*cert_key).all? { |v| v.to_s.empty? }
239
- ctx = localhost_authority && localhost_authority_context(params)
239
+ ctx = localhost_authority && localhost_authority_context
240
240
  end
241
241
 
242
242
  ctx ||=
@@ -313,7 +313,7 @@ module Puma
313
313
  @localhost_authority ||= Localhost::Authority.fetch if defined?(Localhost::Authority) && !Puma::IS_JRUBY
314
314
  end
315
315
 
316
- def localhost_authority_context(params = {})
316
+ def localhost_authority_context
317
317
  return unless localhost_authority
318
318
 
319
319
  key_path, crt_path = if [:key_path, :certificate_path].all? { |m| localhost_authority.respond_to?(m) }
@@ -322,8 +322,7 @@ module Puma
322
322
  local_certificates_path = File.expand_path("~/.localhost")
323
323
  [File.join(local_certificates_path, "localhost.key"), File.join(local_certificates_path, "localhost.crt")]
324
324
  end
325
- params = params.reject { |k, _| k.start_with?("cert", "key") }
326
- MiniSSL::ContextBuilder.new(params.merge("key" => key_path, "cert" => crt_path), @log_writer).context
325
+ MiniSSL::ContextBuilder.new({ "key" => key_path, "cert" => crt_path }, @log_writer).context
327
326
  end
328
327
 
329
328
  # Tell the server to listen on host +host+, port +port+.
data/lib/puma/cli.rb CHANGED
@@ -148,7 +148,7 @@ module Puma
148
148
 
149
149
  o.on "-p", "--port PORT", "Define the TCP port to bind to",
150
150
  "Use -b for more advanced options" do |arg|
151
- user_config.bind "tcp://#{Configuration::DEFAULTS[:tcp_host]}:#{arg}"
151
+ user_config.port arg, Configuration.default_tcp_host
152
152
  end
153
153
 
154
154
  o.on "--pidfile PATH", "Use PATH as a pidfile" do |arg|