actionpack 3.2.22.5 → 5.2.4
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of actionpack might be problematic. Click here for more details.
- 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,34 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "action_dispatch"
|
4
|
+
require "active_support/messages/rotation_configuration"
|
2
5
|
|
3
6
|
module ActionDispatch
|
4
|
-
class Railtie < Rails::Railtie
|
7
|
+
class Railtie < Rails::Railtie # :nodoc:
|
5
8
|
config.action_dispatch = ActiveSupport::OrderedOptions.new
|
6
9
|
config.action_dispatch.x_sendfile_header = nil
|
7
10
|
config.action_dispatch.ip_spoofing_check = true
|
8
11
|
config.action_dispatch.show_exceptions = true
|
9
|
-
config.action_dispatch.best_standards_support = true
|
10
12
|
config.action_dispatch.tld_length = 1
|
11
13
|
config.action_dispatch.ignore_accept_header = false
|
12
|
-
config.action_dispatch.rescue_templates = {
|
13
|
-
config.action_dispatch.rescue_responses = {
|
14
|
+
config.action_dispatch.rescue_templates = {}
|
15
|
+
config.action_dispatch.rescue_responses = {}
|
14
16
|
config.action_dispatch.default_charset = nil
|
17
|
+
config.action_dispatch.rack_cache = false
|
18
|
+
config.action_dispatch.http_auth_salt = "http authentication"
|
19
|
+
config.action_dispatch.signed_cookie_salt = "signed cookie"
|
20
|
+
config.action_dispatch.encrypted_cookie_salt = "encrypted cookie"
|
21
|
+
config.action_dispatch.encrypted_signed_cookie_salt = "signed encrypted cookie"
|
22
|
+
config.action_dispatch.authenticated_encrypted_cookie_salt = "authenticated encrypted cookie"
|
23
|
+
config.action_dispatch.use_authenticated_cookie_encryption = false
|
24
|
+
config.action_dispatch.perform_deep_munge = true
|
15
25
|
|
16
|
-
config.action_dispatch.
|
17
|
-
|
18
|
-
|
19
|
-
|
26
|
+
config.action_dispatch.default_headers = {
|
27
|
+
"X-Frame-Options" => "SAMEORIGIN",
|
28
|
+
"X-XSS-Protection" => "1; mode=block",
|
29
|
+
"X-Content-Type-Options" => "nosniff",
|
30
|
+
"X-Download-Options" => "noopen",
|
31
|
+
"X-Permitted-Cross-Domain-Policies" => "none",
|
32
|
+
"Referrer-Policy" => "strict-origin-when-cross-origin"
|
20
33
|
}
|
21
34
|
|
35
|
+
config.action_dispatch.cookies_rotations = ActiveSupport::Messages::RotationConfiguration.new
|
36
|
+
|
37
|
+
config.eager_load_namespaces << ActionDispatch
|
38
|
+
|
22
39
|
initializer "action_dispatch.configure" do |app|
|
23
40
|
ActionDispatch::Http::URL.tld_length = app.config.action_dispatch.tld_length
|
24
41
|
ActionDispatch::Request.ignore_accept_header = app.config.action_dispatch.ignore_accept_header
|
42
|
+
ActionDispatch::Request::Utils.perform_deep_munge = app.config.action_dispatch.perform_deep_munge
|
25
43
|
ActionDispatch::Response.default_charset = app.config.action_dispatch.default_charset || app.config.encoding
|
44
|
+
ActionDispatch::Response.default_headers = app.config.action_dispatch.default_headers
|
26
45
|
|
27
46
|
ActionDispatch::ExceptionWrapper.rescue_responses.merge!(config.action_dispatch.rescue_responses)
|
28
47
|
ActionDispatch::ExceptionWrapper.rescue_templates.merge!(config.action_dispatch.rescue_templates)
|
29
48
|
|
30
49
|
config.action_dispatch.always_write_cookie = Rails.env.development? if config.action_dispatch.always_write_cookie.nil?
|
31
50
|
ActionDispatch::Cookies::CookieJar.always_write_cookie = config.action_dispatch.always_write_cookie
|
51
|
+
|
52
|
+
ActionDispatch.test_app = app
|
32
53
|
end
|
33
54
|
end
|
34
55
|
end
|
@@ -0,0 +1,234 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rack/session/abstract/id"
|
4
|
+
|
5
|
+
module ActionDispatch
|
6
|
+
class Request
|
7
|
+
# Session is responsible for lazily loading the session from store.
|
8
|
+
class Session # :nodoc:
|
9
|
+
ENV_SESSION_KEY = Rack::RACK_SESSION # :nodoc:
|
10
|
+
ENV_SESSION_OPTIONS_KEY = Rack::RACK_SESSION_OPTIONS # :nodoc:
|
11
|
+
|
12
|
+
# Singleton object used to determine if an optional param wasn't specified.
|
13
|
+
Unspecified = Object.new
|
14
|
+
|
15
|
+
# Creates a session hash, merging the properties of the previous session if any.
|
16
|
+
def self.create(store, req, default_options)
|
17
|
+
session_was = find req
|
18
|
+
session = Request::Session.new(store, req)
|
19
|
+
session.merge! session_was if session_was
|
20
|
+
|
21
|
+
set(req, session)
|
22
|
+
Options.set(req, Request::Session::Options.new(store, default_options))
|
23
|
+
session
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.find(req)
|
27
|
+
req.get_header ENV_SESSION_KEY
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.set(req, session)
|
31
|
+
req.set_header ENV_SESSION_KEY, session
|
32
|
+
end
|
33
|
+
|
34
|
+
class Options #:nodoc:
|
35
|
+
def self.set(req, options)
|
36
|
+
req.set_header ENV_SESSION_OPTIONS_KEY, options
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.find(req)
|
40
|
+
req.get_header ENV_SESSION_OPTIONS_KEY
|
41
|
+
end
|
42
|
+
|
43
|
+
def initialize(by, default_options)
|
44
|
+
@by = by
|
45
|
+
@delegate = default_options.dup
|
46
|
+
end
|
47
|
+
|
48
|
+
def [](key)
|
49
|
+
@delegate[key]
|
50
|
+
end
|
51
|
+
|
52
|
+
def id(req)
|
53
|
+
@delegate.fetch(:id) {
|
54
|
+
@by.send(:extract_session_id, req)
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
def []=(k, v); @delegate[k] = v; end
|
59
|
+
def to_hash; @delegate.dup; end
|
60
|
+
def values_at(*args); @delegate.values_at(*args); end
|
61
|
+
end
|
62
|
+
|
63
|
+
def initialize(by, req)
|
64
|
+
@by = by
|
65
|
+
@req = req
|
66
|
+
@delegate = {}
|
67
|
+
@loaded = false
|
68
|
+
@exists = nil # We haven't checked yet.
|
69
|
+
end
|
70
|
+
|
71
|
+
def id
|
72
|
+
options.id(@req)
|
73
|
+
end
|
74
|
+
|
75
|
+
def options
|
76
|
+
Options.find @req
|
77
|
+
end
|
78
|
+
|
79
|
+
def destroy
|
80
|
+
clear
|
81
|
+
options = self.options || {}
|
82
|
+
@by.send(:delete_session, @req, options.id(@req), options)
|
83
|
+
|
84
|
+
# Load the new sid to be written with the response.
|
85
|
+
@loaded = false
|
86
|
+
load_for_write!
|
87
|
+
end
|
88
|
+
|
89
|
+
# Returns value of the key stored in the session or
|
90
|
+
# +nil+ if the given key is not found in the session.
|
91
|
+
def [](key)
|
92
|
+
load_for_read!
|
93
|
+
@delegate[key.to_s]
|
94
|
+
end
|
95
|
+
|
96
|
+
# Returns true if the session has the given key or false.
|
97
|
+
def has_key?(key)
|
98
|
+
load_for_read!
|
99
|
+
@delegate.key?(key.to_s)
|
100
|
+
end
|
101
|
+
alias :key? :has_key?
|
102
|
+
alias :include? :has_key?
|
103
|
+
|
104
|
+
# Returns keys of the session as Array.
|
105
|
+
def keys
|
106
|
+
load_for_read!
|
107
|
+
@delegate.keys
|
108
|
+
end
|
109
|
+
|
110
|
+
# Returns values of the session as Array.
|
111
|
+
def values
|
112
|
+
load_for_read!
|
113
|
+
@delegate.values
|
114
|
+
end
|
115
|
+
|
116
|
+
# Writes given value to given key of the session.
|
117
|
+
def []=(key, value)
|
118
|
+
load_for_write!
|
119
|
+
@delegate[key.to_s] = value
|
120
|
+
end
|
121
|
+
|
122
|
+
# Clears the session.
|
123
|
+
def clear
|
124
|
+
load_for_write!
|
125
|
+
@delegate.clear
|
126
|
+
end
|
127
|
+
|
128
|
+
# Returns the session as Hash.
|
129
|
+
def to_hash
|
130
|
+
load_for_read!
|
131
|
+
@delegate.dup.delete_if { |_, v| v.nil? }
|
132
|
+
end
|
133
|
+
alias :to_h :to_hash
|
134
|
+
|
135
|
+
# Updates the session with given Hash.
|
136
|
+
#
|
137
|
+
# session.to_hash
|
138
|
+
# # => {"session_id"=>"e29b9ea315edf98aad94cc78c34cc9b2"}
|
139
|
+
#
|
140
|
+
# session.update({ "foo" => "bar" })
|
141
|
+
# # => {"session_id"=>"e29b9ea315edf98aad94cc78c34cc9b2", "foo" => "bar"}
|
142
|
+
#
|
143
|
+
# session.to_hash
|
144
|
+
# # => {"session_id"=>"e29b9ea315edf98aad94cc78c34cc9b2", "foo" => "bar"}
|
145
|
+
def update(hash)
|
146
|
+
load_for_write!
|
147
|
+
@delegate.update stringify_keys(hash)
|
148
|
+
end
|
149
|
+
|
150
|
+
# Deletes given key from the session.
|
151
|
+
def delete(key)
|
152
|
+
load_for_write!
|
153
|
+
@delegate.delete key.to_s
|
154
|
+
end
|
155
|
+
|
156
|
+
# Returns value of the given key from the session, or raises +KeyError+
|
157
|
+
# if can't find the given key and no default value is set.
|
158
|
+
# Returns default value if specified.
|
159
|
+
#
|
160
|
+
# session.fetch(:foo)
|
161
|
+
# # => KeyError: key not found: "foo"
|
162
|
+
#
|
163
|
+
# session.fetch(:foo, :bar)
|
164
|
+
# # => :bar
|
165
|
+
#
|
166
|
+
# session.fetch(:foo) do
|
167
|
+
# :bar
|
168
|
+
# end
|
169
|
+
# # => :bar
|
170
|
+
def fetch(key, default = Unspecified, &block)
|
171
|
+
load_for_read!
|
172
|
+
if default == Unspecified
|
173
|
+
@delegate.fetch(key.to_s, &block)
|
174
|
+
else
|
175
|
+
@delegate.fetch(key.to_s, default, &block)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
def inspect
|
180
|
+
if loaded?
|
181
|
+
super
|
182
|
+
else
|
183
|
+
"#<#{self.class}:0x#{(object_id << 1).to_s(16)} not yet loaded>"
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
def exists?
|
188
|
+
return @exists unless @exists.nil?
|
189
|
+
@exists = @by.send(:session_exists?, @req)
|
190
|
+
end
|
191
|
+
|
192
|
+
def loaded?
|
193
|
+
@loaded
|
194
|
+
end
|
195
|
+
|
196
|
+
def empty?
|
197
|
+
load_for_read!
|
198
|
+
@delegate.empty?
|
199
|
+
end
|
200
|
+
|
201
|
+
def merge!(other)
|
202
|
+
load_for_write!
|
203
|
+
@delegate.merge!(other)
|
204
|
+
end
|
205
|
+
|
206
|
+
def each(&block)
|
207
|
+
to_hash.each(&block)
|
208
|
+
end
|
209
|
+
|
210
|
+
private
|
211
|
+
|
212
|
+
def load_for_read!
|
213
|
+
load! if !loaded? && exists?
|
214
|
+
end
|
215
|
+
|
216
|
+
def load_for_write!
|
217
|
+
load! unless loaded?
|
218
|
+
end
|
219
|
+
|
220
|
+
def load!
|
221
|
+
id, session = @by.load_session @req
|
222
|
+
options[:id] = id
|
223
|
+
@delegate.replace(stringify_keys(session))
|
224
|
+
@loaded = true
|
225
|
+
end
|
226
|
+
|
227
|
+
def stringify_keys(other)
|
228
|
+
other.each_with_object({}) { |(key, value), hash|
|
229
|
+
hash[key.to_s] = value
|
230
|
+
}
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/core_ext/hash/indifferent_access"
|
4
|
+
|
5
|
+
module ActionDispatch
|
6
|
+
class Request
|
7
|
+
class Utils # :nodoc:
|
8
|
+
mattr_accessor :perform_deep_munge, default: true
|
9
|
+
|
10
|
+
def self.each_param_value(params, &block)
|
11
|
+
case params
|
12
|
+
when Array
|
13
|
+
params.each { |element| each_param_value(element, &block) }
|
14
|
+
when Hash
|
15
|
+
params.each_value { |value| each_param_value(value, &block) }
|
16
|
+
when String
|
17
|
+
block.call params
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.normalize_encode_params(params)
|
22
|
+
if perform_deep_munge
|
23
|
+
NoNilParamEncoder.normalize_encode_params params
|
24
|
+
else
|
25
|
+
ParamEncoder.normalize_encode_params params
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.check_param_encoding(params)
|
30
|
+
case params
|
31
|
+
when Array
|
32
|
+
params.each { |element| check_param_encoding(element) }
|
33
|
+
when Hash
|
34
|
+
params.each_value { |value| check_param_encoding(value) }
|
35
|
+
when String
|
36
|
+
unless params.valid_encoding?
|
37
|
+
# Raise Rack::Utils::InvalidParameterError for consistency with Rack.
|
38
|
+
# ActionDispatch::Request#GET will re-raise as a BadRequest error.
|
39
|
+
raise Rack::Utils::InvalidParameterError, "Invalid encoding for parameter: #{params.scrub}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class ParamEncoder # :nodoc:
|
45
|
+
# Convert nested Hash to HashWithIndifferentAccess.
|
46
|
+
def self.normalize_encode_params(params)
|
47
|
+
case params
|
48
|
+
when Array
|
49
|
+
handle_array params
|
50
|
+
when Hash
|
51
|
+
if params.has_key?(:tempfile)
|
52
|
+
ActionDispatch::Http::UploadedFile.new(params)
|
53
|
+
else
|
54
|
+
params.each_with_object({}) do |(key, val), new_hash|
|
55
|
+
new_hash[key] = normalize_encode_params(val)
|
56
|
+
end.with_indifferent_access
|
57
|
+
end
|
58
|
+
else
|
59
|
+
params
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.handle_array(params)
|
64
|
+
params.map! { |el| normalize_encode_params(el) }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# Remove nils from the params hash.
|
69
|
+
class NoNilParamEncoder < ParamEncoder # :nodoc:
|
70
|
+
def self.handle_array(params)
|
71
|
+
list = super
|
72
|
+
list.compact!
|
73
|
+
list
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActionDispatch
|
4
|
+
module Routing
|
5
|
+
class Endpoint # :nodoc:
|
6
|
+
def dispatcher?; false; end
|
7
|
+
def redirect?; false; end
|
8
|
+
def matches?(req); true; end
|
9
|
+
def app; self; end
|
10
|
+
def rack_app; app; end
|
11
|
+
|
12
|
+
def engine?
|
13
|
+
rack_app.is_a?(Class) && rack_app < Rails::Engine
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,225 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "delegate"
|
4
|
+
require "active_support/core_ext/string/strip"
|
5
|
+
|
6
|
+
module ActionDispatch
|
7
|
+
module Routing
|
8
|
+
class RouteWrapper < SimpleDelegator
|
9
|
+
def endpoint
|
10
|
+
app.dispatcher? ? "#{controller}##{action}" : rack_app.inspect
|
11
|
+
end
|
12
|
+
|
13
|
+
def constraints
|
14
|
+
requirements.except(:controller, :action)
|
15
|
+
end
|
16
|
+
|
17
|
+
def rack_app
|
18
|
+
app.rack_app
|
19
|
+
end
|
20
|
+
|
21
|
+
def path
|
22
|
+
super.spec.to_s
|
23
|
+
end
|
24
|
+
|
25
|
+
def name
|
26
|
+
super.to_s
|
27
|
+
end
|
28
|
+
|
29
|
+
def reqs
|
30
|
+
@reqs ||= begin
|
31
|
+
reqs = endpoint
|
32
|
+
reqs += " #{constraints}" unless constraints.empty?
|
33
|
+
reqs
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def controller
|
38
|
+
parts.include?(:controller) ? ":controller" : requirements[:controller]
|
39
|
+
end
|
40
|
+
|
41
|
+
def action
|
42
|
+
parts.include?(:action) ? ":action" : requirements[:action]
|
43
|
+
end
|
44
|
+
|
45
|
+
def internal?
|
46
|
+
internal
|
47
|
+
end
|
48
|
+
|
49
|
+
def engine?
|
50
|
+
app.engine?
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
##
|
55
|
+
# This class is just used for displaying route information when someone
|
56
|
+
# executes `rails routes` or looks at the RoutingError page.
|
57
|
+
# People should not use this class.
|
58
|
+
class RoutesInspector # :nodoc:
|
59
|
+
def initialize(routes)
|
60
|
+
@engines = {}
|
61
|
+
@routes = routes
|
62
|
+
end
|
63
|
+
|
64
|
+
def format(formatter, filter = nil)
|
65
|
+
routes_to_display = filter_routes(normalize_filter(filter))
|
66
|
+
routes = collect_routes(routes_to_display)
|
67
|
+
if routes.none?
|
68
|
+
formatter.no_routes(collect_routes(@routes))
|
69
|
+
return formatter.result
|
70
|
+
end
|
71
|
+
|
72
|
+
formatter.header routes
|
73
|
+
formatter.section routes
|
74
|
+
|
75
|
+
@engines.each do |name, engine_routes|
|
76
|
+
formatter.section_title "Routes for #{name}"
|
77
|
+
formatter.section engine_routes
|
78
|
+
end
|
79
|
+
|
80
|
+
formatter.result
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def normalize_filter(filter)
|
86
|
+
if filter.is_a?(Hash) && filter[:controller]
|
87
|
+
{ controller: /#{filter[:controller].underscore.sub(/_?controller\z/, "")}/ }
|
88
|
+
elsif filter
|
89
|
+
{ controller: /#{filter}/, action: /#{filter}/, verb: /#{filter}/, name: /#{filter}/, path: /#{filter}/ }
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def filter_routes(filter)
|
94
|
+
if filter
|
95
|
+
@routes.select do |route|
|
96
|
+
route_wrapper = RouteWrapper.new(route)
|
97
|
+
filter.any? { |default, value| route_wrapper.send(default) =~ value }
|
98
|
+
end
|
99
|
+
else
|
100
|
+
@routes
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def collect_routes(routes)
|
105
|
+
routes.collect do |route|
|
106
|
+
RouteWrapper.new(route)
|
107
|
+
end.reject(&:internal?).collect do |route|
|
108
|
+
collect_engine_routes(route)
|
109
|
+
|
110
|
+
{ name: route.name,
|
111
|
+
verb: route.verb,
|
112
|
+
path: route.path,
|
113
|
+
reqs: route.reqs }
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def collect_engine_routes(route)
|
118
|
+
name = route.endpoint
|
119
|
+
return unless route.engine?
|
120
|
+
return if @engines[name]
|
121
|
+
|
122
|
+
routes = route.rack_app.routes
|
123
|
+
if routes.is_a?(ActionDispatch::Routing::RouteSet)
|
124
|
+
@engines[name] = collect_routes(routes.routes)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
class ConsoleFormatter
|
130
|
+
def initialize
|
131
|
+
@buffer = []
|
132
|
+
end
|
133
|
+
|
134
|
+
def result
|
135
|
+
@buffer.join("\n")
|
136
|
+
end
|
137
|
+
|
138
|
+
def section_title(title)
|
139
|
+
@buffer << "\n#{title}:"
|
140
|
+
end
|
141
|
+
|
142
|
+
def section(routes)
|
143
|
+
@buffer << draw_section(routes)
|
144
|
+
end
|
145
|
+
|
146
|
+
def header(routes)
|
147
|
+
@buffer << draw_header(routes)
|
148
|
+
end
|
149
|
+
|
150
|
+
def no_routes(routes)
|
151
|
+
@buffer <<
|
152
|
+
if routes.none?
|
153
|
+
<<-MESSAGE.strip_heredoc
|
154
|
+
You don't have any routes defined!
|
155
|
+
|
156
|
+
Please add some routes in config/routes.rb.
|
157
|
+
MESSAGE
|
158
|
+
else
|
159
|
+
"No routes were found for this controller"
|
160
|
+
end
|
161
|
+
@buffer << "For more information about routes, see the Rails guide: http://guides.rubyonrails.org/routing.html."
|
162
|
+
end
|
163
|
+
|
164
|
+
private
|
165
|
+
def draw_section(routes)
|
166
|
+
header_lengths = ["Prefix", "Verb", "URI Pattern"].map(&:length)
|
167
|
+
name_width, verb_width, path_width = widths(routes).zip(header_lengths).map(&:max)
|
168
|
+
|
169
|
+
routes.map do |r|
|
170
|
+
"#{r[:name].rjust(name_width)} #{r[:verb].ljust(verb_width)} #{r[:path].ljust(path_width)} #{r[:reqs]}"
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
def draw_header(routes)
|
175
|
+
name_width, verb_width, path_width = widths(routes)
|
176
|
+
|
177
|
+
"#{"Prefix".rjust(name_width)} #{"Verb".ljust(verb_width)} #{"URI Pattern".ljust(path_width)} Controller#Action"
|
178
|
+
end
|
179
|
+
|
180
|
+
def widths(routes)
|
181
|
+
[routes.map { |r| r[:name].length }.max || 0,
|
182
|
+
routes.map { |r| r[:verb].length }.max || 0,
|
183
|
+
routes.map { |r| r[:path].length }.max || 0]
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
class HtmlTableFormatter
|
188
|
+
def initialize(view)
|
189
|
+
@view = view
|
190
|
+
@buffer = []
|
191
|
+
end
|
192
|
+
|
193
|
+
def section_title(title)
|
194
|
+
@buffer << %(<tr><th colspan="4">#{title}</th></tr>)
|
195
|
+
end
|
196
|
+
|
197
|
+
def section(routes)
|
198
|
+
@buffer << @view.render(partial: "routes/route", collection: routes)
|
199
|
+
end
|
200
|
+
|
201
|
+
# The header is part of the HTML page, so we don't construct it here.
|
202
|
+
def header(routes)
|
203
|
+
end
|
204
|
+
|
205
|
+
def no_routes(*)
|
206
|
+
@buffer << <<-MESSAGE.strip_heredoc
|
207
|
+
<p>You don't have any routes defined!</p>
|
208
|
+
<ul>
|
209
|
+
<li>Please add some routes in <tt>config/routes.rb</tt>.</li>
|
210
|
+
<li>
|
211
|
+
For more information about routes, please see the Rails guide
|
212
|
+
<a href="http://guides.rubyonrails.org/routing.html">Rails Routing from the Outside In</a>.
|
213
|
+
</li>
|
214
|
+
</ul>
|
215
|
+
MESSAGE
|
216
|
+
end
|
217
|
+
|
218
|
+
def result
|
219
|
+
@view.raw @view.render(layout: "routes/table") {
|
220
|
+
@view.raw @buffer.join("\n")
|
221
|
+
}
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|