actionpack 6.1.7.5 → 7.1.3.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.
Potentially problematic release.
This version of actionpack might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +355 -435
- data/MIT-LICENSE +2 -1
- data/README.rdoc +6 -7
- data/lib/abstract_controller/asset_paths.rb +1 -1
- data/lib/abstract_controller/base.rb +33 -37
- data/lib/abstract_controller/caching/fragments.rb +4 -2
- data/lib/abstract_controller/caching.rb +1 -1
- data/lib/abstract_controller/callbacks.rb +50 -11
- data/lib/abstract_controller/collector.rb +2 -2
- data/lib/abstract_controller/deprecator.rb +7 -0
- data/lib/abstract_controller/error.rb +1 -1
- data/lib/abstract_controller/helpers.rb +78 -30
- data/lib/abstract_controller/logger.rb +1 -1
- data/lib/abstract_controller/railties/routes_helpers.rb +3 -16
- data/lib/abstract_controller/rendering.rb +12 -14
- data/lib/abstract_controller/translation.rb +26 -7
- data/lib/abstract_controller/url_for.rb +6 -6
- data/lib/abstract_controller.rb +6 -0
- data/lib/action_controller/api.rb +12 -10
- data/lib/action_controller/base.rb +8 -21
- data/lib/action_controller/caching.rb +2 -0
- data/lib/action_controller/deprecator.rb +7 -0
- data/lib/action_controller/form_builder.rb +4 -2
- data/lib/action_controller/log_subscriber.rb +20 -7
- data/lib/action_controller/metal/basic_implicit_render.rb +3 -1
- data/lib/action_controller/metal/conditional_get.rb +137 -102
- data/lib/action_controller/metal/content_security_policy.rb +37 -3
- data/lib/action_controller/metal/cookies.rb +1 -1
- data/lib/action_controller/metal/data_streaming.rb +25 -31
- data/lib/action_controller/metal/default_headers.rb +2 -0
- data/lib/action_controller/metal/etag_with_flash.rb +3 -1
- data/lib/action_controller/metal/etag_with_template_digest.rb +2 -0
- data/lib/action_controller/metal/exceptions.rb +27 -30
- data/lib/action_controller/metal/flash.rb +6 -2
- data/lib/action_controller/metal/head.rb +9 -7
- data/lib/action_controller/metal/helpers.rb +5 -16
- data/lib/action_controller/metal/http_authentication.rb +78 -42
- data/lib/action_controller/metal/implicit_render.rb +5 -3
- data/lib/action_controller/metal/instrumentation.rb +62 -50
- data/lib/action_controller/metal/live.rb +67 -2
- data/lib/action_controller/metal/mime_responds.rb +5 -5
- data/lib/action_controller/metal/params_wrapper.rb +24 -13
- data/lib/action_controller/metal/permissions_policy.rb +20 -29
- data/lib/action_controller/metal/redirecting.rb +96 -23
- data/lib/action_controller/metal/renderers.rb +14 -15
- data/lib/action_controller/metal/rendering.rb +121 -16
- data/lib/action_controller/metal/request_forgery_protection.rb +208 -68
- data/lib/action_controller/metal/rescue.rb +7 -4
- data/lib/action_controller/metal/streaming.rb +74 -36
- data/lib/action_controller/metal/strong_parameters.rb +254 -151
- data/lib/action_controller/metal/testing.rb +9 -2
- data/lib/action_controller/metal/url_for.rb +10 -5
- data/lib/action_controller/metal.rb +89 -34
- data/lib/action_controller/railtie.rb +66 -9
- data/lib/action_controller/renderer.rb +99 -85
- data/lib/action_controller/test_case.rb +42 -11
- data/lib/action_controller.rb +10 -6
- data/lib/action_dispatch/constants.rb +32 -0
- data/lib/action_dispatch/deprecator.rb +7 -0
- data/lib/action_dispatch/http/cache.rb +21 -16
- data/lib/action_dispatch/http/content_security_policy.rb +122 -44
- data/lib/action_dispatch/http/filter_parameters.rb +14 -23
- data/lib/action_dispatch/http/headers.rb +3 -1
- data/lib/action_dispatch/http/mime_negotiation.rb +25 -15
- data/lib/action_dispatch/http/mime_type.rb +43 -22
- data/lib/action_dispatch/http/mime_types.rb +3 -1
- data/lib/action_dispatch/http/parameters.rb +6 -6
- data/lib/action_dispatch/http/permissions_policy.rb +57 -19
- data/lib/action_dispatch/http/rack_cache.rb +2 -0
- data/lib/action_dispatch/http/request.rb +75 -51
- data/lib/action_dispatch/http/response.rb +81 -77
- data/lib/action_dispatch/http/upload.rb +15 -2
- data/lib/action_dispatch/http/url.rb +11 -19
- data/lib/action_dispatch/journey/formatter.rb +8 -2
- data/lib/action_dispatch/journey/gtg/builder.rb +11 -12
- data/lib/action_dispatch/journey/gtg/simulator.rb +10 -4
- data/lib/action_dispatch/journey/gtg/transition_table.rb +77 -21
- data/lib/action_dispatch/journey/nodes/node.rb +70 -5
- data/lib/action_dispatch/journey/path/pattern.rb +36 -27
- data/lib/action_dispatch/journey/route.rb +8 -14
- data/lib/action_dispatch/journey/router/utils.rb +2 -2
- data/lib/action_dispatch/journey/router.rb +10 -9
- data/lib/action_dispatch/journey/routes.rb +5 -5
- data/lib/action_dispatch/journey/visualizer/fsm.js +49 -24
- data/lib/action_dispatch/journey/visualizer/index.html.erb +1 -1
- data/lib/action_dispatch/log_subscriber.rb +23 -0
- data/lib/action_dispatch/middleware/actionable_exceptions.rb +5 -7
- data/lib/action_dispatch/middleware/assume_ssl.rb +24 -0
- data/lib/action_dispatch/middleware/callbacks.rb +2 -0
- data/lib/action_dispatch/middleware/cookies.rb +97 -107
- data/lib/action_dispatch/middleware/debug_exceptions.rb +31 -28
- data/lib/action_dispatch/middleware/debug_locks.rb +7 -4
- data/lib/action_dispatch/middleware/debug_view.rb +7 -2
- data/lib/action_dispatch/middleware/exception_wrapper.rb +190 -27
- data/lib/action_dispatch/middleware/executor.rb +3 -0
- data/lib/action_dispatch/middleware/flash.rb +24 -18
- data/lib/action_dispatch/middleware/host_authorization.rb +19 -20
- data/lib/action_dispatch/middleware/public_exceptions.rb +5 -3
- data/lib/action_dispatch/middleware/reloader.rb +7 -5
- data/lib/action_dispatch/middleware/remote_ip.rb +32 -19
- data/lib/action_dispatch/middleware/request_id.rb +5 -3
- data/lib/action_dispatch/middleware/server_timing.rb +76 -0
- data/lib/action_dispatch/middleware/session/abstract_store.rb +6 -1
- data/lib/action_dispatch/middleware/session/cache_store.rb +2 -0
- data/lib/action_dispatch/middleware/session/cookie_store.rb +19 -13
- data/lib/action_dispatch/middleware/session/mem_cache_store.rb +3 -1
- data/lib/action_dispatch/middleware/show_exceptions.rb +30 -25
- data/lib/action_dispatch/middleware/ssl.rb +18 -6
- data/lib/action_dispatch/middleware/stack.rb +34 -11
- data/lib/action_dispatch/middleware/static.rb +16 -16
- data/lib/action_dispatch/middleware/templates/rescues/_actions.html.erb +2 -2
- data/lib/action_dispatch/middleware/templates/rescues/_message_and_suggestions.html.erb +5 -5
- data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb +4 -11
- data/lib/action_dispatch/middleware/templates/rescues/_source.html.erb +8 -1
- data/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb +2 -2
- data/lib/action_dispatch/middleware/templates/rescues/blocked_host.html.erb +10 -5
- data/lib/action_dispatch/middleware/templates/rescues/blocked_host.text.erb +7 -3
- data/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb +9 -9
- data/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb +2 -2
- data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.html.erb +3 -3
- data/lib/action_dispatch/middleware/templates/rescues/layout.erb +45 -18
- data/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.html.erb +19 -15
- data/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb +4 -4
- data/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb +6 -6
- data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +7 -7
- data/lib/action_dispatch/middleware/templates/rescues/unknown_action.html.erb +4 -4
- 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 +64 -55
- data/lib/action_dispatch/railtie.rb +20 -4
- data/lib/action_dispatch/request/session.rb +59 -19
- data/lib/action_dispatch/request/utils.rb +8 -3
- data/lib/action_dispatch/routing/inspector.rb +55 -7
- data/lib/action_dispatch/routing/mapper.rb +117 -107
- data/lib/action_dispatch/routing/polymorphic_routes.rb +2 -0
- data/lib/action_dispatch/routing/redirection.rb +20 -8
- data/lib/action_dispatch/routing/route_set.rb +67 -27
- data/lib/action_dispatch/routing/routes_proxy.rb +11 -16
- data/lib/action_dispatch/routing/url_for.rb +29 -26
- data/lib/action_dispatch/routing.rb +12 -13
- data/lib/action_dispatch/system_test_case.rb +8 -8
- data/lib/action_dispatch/system_testing/browser.rb +20 -29
- data/lib/action_dispatch/system_testing/driver.rb +34 -18
- data/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb +35 -20
- data/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb +0 -8
- data/lib/action_dispatch/testing/assertion_response.rb +1 -1
- data/lib/action_dispatch/testing/assertions/response.rb +14 -7
- data/lib/action_dispatch/testing/assertions/routing.rb +70 -30
- data/lib/action_dispatch/testing/assertions.rb +3 -4
- data/lib/action_dispatch/testing/integration.rb +33 -25
- data/lib/action_dispatch/testing/request_encoder.rb +4 -1
- data/lib/action_dispatch/testing/test_process.rb +5 -30
- data/lib/action_dispatch/testing/test_request.rb +1 -1
- data/lib/action_dispatch/testing/test_response.rb +34 -2
- data/lib/action_dispatch.rb +38 -4
- data/lib/action_pack/gem_version.rb +4 -4
- data/lib/action_pack/version.rb +1 -1
- data/lib/action_pack.rb +1 -1
- metadata +67 -30
@@ -1,30 +1,25 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
module ActionController # :nodoc:
|
4
|
+
# = Action Controller \Streaming
|
5
|
+
#
|
6
6
|
# Allows views to be streamed back to the client as they are rendered.
|
7
7
|
#
|
8
|
-
# By default, Rails renders views by first rendering the template
|
8
|
+
# By default, \Rails renders views by first rendering the template
|
9
9
|
# and then the layout. The response is sent to the client after the whole
|
10
10
|
# template is rendered, all queries are made, and the layout is processed.
|
11
11
|
#
|
12
|
-
# Streaming inverts the rendering flow by rendering the layout first and
|
13
|
-
#
|
12
|
+
# \Streaming inverts the rendering flow by rendering the layout first and
|
13
|
+
# subsequently each part of the layout as they are processed. This allows the
|
14
14
|
# header of the HTML (which is usually in the layout) to be streamed back
|
15
|
-
# to client very quickly,
|
15
|
+
# to client very quickly, enabling JavaScripts and stylesheets to be loaded
|
16
16
|
# earlier than usual.
|
17
17
|
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
# Those points are going to be addressed soon.
|
18
|
+
# Several Rack middlewares may not work and you need to be careful when streaming.
|
19
|
+
# This is covered in more detail below, see the Streaming@Middlewares section.
|
21
20
|
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
# Ruby implementation).
|
25
|
-
#
|
26
|
-
# Streaming can be added to a given template easily, all you need to do is
|
27
|
-
# to pass the :stream option.
|
21
|
+
# \Streaming can be added to a given template easily, all you need to do is
|
22
|
+
# to pass the +:stream+ option to +render+.
|
28
23
|
#
|
29
24
|
# class PostsController
|
30
25
|
# def index
|
@@ -35,7 +30,7 @@ module ActionController #:nodoc:
|
|
35
30
|
#
|
36
31
|
# == When to use streaming
|
37
32
|
#
|
38
|
-
# Streaming may be considered to be overkill for lightweight actions like
|
33
|
+
# \Streaming may be considered to be overkill for lightweight actions like
|
39
34
|
# +new+ or +edit+. The real benefit of streaming is on expensive actions
|
40
35
|
# that, for example, do a lot of queries on the database.
|
41
36
|
#
|
@@ -59,20 +54,20 @@ module ActionController #:nodoc:
|
|
59
54
|
# render stream: true
|
60
55
|
# end
|
61
56
|
#
|
62
|
-
# Notice that
|
63
|
-
# or
|
57
|
+
# Notice that +:stream+ only works with templates. \Rendering +:json+
|
58
|
+
# or +:xml+ with +:stream+ won't work.
|
64
59
|
#
|
65
60
|
# == Communication between layout and template
|
66
61
|
#
|
67
62
|
# When streaming, rendering happens top-down instead of inside-out.
|
68
|
-
# Rails starts with the layout, and the template is rendered later,
|
63
|
+
# \Rails starts with the layout, and the template is rendered later,
|
69
64
|
# when its +yield+ is reached.
|
70
65
|
#
|
71
66
|
# This means that, if your application currently relies on instance
|
72
67
|
# variables set in the template to be used in the layout, they won't
|
73
68
|
# work once you move to streaming. The proper way to communicate
|
74
69
|
# between layout and template, regardless of whether you use streaming
|
75
|
-
# or not, is by using +content_for+, +provide
|
70
|
+
# or not, is by using +content_for+, +provide+, and +yield+.
|
76
71
|
#
|
77
72
|
# Take a simple example where the layout expects the template to tell
|
78
73
|
# which title to use:
|
@@ -112,7 +107,7 @@ module ActionController #:nodoc:
|
|
112
107
|
# This means that, if you have <code>yield :title</code> in your layout
|
113
108
|
# and you want to use streaming, you would have to render the whole template
|
114
109
|
# (and eventually trigger all queries) before streaming the title and all
|
115
|
-
# assets, which
|
110
|
+
# assets, which defeats the purpose of streaming. Alternatively, you can use
|
116
111
|
# a helper called +provide+ that does the same as +content_for+ but tells the
|
117
112
|
# layout to stop searching for other entries and continue rendering.
|
118
113
|
#
|
@@ -122,7 +117,7 @@ module ActionController #:nodoc:
|
|
122
117
|
# Hello
|
123
118
|
# <%= content_for :title, " page" %>
|
124
119
|
#
|
125
|
-
#
|
120
|
+
# Resulting in:
|
126
121
|
#
|
127
122
|
# <html>
|
128
123
|
# <head><title>Main</title></head>
|
@@ -132,7 +127,9 @@ module ActionController #:nodoc:
|
|
132
127
|
# That said, when streaming, you need to properly check your templates
|
133
128
|
# and choose when to use +provide+ and +content_for+.
|
134
129
|
#
|
135
|
-
#
|
130
|
+
# See also ActionView::Helpers::CaptureHelper for more information.
|
131
|
+
#
|
132
|
+
# == Headers, cookies, session, and flash
|
136
133
|
#
|
137
134
|
# When streaming, the HTTP headers are sent to the client right before
|
138
135
|
# it renders the first line. This means that, modifying headers, cookies,
|
@@ -143,11 +140,11 @@ module ActionController #:nodoc:
|
|
143
140
|
#
|
144
141
|
# Middlewares that need to manipulate the body won't work with streaming.
|
145
142
|
# You should disable those middlewares whenever streaming in development
|
146
|
-
# or production. For instance,
|
143
|
+
# or production. For instance, +Rack::Bug+ won't work when streaming as it
|
147
144
|
# needs to inject contents in the HTML body.
|
148
145
|
#
|
149
|
-
# Also
|
150
|
-
# streaming bodies yet. Whenever streaming Cache-Control is automatically
|
146
|
+
# Also +Rack::Cache+ won't work with streaming as it does not support
|
147
|
+
# streaming bodies yet. Whenever streaming +Cache-Control+ is automatically
|
151
148
|
# set to "no-cache".
|
152
149
|
#
|
153
150
|
# == Errors
|
@@ -156,14 +153,14 @@ module ActionController #:nodoc:
|
|
156
153
|
# happens because part of the template was already rendered and streamed to
|
157
154
|
# the client, making it impossible to render a whole exception page.
|
158
155
|
#
|
159
|
-
# Currently, when an exception happens in development or production, Rails
|
156
|
+
# Currently, when an exception happens in development or production, \Rails
|
160
157
|
# will automatically stream to the client:
|
161
158
|
#
|
162
159
|
# "><script>window.location = "/500.html"</script></html>
|
163
160
|
#
|
164
|
-
# The first two characters (">) are required in case the exception
|
165
|
-
# while rendering attributes for a given tag. You can check the real
|
166
|
-
# for the exception in your logger.
|
161
|
+
# The first two characters (<tt>"></tt>) are required in case the exception
|
162
|
+
# happens while rendering attributes for a given tag. You can check the real
|
163
|
+
# cause for the exception in your logger.
|
167
164
|
#
|
168
165
|
# == Web server support
|
169
166
|
#
|
@@ -183,17 +180,58 @@ module ActionController #:nodoc:
|
|
183
180
|
# unicorn_rails --config-file unicorn.config.rb
|
184
181
|
#
|
185
182
|
# You may also want to configure other parameters like <tt>:tcp_nodelay</tt>.
|
186
|
-
#
|
183
|
+
#
|
184
|
+
# For more information, please check the
|
185
|
+
# {documentation}[https://bogomips.org/unicorn/Unicorn/Configurator.html#method-i-listen].
|
187
186
|
#
|
188
187
|
# If you are using Unicorn with NGINX, you may need to tweak NGINX.
|
189
|
-
# Streaming should work out of the box on Rainbows.
|
188
|
+
# \Streaming should work out of the box on Rainbows.
|
190
189
|
#
|
191
190
|
# ==== Passenger
|
192
191
|
#
|
193
|
-
#
|
192
|
+
# Phusion Passenger with NGINX, offers two streaming mechanisms out of the box.
|
193
|
+
#
|
194
|
+
# 1. NGINX response buffering mechanism which is dependent on the value of
|
195
|
+
# +passenger_buffer_response+ option (default is "off").
|
196
|
+
# 2. Passenger buffering system which is always 'on' irrespective of the value
|
197
|
+
# of +passenger_buffer_response+.
|
198
|
+
#
|
199
|
+
# When +passenger_buffer_response+ is turned "on", then streaming would be
|
200
|
+
# done at the NGINX level which waits until the application is done sending
|
201
|
+
# the response back to the client.
|
202
|
+
#
|
203
|
+
# For more information, please check the
|
204
|
+
# {documentation}[https://www.phusionpassenger.com/docs/references/config_reference/nginx/#passenger_buffer_response].
|
194
205
|
#
|
195
206
|
module Streaming
|
196
|
-
|
207
|
+
class Body # :nodoc:
|
208
|
+
TERM = "\r\n"
|
209
|
+
TAIL = "0#{TERM}"
|
210
|
+
|
211
|
+
# Store the response body to be chunked.
|
212
|
+
def initialize(body)
|
213
|
+
@body = body
|
214
|
+
end
|
215
|
+
|
216
|
+
# For each element yielded by the response body, yield
|
217
|
+
# the element in chunked encoding.
|
218
|
+
def each(&block)
|
219
|
+
term = TERM
|
220
|
+
@body.each do |chunk|
|
221
|
+
size = chunk.bytesize
|
222
|
+
next if size == 0
|
223
|
+
|
224
|
+
yield [size.to_s(16), term, chunk.b, term].join
|
225
|
+
end
|
226
|
+
yield TAIL
|
227
|
+
yield term
|
228
|
+
end
|
229
|
+
|
230
|
+
# Close the response body if the response body supports it.
|
231
|
+
def close
|
232
|
+
@body.close if @body.respond_to?(:close)
|
233
|
+
end
|
234
|
+
end
|
197
235
|
|
198
236
|
private
|
199
237
|
# Set proper cache control and transfer encoding when streaming
|
@@ -213,7 +251,7 @@ module ActionController #:nodoc:
|
|
213
251
|
# Call render_body if we are streaming instead of usual +render+.
|
214
252
|
def _render_template(options)
|
215
253
|
if options.delete(:stream)
|
216
|
-
|
254
|
+
Body.new view_renderer.render_body(view_context, options)
|
217
255
|
else
|
218
256
|
super
|
219
257
|
end
|