actionpack 3.2.22.5 → 5.2.4
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 +5 -5
- data/CHANGELOG.md +279 -603
- data/MIT-LICENSE +1 -1
- data/README.rdoc +13 -297
- data/lib/abstract_controller/asset_paths.rb +4 -2
- data/lib/abstract_controller/base.rb +82 -52
- data/lib/abstract_controller/caching/fragments.rb +166 -0
- data/lib/abstract_controller/caching.rb +66 -0
- data/lib/abstract_controller/callbacks.rb +117 -103
- data/lib/abstract_controller/collector.rb +18 -7
- data/lib/abstract_controller/error.rb +6 -0
- data/lib/abstract_controller/helpers.rb +65 -38
- data/lib/abstract_controller/logger.rb +3 -2
- data/lib/abstract_controller/railties/routes_helpers.rb +5 -3
- data/lib/abstract_controller/rendering.rb +77 -129
- data/lib/abstract_controller/translation.rb +21 -3
- data/lib/abstract_controller/url_for.rb +9 -7
- data/lib/abstract_controller.rb +12 -13
- data/lib/action_controller/api/api_rendering.rb +16 -0
- data/lib/action_controller/api.rb +149 -0
- data/lib/action_controller/base.rb +81 -40
- data/lib/action_controller/caching.rb +22 -62
- data/lib/action_controller/form_builder.rb +50 -0
- data/lib/action_controller/log_subscriber.rb +30 -18
- data/lib/action_controller/metal/basic_implicit_render.rb +13 -0
- data/lib/action_controller/metal/conditional_get.rb +190 -47
- data/lib/action_controller/metal/content_security_policy.rb +52 -0
- data/lib/action_controller/metal/cookies.rb +3 -3
- data/lib/action_controller/metal/data_streaming.rb +40 -65
- data/lib/action_controller/metal/etag_with_flash.rb +18 -0
- data/lib/action_controller/metal/etag_with_template_digest.rb +57 -0
- data/lib/action_controller/metal/exceptions.rb +19 -12
- data/lib/action_controller/metal/flash.rb +42 -9
- data/lib/action_controller/metal/force_ssl.rb +79 -19
- data/lib/action_controller/metal/head.rb +35 -10
- data/lib/action_controller/metal/helpers.rb +31 -21
- data/lib/action_controller/metal/http_authentication.rb +182 -134
- data/lib/action_controller/metal/implicit_render.rb +62 -8
- data/lib/action_controller/metal/instrumentation.rb +28 -26
- data/lib/action_controller/metal/live.rb +312 -0
- data/lib/action_controller/metal/mime_responds.rb +159 -163
- data/lib/action_controller/metal/parameter_encoding.rb +51 -0
- data/lib/action_controller/metal/params_wrapper.rb +146 -93
- data/lib/action_controller/metal/redirecting.rb +80 -56
- data/lib/action_controller/metal/renderers.rb +119 -47
- data/lib/action_controller/metal/rendering.rb +89 -32
- data/lib/action_controller/metal/request_forgery_protection.rb +373 -41
- data/lib/action_controller/metal/rescue.rb +9 -16
- data/lib/action_controller/metal/streaming.rb +39 -45
- data/lib/action_controller/metal/strong_parameters.rb +1086 -0
- data/lib/action_controller/metal/testing.rb +8 -29
- data/lib/action_controller/metal/url_for.rb +43 -32
- data/lib/action_controller/metal.rb +112 -106
- data/lib/action_controller/railtie.rb +56 -18
- data/lib/action_controller/railties/helpers.rb +24 -0
- data/lib/action_controller/renderer.rb +117 -0
- data/lib/action_controller/template_assertions.rb +11 -0
- data/lib/action_controller/test_case.rb +402 -347
- data/lib/action_controller.rb +31 -30
- data/lib/action_dispatch/http/cache.rb +133 -34
- data/lib/action_dispatch/http/content_security_policy.rb +272 -0
- data/lib/action_dispatch/http/filter_parameters.rb +40 -24
- data/lib/action_dispatch/http/filter_redirect.rb +37 -0
- data/lib/action_dispatch/http/headers.rb +117 -16
- data/lib/action_dispatch/http/mime_negotiation.rb +98 -33
- data/lib/action_dispatch/http/mime_type.rb +198 -146
- data/lib/action_dispatch/http/mime_types.rb +22 -7
- data/lib/action_dispatch/http/parameter_filter.rb +61 -49
- data/lib/action_dispatch/http/parameters.rb +94 -51
- data/lib/action_dispatch/http/rack_cache.rb +4 -3
- data/lib/action_dispatch/http/request.rb +262 -117
- data/lib/action_dispatch/http/response.rb +400 -86
- data/lib/action_dispatch/http/upload.rb +66 -29
- data/lib/action_dispatch/http/url.rb +232 -60
- data/lib/action_dispatch/journey/formatter.rb +189 -0
- data/lib/action_dispatch/journey/gtg/builder.rb +164 -0
- data/lib/action_dispatch/journey/gtg/simulator.rb +41 -0
- data/lib/action_dispatch/journey/gtg/transition_table.rb +158 -0
- data/lib/action_dispatch/journey/nfa/builder.rb +78 -0
- data/lib/action_dispatch/journey/nfa/dot.rb +36 -0
- data/lib/action_dispatch/journey/nfa/simulator.rb +49 -0
- data/lib/action_dispatch/journey/nfa/transition_table.rb +120 -0
- data/lib/action_dispatch/journey/nodes/node.rb +140 -0
- data/lib/action_dispatch/journey/parser.rb +199 -0
- data/lib/action_dispatch/journey/parser.y +50 -0
- data/lib/action_dispatch/journey/parser_extras.rb +31 -0
- data/lib/action_dispatch/journey/path/pattern.rb +199 -0
- data/lib/action_dispatch/journey/route.rb +203 -0
- data/lib/action_dispatch/journey/router/utils.rb +102 -0
- data/lib/action_dispatch/journey/router.rb +156 -0
- data/lib/action_dispatch/journey/routes.rb +82 -0
- data/lib/action_dispatch/journey/scanner.rb +64 -0
- data/lib/action_dispatch/journey/visitors.rb +268 -0
- data/lib/action_dispatch/journey/visualizer/fsm.css +30 -0
- data/lib/action_dispatch/journey/visualizer/fsm.js +134 -0
- data/lib/action_dispatch/journey/visualizer/index.html.erb +52 -0
- data/lib/action_dispatch/journey.rb +7 -0
- data/lib/action_dispatch/middleware/callbacks.rb +17 -13
- data/lib/action_dispatch/middleware/cookies.rb +494 -162
- data/lib/action_dispatch/middleware/debug_exceptions.rb +176 -53
- data/lib/action_dispatch/middleware/debug_locks.rb +124 -0
- data/lib/action_dispatch/middleware/exception_wrapper.rb +103 -38
- data/lib/action_dispatch/middleware/executor.rb +21 -0
- data/lib/action_dispatch/middleware/flash.rb +128 -91
- data/lib/action_dispatch/middleware/public_exceptions.rb +43 -16
- data/lib/action_dispatch/middleware/reloader.rb +6 -83
- data/lib/action_dispatch/middleware/remote_ip.rb +151 -49
- data/lib/action_dispatch/middleware/request_id.rb +19 -15
- data/lib/action_dispatch/middleware/session/abstract_store.rb +38 -34
- data/lib/action_dispatch/middleware/session/cache_store.rb +14 -9
- data/lib/action_dispatch/middleware/session/cookie_store.rb +94 -44
- data/lib/action_dispatch/middleware/session/mem_cache_store.rb +15 -4
- data/lib/action_dispatch/middleware/show_exceptions.rb +36 -61
- data/lib/action_dispatch/middleware/ssl.rb +150 -0
- data/lib/action_dispatch/middleware/stack.rb +33 -41
- data/lib/action_dispatch/middleware/static.rb +92 -48
- data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb +22 -0
- data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb +23 -0
- data/lib/action_dispatch/middleware/templates/rescues/_source.html.erb +27 -0
- data/lib/action_dispatch/middleware/templates/rescues/_source.text.erb +8 -0
- data/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb +52 -0
- data/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb +9 -0
- data/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb +16 -0
- data/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb +9 -0
- data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.html.erb +21 -0
- data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.text.erb +13 -0
- data/lib/action_dispatch/middleware/templates/rescues/layout.erb +134 -5
- data/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb +11 -0
- data/lib/action_dispatch/middleware/templates/rescues/missing_template.text.erb +3 -0
- data/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb +32 -0
- data/lib/action_dispatch/middleware/templates/rescues/routing_error.text.erb +11 -0
- data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +20 -0
- data/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb +7 -0
- data/lib/action_dispatch/middleware/templates/rescues/unknown_action.html.erb +6 -0
- data/lib/action_dispatch/middleware/templates/rescues/unknown_action.text.erb +3 -0
- data/lib/action_dispatch/middleware/templates/routes/_route.html.erb +16 -0
- data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +200 -0
- data/lib/action_dispatch/railtie.rb +29 -8
- data/lib/action_dispatch/request/session.rb +234 -0
- data/lib/action_dispatch/request/utils.rb +78 -0
- data/lib/action_dispatch/routing/endpoint.rb +17 -0
- data/lib/action_dispatch/routing/inspector.rb +225 -0
- data/lib/action_dispatch/routing/mapper.rb +1329 -582
- data/lib/action_dispatch/routing/polymorphic_routes.rb +237 -94
- data/lib/action_dispatch/routing/redirection.rb +120 -50
- data/lib/action_dispatch/routing/route_set.rb +545 -322
- data/lib/action_dispatch/routing/routes_proxy.rb +37 -7
- data/lib/action_dispatch/routing/url_for.rb +103 -34
- data/lib/action_dispatch/routing.rb +66 -99
- data/lib/action_dispatch/system_test_case.rb +147 -0
- data/lib/action_dispatch/system_testing/browser.rb +49 -0
- data/lib/action_dispatch/system_testing/driver.rb +59 -0
- data/lib/action_dispatch/system_testing/server.rb +31 -0
- data/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb +96 -0
- data/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb +31 -0
- data/lib/action_dispatch/system_testing/test_helpers/undef_methods.rb +26 -0
- data/lib/action_dispatch/testing/assertion_response.rb +47 -0
- data/lib/action_dispatch/testing/assertions/response.rb +53 -42
- data/lib/action_dispatch/testing/assertions/routing.rb +79 -74
- data/lib/action_dispatch/testing/assertions.rb +15 -9
- data/lib/action_dispatch/testing/integration.rb +361 -207
- data/lib/action_dispatch/testing/request_encoder.rb +55 -0
- data/lib/action_dispatch/testing/test_process.rb +28 -19
- data/lib/action_dispatch/testing/test_request.rb +30 -33
- data/lib/action_dispatch/testing/test_response.rb +35 -11
- data/lib/action_dispatch.rb +42 -32
- data/lib/action_pack/gem_version.rb +17 -0
- data/lib/action_pack/version.rb +7 -7
- data/lib/action_pack.rb +4 -2
- metadata +116 -175
- data/lib/abstract_controller/layouts.rb +0 -423
- data/lib/abstract_controller/view_paths.rb +0 -96
- data/lib/action_controller/caching/actions.rb +0 -185
- data/lib/action_controller/caching/fragments.rb +0 -127
- data/lib/action_controller/caching/pages.rb +0 -187
- data/lib/action_controller/caching/sweeping.rb +0 -97
- data/lib/action_controller/deprecated/integration_test.rb +0 -2
- data/lib/action_controller/deprecated/performance_test.rb +0 -1
- data/lib/action_controller/deprecated.rb +0 -3
- data/lib/action_controller/metal/compatibility.rb +0 -65
- data/lib/action_controller/metal/hide_actions.rb +0 -41
- data/lib/action_controller/metal/rack_delegation.rb +0 -26
- data/lib/action_controller/metal/responder.rb +0 -286
- data/lib/action_controller/metal/session_management.rb +0 -14
- data/lib/action_controller/middleware.rb +0 -39
- data/lib/action_controller/railties/paths.rb +0 -25
- data/lib/action_controller/record_identifier.rb +0 -85
- data/lib/action_controller/vendor/html-scanner/html/document.rb +0 -68
- data/lib/action_controller/vendor/html-scanner/html/node.rb +0 -532
- data/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +0 -177
- data/lib/action_controller/vendor/html-scanner/html/selector.rb +0 -830
- data/lib/action_controller/vendor/html-scanner/html/tokenizer.rb +0 -107
- data/lib/action_controller/vendor/html-scanner/html/version.rb +0 -11
- data/lib/action_controller/vendor/html-scanner.rb +0 -20
- data/lib/action_dispatch/middleware/best_standards_support.rb +0 -30
- data/lib/action_dispatch/middleware/body_proxy.rb +0 -30
- data/lib/action_dispatch/middleware/head.rb +0 -18
- data/lib/action_dispatch/middleware/params_parser.rb +0 -75
- data/lib/action_dispatch/middleware/rescue.rb +0 -26
- data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb +0 -31
- data/lib/action_dispatch/middleware/templates/rescues/_trace.erb +0 -26
- data/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb +0 -10
- data/lib/action_dispatch/middleware/templates/rescues/missing_template.erb +0 -2
- data/lib/action_dispatch/middleware/templates/rescues/routing_error.erb +0 -15
- data/lib/action_dispatch/middleware/templates/rescues/template_error.erb +0 -17
- data/lib/action_dispatch/middleware/templates/rescues/unknown_action.erb +0 -2
- data/lib/action_dispatch/testing/assertions/dom.rb +0 -37
- data/lib/action_dispatch/testing/assertions/selector.rb +0 -435
- data/lib/action_dispatch/testing/assertions/tag.rb +0 -138
- data/lib/action_dispatch/testing/performance_test.rb +0 -10
- data/lib/action_view/asset_paths.rb +0 -142
- data/lib/action_view/base.rb +0 -220
- data/lib/action_view/buffers.rb +0 -43
- data/lib/action_view/context.rb +0 -36
- data/lib/action_view/flows.rb +0 -79
- data/lib/action_view/helpers/active_model_helper.rb +0 -50
- data/lib/action_view/helpers/asset_paths.rb +0 -7
- data/lib/action_view/helpers/asset_tag_helper.rb +0 -457
- data/lib/action_view/helpers/asset_tag_helpers/asset_include_tag.rb +0 -146
- data/lib/action_view/helpers/asset_tag_helpers/asset_paths.rb +0 -93
- data/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb +0 -193
- data/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb +0 -148
- data/lib/action_view/helpers/atom_feed_helper.rb +0 -200
- data/lib/action_view/helpers/cache_helper.rb +0 -64
- data/lib/action_view/helpers/capture_helper.rb +0 -203
- data/lib/action_view/helpers/controller_helper.rb +0 -25
- data/lib/action_view/helpers/csrf_helper.rb +0 -32
- data/lib/action_view/helpers/date_helper.rb +0 -1062
- data/lib/action_view/helpers/debug_helper.rb +0 -40
- data/lib/action_view/helpers/form_helper.rb +0 -1486
- data/lib/action_view/helpers/form_options_helper.rb +0 -658
- data/lib/action_view/helpers/form_tag_helper.rb +0 -685
- data/lib/action_view/helpers/javascript_helper.rb +0 -110
- data/lib/action_view/helpers/number_helper.rb +0 -622
- data/lib/action_view/helpers/output_safety_helper.rb +0 -38
- data/lib/action_view/helpers/record_tag_helper.rb +0 -111
- data/lib/action_view/helpers/rendering_helper.rb +0 -92
- data/lib/action_view/helpers/sanitize_helper.rb +0 -259
- data/lib/action_view/helpers/tag_helper.rb +0 -167
- data/lib/action_view/helpers/text_helper.rb +0 -426
- data/lib/action_view/helpers/translation_helper.rb +0 -91
- data/lib/action_view/helpers/url_helper.rb +0 -693
- data/lib/action_view/helpers.rb +0 -60
- data/lib/action_view/locale/en.yml +0 -160
- data/lib/action_view/log_subscriber.rb +0 -28
- data/lib/action_view/lookup_context.rb +0 -258
- data/lib/action_view/path_set.rb +0 -101
- data/lib/action_view/railtie.rb +0 -55
- data/lib/action_view/renderer/abstract_renderer.rb +0 -41
- data/lib/action_view/renderer/partial_renderer.rb +0 -415
- data/lib/action_view/renderer/renderer.rb +0 -61
- data/lib/action_view/renderer/streaming_template_renderer.rb +0 -106
- data/lib/action_view/renderer/template_renderer.rb +0 -95
- data/lib/action_view/template/error.rb +0 -128
- data/lib/action_view/template/handlers/builder.rb +0 -26
- data/lib/action_view/template/handlers/erb.rb +0 -125
- data/lib/action_view/template/handlers.rb +0 -50
- data/lib/action_view/template/resolver.rb +0 -298
- data/lib/action_view/template/text.rb +0 -30
- data/lib/action_view/template.rb +0 -337
- data/lib/action_view/test_case.rb +0 -246
- data/lib/action_view/testing/resolvers.rb +0 -49
- data/lib/action_view.rb +0 -84
- data/lib/sprockets/assets.rake +0 -99
- data/lib/sprockets/bootstrap.rb +0 -37
- data/lib/sprockets/compressors.rb +0 -83
- data/lib/sprockets/helpers/isolated_helper.rb +0 -13
- data/lib/sprockets/helpers/rails_helper.rb +0 -182
- data/lib/sprockets/helpers.rb +0 -6
- data/lib/sprockets/railtie.rb +0 -62
- data/lib/sprockets/static_compiler.rb +0 -56
|
@@ -1,40 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module ActionController
|
|
2
4
|
class ActionControllerError < StandardError #:nodoc:
|
|
3
5
|
end
|
|
4
6
|
|
|
7
|
+
class BadRequest < ActionControllerError #:nodoc:
|
|
8
|
+
def initialize(msg = nil)
|
|
9
|
+
super(msg)
|
|
10
|
+
set_backtrace $!.backtrace if $!
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
5
14
|
class RenderError < ActionControllerError #:nodoc:
|
|
6
15
|
end
|
|
7
16
|
|
|
8
17
|
class RoutingError < ActionControllerError #:nodoc:
|
|
9
18
|
attr_reader :failures
|
|
10
|
-
def initialize(message, failures=[])
|
|
19
|
+
def initialize(message, failures = [])
|
|
11
20
|
super(message)
|
|
12
21
|
@failures = failures
|
|
13
22
|
end
|
|
14
23
|
end
|
|
15
24
|
|
|
16
|
-
class
|
|
17
|
-
|
|
25
|
+
class ActionController::UrlGenerationError < ActionControllerError #:nodoc:
|
|
26
|
+
end
|
|
18
27
|
|
|
28
|
+
class MethodNotAllowed < ActionControllerError #:nodoc:
|
|
19
29
|
def initialize(*allowed_methods)
|
|
20
|
-
super("Only #{allowed_methods.to_sentence(:
|
|
30
|
+
super("Only #{allowed_methods.to_sentence(locale: :en)} requests are allowed.")
|
|
21
31
|
end
|
|
22
32
|
end
|
|
23
33
|
|
|
24
34
|
class NotImplemented < MethodNotAllowed #:nodoc:
|
|
25
35
|
end
|
|
26
36
|
|
|
27
|
-
class UnknownController < ActionControllerError #:nodoc:
|
|
28
|
-
end
|
|
29
|
-
|
|
30
37
|
class MissingFile < ActionControllerError #:nodoc:
|
|
31
38
|
end
|
|
32
39
|
|
|
33
|
-
class RenderError < ActionControllerError #:nodoc:
|
|
34
|
-
end
|
|
35
|
-
|
|
36
40
|
class SessionOverflowError < ActionControllerError #:nodoc:
|
|
37
|
-
DEFAULT_MESSAGE =
|
|
41
|
+
DEFAULT_MESSAGE = "Your session data is larger than the data column in which it is to be stored. You must increase the size of your data column if you intend to store large data."
|
|
38
42
|
|
|
39
43
|
def initialize(message = nil)
|
|
40
44
|
super(message || DEFAULT_MESSAGE)
|
|
@@ -43,4 +47,7 @@ module ActionController
|
|
|
43
47
|
|
|
44
48
|
class UnknownHttpMethod < ActionControllerError #:nodoc:
|
|
45
49
|
end
|
|
46
|
-
|
|
50
|
+
|
|
51
|
+
class UnknownFormat < ActionControllerError #:nodoc:
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -1,21 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module ActionController #:nodoc:
|
|
2
4
|
module Flash
|
|
3
5
|
extend ActiveSupport::Concern
|
|
4
6
|
|
|
5
7
|
included do
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
class_attribute :_flash_types, instance_accessor: false, default: []
|
|
9
|
+
|
|
10
|
+
delegate :flash, to: :request
|
|
11
|
+
add_flash_types(:alert, :notice)
|
|
9
12
|
end
|
|
10
13
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
module ClassMethods
|
|
15
|
+
# 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
|
+
#
|
|
19
|
+
# # in application_controller.rb
|
|
20
|
+
# class ApplicationController < ActionController::Base
|
|
21
|
+
# add_flash_types :warning
|
|
22
|
+
# end
|
|
23
|
+
#
|
|
24
|
+
# # in your controller
|
|
25
|
+
# redirect_to user_path(@user), warning: "Incomplete profile"
|
|
26
|
+
#
|
|
27
|
+
# # in your view
|
|
28
|
+
# <%= warning %>
|
|
29
|
+
#
|
|
30
|
+
# This method will automatically define a new method for each of the given
|
|
31
|
+
# names, and it will be available in your views.
|
|
32
|
+
def add_flash_types(*types)
|
|
33
|
+
types.each do |type|
|
|
34
|
+
next if _flash_types.include?(type)
|
|
35
|
+
|
|
36
|
+
define_method(type) do
|
|
37
|
+
request.flash[type]
|
|
38
|
+
end
|
|
39
|
+
helper_method type
|
|
40
|
+
|
|
41
|
+
self._flash_types += [type]
|
|
15
42
|
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
16
45
|
|
|
17
|
-
|
|
18
|
-
|
|
46
|
+
private
|
|
47
|
+
def redirect_to(options = {}, response_status_and_flash = {}) #:doc:
|
|
48
|
+
self.class._flash_types.each do |flash_type|
|
|
49
|
+
if type = response_status_and_flash.delete(flash_type)
|
|
50
|
+
flash[flash_type] = type
|
|
51
|
+
end
|
|
19
52
|
end
|
|
20
53
|
|
|
21
54
|
if other_flashes = response_status_and_flash.delete(:flash)
|
|
@@ -1,39 +1,99 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "active_support/core_ext/hash/except"
|
|
4
|
+
require "active_support/core_ext/hash/slice"
|
|
5
|
+
|
|
1
6
|
module ActionController
|
|
2
|
-
# This module provides a method which will redirect browser to use HTTPS
|
|
3
|
-
# protocol. This will ensure that
|
|
4
|
-
# transferred safely over the internet. You _should_ always force browser
|
|
7
|
+
# This module provides a method which will redirect the browser to use the secured HTTPS
|
|
8
|
+
# protocol. This will ensure that users' sensitive information will be
|
|
9
|
+
# transferred safely over the internet. You _should_ always force the browser
|
|
5
10
|
# to use HTTPS when you're transferring sensitive information such as
|
|
6
11
|
# user authentication, account information, or credit card information.
|
|
7
12
|
#
|
|
8
13
|
# Note that if you are really concerned about your application security,
|
|
9
14
|
# you might consider using +config.force_ssl+ in your config file instead.
|
|
10
|
-
# That will ensure all the data transferred via HTTPS
|
|
11
|
-
# user from getting session hijacked when accessing the
|
|
12
|
-
# HTTP protocol.
|
|
15
|
+
# That will ensure all the data is transferred via HTTPS, and will
|
|
16
|
+
# prevent the user from getting their session hijacked when accessing the
|
|
17
|
+
# site over unsecured HTTP protocol.
|
|
13
18
|
module ForceSSL
|
|
14
19
|
extend ActiveSupport::Concern
|
|
15
20
|
include AbstractController::Callbacks
|
|
16
21
|
|
|
22
|
+
ACTION_OPTIONS = [:only, :except, :if, :unless]
|
|
23
|
+
URL_OPTIONS = [:protocol, :host, :domain, :subdomain, :port, :path]
|
|
24
|
+
REDIRECT_OPTIONS = [:status, :flash, :alert, :notice]
|
|
25
|
+
|
|
17
26
|
module ClassMethods
|
|
18
27
|
# Force the request to this particular controller or specified actions to be
|
|
19
|
-
#
|
|
28
|
+
# through the HTTPS protocol.
|
|
29
|
+
#
|
|
30
|
+
# If you need to disable this for any reason (e.g. development) then you can use
|
|
31
|
+
# an +:if+ or +:unless+ condition.
|
|
32
|
+
#
|
|
33
|
+
# class AccountsController < ApplicationController
|
|
34
|
+
# force_ssl if: :ssl_configured?
|
|
35
|
+
#
|
|
36
|
+
# def ssl_configured?
|
|
37
|
+
# !Rails.env.development?
|
|
38
|
+
# end
|
|
39
|
+
# end
|
|
40
|
+
#
|
|
41
|
+
# ==== URL Options
|
|
42
|
+
# You can pass any of the following options to affect the redirect URL
|
|
43
|
+
# * <tt>host</tt> - Redirect to a different host name
|
|
44
|
+
# * <tt>subdomain</tt> - Redirect to a different subdomain
|
|
45
|
+
# * <tt>domain</tt> - Redirect to a different domain
|
|
46
|
+
# * <tt>port</tt> - Redirect to a non-standard port
|
|
47
|
+
# * <tt>path</tt> - Redirect to a different path
|
|
20
48
|
#
|
|
21
|
-
#
|
|
49
|
+
# ==== Redirect Options
|
|
50
|
+
# You can pass any of the following options to affect the redirect status and response
|
|
51
|
+
# * <tt>status</tt> - Redirect with a custom status (default is 301 Moved Permanently)
|
|
52
|
+
# * <tt>flash</tt> - Set a flash message when redirecting
|
|
53
|
+
# * <tt>alert</tt> - Set an alert message when redirecting
|
|
54
|
+
# * <tt>notice</tt> - Set a notice message when redirecting
|
|
22
55
|
#
|
|
23
|
-
# ==== Options
|
|
24
|
-
#
|
|
25
|
-
# * <tt>
|
|
56
|
+
# ==== Action Options
|
|
57
|
+
# You can pass any of the following options to affect the before_action callback
|
|
58
|
+
# * <tt>only</tt> - The callback should be run only for this action
|
|
59
|
+
# * <tt>except</tt> - The callback should be run for all actions except this action
|
|
60
|
+
# * <tt>if</tt> - A symbol naming an instance method or a proc; the
|
|
61
|
+
# callback will be called only when it returns a true value.
|
|
62
|
+
# * <tt>unless</tt> - A symbol naming an instance method or a proc; the
|
|
63
|
+
# callback will be called only when it returns a false value.
|
|
26
64
|
def force_ssl(options = {})
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
redirect_options.merge!(:host => host) if host
|
|
32
|
-
redirect_options.merge!(:params => request.query_parameters)
|
|
33
|
-
redirect_to redirect_options
|
|
34
|
-
end
|
|
65
|
+
action_options = options.slice(*ACTION_OPTIONS)
|
|
66
|
+
redirect_options = options.except(*ACTION_OPTIONS)
|
|
67
|
+
before_action(action_options) do
|
|
68
|
+
force_ssl_redirect(redirect_options)
|
|
35
69
|
end
|
|
36
70
|
end
|
|
37
71
|
end
|
|
72
|
+
|
|
73
|
+
# Redirect the existing request to use the HTTPS protocol.
|
|
74
|
+
#
|
|
75
|
+
# ==== Parameters
|
|
76
|
+
# * <tt>host_or_options</tt> - Either a host name or any of the URL and
|
|
77
|
+
# redirect options available to the <tt>force_ssl</tt> method.
|
|
78
|
+
def force_ssl_redirect(host_or_options = nil)
|
|
79
|
+
unless request.ssl?
|
|
80
|
+
options = {
|
|
81
|
+
protocol: "https://",
|
|
82
|
+
host: request.host,
|
|
83
|
+
path: request.fullpath,
|
|
84
|
+
status: :moved_permanently
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if host_or_options.is_a?(Hash)
|
|
88
|
+
options.merge!(host_or_options)
|
|
89
|
+
elsif host_or_options
|
|
90
|
+
options[:host] = host_or_options
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
secure_url = ActionDispatch::Http::URL.url_for(options.slice(*URL_OPTIONS))
|
|
94
|
+
flash.keep if respond_to?(:flash) && request.respond_to?(:flash)
|
|
95
|
+
redirect_to secure_url, options.slice(*REDIRECT_OPTIONS)
|
|
96
|
+
end
|
|
97
|
+
end
|
|
38
98
|
end
|
|
39
99
|
end
|
|
@@ -1,35 +1,60 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module ActionController
|
|
2
4
|
module Head
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
# Return a response that has no content (merely headers). The options
|
|
5
|
+
# Returns a response that has no content (merely headers). The options
|
|
6
6
|
# argument is interpreted to be a hash of header names and values.
|
|
7
7
|
# This allows you to easily return a response that consists only of
|
|
8
8
|
# significant headers:
|
|
9
9
|
#
|
|
10
|
-
# head :created, :
|
|
10
|
+
# head :created, location: person_path(@person)
|
|
11
11
|
#
|
|
12
|
-
# head :created, :
|
|
12
|
+
# head :created, location: @person
|
|
13
13
|
#
|
|
14
14
|
# It can also be used to return exceptional conditions:
|
|
15
15
|
#
|
|
16
16
|
# return head(:method_not_allowed) unless request.post?
|
|
17
17
|
# return head(:bad_request) unless valid_request?
|
|
18
18
|
# render
|
|
19
|
+
#
|
|
20
|
+
# See Rack::Utils::SYMBOL_TO_STATUS_CODE for a full list of valid +status+ symbols.
|
|
19
21
|
def head(status, options = {})
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
if status.is_a?(Hash)
|
|
23
|
+
raise ArgumentError, "#{status.inspect} is not a valid value for `status`."
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
status ||= :ok
|
|
27
|
+
|
|
22
28
|
location = options.delete(:location)
|
|
23
29
|
content_type = options.delete(:content_type)
|
|
24
30
|
|
|
25
31
|
options.each do |key, value|
|
|
26
|
-
headers[key.to_s.dasherize.split(
|
|
32
|
+
headers[key.to_s.dasherize.split("-").each { |v| v[0] = v[0].chr.upcase }.join("-")] = value.to_s
|
|
27
33
|
end
|
|
28
34
|
|
|
29
35
|
self.status = status
|
|
30
36
|
self.location = url_for(location) if location
|
|
31
|
-
|
|
32
|
-
self.response_body = "
|
|
37
|
+
|
|
38
|
+
self.response_body = ""
|
|
39
|
+
|
|
40
|
+
if include_content?(response_code)
|
|
41
|
+
self.content_type = content_type || (Mime[formats.first] if formats)
|
|
42
|
+
response.charset = false
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
true
|
|
33
46
|
end
|
|
47
|
+
|
|
48
|
+
private
|
|
49
|
+
def include_content?(status)
|
|
50
|
+
case status
|
|
51
|
+
when 100..199
|
|
52
|
+
false
|
|
53
|
+
when 204, 205, 304
|
|
54
|
+
false
|
|
55
|
+
else
|
|
56
|
+
true
|
|
57
|
+
end
|
|
58
|
+
end
|
|
34
59
|
end
|
|
35
60
|
end
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
require 'active_support/core_ext/class/attribute'
|
|
1
|
+
# frozen_string_literal: true
|
|
3
2
|
|
|
4
3
|
module ActionController
|
|
5
4
|
# The \Rails framework provides a large number of helpers for working with assets, dates, forms,
|
|
@@ -8,16 +7,15 @@ module ActionController
|
|
|
8
7
|
#
|
|
9
8
|
# In addition to using the standard template helpers provided, creating custom helpers to
|
|
10
9
|
# extract complicated logic or reusable functionality is strongly encouraged. By default, each controller
|
|
11
|
-
# will include all helpers.
|
|
10
|
+
# will include all helpers. These helpers are only accessible on the controller through <tt>#helpers</tt>
|
|
12
11
|
#
|
|
13
|
-
# In previous versions of \Rails the controller will include a helper
|
|
14
|
-
#
|
|
12
|
+
# In previous versions of \Rails the controller will include a helper which
|
|
13
|
+
# matches the name of the controller, e.g., <tt>MyController</tt> will automatically
|
|
15
14
|
# include <tt>MyHelper</tt>. To return old behavior set +config.action_controller.include_all_helpers+ to +false+.
|
|
16
15
|
#
|
|
17
16
|
# Additional helpers can be specified using the +helper+ class method in ActionController::Base or any
|
|
18
17
|
# controller which inherits from it.
|
|
19
18
|
#
|
|
20
|
-
# ==== Examples
|
|
21
19
|
# The +to_s+ method from the \Time class can be wrapped in a helper method to display a custom message if
|
|
22
20
|
# a \Time object is blank:
|
|
23
21
|
#
|
|
@@ -48,17 +46,17 @@ module ActionController
|
|
|
48
46
|
# the output might look like this:
|
|
49
47
|
#
|
|
50
48
|
# 23 Aug 11:30 | Carolina Railhawks Soccer Match
|
|
51
|
-
# N/A | Carolina
|
|
49
|
+
# N/A | Carolina Railhawks Training Workshop
|
|
52
50
|
#
|
|
53
51
|
module Helpers
|
|
54
52
|
extend ActiveSupport::Concern
|
|
55
53
|
|
|
54
|
+
class << self; attr_accessor :helpers_path; end
|
|
56
55
|
include AbstractController::Helpers
|
|
57
56
|
|
|
58
57
|
included do
|
|
59
|
-
class_attribute :helpers_path, :
|
|
60
|
-
|
|
61
|
-
self.include_all_helpers = true
|
|
58
|
+
class_attribute :helpers_path, default: []
|
|
59
|
+
class_attribute :include_all_helpers, default: true
|
|
62
60
|
end
|
|
63
61
|
|
|
64
62
|
module ClassMethods
|
|
@@ -74,9 +72,13 @@ module ActionController
|
|
|
74
72
|
attrs.flatten.each { |attr| helper_method(attr, "#{attr}=") }
|
|
75
73
|
end
|
|
76
74
|
|
|
77
|
-
# Provides a proxy to access
|
|
75
|
+
# Provides a proxy to access helper methods from outside the view.
|
|
78
76
|
def helpers
|
|
79
|
-
@helper_proxy ||=
|
|
77
|
+
@helper_proxy ||= begin
|
|
78
|
+
proxy = ActionView::Base.new
|
|
79
|
+
proxy.config = config.inheritable_copy
|
|
80
|
+
proxy.extend(_helpers)
|
|
81
|
+
end
|
|
80
82
|
end
|
|
81
83
|
|
|
82
84
|
# Overwrite modules_for_helpers to accept :all as argument, which loads
|
|
@@ -92,22 +94,30 @@ module ActionController
|
|
|
92
94
|
super(args)
|
|
93
95
|
end
|
|
94
96
|
|
|
97
|
+
# Returns a list of helper names in a given path.
|
|
98
|
+
#
|
|
99
|
+
# ActionController::Base.all_helpers_from_path 'app/helpers'
|
|
100
|
+
# # => ["application", "chart", "rubygems"]
|
|
95
101
|
def all_helpers_from_path(path)
|
|
96
|
-
helpers =
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
102
|
+
helpers = Array(path).flat_map do |_path|
|
|
103
|
+
extract = /^#{Regexp.quote(_path.to_s)}\/?(.*)_helper.rb$/
|
|
104
|
+
names = Dir["#{_path}/**/*_helper.rb"].map { |file| file.sub(extract, '\1'.freeze) }
|
|
105
|
+
names.sort!
|
|
100
106
|
end
|
|
101
|
-
helpers.sort!
|
|
102
107
|
helpers.uniq!
|
|
103
108
|
helpers
|
|
104
109
|
end
|
|
105
110
|
|
|
106
111
|
private
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
112
|
+
# Extract helper names from files in <tt>app/helpers/**/*_helper.rb</tt>
|
|
113
|
+
def all_application_helpers
|
|
114
|
+
all_helpers_from_path(helpers_path)
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# Provides a proxy to access helper methods from outside the view.
|
|
119
|
+
def helpers
|
|
120
|
+
@_helper_proxy ||= view_context
|
|
111
121
|
end
|
|
112
122
|
end
|
|
113
123
|
end
|