puma 8.0.2 → 8.1.2

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 (67) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +154 -0
  3. data/README.md +28 -378
  4. data/docs/binding.md +135 -0
  5. data/docs/cluster_mode.md +241 -0
  6. data/docs/configuration.md +78 -0
  7. data/docs/{stats.md → control_server.md} +28 -8
  8. data/docs/{deployment.md → deployment/README.md} +23 -7
  9. data/docs/{kubernetes.md → deployment/kubernetes.md} +4 -4
  10. data/docs/{systemd.md → deployment/systemd.md} +4 -2
  11. data/docs/plugins.md +62 -3
  12. data/docs/puma_support.md +92 -0
  13. data/docs/rails_dev_mode.md +2 -2
  14. data/docs/restart.md +8 -3
  15. data/docs/signals.md +4 -2
  16. data/docs/{5.0-Upgrade.md → upgrading/5.0-Upgrade.md} +3 -3
  17. data/docs/{6.0-Upgrade.md → upgrading/6.0-Upgrade.md} +3 -3
  18. data/docs/{7.0-Upgrade.md → upgrading/7.0-Upgrade.md} +2 -2
  19. data/docs/{8.0-Upgrade.md → upgrading/8.0-Upgrade.md} +4 -4
  20. data/ext/puma_http11/extconf.rb +2 -0
  21. data/ext/puma_http11/http11_parser.c +6 -2
  22. data/ext/puma_http11/mini_ssl.c +18 -7
  23. data/ext/puma_http11/puma_http11.c +28 -3
  24. data/lib/puma/binder.rb +29 -0
  25. data/lib/puma/cli.rb +6 -0
  26. data/lib/puma/client.rb +178 -44
  27. data/lib/puma/client_env.rb +32 -18
  28. data/lib/puma/cluster/worker.rb +109 -33
  29. data/lib/puma/cluster/worker_handle.rb +16 -0
  30. data/lib/puma/cluster.rb +173 -45
  31. data/lib/puma/commonlogger.rb +3 -3
  32. data/lib/puma/configuration.rb +23 -3
  33. data/lib/puma/const.rb +14 -9
  34. data/lib/puma/control_cli.rb +14 -3
  35. data/lib/puma/dsl.rb +279 -92
  36. data/lib/puma/launcher.rb +6 -4
  37. data/lib/puma/minissl.rb +98 -56
  38. data/lib/puma/plugin/systemd.rb +1 -1
  39. data/lib/puma/reactor.rb +35 -3
  40. data/lib/puma/response.rb +28 -6
  41. data/lib/puma/runner.rb +5 -1
  42. data/lib/puma/sd_notify.rb +4 -1
  43. data/lib/puma/server.rb +131 -35
  44. data/lib/puma/thread_pool.rb +12 -1
  45. data/lib/puma/util.rb +8 -4
  46. data/lib/puma.rb +1 -1
  47. metadata +19 -31
  48. data/docs/fork_worker.md +0 -41
  49. data/docs/grpc.md +0 -62
  50. data/docs/jungle/README.md +0 -9
  51. data/docs/testing_benchmarks_local_files.md +0 -150
  52. data/docs/testing_test_rackup_ci_files.md +0 -36
  53. data/ext/puma_http11/PumaHttp11Service.java +0 -17
  54. data/ext/puma_http11/http11_parser.java.rl +0 -131
  55. data/ext/puma_http11/http11_parser.rl +0 -149
  56. data/ext/puma_http11/http11_parser_common.rl +0 -54
  57. data/ext/puma_http11/no_ssl/PumaHttp11Service.java +0 -15
  58. data/ext/puma_http11/org/jruby/puma/EnvKey.java +0 -241
  59. data/ext/puma_http11/org/jruby/puma/Http11.java +0 -321
  60. data/ext/puma_http11/org/jruby/puma/Http11Parser.java +0 -441
  61. data/ext/puma_http11/org/jruby/puma/MiniSSL.java +0 -509
  62. data/tools/Dockerfile +0 -26
  63. data/tools/trickletest.rb +0 -44
  64. /data/docs/{nginx.md → deployment/nginx.md} +0 -0
  65. /data/docs/{jungle → deployment}/rc.d/README.md +0 -0
  66. /data/docs/{jungle → deployment}/rc.d/puma +0 -0
  67. /data/docs/{jungle → deployment}/rc.d/puma.conf +0 -0
data/lib/puma/dsl.rb CHANGED
@@ -5,7 +5,7 @@ require_relative 'util'
5
5
 
6
6
  module Puma
7
7
  # The methods that are available for use inside the configuration file.
8
- # These same methods are used in Puma cli and the rack handler
8
+ # These same methods are used in Puma CLI and the Rack handler
9
9
  # internally.
10
10
  #
11
11
  # Used manually (via CLI class):
@@ -33,12 +33,12 @@ module Puma
33
33
  # +test/config+.
34
34
  #
35
35
  # Puma v6 adds the option to specify a key name (String or Symbol) to the
36
- # hooks that run inside the forked workers. All the hooks run inside the
36
+ # hooks that run inside the forked workers. All the hooks run inside the
37
37
  # {Puma::Cluster::Worker#run} method.
38
38
  #
39
39
  # Previously, the worker index and the LogWriter instance were passed to the
40
- # hook blocks/procs. If a key name is specified, a hash is passed as the last
41
- # parameter. This allows storage of data, typically objects that are created
40
+ # hook blocks/procs. If a key name is specified, a hash is passed as the last
41
+ # parameter. This allows storage of data, typically objects that are created
42
42
  # before the worker that need to be passed to the hook when the worker is shutdown.
43
43
  #
44
44
  # The following hooks have been updated:
@@ -48,6 +48,8 @@ module Puma
48
48
  # | before_worker_shutdown | :before_worker_shutdown | inside, after |
49
49
  # | before_refork | :before_refork | inside |
50
50
  # | after_refork | :after_refork | inside |
51
+ # | after_mold_promotion | :after_mold_promotion | inside |
52
+ # | before_mold_shutdown | :before_mold_shutdown | inside |
51
53
  #
52
54
  class DSL
53
55
  ON_WORKER_KEY = [String, Symbol].freeze
@@ -299,19 +301,16 @@ module Puma
299
301
  # Bind to (systemd) activated sockets, regardless of configured binds.
300
302
  #
301
303
  # Systemd can present sockets as file descriptors that are already opened.
302
- # By default Puma will use these but only if it was explicitly told to bind
303
- # to the socket. If not, it will close the activated sockets. This means
304
- # all configuration is duplicated.
304
+ # By default Puma only uses these if it was explicitly told to bind to
305
+ # the socket, otherwise it closes them. Since only SSL config on a bind
306
+ # is relevant for activated sockets (unix and TCP socket options are
307
+ # ignored), this often means duplicating configuration for no benefit.
305
308
  #
306
- # Binds can contain additional configuration, but only SSL config is really
307
- # relevant since the unix and TCP socket options are ignored.
309
+ # This method tells the launcher to bind to all activated sockets,
310
+ # regardless of existing binds. Passing `'only'` also clears any
311
+ # configured binds so that only activated sockets are used.
308
312
  #
309
- # This means there is a lot of duplicated configuration for no additional
310
- # value in most setups. This method tells the launcher to bind to all
311
- # activated sockets, regardless of existing bind.
312
- #
313
- # To clear configured binds, the value only can be passed. This will clear
314
- # out any binds that may have been configured.
313
+ # The default is +nil+.
315
314
  #
316
315
  # @example Use any systemd activated sockets as well as configured binds
317
316
  # bind_to_activated_sockets
@@ -335,7 +334,7 @@ module Puma
335
334
  bind URI::Generic.build(scheme: 'tcp', host: host, port: Integer(port)).to_s
336
335
  end
337
336
 
338
- # Define how long the tcp socket stays open, if no data has been received.
337
+ # Define how long the TCP socket stays open when no data has been received.
339
338
  #
340
339
  # The default is 30 seconds.
341
340
  #
@@ -390,8 +389,12 @@ module Puma
390
389
  alias clean_thread_locals fiber_per_request
391
390
 
392
391
  # When shutting down, drain the accept socket of pending connections and
393
- # process them. This loops over the accept socket until there are no more
394
- # read events and then stops looking and waits for the requests to finish.
392
+ # process them before waiting for in-flight requests to finish.
393
+ #
394
+ # The default is +nil+.
395
+ #
396
+ # @example
397
+ # drain_on_shutdown
395
398
  #
396
399
  # @see Puma::Server#graceful_shutdown
397
400
  #
@@ -399,7 +402,20 @@ module Puma
399
402
  @options[:drain_on_shutdown] = which
400
403
  end
401
404
 
402
- # Set the environment in which the rack's app will run. The value must be
405
+ # Define how long an incomplete request may continue to be read during shutdown.
406
+ #
407
+ # The default is 25 seconds.
408
+ #
409
+ # @example
410
+ # shutdown_body_timeout 10
411
+ #
412
+ # @see Puma::Server#graceful_shutdown
413
+ #
414
+ def shutdown_body_timeout(seconds)
415
+ @options[:shutdown_body_timeout] = Float(seconds)
416
+ end
417
+
418
+ # Set the environment in which the Rack app will run. The value must be
403
419
  # a string.
404
420
  #
405
421
  # The default is "development".
@@ -412,14 +428,17 @@ module Puma
412
428
  end
413
429
 
414
430
  # How long to wait for threads to stop when shutting them down.
415
- # Specifying :immediately will cause Puma to kill the threads immediately.
431
+ # Specifying `:immediately` will cause Puma to kill the threads immediately.
416
432
  # Otherwise the value is the number of seconds to wait.
417
433
  #
418
434
  # Puma always waits a few seconds after killing a thread for it to try
419
- # to finish up it's work, even in :immediately mode.
435
+ # to finish up its work, even in `:immediately` mode.
420
436
  #
421
437
  # The default is +:forever+.
422
438
  #
439
+ # @example
440
+ # force_shutdown_after 30
441
+ #
423
442
  # @see Puma::Server#graceful_shutdown
424
443
  #
425
444
  def force_shutdown_after(val=:forever)
@@ -454,7 +473,7 @@ module Puma
454
473
  alias_method :on_restart, :before_restart
455
474
 
456
475
  # Command to use to restart Puma. This should be just how to
457
- # load Puma itself (ie. 'ruby -Ilib bin/puma'), not the arguments
476
+ # load Puma itself (i.e. `ruby -Ilib bin/puma`), not the arguments
458
477
  # to Puma, as those are the same as the original process.
459
478
  #
460
479
  # @example
@@ -464,7 +483,7 @@ module Puma
464
483
  @options[:restart_cmd] = cmd.to_s
465
484
  end
466
485
 
467
- # Store the pid of the server in the file at "path".
486
+ # Store the PID of the server in the file at +path+.
468
487
  #
469
488
  # @example
470
489
  # pidfile '/u/apps/lolcat/tmp/pids/puma.pid'
@@ -475,11 +494,13 @@ module Puma
475
494
 
476
495
  # Disable request logging, the inverse of `log_requests`.
477
496
  #
478
- # The default is +true+.
497
+ # The default is +false+.
479
498
  #
480
499
  # @example
481
500
  # quiet
482
501
  #
502
+ # @see log_requests
503
+ #
483
504
  def quiet(which=true)
484
505
  @options[:log_requests] = !which
485
506
  end
@@ -491,11 +512,13 @@ module Puma
491
512
  # @example
492
513
  # log_requests
493
514
  #
515
+ # @see quiet
516
+ #
494
517
  def log_requests(which=true)
495
518
  @options[:log_requests] = which
496
519
  end
497
520
 
498
- # Pass in a custom logging class instance
521
+ # Pass in a custom logging class instance.
499
522
  #
500
523
  # @example
501
524
  # custom_logger Logger.new('t.log')
@@ -504,7 +527,7 @@ module Puma
504
527
  @options[:custom_logger] = custom_logger
505
528
  end
506
529
 
507
- # Show debugging info
530
+ # Show debugging info.
508
531
  #
509
532
  # The default is +false+.
510
533
  #
@@ -526,9 +549,14 @@ module Puma
526
549
  @options[:rackup] ||= path.to_s
527
550
  end
528
551
 
529
- # Allows setting `env['rack.url_scheme']`.
530
- # Only necessary if X-Forwarded-Proto is not being set by your proxy
531
- # Normal values are 'http' or 'https'.
552
+ # Set `env['rack.url_scheme']`. Only necessary if `X-Forwarded-Proto`
553
+ # is not being set by your proxy. Normal values are `'http'` or
554
+ # `'https'`.
555
+ #
556
+ # The default is +nil+.
557
+ #
558
+ # @example
559
+ # rack_url_scheme 'https'
532
560
  #
533
561
  def rack_url_scheme(scheme=nil)
534
562
  @options[:rack_url_scheme] = scheme
@@ -546,9 +574,7 @@ module Puma
546
574
  end
547
575
 
548
576
  # Redirect +STDOUT+ and +STDERR+ to files specified. The +append+ parameter
549
- # specifies whether the output is appended.
550
- #
551
- # The default is +false+.
577
+ # specifies whether the output is appended, and defaults to +false+.
552
578
  #
553
579
  # @example
554
580
  # stdout_redirect '/app/lolcat/log/stdout', '/app/lolcat/log/stderr'
@@ -561,6 +587,16 @@ module Puma
561
587
  @options[:redirect_append] = append
562
588
  end
563
589
 
590
+ # Provide a block to format log messages. The block receives the message
591
+ # string and should return the formatted string.
592
+ #
593
+ # @example
594
+ # log_formatter do |str|
595
+ # "[#{Time.now}] #{str}"
596
+ # end
597
+ #
598
+ # @see Puma::LogWriter
599
+ #
564
600
  def log_formatter(&block)
565
601
  @options[:log_formatter] = block
566
602
  end
@@ -569,10 +605,10 @@ module Puma
569
605
  #
570
606
  # It can be a single fixed number, or a +min+ and a +max+.
571
607
  #
572
- # The default is the environment variables +PUMA_MIN_THREADS+ / +PUMA_MAX_THREADS+
573
- # (or +MIN_THREADS+ / +MAX_THREADS+ if the +PUMA_+ variables aren't set).
574
- #
575
- # If these environment variables aren't set, the default is "0, 5" in MRI or "0, 16" for other interpreters.
608
+ # The default is taken from the +PUMA_MIN_THREADS+ / +PUMA_MAX_THREADS+
609
+ # environment variables (or +MIN_THREADS+ / +MAX_THREADS+ if the +PUMA_+
610
+ # variables are not set). If those environment variables are also unset,
611
+ # the default is `0, 5` in MRI or `0, 16` for other interpreters.
576
612
  #
577
613
  # @example
578
614
  # threads 5
@@ -601,15 +637,17 @@ module Puma
601
637
  # When request handlers know the current requests will no longer use a significant amount
602
638
  # of CPU, they can mark the current request as IO bound using <tt>env["puma.mark_as_io_bound"]</tt>.
603
639
  #
604
- # Threads marked as IO bound are allowed to go over the max thread limit.
640
+ # Threads marked as IO bound are allowed to go over the max thread limit. Any IO thread
641
+ # over the limit is counted as a regular thread, so a configuration of 5 regular threads
642
+ # and 5 IO threads may also allow, for example, 3 regular threads and 7 IO threads to
643
+ # process requests concurrently.
644
+ #
645
+ # The default is +0+.
605
646
  #
606
647
  # @example
607
648
  # threads 5
608
649
  # max_io_threads 5
609
650
  #
610
- # The above example allows for 5 regular threads and 5 IO threads to process requests concurrently.
611
- # Any IO thread over the limit is counted as a regular thread, hence the above configuration also
612
- # allows for 3 regular threads and 7 IO threads for example.
613
651
  def max_io_threads(max)
614
652
  max = Integer(max)
615
653
  if max < 0
@@ -623,7 +661,7 @@ module Puma
623
661
  #
624
662
  # bind 'ssl://127.0.0.1:9292?key=key_path&cert=cert_path'
625
663
  #
626
- # you can use the this method.
664
+ # you can use this method.
627
665
  #
628
666
  # When binding on localhost you don't need to specify +cert+ and +key+,
629
667
  # Puma will assume you are using the +localhost+ gem and try to load the
@@ -636,8 +674,8 @@ module Puma
636
674
  # The `cert:` options hash parameter can be the path to a certificate
637
675
  # file including all intermediate certificates in PEM format.
638
676
  #
639
- # The `cert_pem:` options hash parameter can be String containing the
640
- # cerificate and all intermediate certificates in PEM format.
677
+ # The `cert_pem:` options hash parameter can be a String containing the
678
+ # certificate and all intermediate certificates in PEM format.
641
679
  #
642
680
  # @example
643
681
  # ssl_bind '127.0.0.1', '9292', {
@@ -683,7 +721,7 @@ module Puma
683
721
  @options[:state] = path.to_s
684
722
  end
685
723
 
686
- # Use +permission+ to restrict permissions for the state file. By convention,
724
+ # Use +permission+ to restrict permissions for the state file. By convention,
687
725
  # +permission+ is an octal number (e.g. `0640` or `0o640`).
688
726
  #
689
727
  # @example
@@ -734,13 +772,13 @@ module Puma
734
772
  # @note Cluster mode only.
735
773
  #
736
774
  # @example
737
- # silence_single_worker_warning
775
+ # silence_single_worker_warning
738
776
  #
739
777
  def silence_single_worker_warning
740
778
  @options[:silence_single_worker_warning] = true
741
779
  end
742
780
 
743
- # Disable warning message when running single mode with callback hook defined.
781
+ # Disable the warning when running in single mode with a cluster-only callback hook defined.
744
782
  #
745
783
  # The default is +false+.
746
784
  #
@@ -809,8 +847,8 @@ module Puma
809
847
  process_hook :before_fork, nil, block, cluster_only: true
810
848
  end
811
849
 
812
- # Code to run in a worker when it boots to setup
813
- # the process before booting the app.
850
+ # Code to run in a worker on boot to set up the process before
851
+ # the app is loaded. The worker's index is passed as an argument.
814
852
  #
815
853
  # This can be called multiple times to add several hooks.
816
854
  #
@@ -875,7 +913,7 @@ module Puma
875
913
  # Code to run in the master after a worker has been started. The worker's
876
914
  # index is passed as an argument.
877
915
  #
878
- # This is called everytime a worker is to be started.
916
+ # This is called every time a worker is to be started.
879
917
  #
880
918
  # @note Cluster mode only.
881
919
  #
@@ -890,8 +928,10 @@ module Puma
890
928
 
891
929
  alias_method :after_worker_boot, :after_worker_fork
892
930
 
893
- # Code to run in the master right after a worker has stopped. The worker's
894
- # index and Process::Status are passed as arguments.
931
+ # Code to run in the master right after a worker has stopped. A
932
+ # `Puma::Cluster::WorkerHandle` is passed as an argument.
933
+ #
934
+ # This can be called multiple times to add several hooks.
895
935
  #
896
936
  # @note Cluster mode only.
897
937
  #
@@ -904,7 +944,7 @@ module Puma
904
944
  process_hook :after_worker_shutdown, nil, block, cluster_only: true
905
945
  end
906
946
 
907
- # Code to run after puma is booted (works for both single and cluster modes).
947
+ # Code to run after Puma is booted (works for both single and cluster modes).
908
948
  #
909
949
  # @example
910
950
  # after_booted do
@@ -919,7 +959,7 @@ module Puma
919
959
 
920
960
  alias_method :on_booted, :after_booted
921
961
 
922
- # Code to run after puma is stopped (works for both: single and clustered)
962
+ # Code to run after Puma is stopped (works for both single and cluster modes).
923
963
  #
924
964
  # @example
925
965
  # after_stopped do
@@ -982,10 +1022,47 @@ module Puma
982
1022
  process_hook :after_refork, key, block
983
1023
  end
984
1024
 
1025
+ # When `mold_worker` is enabled, code to run in a worker after it stops
1026
+ # serving requests and becomes a mold, before any workers are forked from it.
1027
+ # The worker's index is passed as an argument.
1028
+ #
1029
+ # This can be used to close any connections to remote servers (database,
1030
+ # Redis, ...) or to run garbage collection to maximize copy-on-write
1031
+ # efficiency.
1032
+ #
1033
+ # This can be called multiple times to add several hooks.
1034
+ #
1035
+ # @note Cluster mode with `mold_worker` enabled only.
1036
+ #
1037
+ # @example
1038
+ # after_mold_promotion do
1039
+ # 3.times { GC.start }
1040
+ # end
1041
+ #
1042
+ def after_mold_promotion(key = nil, &block)
1043
+ process_hook :after_mold_promotion, key, block, cluster_only: true
1044
+ end
1045
+
1046
+ # When `mold_worker` is enabled, code to run in a mold before it exits.
1047
+ # The mold's index is passed as an argument.
1048
+ #
1049
+ # This can be called multiple times to add several hooks.
1050
+ #
1051
+ # @note Cluster mode with `mold_worker` enabled only.
1052
+ #
1053
+ # @example
1054
+ # before_mold_shutdown do
1055
+ # puts 'Mold shutting down...'
1056
+ # end
1057
+ #
1058
+ def before_mold_shutdown(key = nil, &block)
1059
+ process_hook :before_mold_shutdown, key, block, cluster_only: true
1060
+ end
1061
+
985
1062
  # Provide a block to be executed just before a thread is added to the thread
986
- # pool. Be careful: while the block executes, thread creation is delayed, and
987
- # probably a request will have to wait too! The new thread will not be added to
988
- # the threadpool until the provided block returns.
1063
+ # pool. Note that while the block executes, thread creation is delayed, and
1064
+ # a request may have to wait. The new thread will not be added to the
1065
+ # threadpool until the provided block returns.
989
1066
  #
990
1067
  # Return values are ignored.
991
1068
  # Raising an exception will log a warning.
@@ -1008,8 +1085,8 @@ module Puma
1008
1085
  alias_method :on_thread_start, :before_thread_start
1009
1086
 
1010
1087
  # Provide a block to be executed after a thread is trimmed from the thread
1011
- # pool. Be careful: while this block executes, Puma's main loop is
1012
- # blocked, so no new requests will be picked up.
1088
+ # pool. Note that while this block executes, Puma's main loop is blocked,
1089
+ # so no new requests will be picked up.
1013
1090
  #
1014
1091
  # This hook only runs when a thread in the threadpool is trimmed by Puma.
1015
1092
  # It does not run when a thread dies due to exceptions or any other cause.
@@ -1045,6 +1122,11 @@ module Puma
1045
1122
  #
1046
1123
  # This can be called multiple times to add several hooks.
1047
1124
  #
1125
+ # @example
1126
+ # out_of_band do
1127
+ # GC.start
1128
+ # end
1129
+ #
1048
1130
  def out_of_band(&block)
1049
1131
  process_hook :out_of_band, nil, block
1050
1132
  end
@@ -1089,6 +1171,43 @@ module Puma
1089
1171
  @options[:lowlevel_error_handler] = obj
1090
1172
  end
1091
1173
 
1174
+ # Use +obj+ or +block+ to handle exceptions raised by +before_fork+,
1175
+ # +before_worker_fork+, +after_worker_fork+, +before_worker_boot+,
1176
+ # +before_worker_shutdown+, +after_worker_shutdown+, +before_refork+,
1177
+ # +after_refork+, +after_mold_promotion+, +before_mold_shutdown+, and
1178
+ # +before_restart+ hooks.
1179
+ #
1180
+ # @example Crash workers instead of booting them half-configured
1181
+ # master_pid = Process.pid
1182
+ # hook_error_handler do |err, hook|
1183
+ # raise err unless Process.pid == master_pid
1184
+ # end
1185
+ #
1186
+ def hook_error_handler(obj=nil, &block)
1187
+ obj ||= block
1188
+ raise "Provide either a #call'able or a block" unless obj
1189
+ @options[:hook_error_handler] = obj
1190
+ end
1191
+
1192
+ # Use +obj+ or +block+ to answer a request that sends
1193
+ # <tt>Expect: 100-continue</tt> before Puma replies +100 Continue+ and reads
1194
+ # the body. It receives the Rack env (headers, no body) and can run on the
1195
+ # reactor thread, so it must return quickly.
1196
+ #
1197
+ # Return +false+ to carry on as usual, or a Rack response to send instead:
1198
+ # the app is not called and the connection is closed afterwards.
1199
+ #
1200
+ # @example Refuse oversized uploads without receiving them
1201
+ # continue_callback do |env|
1202
+ # env['CONTENT_LENGTH'].to_i > 10_000_000 ? [413, {}, []] : false
1203
+ # end
1204
+ #
1205
+ def continue_callback(obj=nil, &block)
1206
+ obj ||= block
1207
+ raise "Provide either a #call'able or a block" unless obj
1208
+ @options[:continue_callback] = obj
1209
+ end
1210
+
1092
1211
  # This option is used to allow your app and its gems to be
1093
1212
  # properly reloaded when not using preload.
1094
1213
  #
@@ -1102,9 +1221,14 @@ module Puma
1102
1221
  # new Bundler context and thus can float around as the release
1103
1222
  # dictates.
1104
1223
  #
1224
+ # The default is +false+.
1225
+ #
1105
1226
  # @note Cluster mode only.
1106
1227
  # @note This is incompatible with +preload_app!+.
1107
- # @note This is only supported for RubyGems 2.2+
1228
+ # @note This is only supported for RubyGems 2.2+.
1229
+ #
1230
+ # @example
1231
+ # prune_bundler
1108
1232
  #
1109
1233
  # @see extra_runtime_dependencies
1110
1234
  #
@@ -1164,7 +1288,7 @@ module Puma
1164
1288
  @options[:tag] = string.to_s
1165
1289
  end
1166
1290
 
1167
- # Change the default interval for checking workers.
1291
+ # Set the interval for checking workers.
1168
1292
  #
1169
1293
  # The default is 5 seconds.
1170
1294
  #
@@ -1176,13 +1300,13 @@ module Puma
1176
1300
  # @see Puma::Cluster#check_workers
1177
1301
  #
1178
1302
  def worker_check_interval(interval)
1179
- @options[:worker_check_interval] = Integer(interval)
1303
+ @options[:worker_check_interval] = Float(interval)
1180
1304
  end
1181
1305
 
1182
1306
  # Verifies that all workers have checked in to the master process within
1183
- # the given timeout. If not the worker process will be restarted. This is
1184
- # not a request timeout, it is to protect against a hung or dead process.
1185
- # Setting this value will not protect against slow requests.
1307
+ # the given timeout. If not, the worker process will be restarted. This
1308
+ # is not a request timeout, it is to protect against a hung or dead
1309
+ # process. Setting this value will not protect against slow requests.
1186
1310
  #
1187
1311
  # This value must be greater than worker_check_interval.
1188
1312
  #
@@ -1206,7 +1330,7 @@ module Puma
1206
1330
  @options[:worker_timeout] = timeout
1207
1331
  end
1208
1332
 
1209
- # Change the default worker timeout for booting.
1333
+ # Set the worker timeout for booting.
1210
1334
  #
1211
1335
  # The default is 60 seconds.
1212
1336
  #
@@ -1264,23 +1388,28 @@ module Puma
1264
1388
  @options[:worker_culling_strategy] = strategy
1265
1389
  end
1266
1390
 
1267
- # When set to true, workers accept all requests
1268
- # and queue them before passing them to the handlers.
1269
- # When set to false, each worker process accepts exactly as
1270
- # many requests as it is configured to simultaneously handle.
1391
+ # When `true`, a worker thread that receives a client with an
1392
+ # incomplete request body hands the client to a Reactor thread
1393
+ # and returns to the pool. The Reactor re-enqueues the client
1394
+ # once the body has been received. This frees workers from
1395
+ # blocking on slow client sends and enables HTTP keep-alive. A
1396
+ # worker must still receive each client first, so this does
1397
+ # not queue new connections when the pool is saturated.
1271
1398
  #
1272
- # Queueing requests generally improves performance. In some
1273
- # cases, such as a single threaded application, it may be
1274
- # better to ensure requests get balanced across workers.
1275
- #
1276
- # Note that setting this to false disables HTTP keepalive and
1277
- # slow clients will occupy a handler thread while the request
1278
- # is being sent. A reverse proxy, such as nginx, can handle
1279
- # slow clients and queue requests before they reach Puma.
1399
+ # When `false`, no Reactor runs. A worker thread reads each
1400
+ # request synchronously and remains occupied for the duration
1401
+ # of the client's request send, and HTTP keep-alive is
1402
+ # disabled. Consider running Puma behind a reverse proxy such
1403
+ # as nginx that can buffer requests and protect Puma from slow
1404
+ # clients.
1280
1405
  #
1281
1406
  # The default is +true+.
1282
1407
  #
1408
+ # @example
1409
+ # queue_requests false
1410
+ #
1283
1411
  # @see Puma::Server
1412
+ # @see Puma::Reactor
1284
1413
  #
1285
1414
  def queue_requests(answer=true)
1286
1415
  @options[:queue_requests] = answer
@@ -1293,7 +1422,13 @@ module Puma
1293
1422
  # If `on_force` is true, the backtraces will be written only
1294
1423
  # when the shutdown is forced i.e. not graceful.
1295
1424
  #
1425
+ # The default is +nil+.
1426
+ #
1427
+ # @example
1428
+ # shutdown_debug
1429
+ #
1296
1430
  # @see force_shutdown_after
1431
+ #
1297
1432
  def shutdown_debug(val = true, on_force: false)
1298
1433
  @options[:shutdown_debug] = val && on_force ? :on_force : val
1299
1434
  end
@@ -1341,7 +1476,7 @@ module Puma
1341
1476
  # HAproxy PROXY protocol, version 1. If the request does not have the PROXY
1342
1477
  # protocol attached to it, will fall back to :socket
1343
1478
  # 5. **\<Any string\>** - this allows you to hardcode remote address to any value
1344
- # you wish. Because Puma never uses this field anyway, it's format is
1479
+ # you wish. Because Puma never uses this field anyway, its format is
1345
1480
  # entirely in your hands.
1346
1481
  #
1347
1482
  # The default is +:socket+.
@@ -1380,7 +1515,7 @@ module Puma
1380
1515
 
1381
1516
  # When enabled, workers will be forked from worker 0 instead of from the master process.
1382
1517
  # This option is similar to `preload_app` because the app is preloaded before forking,
1383
- # but it is compatible with phased restart.
1518
+ # but it is compatible with phased restart when `preload_app!` is disabled.
1384
1519
  #
1385
1520
  # This option also enables the `refork` command (SIGURG), which optimizes copy-on-write performance
1386
1521
  # in a running app.
@@ -1388,13 +1523,41 @@ module Puma
1388
1523
  # A refork will automatically trigger once after the specified number of requests
1389
1524
  # (default 1000), or pass 0 to disable auto refork.
1390
1525
  #
1526
+ # The default is +nil+.
1527
+ #
1391
1528
  # @note This is experimental.
1392
1529
  # @note Cluster mode only.
1393
1530
  #
1531
+ # @example
1532
+ # fork_worker
1533
+ #
1394
1534
  def fork_worker(after_requests=1000)
1395
1535
  @options[:fork_worker] = Integer(after_requests)
1396
1536
  end
1397
1537
 
1538
+ # When enabled, a worker that reaches the given request count stops serving
1539
+ # requests and becomes a "mold", a template process that every new worker
1540
+ # is forked from. Each threshold promotes a new mold and reforks all workers
1541
+ # from it. Thresholds are per worker, counted from when that worker booted.
1542
+ #
1543
+ # This option also enables the `refork` command (SIGURG), which promotes
1544
+ # the busiest worker to a new mold at any time.
1545
+ #
1546
+ # Incompatible with `fork_worker`.
1547
+ #
1548
+ # The default is +nil+.
1549
+ #
1550
+ # @note This is experimental.
1551
+ # @note Cluster mode only.
1552
+ #
1553
+ # @example
1554
+ # mold_worker 1000, 2000, 4000
1555
+ #
1556
+ def mold_worker(*thresholds)
1557
+ thresholds = [1000] if thresholds.empty?
1558
+ @options[:mold_worker] = thresholds.map { |t| Integer(t) }
1559
+ end
1560
+
1398
1561
  # @deprecated Use {#max_keep_alive} instead.
1399
1562
  #
1400
1563
  def max_fast_inline(num_of_requests)
@@ -1404,13 +1567,15 @@ module Puma
1404
1567
 
1405
1568
  # The number of requests a keep-alive client can submit before being closed.
1406
1569
  # Note that some applications (server to server) may benefit from a very high
1407
- # number or Float::INFINITY.
1570
+ # number or +Float::INFINITY+.
1408
1571
  #
1409
- # The default is 999.
1572
+ # The default is +999+.
1410
1573
  #
1411
1574
  # @example
1412
1575
  # max_keep_alive 20
1413
1576
  #
1577
+ # @see enable_keep_alives
1578
+ #
1414
1579
  def max_keep_alive(num_of_requests)
1415
1580
  @options[:max_keep_alive] = Float(num_of_requests) unless num_of_requests.nil?
1416
1581
  end
@@ -1441,6 +1606,25 @@ module Puma
1441
1606
  @options[:enable_keep_alives] = enabled
1442
1607
  end
1443
1608
 
1609
+ # When +false+, request headers with underscores in their names are discarded.
1610
+ # When such headers are present, their names are exposed in
1611
+ # +env["puma.underscore_headers"]+ for auditing. This value is
1612
+ # client-triggerable, so rate-limit or sample external reporting.
1613
+ #
1614
+ # Requests containing +Content_Length+ or +Transfer_Encoding+ are always
1615
+ # rejected with 400 and the connection is closed, regardless of this option.
1616
+ # Clients must use the standard +Content-Length+ and +Transfer-Encoding+ names.
1617
+ #
1618
+ # The default is +true+, but will change to +false+ in a future major
1619
+ # version, when this env metadata will be removed.
1620
+ #
1621
+ # @example
1622
+ # allow_underscore_headers false
1623
+ #
1624
+ def allow_underscore_headers(allowed=true)
1625
+ @options[:allow_underscore_headers] = allowed
1626
+ end
1627
+
1444
1628
  # Specify the backend for the IO selector.
1445
1629
  #
1446
1630
  # Provided values will be passed directly to +NIO::Selector.new+, with the
@@ -1454,14 +1638,17 @@ module Puma
1454
1638
  #
1455
1639
  # The default is +:auto+.
1456
1640
  #
1641
+ # @example
1642
+ # io_selector_backend :epoll
1643
+ #
1457
1644
  # @see https://github.com/socketry/nio4r/blob/main/lib/nio/selector.rb
1458
1645
  #
1459
1646
  def io_selector_backend(backend)
1460
1647
  @options[:io_selector_backend] = backend.to_sym
1461
1648
  end
1462
1649
 
1463
- # Ensures +STDOUT+ and +STDERR+ is immediately flushed to the underlying
1464
- # operating system and is not buffered internally
1650
+ # Ensures +STDOUT+ and +STDERR+ are immediately flushed to the underlying
1651
+ # operating system and are not buffered internally.
1465
1652
  #
1466
1653
  # The default is +true+.
1467
1654
  #
@@ -1472,13 +1659,13 @@ module Puma
1472
1659
  @options[:mutate_stdout_and_stderr_to_sync_on_write] = enabled
1473
1660
  end
1474
1661
 
1475
- # Specify how big the request payload should be, in bytes.
1476
- # This limit is compared against Content-Length HTTP header.
1477
- # If the payload size (CONTENT_LENGTH) is larger than http_content_length_limit,
1478
- # HTTP 413 status code is returned.
1662
+ # Specify the maximum request payload size, in bytes. If the value of
1663
+ # the +Content-Length+ header exceeds this limit, an HTTP 413 status
1664
+ # code is returned.
1479
1665
  #
1480
- # When no Content-Length http header is present, it is compared against the
1481
- # size of the body of the request.
1666
+ # This limit is only applicable when the client sends a `Content-Length`
1667
+ # header, or `Transfer-Encoding` is `chunked`. Otherwise there is no
1668
+ # request body.
1482
1669
  #
1483
1670
  # The default is +nil+.
1484
1671
  #
@@ -1490,15 +1677,15 @@ module Puma
1490
1677
  end
1491
1678
 
1492
1679
  # Supported http methods, which will replace `Puma::Const::SUPPORTED_HTTP_METHODS`.
1493
- # The value of `:any` will allows all methods, otherwise, the value must be
1494
- # an array of strings. Note that methods are all uppercase.
1680
+ # The value of `:any` will allow all methods, otherwise, the value must be
1681
+ # an array of strings. Note that methods are all uppercase.
1495
1682
  #
1496
1683
  # `Puma::Const::SUPPORTED_HTTP_METHODS` is conservative, if you want a
1497
1684
  # complete set of methods, the methods defined by the
1498
1685
  # [IANA Method Registry](https://www.iana.org/assignments/http-methods/http-methods.xhtml)
1499
1686
  # are pre-defined as the constant `Puma::Const::IANA_HTTP_METHODS`.
1500
1687
  #
1501
- # @note If the `methods` value is `:any`, no method check with be performed,
1688
+ # @note If the `methods` value is `:any`, no method check will be performed,
1502
1689
  # similar to Puma v5 and earlier.
1503
1690
  #
1504
1691
  # @example Adds 'PROPFIND' to existing supported methods