actionpack 7.1.5.1 → 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 (177) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +308 -523
  3. data/README.rdoc +1 -1
  4. data/lib/abstract_controller/asset_paths.rb +6 -2
  5. data/lib/abstract_controller/base.rb +104 -105
  6. data/lib/abstract_controller/caching/fragments.rb +50 -53
  7. data/lib/abstract_controller/caching.rb +8 -3
  8. data/lib/abstract_controller/callbacks.rb +70 -62
  9. data/lib/abstract_controller/collector.rb +7 -7
  10. data/lib/abstract_controller/deprecator.rb +2 -0
  11. data/lib/abstract_controller/error.rb +2 -0
  12. data/lib/abstract_controller/helpers.rb +71 -84
  13. data/lib/abstract_controller/logger.rb +4 -1
  14. data/lib/abstract_controller/railties/routes_helpers.rb +2 -0
  15. data/lib/abstract_controller/rendering.rb +13 -13
  16. data/lib/abstract_controller/translation.rb +12 -13
  17. data/lib/abstract_controller/url_for.rb +8 -6
  18. data/lib/abstract_controller.rb +2 -0
  19. data/lib/action_controller/api/api_rendering.rb +2 -0
  20. data/lib/action_controller/api.rb +76 -72
  21. data/lib/action_controller/base.rb +199 -126
  22. data/lib/action_controller/caching.rb +16 -14
  23. data/lib/action_controller/deprecator.rb +2 -0
  24. data/lib/action_controller/form_builder.rb +21 -18
  25. data/lib/action_controller/log_subscriber.rb +23 -2
  26. data/lib/action_controller/metal/allow_browser.rb +133 -0
  27. data/lib/action_controller/metal/basic_implicit_render.rb +2 -0
  28. data/lib/action_controller/metal/conditional_get.rb +217 -175
  29. data/lib/action_controller/metal/content_security_policy.rb +25 -24
  30. data/lib/action_controller/metal/cookies.rb +4 -2
  31. data/lib/action_controller/metal/data_streaming.rb +72 -63
  32. data/lib/action_controller/metal/default_headers.rb +5 -3
  33. data/lib/action_controller/metal/etag_with_flash.rb +3 -1
  34. data/lib/action_controller/metal/etag_with_template_digest.rb +17 -15
  35. data/lib/action_controller/metal/exceptions.rb +16 -9
  36. data/lib/action_controller/metal/flash.rb +13 -14
  37. data/lib/action_controller/metal/head.rb +15 -11
  38. data/lib/action_controller/metal/helpers.rb +63 -55
  39. data/lib/action_controller/metal/http_authentication.rb +209 -201
  40. data/lib/action_controller/metal/implicit_render.rb +17 -15
  41. data/lib/action_controller/metal/instrumentation.rb +16 -14
  42. data/lib/action_controller/metal/live.rb +177 -128
  43. data/lib/action_controller/metal/logging.rb +6 -4
  44. data/lib/action_controller/metal/mime_responds.rb +151 -142
  45. data/lib/action_controller/metal/parameter_encoding.rb +34 -32
  46. data/lib/action_controller/metal/params_wrapper.rb +57 -59
  47. data/lib/action_controller/metal/permissions_policy.rb +22 -12
  48. data/lib/action_controller/metal/rate_limiting.rb +92 -0
  49. data/lib/action_controller/metal/redirecting.rb +213 -94
  50. data/lib/action_controller/metal/renderers.rb +78 -57
  51. data/lib/action_controller/metal/rendering.rb +111 -77
  52. data/lib/action_controller/metal/request_forgery_protection.rb +182 -143
  53. data/lib/action_controller/metal/rescue.rb +20 -9
  54. data/lib/action_controller/metal/streaming.rb +118 -195
  55. data/lib/action_controller/metal/strong_parameters.rb +720 -530
  56. data/lib/action_controller/metal/testing.rb +2 -0
  57. data/lib/action_controller/metal/url_for.rb +17 -15
  58. data/lib/action_controller/metal.rb +86 -60
  59. data/lib/action_controller/railtie.rb +36 -15
  60. data/lib/action_controller/railties/helpers.rb +2 -0
  61. data/lib/action_controller/renderer.rb +41 -36
  62. data/lib/action_controller/structured_event_subscriber.rb +116 -0
  63. data/lib/action_controller/template_assertions.rb +4 -2
  64. data/lib/action_controller/test_case.rb +160 -131
  65. data/lib/action_controller.rb +5 -1
  66. data/lib/action_dispatch/constants.rb +8 -0
  67. data/lib/action_dispatch/deprecator.rb +2 -0
  68. data/lib/action_dispatch/http/cache.rb +163 -35
  69. data/lib/action_dispatch/http/content_disposition.rb +2 -0
  70. data/lib/action_dispatch/http/content_security_policy.rb +54 -39
  71. data/lib/action_dispatch/http/filter_parameters.rb +14 -8
  72. data/lib/action_dispatch/http/filter_redirect.rb +22 -1
  73. data/lib/action_dispatch/http/headers.rb +22 -22
  74. data/lib/action_dispatch/http/mime_negotiation.rb +89 -41
  75. data/lib/action_dispatch/http/mime_type.rb +25 -21
  76. data/lib/action_dispatch/http/mime_types.rb +3 -0
  77. data/lib/action_dispatch/http/param_builder.rb +187 -0
  78. data/lib/action_dispatch/http/param_error.rb +26 -0
  79. data/lib/action_dispatch/http/parameters.rb +14 -12
  80. data/lib/action_dispatch/http/permissions_policy.rb +25 -36
  81. data/lib/action_dispatch/http/query_parser.rb +55 -0
  82. data/lib/action_dispatch/http/rack_cache.rb +2 -0
  83. data/lib/action_dispatch/http/request.rb +141 -92
  84. data/lib/action_dispatch/http/response.rb +137 -77
  85. data/lib/action_dispatch/http/upload.rb +18 -16
  86. data/lib/action_dispatch/http/url.rb +187 -89
  87. data/lib/action_dispatch/journey/formatter.rb +21 -9
  88. data/lib/action_dispatch/journey/gtg/builder.rb +4 -3
  89. data/lib/action_dispatch/journey/gtg/simulator.rb +34 -11
  90. data/lib/action_dispatch/journey/gtg/transition_table.rb +47 -53
  91. data/lib/action_dispatch/journey/nfa/dot.rb +2 -0
  92. data/lib/action_dispatch/journey/nodes/node.rb +8 -6
  93. data/lib/action_dispatch/journey/parser.rb +99 -195
  94. data/lib/action_dispatch/journey/path/pattern.rb +4 -1
  95. data/lib/action_dispatch/journey/route.rb +54 -38
  96. data/lib/action_dispatch/journey/router/utils.rb +22 -27
  97. data/lib/action_dispatch/journey/router.rb +63 -83
  98. data/lib/action_dispatch/journey/routes.rb +11 -2
  99. data/lib/action_dispatch/journey/scanner.rb +46 -42
  100. data/lib/action_dispatch/journey/visitors.rb +57 -23
  101. data/lib/action_dispatch/journey/visualizer/fsm.js +4 -6
  102. data/lib/action_dispatch/journey.rb +2 -0
  103. data/lib/action_dispatch/log_subscriber.rb +7 -1
  104. data/lib/action_dispatch/middleware/actionable_exceptions.rb +2 -0
  105. data/lib/action_dispatch/middleware/assume_ssl.rb +8 -5
  106. data/lib/action_dispatch/middleware/callbacks.rb +3 -1
  107. data/lib/action_dispatch/middleware/cookies.rb +125 -106
  108. data/lib/action_dispatch/middleware/debug_exceptions.rb +37 -8
  109. data/lib/action_dispatch/middleware/debug_locks.rb +15 -13
  110. data/lib/action_dispatch/middleware/debug_view.rb +13 -5
  111. data/lib/action_dispatch/middleware/exception_wrapper.rb +18 -23
  112. data/lib/action_dispatch/middleware/executor.rb +19 -4
  113. data/lib/action_dispatch/middleware/flash.rb +63 -51
  114. data/lib/action_dispatch/middleware/host_authorization.rb +17 -15
  115. data/lib/action_dispatch/middleware/public_exceptions.rb +14 -12
  116. data/lib/action_dispatch/middleware/reloader.rb +5 -3
  117. data/lib/action_dispatch/middleware/remote_ip.rb +87 -77
  118. data/lib/action_dispatch/middleware/request_id.rb +16 -10
  119. data/lib/action_dispatch/middleware/server_timing.rb +4 -2
  120. data/lib/action_dispatch/middleware/session/abstract_store.rb +2 -0
  121. data/lib/action_dispatch/middleware/session/cache_store.rb +30 -8
  122. data/lib/action_dispatch/middleware/session/cookie_store.rb +27 -26
  123. data/lib/action_dispatch/middleware/session/mem_cache_store.rb +7 -3
  124. data/lib/action_dispatch/middleware/show_exceptions.rb +16 -16
  125. data/lib/action_dispatch/middleware/ssl.rb +53 -40
  126. data/lib/action_dispatch/middleware/stack.rb +11 -10
  127. data/lib/action_dispatch/middleware/static.rb +33 -31
  128. data/lib/action_dispatch/middleware/templates/rescues/_copy_button.html.erb +1 -0
  129. data/lib/action_dispatch/middleware/templates/rescues/_source.html.erb +3 -5
  130. data/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb +9 -5
  131. data/lib/action_dispatch/middleware/templates/rescues/blocked_host.html.erb +1 -0
  132. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb +1 -0
  133. data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.html.erb +4 -0
  134. data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.text.erb +3 -0
  135. data/lib/action_dispatch/middleware/templates/rescues/layout.erb +50 -0
  136. data/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.html.erb +1 -0
  137. data/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb +1 -0
  138. data/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb +1 -0
  139. data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +1 -0
  140. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.html.erb +1 -0
  141. data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +1 -1
  142. data/lib/action_dispatch/railtie.rb +23 -3
  143. data/lib/action_dispatch/request/session.rb +24 -21
  144. data/lib/action_dispatch/request/utils.rb +11 -3
  145. data/lib/action_dispatch/routing/endpoint.rb +2 -0
  146. data/lib/action_dispatch/routing/inspector.rb +85 -60
  147. data/lib/action_dispatch/routing/mapper.rb +1031 -851
  148. data/lib/action_dispatch/routing/polymorphic_routes.rb +69 -62
  149. data/lib/action_dispatch/routing/redirection.rb +47 -39
  150. data/lib/action_dispatch/routing/route_set.rb +79 -56
  151. data/lib/action_dispatch/routing/routes_proxy.rb +7 -4
  152. data/lib/action_dispatch/routing/url_for.rb +130 -125
  153. data/lib/action_dispatch/routing.rb +150 -148
  154. data/lib/action_dispatch/structured_event_subscriber.rb +20 -0
  155. data/lib/action_dispatch/system_test_case.rb +91 -81
  156. data/lib/action_dispatch/system_testing/browser.rb +16 -23
  157. data/lib/action_dispatch/system_testing/driver.rb +2 -0
  158. data/lib/action_dispatch/system_testing/server.rb +2 -0
  159. data/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb +34 -23
  160. data/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb +2 -0
  161. data/lib/action_dispatch/testing/assertion_response.rb +9 -7
  162. data/lib/action_dispatch/testing/assertions/response.rb +52 -25
  163. data/lib/action_dispatch/testing/assertions/routing.rb +168 -87
  164. data/lib/action_dispatch/testing/assertions.rb +2 -0
  165. data/lib/action_dispatch/testing/integration.rb +233 -223
  166. data/lib/action_dispatch/testing/request_encoder.rb +11 -9
  167. data/lib/action_dispatch/testing/test_helpers/page_dump_helper.rb +35 -0
  168. data/lib/action_dispatch/testing/test_process.rb +11 -8
  169. data/lib/action_dispatch/testing/test_request.rb +3 -1
  170. data/lib/action_dispatch/testing/test_response.rb +27 -26
  171. data/lib/action_dispatch.rb +36 -32
  172. data/lib/action_pack/gem_version.rb +6 -4
  173. data/lib/action_pack/version.rb +3 -1
  174. data/lib/action_pack.rb +17 -16
  175. metadata +36 -32
  176. data/lib/action_dispatch/journey/parser.y +0 -50
  177. data/lib/action_dispatch/journey/parser_extras.rb +0 -31
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  module ActionController # :nodoc:
4
6
  module ContentSecurityPolicy
5
7
  extend ActiveSupport::Concern
@@ -13,29 +15,28 @@ module ActionController # :nodoc:
13
15
  end
14
16
 
15
17
  module ClassMethods
16
- # Overrides parts of the globally configured +Content-Security-Policy+
17
- # header:
18
+ # Overrides parts of the globally configured `Content-Security-Policy` header:
18
19
  #
19
- # class PostsController < ApplicationController
20
- # content_security_policy do |policy|
21
- # policy.base_uri "https://www.example.com"
20
+ # class PostsController < ApplicationController
21
+ # content_security_policy do |policy|
22
+ # policy.base_uri "https://www.example.com"
23
+ # end
22
24
  # end
23
- # end
24
25
  #
25
- # Options can be passed similar to +before_action+. For example, pass
26
- # <tt>only: :index</tt> to override the header on the index action only:
26
+ # Options can be passed similar to `before_action`. For example, pass `only:
27
+ # :index` to override the header on the index action only:
27
28
  #
28
- # class PostsController < ApplicationController
29
- # content_security_policy(only: :index) do |policy|
30
- # policy.default_src :self, :https
29
+ # class PostsController < ApplicationController
30
+ # content_security_policy(only: :index) do |policy|
31
+ # policy.default_src :self, :https
32
+ # end
31
33
  # end
32
- # end
33
34
  #
34
- # Pass +false+ to remove the +Content-Security-Policy+ header:
35
+ # Pass `false` to remove the `Content-Security-Policy` header:
35
36
  #
36
- # class PostsController < ApplicationController
37
- # content_security_policy false, only: :index
38
- # end
37
+ # class PostsController < ApplicationController
38
+ # content_security_policy false, only: :index
39
+ # end
39
40
  def content_security_policy(enabled = true, **options, &block)
40
41
  before_action(options) do
41
42
  if block_given?
@@ -50,18 +51,18 @@ module ActionController # :nodoc:
50
51
  end
51
52
  end
52
53
 
53
- # Overrides the globally configured +Content-Security-Policy-Report-Only+
54
+ # Overrides the globally configured `Content-Security-Policy-Report-Only`
54
55
  # header:
55
56
  #
56
- # class PostsController < ApplicationController
57
- # content_security_policy_report_only only: :index
58
- # end
57
+ # class PostsController < ApplicationController
58
+ # content_security_policy_report_only only: :index
59
+ # end
59
60
  #
60
- # Pass +false+ to remove the +Content-Security-Policy-Report-Only+ header:
61
+ # Pass `false` to remove the `Content-Security-Policy-Report-Only` header:
61
62
  #
62
- # class PostsController < ApplicationController
63
- # content_security_policy_report_only false, only: :index
64
- # end
63
+ # class PostsController < ApplicationController
64
+ # content_security_policy_report_only false, only: :index
65
+ # end
65
66
  def content_security_policy_report_only(report_only = true, **options)
66
67
  before_action(options) do
67
68
  request.content_security_policy_report_only = report_only
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  module ActionController # :nodoc:
4
6
  module Cookies
5
7
  extend ActiveSupport::Concern
@@ -9,8 +11,8 @@ module ActionController # :nodoc:
9
11
  end
10
12
 
11
13
  private
12
- # The cookies for the current request. See ActionDispatch::Cookies for
13
- # more information.
14
+ # The cookies for the current request. See ActionDispatch::Cookies for more
15
+ # information.
14
16
  def cookies # :doc:
15
17
  request.cookie_jar
16
18
  end
@@ -1,10 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  require "action_controller/metal/exceptions"
4
6
  require "action_dispatch/http/content_disposition"
5
7
 
6
8
  module ActionController # :nodoc:
7
- # = Action Controller Data \Streaming
9
+ # # Action Controller Data Streaming
8
10
  #
9
11
  # Methods for sending arbitrary data and for streaming files to the browser,
10
12
  # instead of rendering.
@@ -17,57 +19,61 @@ module ActionController # :nodoc:
17
19
  DEFAULT_SEND_FILE_DISPOSITION = "attachment" # :nodoc:
18
20
 
19
21
  private
20
- # Sends the file. This uses a server-appropriate method (such as +X-Sendfile+)
21
- # via the +Rack::Sendfile+ middleware. The header to use is set via
22
- # +config.action_dispatch.x_sendfile_header+.
23
- # Your server can also configure this for you by setting the +X-Sendfile-Type+ header.
24
- #
25
- # Be careful to sanitize the path parameter if it is coming from a web
26
- # page. <tt>send_file(params[:path])</tt> allows a malicious user to
27
- # download any file on your server.
28
- #
29
- # Options:
30
- # * <tt>:filename</tt> - suggests a filename for the browser to use.
31
- # Defaults to <tt>File.basename(path)</tt>.
32
- # * <tt>:type</tt> - specifies an HTTP content type.
33
- # You can specify either a string or a symbol for a registered type with <tt>Mime::Type.register</tt>, for example +:json+.
34
- # If omitted, the type will be inferred from the file extension specified in <tt>:filename</tt>.
35
- # If no content type is registered for the extension, the default type +application/octet-stream+ will be used.
36
- # * <tt>:disposition</tt> - specifies whether the file will be shown inline or downloaded.
37
- # Valid values are <tt>"inline"</tt> and <tt>"attachment"</tt> (default).
38
- # * <tt>:status</tt> - specifies the status code to send with the response. Defaults to 200.
39
- # * <tt>:url_based_filename</tt> - set to +true+ if you want the browser to guess the filename from
40
- # the URL, which is necessary for i18n filenames on certain browsers
41
- # (setting <tt>:filename</tt> overrides this option).
42
- #
43
- # The default +Content-Type+ and +Content-Disposition+ headers are
44
- # set to download arbitrary binary files in as many browsers as
45
- # possible. IE versions 4, 5, 5.5, and 6 are all known to have
46
- # a variety of quirks (especially when downloading over SSL).
22
+ # Sends the file. This uses a server-appropriate method (such as `X-Sendfile`)
23
+ # via the `Rack::Sendfile` middleware. The header to use is set via
24
+ # `config.action_dispatch.x_sendfile_header`. Your server can also configure
25
+ # this for you by setting the `X-Sendfile-Type` header.
26
+ #
27
+ # Be careful to sanitize the path parameter if it is coming from a web page.
28
+ # `send_file(params[:path])` allows a malicious user to download any file on
29
+ # your server.
30
+ #
31
+ # #### Options:
32
+ #
33
+ # * `:filename` - suggests a filename for the browser to use. Defaults to
34
+ # `File.basename(path)`.
35
+ # * `:type` - specifies an HTTP content type. You can specify either a string
36
+ # or a symbol for a registered type with `Mime::Type.register`, for example
37
+ # `:json`. If omitted, the type will be inferred from the file extension
38
+ # specified in `:filename`. If no content type is registered for the
39
+ # extension, the default type `application/octet-stream` will be used.
40
+ # * `:disposition` - specifies whether the file will be shown inline or
41
+ # downloaded. Valid values are `"inline"` and `"attachment"` (default).
42
+ # * `:status` - specifies the status code to send with the response. Defaults
43
+ # to 200.
44
+ # * `:url_based_filename` - set to `true` if you want the browser to guess the
45
+ # filename from the URL, which is necessary for i18n filenames on certain
46
+ # browsers (setting `:filename` overrides this option).
47
+ #
48
+ #
49
+ # The default `Content-Type` and `Content-Disposition` headers are set to
50
+ # download arbitrary binary files in as many browsers as possible. IE versions
51
+ # 4, 5, 5.5, and 6 are all known to have a variety of quirks (especially when
52
+ # downloading over SSL).
47
53
  #
48
54
  # Simple download:
49
55
  #
50
- # send_file '/path/to.zip'
56
+ # send_file '/path/to.zip'
51
57
  #
52
58
  # Show a JPEG in the browser:
53
59
  #
54
- # send_file '/path/to.jpeg', type: 'image/jpeg', disposition: 'inline'
60
+ # send_file '/path/to.jpeg', type: 'image/jpeg', disposition: 'inline'
55
61
  #
56
62
  # Show a 404 page in the browser:
57
63
  #
58
- # send_file '/path/to/404.html', type: 'text/html; charset=utf-8', disposition: 'inline', status: 404
64
+ # send_file '/path/to/404.html', type: 'text/html; charset=utf-8', disposition: 'inline', status: 404
59
65
  #
60
- # You can use other <tt>Content-*</tt> HTTP headers to provide additional
61
- # information to the client. See MDN for a
62
- # {list of HTTP headers}[https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers].
66
+ # You can use other `Content-*` HTTP headers to provide additional information
67
+ # to the client. See MDN for a [list of HTTP
68
+ # headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers).
63
69
  #
64
- # Also be aware that the document may be cached by proxies and browsers.
65
- # The +Pragma+ and +Cache-Control+ headers declare how the file may be cached
66
- # by intermediaries. They default to require clients to validate with
67
- # the server before releasing cached responses. See
68
- # https://www.mnot.net/cache_docs/ for an overview of web caching and
69
- # {RFC 9111}[https://www.rfc-editor.org/rfc/rfc9111.html#name-cache-control]
70
- # for the +Cache-Control+ header spec.
70
+ # Also be aware that the document may be cached by proxies and browsers. The
71
+ # `Pragma` and `Cache-Control` headers declare how the file may be cached by
72
+ # intermediaries. They default to require clients to validate with the server
73
+ # before releasing cached responses. See https://www.mnot.net/cache_docs/ for an
74
+ # overview of web caching and [RFC
75
+ # 9111](https://www.rfc-editor.org/rfc/rfc9111.html#name-cache-control) for the
76
+ # `Cache-Control` header spec.
71
77
  def send_file(path, options = {}) # :doc:
72
78
  raise MissingFile, "Cannot read file #{path}" unless File.file?(path) && File.readable?(path)
73
79
 
@@ -79,35 +85,40 @@ module ActionController # :nodoc:
79
85
  response.send_file path
80
86
  end
81
87
 
82
- # Sends the given binary data to the browser. This method is similar to
83
- # <tt>render plain: data</tt>, but also allows you to specify whether
84
- # the browser should display the response as a file attachment (i.e. in a
85
- # download dialog) or as inline data. You may also set the content type,
86
- # the file name, and other things.
87
- #
88
- # Options:
89
- # * <tt>:filename</tt> - suggests a filename for the browser to use.
90
- # * <tt>:type</tt> - specifies an HTTP content type. Defaults to +application/octet-stream+.
91
- # You can specify either a string or a symbol for a registered type with <tt>Mime::Type.register</tt>, for example +:json+.
92
- # If omitted, type will be inferred from the file extension specified in <tt>:filename</tt>.
93
- # If no content type is registered for the extension, the default type +application/octet-stream+ will be used.
94
- # * <tt>:disposition</tt> - specifies whether the file will be shown inline or downloaded.
95
- # Valid values are <tt>"inline"</tt> and <tt>"attachment"</tt> (default).
96
- # * <tt>:status</tt> - specifies the status code to send with the response. Defaults to 200.
88
+ # Sends the given binary data to the browser. This method is similar to `render
89
+ # plain: data`, but also allows you to specify whether the browser should
90
+ # display the response as a file attachment (i.e. in a download dialog) or as
91
+ # inline data. You may also set the content type, the file name, and other
92
+ # things.
93
+ #
94
+ # #### Options:
95
+ #
96
+ # * `:filename` - suggests a filename for the browser to use.
97
+ # * `:type` - specifies an HTTP content type. Defaults to
98
+ # `application/octet-stream`. You can specify either a string or a symbol
99
+ # for a registered type with `Mime::Type.register`, for example `:json`. If
100
+ # omitted, type will be inferred from the file extension specified in
101
+ # `:filename`. If no content type is registered for the extension, the
102
+ # default type `application/octet-stream` will be used.
103
+ # * `:disposition` - specifies whether the file will be shown inline or
104
+ # downloaded. Valid values are `"inline"` and `"attachment"` (default).
105
+ # * `:status` - specifies the status code to send with the response. Defaults
106
+ # to 200.
107
+ #
97
108
  #
98
109
  # Generic data download:
99
110
  #
100
- # send_data buffer
111
+ # send_data buffer
101
112
  #
102
113
  # Download a dynamically-generated tarball:
103
114
  #
104
- # send_data generate_tgz('dir'), filename: 'dir.tgz'
115
+ # send_data generate_tgz('dir'), filename: 'dir.tgz'
105
116
  #
106
117
  # Display an image Active Record in the browser:
107
118
  #
108
- # send_data image.data, type: image.content_type, disposition: 'inline'
119
+ # send_data image.data, type: image.content_type, disposition: 'inline'
109
120
  #
110
- # See +send_file+ for more information on HTTP <tt>Content-*</tt> headers and caching.
121
+ # See `send_file` for more information on HTTP `Content-*` headers and caching.
111
122
  def send_data(data, options = {}) # :doc:
112
123
  send_file_headers! options
113
124
  render options.slice(:status, :content_type).merge(body: data)
@@ -123,9 +134,7 @@ module ActionController # :nodoc:
123
134
  raise ArgumentError, ":type option required" if content_type.nil?
124
135
 
125
136
  if content_type.is_a?(Symbol)
126
- extension = Mime[content_type]
127
- raise ArgumentError, "Unknown MIME type #{options[:type]}" unless extension
128
- self.content_type = extension
137
+ self.content_type = content_type
129
138
  else
130
139
  if !type_provided && options[:filename]
131
140
  # If type wasn't provided, try guessing from file extension.
@@ -1,10 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  module ActionController
4
- # = Action Controller Default Headers
6
+ # # Action Controller Default Headers
5
7
  #
6
- # Allows configuring default headers that will be automatically merged into
7
- # each response.
8
+ # Allows configuring default headers that will be automatically merged into each
9
+ # response.
8
10
  module DefaultHeaders
9
11
  extend ActiveSupport::Concern
10
12
 
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  module ActionController
4
- # = Action Controller Etag With \Flash
6
+ # # Action Controller Etag With Flash
5
7
  #
6
8
  # When you're using the flash, it's generally used as a conditional on the view.
7
9
  # This means the content of the view depends on the flash. Which in turn means
@@ -1,24 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  module ActionController
4
- # = Action Controller Etag With Template \Digest
6
+ # # Action Controller Etag With Template Digest
5
7
  #
6
- # When our views change, they should bubble up into HTTP cache freshness
7
- # and bust browser caches. So the template digest for the current action
8
- # is automatically included in the ETag.
8
+ # When our views change, they should bubble up into HTTP cache freshness and
9
+ # bust browser caches. So the template digest for the current action is
10
+ # automatically included in the ETag.
9
11
  #
10
12
  # Enabled by default for apps that use Action View. Disable by setting
11
13
  #
12
- # config.action_controller.etag_with_template_digest = false
14
+ # config.action_controller.etag_with_template_digest = false
13
15
  #
14
- # Override the template to digest by passing +:template+ to +fresh_when+
15
- # and +stale?+ calls. For example:
16
+ # Override the template to digest by passing `:template` to `fresh_when` and
17
+ # `stale?` calls. For example:
16
18
  #
17
- # # We're going to render widgets/show, not posts/show
18
- # fresh_when @post, template: 'widgets/show'
19
+ # # We're going to render widgets/show, not posts/show
20
+ # fresh_when @post, template: 'widgets/show'
19
21
  #
20
- # # We're not going to render a template, so omit it from the ETag.
21
- # fresh_when @post, template: false
22
+ # # We're not going to render a template, so omit it from the ETag.
23
+ # fresh_when @post, template: false
22
24
  #
23
25
  module EtagWithTemplateDigest
24
26
  extend ActiveSupport::Concern
@@ -40,10 +42,10 @@ module ActionController
40
42
  end
41
43
  end
42
44
 
43
- # Pick the template digest to include in the ETag. If the +:template+ option
44
- # is present, use the named template. If +:template+ is +nil+ or absent, use
45
- # the default controller/action template. If +:template+ is false, omit the
46
- # template digest from the ETag.
45
+ # Pick the template digest to include in the ETag. If the `:template` option is
46
+ # present, use the named template. If `:template` is `nil` or absent, use the
47
+ # default controller/action template. If `:template` is false, omit the template
48
+ # digest from the ETag.
47
49
  def pick_template_for_etag(options)
48
50
  unless options[:template] == false
49
51
  options[:template] || lookup_context.find_all(action_name, _prefixes).first&.virtual_path
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  module ActionController
4
6
  class ActionControllerError < StandardError # :nodoc:
5
7
  end
@@ -73,16 +75,16 @@ module ActionController
73
75
  class UnknownFormat < ActionControllerError # :nodoc:
74
76
  end
75
77
 
76
- # Raised when a nested respond_to is triggered and the content types of each
77
- # are incompatible. For example:
78
+ # Raised when a nested respond_to is triggered and the content types of each are
79
+ # incompatible. For example:
78
80
  #
79
- # respond_to do |outer_type|
80
- # outer_type.js do
81
- # respond_to do |inner_type|
82
- # inner_type.html { render body: "HTML" }
83
- # end
84
- # end
85
- # end
81
+ # respond_to do |outer_type|
82
+ # outer_type.js do
83
+ # respond_to do |inner_type|
84
+ # inner_type.html { render body: "HTML" }
85
+ # end
86
+ # end
87
+ # end
86
88
  class RespondToMismatchError < ActionControllerError
87
89
  DEFAULT_MESSAGE = "respond_to was called multiple times and matched with conflicting formats in this action. Please note that you may only call respond_to and match on a single format per action."
88
90
 
@@ -101,4 +103,9 @@ module ActionController
101
103
  super(message)
102
104
  end
103
105
  end
106
+
107
+ # Raised when a Rate Limit is exceeded by too many requests within a period of
108
+ # time.
109
+ class TooManyRequests < ActionControllerError
110
+ end
104
111
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  module ActionController # :nodoc:
4
6
  module Flash
5
7
  extend ActiveSupport::Concern
@@ -13,19 +15,19 @@ module ActionController # :nodoc:
13
15
 
14
16
  module ClassMethods
15
17
  # Creates new flash types. You can pass as many types as you want to create
16
- # flash types other than the default <tt>alert</tt> and <tt>notice</tt> in
17
- # your controllers and views. For instance:
18
+ # flash types other than the default `alert` and `notice` in your controllers
19
+ # and views. For instance:
18
20
  #
19
- # # in application_controller.rb
20
- # class ApplicationController < ActionController::Base
21
- # add_flash_types :warning
22
- # end
21
+ # # in application_controller.rb
22
+ # class ApplicationController < ActionController::Base
23
+ # add_flash_types :warning
24
+ # end
23
25
  #
24
- # # in your controller
25
- # redirect_to user_path(@user), warning: "Incomplete profile"
26
+ # # in your controller
27
+ # redirect_to user_path(@user), warning: "Incomplete profile"
26
28
  #
27
- # # in your view
28
- # <%= warning %>
29
+ # # in your view
30
+ # <%= warning %>
29
31
  #
30
32
  # This method will automatically define a new method for each of the given
31
33
  # names, and it will be available in your views.
@@ -36,15 +38,12 @@ module ActionController # :nodoc:
36
38
  define_method(type) do
37
39
  request.flash[type]
38
40
  end
41
+ private type
39
42
  helper_method(type) if respond_to?(:helper_method)
40
43
 
41
44
  self._flash_types += [type]
42
45
  end
43
46
  end
44
-
45
- def action_methods # :nodoc:
46
- @action_methods ||= super - _flash_types.map(&:to_s).to_set
47
- end
48
47
  end
49
48
 
50
49
  private
@@ -1,28 +1,32 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  module ActionController
4
6
  module Head
5
- # Returns a response that has no content (merely headers). The options
6
- # argument is interpreted to be a hash of header names and values.
7
- # This allows you to easily return a response that consists only of
8
- # significant headers:
7
+ # Returns a response that has no content (merely headers). The options argument
8
+ # is interpreted to be a hash of header names and values. This allows you to
9
+ # easily return a response that consists only of significant headers:
9
10
  #
10
- # head :created, location: person_path(@person)
11
+ # head :created, location: person_path(@person)
11
12
  #
12
- # head :created, location: @person
13
+ # head :created, location: @person
13
14
  #
14
15
  # It can also be used to return exceptional conditions:
15
16
  #
16
- # return head(:method_not_allowed) unless request.post?
17
- # return head(:bad_request) unless valid_request?
18
- # render
17
+ # return head(:method_not_allowed) unless request.post?
18
+ # return head(:bad_request) unless valid_request?
19
+ # render
19
20
  #
20
- # See +Rack::Utils::SYMBOL_TO_STATUS_CODE+ for a full list of valid +status+ symbols.
21
+ # See `Rack::Utils::SYMBOL_TO_STATUS_CODE` for a full list of valid `status`
22
+ # symbols.
21
23
  def head(status, options = nil)
22
24
  if status.is_a?(Hash)
23
25
  raise ArgumentError, "#{status.inspect} is not a valid value for `status`."
24
26
  end
25
27
 
28
+ raise ::AbstractController::DoubleRenderError if response_body
29
+
26
30
  status ||= :ok
27
31
 
28
32
  if options
@@ -39,7 +43,7 @@ module ActionController
39
43
 
40
44
  if include_content?(response_code)
41
45
  unless self.media_type
42
- self.content_type = content_type || ((f = formats) && Mime[f.first]) || Mime[:html]
46
+ self.content_type = content_type || ((f = formats) && Mime[f.first]) || :html
43
47
  end
44
48
 
45
49
  response.charset = false