puma 3.12.0 → 5.6.8

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 (94) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +1620 -439
  3. data/LICENSE +23 -20
  4. data/README.md +175 -63
  5. data/bin/puma-wild +3 -9
  6. data/docs/architecture.md +59 -21
  7. data/docs/compile_options.md +21 -0
  8. data/docs/deployment.md +69 -58
  9. data/docs/fork_worker.md +33 -0
  10. data/docs/jungle/README.md +9 -0
  11. data/{tools → docs}/jungle/rc.d/README.md +1 -1
  12. data/{tools → docs}/jungle/rc.d/puma +2 -2
  13. data/docs/kubernetes.md +66 -0
  14. data/docs/nginx.md +1 -1
  15. data/docs/plugins.md +22 -12
  16. data/docs/rails_dev_mode.md +28 -0
  17. data/docs/restart.md +47 -22
  18. data/docs/signals.md +13 -11
  19. data/docs/stats.md +142 -0
  20. data/docs/systemd.md +95 -120
  21. data/ext/puma_http11/PumaHttp11Service.java +2 -2
  22. data/ext/puma_http11/ext_help.h +1 -1
  23. data/ext/puma_http11/extconf.rb +57 -2
  24. data/ext/puma_http11/http11_parser.c +105 -117
  25. data/ext/puma_http11/http11_parser.h +1 -1
  26. data/ext/puma_http11/http11_parser.java.rl +22 -38
  27. data/ext/puma_http11/http11_parser.rl +4 -2
  28. data/ext/puma_http11/http11_parser_common.rl +4 -4
  29. data/ext/puma_http11/mini_ssl.c +347 -94
  30. data/ext/puma_http11/no_ssl/PumaHttp11Service.java +15 -0
  31. data/ext/puma_http11/org/jruby/puma/Http11.java +108 -116
  32. data/ext/puma_http11/org/jruby/puma/Http11Parser.java +84 -99
  33. data/ext/puma_http11/org/jruby/puma/MiniSSL.java +124 -71
  34. data/ext/puma_http11/puma_http11.c +35 -51
  35. data/lib/puma/app/status.rb +71 -49
  36. data/lib/puma/binder.rb +241 -143
  37. data/lib/puma/cli.rb +30 -18
  38. data/lib/puma/client.rb +379 -229
  39. data/lib/puma/cluster/worker.rb +173 -0
  40. data/lib/puma/cluster/worker_handle.rb +94 -0
  41. data/lib/puma/cluster.rb +249 -232
  42. data/lib/puma/commonlogger.rb +4 -2
  43. data/lib/puma/configuration.rb +63 -51
  44. data/lib/puma/const.rb +44 -21
  45. data/lib/puma/control_cli.rb +123 -73
  46. data/lib/puma/detect.rb +31 -2
  47. data/lib/puma/dsl.rb +631 -125
  48. data/lib/puma/error_logger.rb +104 -0
  49. data/lib/puma/events.rb +57 -31
  50. data/lib/puma/io_buffer.rb +9 -5
  51. data/lib/puma/jruby_restart.rb +2 -58
  52. data/lib/puma/json_serialization.rb +96 -0
  53. data/lib/puma/launcher.rb +196 -70
  54. data/lib/puma/minissl/context_builder.rb +81 -0
  55. data/lib/puma/minissl.rb +172 -65
  56. data/lib/puma/null_io.rb +20 -1
  57. data/lib/puma/plugin/tmp_restart.rb +2 -0
  58. data/lib/puma/plugin.rb +9 -13
  59. data/lib/puma/queue_close.rb +26 -0
  60. data/lib/puma/rack/builder.rb +5 -6
  61. data/lib/puma/rack/urlmap.rb +2 -0
  62. data/lib/puma/rack_default.rb +2 -0
  63. data/lib/puma/reactor.rb +87 -316
  64. data/lib/puma/request.rb +476 -0
  65. data/lib/puma/runner.rb +50 -55
  66. data/lib/puma/server.rb +307 -695
  67. data/lib/puma/single.rb +13 -67
  68. data/lib/puma/state_file.rb +49 -7
  69. data/lib/puma/systemd.rb +46 -0
  70. data/lib/puma/thread_pool.rb +134 -82
  71. data/lib/puma/util.rb +34 -10
  72. data/lib/puma.rb +56 -0
  73. data/lib/rack/handler/puma.rb +8 -6
  74. data/lib/rack/version_restriction.rb +15 -0
  75. data/tools/Dockerfile +16 -0
  76. data/tools/trickletest.rb +0 -1
  77. metadata +49 -32
  78. data/ext/puma_http11/io_buffer.c +0 -155
  79. data/lib/puma/accept_nonblock.rb +0 -23
  80. data/lib/puma/compat.rb +0 -14
  81. data/lib/puma/convenient.rb +0 -23
  82. data/lib/puma/daemon_ext.rb +0 -31
  83. data/lib/puma/delegation.rb +0 -11
  84. data/lib/puma/java_io_buffer.rb +0 -45
  85. data/lib/puma/rack/backports/uri/common_193.rb +0 -33
  86. data/lib/puma/tcp_logger.rb +0 -39
  87. data/tools/jungle/README.md +0 -19
  88. data/tools/jungle/init.d/README.md +0 -61
  89. data/tools/jungle/init.d/puma +0 -421
  90. data/tools/jungle/init.d/run-puma +0 -18
  91. data/tools/jungle/upstart/README.md +0 -61
  92. data/tools/jungle/upstart/puma-manager.conf +0 -31
  93. data/tools/jungle/upstart/puma.conf +0 -69
  94. /data/{tools → docs}/jungle/rc.d/puma.conf +0 -0
@@ -1,73 +1,95 @@
1
+ # frozen_string_literal: true
2
+ require 'puma/json_serialization'
3
+
1
4
  module Puma
2
5
  module App
6
+ # Check out {#call}'s source code to see what actions this web application
7
+ # can respond to.
3
8
  class Status
4
- def initialize(cli)
5
- @cli = cli
6
- @auth_token = nil
7
- end
8
9
  OK_STATUS = '{ "status": "ok" }'.freeze
9
10
 
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]]
11
+ # @param launcher [::Puma::Launcher]
12
+ # @param token [String, nil] the token used for authentication
13
+ #
14
+ def initialize(launcher, token = nil)
15
+ @launcher = launcher
16
+ @auth_token = token
24
17
  end
25
18
 
19
+ # most commands call methods in `::Puma::Launcher` based on command in
20
+ # `env['PATH_INFO']`
26
21
  def call(env)
27
22
  unless authenticate(env)
28
23
  return rack_response(403, 'Invalid auth token', 'text/plain')
29
24
  end
30
25
 
31
- case env['PATH_INFO']
32
- when /\/stop$/
33
- @cli.stop
34
- return rack_response(200, OK_STATUS)
26
+ # resp_type is processed by following case statement, return
27
+ # is a number (status) or a string used as the body of a 200 response
28
+ resp_type =
29
+ case env['PATH_INFO'][/\/([^\/]+)$/, 1]
30
+ when 'stop'
31
+ @launcher.stop ; 200
35
32
 
36
- when /\/halt$/
37
- @cli.halt
38
- return rack_response(200, OK_STATUS)
33
+ when 'halt'
34
+ @launcher.halt ; 200
39
35
 
40
- when /\/restart$/
41
- @cli.restart
42
- return rack_response(200, OK_STATUS)
36
+ when 'restart'
37
+ @launcher.restart ; 200
43
38
 
44
- when /\/phased-restart$/
45
- if !@cli.phased_restart
46
- return rack_response(404, '{ "error": "phased restart not available" }')
47
- else
48
- return rack_response(200, OK_STATUS)
49
- end
39
+ when 'phased-restart'
40
+ @launcher.phased_restart ? 200 : 404
41
+
42
+ when 'refork'
43
+ @launcher.refork ? 200 : 404
44
+
45
+ when 'reload-worker-directory'
46
+ @launcher.send(:reload_worker_directory) ? 200 : 404
47
+
48
+ when 'gc'
49
+ GC.start ; 200
50
+
51
+ when 'gc-stats'
52
+ Puma::JSONSerialization.generate GC.stat
53
+
54
+ when 'stats'
55
+ Puma::JSONSerialization.generate @launcher.stats
56
+
57
+ when 'thread-backtraces'
58
+ backtraces = []
59
+ @launcher.thread_status do |name, backtrace|
60
+ backtraces << { name: name, backtrace: backtrace }
61
+ end
62
+ Puma::JSONSerialization.generate backtraces
50
63
 
51
- when /\/reload-worker-directory$/
52
- if !@cli.send(:reload_worker_directory)
53
- return rack_response(404, '{ "error": "reload_worker_directory not available" }')
54
64
  else
55
- return rack_response(200, OK_STATUS)
65
+ return rack_response(404, "Unsupported action", 'text/plain')
56
66
  end
57
67
 
58
- when /\/gc$/
59
- GC.start
60
- return rack_response(200, OK_STATUS)
68
+ case resp_type
69
+ when String
70
+ rack_response 200, resp_type
71
+ when 200
72
+ rack_response 200, OK_STATUS
73
+ when 404
74
+ str = env['PATH_INFO'][/\/(\S+)/, 1].tr '-', '_'
75
+ rack_response 404, "{ \"error\": \"#{str} not available\" }"
76
+ end
77
+ end
61
78
 
62
- when /\/gc-stats$/
63
- json = "{" + GC.stat.map { |k, v| "\"#{k}\": #{v}" }.join(",") + "}"
64
- return rack_response(200, json)
79
+ private
65
80
 
66
- when /\/stats$/
67
- return rack_response(200, @cli.stats)
68
- else
69
- rack_response 404, "Unsupported action", 'text/plain'
70
- end
81
+ def authenticate(env)
82
+ return true unless @auth_token
83
+ env['QUERY_STRING'].to_s.split(/&;/).include?("token=#{@auth_token}")
84
+ end
85
+
86
+ def rack_response(status, body, content_type='application/json')
87
+ headers = {
88
+ 'Content-Type' => content_type,
89
+ 'Content-Length' => body.bytesize.to_s
90
+ }
91
+
92
+ [status, headers, [body]]
71
93
  end
72
94
  end
73
95
  end