actionpack 7.0.8.1 → 7.2.2.1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +94 -500
- data/MIT-LICENSE +1 -1
- data/README.rdoc +2 -2
- data/lib/abstract_controller/asset_paths.rb +2 -0
- data/lib/abstract_controller/base.rb +119 -106
- data/lib/abstract_controller/caching/fragments.rb +51 -52
- data/lib/abstract_controller/caching.rb +2 -0
- data/lib/abstract_controller/callbacks.rb +94 -67
- data/lib/abstract_controller/collector.rb +6 -6
- data/lib/abstract_controller/deprecator.rb +9 -0
- data/lib/abstract_controller/error.rb +2 -0
- data/lib/abstract_controller/helpers.rb +121 -91
- data/lib/abstract_controller/logger.rb +2 -0
- data/lib/abstract_controller/railties/routes_helpers.rb +3 -16
- data/lib/abstract_controller/rendering.rb +14 -13
- data/lib/abstract_controller/translation.rb +12 -30
- data/lib/abstract_controller/url_for.rb +9 -5
- data/lib/abstract_controller.rb +8 -0
- data/lib/action_controller/api/api_rendering.rb +2 -0
- data/lib/action_controller/api.rb +78 -73
- data/lib/action_controller/base.rb +199 -141
- data/lib/action_controller/caching.rb +16 -11
- data/lib/action_controller/deprecator.rb +9 -0
- data/lib/action_controller/form_builder.rb +21 -16
- data/lib/action_controller/log_subscriber.rb +19 -5
- data/lib/action_controller/metal/allow_browser.rb +123 -0
- data/lib/action_controller/metal/basic_implicit_render.rb +2 -0
- data/lib/action_controller/metal/conditional_get.rb +187 -174
- data/lib/action_controller/metal/content_security_policy.rb +26 -25
- data/lib/action_controller/metal/cookies.rb +4 -2
- data/lib/action_controller/metal/data_streaming.rb +65 -54
- data/lib/action_controller/metal/default_headers.rb +6 -2
- data/lib/action_controller/metal/etag_with_flash.rb +4 -0
- data/lib/action_controller/metal/etag_with_template_digest.rb +18 -14
- data/lib/action_controller/metal/exceptions.rb +19 -9
- data/lib/action_controller/metal/flash.rb +12 -10
- data/lib/action_controller/metal/head.rb +20 -16
- data/lib/action_controller/metal/helpers.rb +64 -67
- data/lib/action_controller/metal/http_authentication.rb +214 -200
- data/lib/action_controller/metal/implicit_render.rb +21 -17
- data/lib/action_controller/metal/instrumentation.rb +22 -12
- data/lib/action_controller/metal/live.rb +125 -92
- data/lib/action_controller/metal/logging.rb +6 -4
- data/lib/action_controller/metal/mime_responds.rb +151 -142
- data/lib/action_controller/metal/parameter_encoding.rb +34 -32
- data/lib/action_controller/metal/params_wrapper.rb +58 -58
- data/lib/action_controller/metal/permissions_policy.rb +14 -13
- data/lib/action_controller/metal/rate_limiting.rb +62 -0
- data/lib/action_controller/metal/redirecting.rb +110 -84
- data/lib/action_controller/metal/renderers.rb +50 -49
- data/lib/action_controller/metal/rendering.rb +103 -82
- data/lib/action_controller/metal/request_forgery_protection.rb +279 -161
- data/lib/action_controller/metal/rescue.rb +12 -8
- data/lib/action_controller/metal/streaming.rb +174 -132
- data/lib/action_controller/metal/strong_parameters.rb +598 -473
- data/lib/action_controller/metal/testing.rb +2 -0
- data/lib/action_controller/metal/url_for.rb +23 -14
- data/lib/action_controller/metal.rb +145 -61
- data/lib/action_controller/railtie.rb +25 -9
- data/lib/action_controller/railties/helpers.rb +2 -0
- data/lib/action_controller/renderer.rb +105 -66
- data/lib/action_controller/template_assertions.rb +4 -2
- data/lib/action_controller/test_case.rb +157 -128
- data/lib/action_controller.rb +17 -3
- data/lib/action_dispatch/constants.rb +34 -0
- data/lib/action_dispatch/deprecator.rb +9 -0
- data/lib/action_dispatch/http/cache.rb +28 -29
- data/lib/action_dispatch/http/content_disposition.rb +2 -0
- data/lib/action_dispatch/http/content_security_policy.rb +69 -49
- data/lib/action_dispatch/http/filter_parameters.rb +27 -12
- data/lib/action_dispatch/http/filter_redirect.rb +22 -1
- data/lib/action_dispatch/http/headers.rb +23 -21
- data/lib/action_dispatch/http/mime_negotiation.rb +37 -48
- data/lib/action_dispatch/http/mime_type.rb +60 -30
- data/lib/action_dispatch/http/mime_types.rb +5 -1
- data/lib/action_dispatch/http/parameters.rb +12 -10
- data/lib/action_dispatch/http/permissions_policy.rb +32 -34
- data/lib/action_dispatch/http/rack_cache.rb +4 -0
- data/lib/action_dispatch/http/request.rb +132 -79
- data/lib/action_dispatch/http/response.rb +136 -103
- data/lib/action_dispatch/http/upload.rb +19 -15
- data/lib/action_dispatch/http/url.rb +75 -73
- data/lib/action_dispatch/journey/formatter.rb +19 -6
- data/lib/action_dispatch/journey/gtg/builder.rb +4 -3
- data/lib/action_dispatch/journey/gtg/simulator.rb +2 -0
- data/lib/action_dispatch/journey/gtg/transition_table.rb +10 -8
- data/lib/action_dispatch/journey/nfa/dot.rb +2 -0
- data/lib/action_dispatch/journey/nodes/node.rb +6 -5
- data/lib/action_dispatch/journey/parser.rb +4 -3
- data/lib/action_dispatch/journey/parser_extras.rb +2 -0
- data/lib/action_dispatch/journey/path/pattern.rb +18 -15
- data/lib/action_dispatch/journey/route.rb +12 -9
- data/lib/action_dispatch/journey/router/utils.rb +16 -15
- data/lib/action_dispatch/journey/router.rb +13 -10
- data/lib/action_dispatch/journey/routes.rb +6 -4
- data/lib/action_dispatch/journey/scanner.rb +4 -2
- data/lib/action_dispatch/journey/visitors.rb +2 -0
- data/lib/action_dispatch/journey.rb +2 -0
- data/lib/action_dispatch/log_subscriber.rb +25 -0
- data/lib/action_dispatch/middleware/actionable_exceptions.rb +7 -6
- data/lib/action_dispatch/middleware/assume_ssl.rb +27 -0
- data/lib/action_dispatch/middleware/callbacks.rb +4 -0
- data/lib/action_dispatch/middleware/cookies.rb +192 -194
- data/lib/action_dispatch/middleware/debug_exceptions.rb +36 -27
- data/lib/action_dispatch/middleware/debug_locks.rb +18 -13
- data/lib/action_dispatch/middleware/debug_view.rb +9 -2
- data/lib/action_dispatch/middleware/exception_wrapper.rb +181 -27
- data/lib/action_dispatch/middleware/executor.rb +9 -1
- data/lib/action_dispatch/middleware/flash.rb +65 -46
- data/lib/action_dispatch/middleware/host_authorization.rb +22 -17
- data/lib/action_dispatch/middleware/public_exceptions.rb +12 -8
- data/lib/action_dispatch/middleware/reloader.rb +9 -5
- data/lib/action_dispatch/middleware/remote_ip.rb +88 -83
- data/lib/action_dispatch/middleware/request_id.rb +15 -8
- data/lib/action_dispatch/middleware/server_timing.rb +8 -6
- data/lib/action_dispatch/middleware/session/abstract_store.rb +7 -0
- data/lib/action_dispatch/middleware/session/cache_store.rb +14 -7
- data/lib/action_dispatch/middleware/session/cookie_store.rb +32 -25
- data/lib/action_dispatch/middleware/session/mem_cache_store.rb +9 -3
- data/lib/action_dispatch/middleware/show_exceptions.rb +42 -28
- data/lib/action_dispatch/middleware/ssl.rb +60 -45
- data/lib/action_dispatch/middleware/stack.rb +15 -9
- data/lib/action_dispatch/middleware/static.rb +40 -34
- data/lib/action_dispatch/middleware/templates/rescues/_actions.html.erb +2 -2
- data/lib/action_dispatch/middleware/templates/rescues/_message_and_suggestions.html.erb +4 -4
- data/lib/action_dispatch/middleware/templates/rescues/_source.html.erb +8 -1
- data/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb +7 -7
- data/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb +2 -2
- data/lib/action_dispatch/middleware/templates/rescues/layout.erb +17 -0
- data/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.html.erb +16 -12
- data/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb +1 -1
- data/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb +3 -3
- data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +4 -4
- data/lib/action_dispatch/middleware/templates/rescues/unknown_action.html.erb +1 -1
- data/lib/action_dispatch/middleware/templates/rescues/unknown_action.text.erb +1 -1
- data/lib/action_dispatch/middleware/templates/routes/_route.html.erb +3 -0
- data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +47 -38
- data/lib/action_dispatch/railtie.rb +12 -4
- data/lib/action_dispatch/request/session.rb +39 -27
- data/lib/action_dispatch/request/utils.rb +10 -3
- data/lib/action_dispatch/routing/endpoint.rb +2 -0
- data/lib/action_dispatch/routing/inspector.rb +59 -9
- data/lib/action_dispatch/routing/mapper.rb +686 -639
- data/lib/action_dispatch/routing/polymorphic_routes.rb +70 -61
- data/lib/action_dispatch/routing/redirection.rb +52 -38
- data/lib/action_dispatch/routing/route_set.rb +106 -62
- data/lib/action_dispatch/routing/routes_proxy.rb +16 -19
- data/lib/action_dispatch/routing/url_for.rb +131 -122
- data/lib/action_dispatch/routing.rb +152 -150
- data/lib/action_dispatch/system_test_case.rb +91 -81
- data/lib/action_dispatch/system_testing/browser.rb +27 -19
- data/lib/action_dispatch/system_testing/driver.rb +16 -22
- data/lib/action_dispatch/system_testing/server.rb +2 -0
- data/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb +53 -31
- data/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb +2 -0
- data/lib/action_dispatch/testing/assertion_response.rb +9 -7
- data/lib/action_dispatch/testing/assertions/response.rb +36 -26
- data/lib/action_dispatch/testing/assertions/routing.rb +203 -95
- data/lib/action_dispatch/testing/assertions.rb +5 -1
- data/lib/action_dispatch/testing/integration.rb +240 -229
- data/lib/action_dispatch/testing/request_encoder.rb +6 -1
- data/lib/action_dispatch/testing/test_helpers/page_dump_helper.rb +35 -0
- data/lib/action_dispatch/testing/test_process.rb +14 -9
- data/lib/action_dispatch/testing/test_request.rb +4 -2
- data/lib/action_dispatch/testing/test_response.rb +34 -19
- data/lib/action_dispatch.rb +52 -21
- data/lib/action_pack/gem_version.rb +5 -3
- data/lib/action_pack/version.rb +3 -1
- data/lib/action_pack.rb +18 -17
- metadata +91 -32
@@ -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,34 +15,33 @@ module ActionController # :nodoc:
|
|
13
15
|
end
|
14
16
|
|
15
17
|
module ClassMethods
|
16
|
-
# Overrides parts of the globally configured
|
17
|
-
# header:
|
18
|
+
# Overrides parts of the globally configured `Content-Security-Policy` header:
|
18
19
|
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
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
|
26
|
-
#
|
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
|
-
#
|
29
|
-
#
|
30
|
-
#
|
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
|
35
|
+
# Pass `false` to remove the `Content-Security-Policy` header:
|
35
36
|
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
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?
|
42
43
|
policy = current_content_security_policy
|
43
|
-
|
44
|
+
instance_exec(policy, &block)
|
44
45
|
request.content_security_policy = policy
|
45
46
|
end
|
46
47
|
|
@@ -50,18 +51,18 @@ module ActionController # :nodoc:
|
|
50
51
|
end
|
51
52
|
end
|
52
53
|
|
53
|
-
# Overrides the globally configured
|
54
|
+
# Overrides the globally configured `Content-Security-Policy-Report-Only`
|
54
55
|
# header:
|
55
56
|
#
|
56
|
-
#
|
57
|
-
#
|
58
|
-
#
|
57
|
+
# class PostsController < ApplicationController
|
58
|
+
# content_security_policy_report_only only: :index
|
59
|
+
# end
|
59
60
|
#
|
60
|
-
# Pass
|
61
|
+
# Pass `false` to remove the `Content-Security-Policy-Report-Only` header:
|
61
62
|
#
|
62
|
-
#
|
63
|
-
#
|
64
|
-
#
|
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
|
-
#
|
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,9 +1,13 @@
|
|
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:
|
9
|
+
# # Action Controller Data Streaming
|
10
|
+
#
|
7
11
|
# Methods for sending arbitrary data and for streaming files to the browser,
|
8
12
|
# instead of rendering.
|
9
13
|
module DataStreaming
|
@@ -15,57 +19,60 @@ module ActionController # :nodoc:
|
|
15
19
|
DEFAULT_SEND_FILE_DISPOSITION = "attachment" # :nodoc:
|
16
20
|
|
17
21
|
private
|
18
|
-
# Sends the file. This uses a server-appropriate method (such as
|
19
|
-
# via the
|
20
|
-
#
|
21
|
-
#
|
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.
|
22
26
|
#
|
23
|
-
# Be careful to sanitize the path parameter if it is coming from a web
|
24
|
-
#
|
25
|
-
#
|
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.
|
26
30
|
#
|
27
31
|
# Options:
|
28
|
-
# *
|
29
|
-
#
|
30
|
-
# *
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
# *
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
32
|
+
# * `:filename` - suggests a filename for the browser to use. Defaults to
|
33
|
+
# `File.basename(path)`.
|
34
|
+
# * `:type` - specifies an HTTP content type. You can specify either a string
|
35
|
+
# or a symbol for a registered type with `Mime::Type.register`, for example
|
36
|
+
# `:json`. If omitted, the type will be inferred from the file extension
|
37
|
+
# specified in `:filename`. If no content type is registered for the
|
38
|
+
# extension, the default type `application/octet-stream` will be used.
|
39
|
+
# * `:disposition` - specifies whether the file will be shown inline or
|
40
|
+
# downloaded. Valid values are `"inline"` and `"attachment"` (default).
|
41
|
+
# * `:status` - specifies the status code to send with the response. Defaults
|
42
|
+
# to 200.
|
43
|
+
# * `:url_based_filename` - set to `true` if you want the browser to guess the
|
44
|
+
# filename from the URL, which is necessary for i18n filenames on certain
|
45
|
+
# browsers (setting `:filename` overrides this option).
|
46
|
+
#
|
47
|
+
#
|
48
|
+
# The default `Content-Type` and `Content-Disposition` headers are set to
|
49
|
+
# download arbitrary binary files in as many browsers as possible. IE versions
|
50
|
+
# 4, 5, 5.5, and 6 are all known to have a variety of quirks (especially when
|
51
|
+
# downloading over SSL).
|
45
52
|
#
|
46
53
|
# Simple download:
|
47
54
|
#
|
48
|
-
#
|
55
|
+
# send_file '/path/to.zip'
|
49
56
|
#
|
50
57
|
# Show a JPEG in the browser:
|
51
58
|
#
|
52
|
-
#
|
59
|
+
# send_file '/path/to.jpeg', type: 'image/jpeg', disposition: 'inline'
|
53
60
|
#
|
54
61
|
# Show a 404 page in the browser:
|
55
62
|
#
|
56
|
-
#
|
63
|
+
# send_file '/path/to/404.html', type: 'text/html; charset=utf-8', disposition: 'inline', status: 404
|
57
64
|
#
|
58
|
-
# You can use other
|
59
|
-
#
|
60
|
-
#
|
65
|
+
# You can use other `Content-*` HTTP headers to provide additional information
|
66
|
+
# to the client. See MDN for a [list of HTTP
|
67
|
+
# headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers).
|
61
68
|
#
|
62
|
-
# Also be aware that the document may be cached by proxies and browsers.
|
63
|
-
#
|
64
|
-
#
|
65
|
-
#
|
66
|
-
#
|
67
|
-
#
|
68
|
-
#
|
69
|
+
# Also be aware that the document may be cached by proxies and browsers. The
|
70
|
+
# `Pragma` and `Cache-Control` headers declare how the file may be cached by
|
71
|
+
# intermediaries. They default to require clients to validate with the server
|
72
|
+
# before releasing cached responses. See https://www.mnot.net/cache_docs/ for an
|
73
|
+
# overview of web caching and [RFC
|
74
|
+
# 9111](https://www.rfc-editor.org/rfc/rfc9111.html#name-cache-control) for the
|
75
|
+
# `Cache-Control` header spec.
|
69
76
|
def send_file(path, options = {}) # :doc:
|
70
77
|
raise MissingFile, "Cannot read file #{path}" unless File.file?(path) && File.readable?(path)
|
71
78
|
|
@@ -77,35 +84,39 @@ module ActionController # :nodoc:
|
|
77
84
|
response.send_file path
|
78
85
|
end
|
79
86
|
|
80
|
-
# Sends the given binary data to the browser. This method is similar to
|
81
|
-
#
|
82
|
-
#
|
83
|
-
#
|
84
|
-
#
|
87
|
+
# Sends the given binary data to the browser. This method is similar to `render
|
88
|
+
# plain: data`, but also allows you to specify whether the browser should
|
89
|
+
# display the response as a file attachment (i.e. in a download dialog) or as
|
90
|
+
# inline data. You may also set the content type, the file name, and other
|
91
|
+
# things.
|
85
92
|
#
|
86
93
|
# Options:
|
87
|
-
# *
|
88
|
-
# *
|
89
|
-
#
|
90
|
-
#
|
91
|
-
#
|
92
|
-
#
|
93
|
-
#
|
94
|
-
# *
|
94
|
+
# * `:filename` - suggests a filename for the browser to use.
|
95
|
+
# * `:type` - specifies an HTTP content type. Defaults to
|
96
|
+
# `application/octet-stream`. You can specify either a string or a symbol
|
97
|
+
# for a registered type with `Mime::Type.register`, for example `:json`. If
|
98
|
+
# omitted, type will be inferred from the file extension specified in
|
99
|
+
# `:filename`. If no content type is registered for the extension, the
|
100
|
+
# default type `application/octet-stream` will be used.
|
101
|
+
# * `:disposition` - specifies whether the file will be shown inline or
|
102
|
+
# downloaded. Valid values are `"inline"` and `"attachment"` (default).
|
103
|
+
# * `:status` - specifies the status code to send with the response. Defaults
|
104
|
+
# to 200.
|
105
|
+
#
|
95
106
|
#
|
96
107
|
# Generic data download:
|
97
108
|
#
|
98
|
-
#
|
109
|
+
# send_data buffer
|
99
110
|
#
|
100
111
|
# Download a dynamically-generated tarball:
|
101
112
|
#
|
102
|
-
#
|
113
|
+
# send_data generate_tgz('dir'), filename: 'dir.tgz'
|
103
114
|
#
|
104
115
|
# Display an image Active Record in the browser:
|
105
116
|
#
|
106
|
-
#
|
117
|
+
# send_data image.data, type: image.content_type, disposition: 'inline'
|
107
118
|
#
|
108
|
-
# See
|
119
|
+
# See `send_file` for more information on HTTP `Content-*` headers and caching.
|
109
120
|
def send_data(data, options = {}) # :doc:
|
110
121
|
send_file_headers! options
|
111
122
|
render options.slice(:status, :content_type).merge(body: data)
|
@@ -1,8 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# :markup: markdown
|
4
|
+
|
3
5
|
module ActionController
|
4
|
-
#
|
5
|
-
#
|
6
|
+
# # Action Controller Default Headers
|
7
|
+
#
|
8
|
+
# Allows configuring default headers that will be automatically merged into each
|
9
|
+
# response.
|
6
10
|
module DefaultHeaders
|
7
11
|
extend ActiveSupport::Concern
|
8
12
|
|
@@ -1,6 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# :markup: markdown
|
4
|
+
|
3
5
|
module ActionController
|
6
|
+
# # Action Controller Etag With Flash
|
7
|
+
#
|
4
8
|
# When you're using the flash, it's generally used as a conditional on the view.
|
5
9
|
# This means the content of the view depends on the flash. Which in turn means
|
6
10
|
# that the ETag for a response should be computed with the content of the flash
|
@@ -1,22 +1,26 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# :markup: markdown
|
4
|
+
|
3
5
|
module ActionController
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
6
|
+
# # Action Controller Etag With Template Digest
|
7
|
+
#
|
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.
|
7
11
|
#
|
8
12
|
# Enabled by default for apps that use Action View. Disable by setting
|
9
13
|
#
|
10
|
-
#
|
14
|
+
# config.action_controller.etag_with_template_digest = false
|
11
15
|
#
|
12
|
-
# Override the template to digest by passing
|
13
|
-
#
|
16
|
+
# Override the template to digest by passing `:template` to `fresh_when` and
|
17
|
+
# `stale?` calls. For example:
|
14
18
|
#
|
15
|
-
#
|
16
|
-
#
|
19
|
+
# # We're going to render widgets/show, not posts/show
|
20
|
+
# fresh_when @post, template: 'widgets/show'
|
17
21
|
#
|
18
|
-
#
|
19
|
-
#
|
22
|
+
# # We're not going to render a template, so omit it from the ETag.
|
23
|
+
# fresh_when @post, template: false
|
20
24
|
#
|
21
25
|
module EtagWithTemplateDigest
|
22
26
|
extend ActiveSupport::Concern
|
@@ -38,10 +42,10 @@ module ActionController
|
|
38
42
|
end
|
39
43
|
end
|
40
44
|
|
41
|
-
# Pick the template digest to include in the ETag. If the
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
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.
|
45
49
|
def pick_template_for_etag(options)
|
46
50
|
unless options[:template] == false
|
47
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
|
-
#
|
78
|
+
# Raised when a nested respond_to is triggered and the content types of each are
|
79
|
+
# incompatible. For example:
|
78
80
|
#
|
79
|
-
#
|
80
|
-
#
|
81
|
-
#
|
82
|
-
#
|
83
|
-
#
|
84
|
-
#
|
85
|
-
#
|
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
|
|
@@ -92,5 +94,13 @@ module ActionController
|
|
92
94
|
end
|
93
95
|
|
94
96
|
class MissingExactTemplate < UnknownFormat # :nodoc:
|
97
|
+
attr_reader :controller, :action_name
|
98
|
+
|
99
|
+
def initialize(message, controller, action_name)
|
100
|
+
@controller = controller
|
101
|
+
@action_name = action_name
|
102
|
+
|
103
|
+
super(message)
|
104
|
+
end
|
95
105
|
end
|
96
106
|
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
|
17
|
-
#
|
18
|
+
# flash types other than the default `alert` and `notice` in your controllers
|
19
|
+
# and views. For instance:
|
18
20
|
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
21
|
+
# # in application_controller.rb
|
22
|
+
# class ApplicationController < ActionController::Base
|
23
|
+
# add_flash_types :warning
|
24
|
+
# end
|
23
25
|
#
|
24
|
-
#
|
25
|
-
#
|
26
|
+
# # in your controller
|
27
|
+
# redirect_to user_path(@user), warning: "Incomplete profile"
|
26
28
|
#
|
27
|
-
#
|
28
|
-
#
|
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.
|
@@ -1,35 +1,39 @@
|
|
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
|
-
#
|
7
|
-
#
|
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
|
-
#
|
11
|
+
# head :created, location: person_path(@person)
|
11
12
|
#
|
12
|
-
#
|
13
|
+
# head :created, location: @person
|
13
14
|
#
|
14
15
|
# It can also be used to return exceptional conditions:
|
15
16
|
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
17
|
+
# return head(:method_not_allowed) unless request.post?
|
18
|
+
# return head(:bad_request) unless valid_request?
|
19
|
+
# render
|
19
20
|
#
|
20
|
-
# See
|
21
|
-
|
21
|
+
# See `Rack::Utils::SYMBOL_TO_STATUS_CODE` for a full list of valid `status`
|
22
|
+
# symbols.
|
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
|
|
26
28
|
status ||= :ok
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
+
if options
|
31
|
+
location = options.delete(:location)
|
32
|
+
content_type = options.delete(:content_type)
|
30
33
|
|
31
|
-
|
32
|
-
|
34
|
+
options.each do |key, value|
|
35
|
+
headers[key.to_s.split(/[-_]/).each { |v| v[0] = v[0].upcase }.join("-")] = value.to_s
|
36
|
+
end
|
33
37
|
end
|
34
38
|
|
35
39
|
self.status = status
|
@@ -37,7 +41,7 @@ module ActionController
|
|
37
41
|
|
38
42
|
if include_content?(response_code)
|
39
43
|
unless self.media_type
|
40
|
-
self.content_type = content_type || (Mime[
|
44
|
+
self.content_type = content_type || ((f = formats) && Mime[f.first]) || Mime[:html]
|
41
45
|
end
|
42
46
|
|
43
47
|
response.charset = false
|