halorgium-actionpack 3.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +5179 -0
- data/MIT-LICENSE +21 -0
- data/README +409 -0
- data/lib/abstract_controller.rb +16 -0
- data/lib/abstract_controller/base.rb +158 -0
- data/lib/abstract_controller/callbacks.rb +113 -0
- data/lib/abstract_controller/exceptions.rb +12 -0
- data/lib/abstract_controller/helpers.rb +151 -0
- data/lib/abstract_controller/layouts.rb +250 -0
- data/lib/abstract_controller/localized_cache.rb +49 -0
- data/lib/abstract_controller/logger.rb +61 -0
- data/lib/abstract_controller/rendering_controller.rb +188 -0
- data/lib/action_controller.rb +72 -0
- data/lib/action_controller/base.rb +168 -0
- data/lib/action_controller/caching.rb +80 -0
- data/lib/action_controller/caching/actions.rb +163 -0
- data/lib/action_controller/caching/fragments.rb +116 -0
- data/lib/action_controller/caching/pages.rb +154 -0
- data/lib/action_controller/caching/sweeping.rb +97 -0
- data/lib/action_controller/deprecated.rb +4 -0
- data/lib/action_controller/deprecated/integration_test.rb +2 -0
- data/lib/action_controller/deprecated/performance_test.rb +1 -0
- data/lib/action_controller/dispatch/dispatcher.rb +57 -0
- data/lib/action_controller/metal.rb +129 -0
- data/lib/action_controller/metal/benchmarking.rb +73 -0
- data/lib/action_controller/metal/compatibility.rb +145 -0
- data/lib/action_controller/metal/conditional_get.rb +86 -0
- data/lib/action_controller/metal/configuration.rb +28 -0
- data/lib/action_controller/metal/cookies.rb +105 -0
- data/lib/action_controller/metal/exceptions.rb +55 -0
- data/lib/action_controller/metal/filter_parameter_logging.rb +77 -0
- data/lib/action_controller/metal/flash.rb +162 -0
- data/lib/action_controller/metal/head.rb +27 -0
- data/lib/action_controller/metal/helpers.rb +115 -0
- data/lib/action_controller/metal/hide_actions.rb +47 -0
- data/lib/action_controller/metal/http_authentication.rb +312 -0
- data/lib/action_controller/metal/layouts.rb +171 -0
- data/lib/action_controller/metal/mime_responds.rb +317 -0
- data/lib/action_controller/metal/rack_convenience.rb +27 -0
- data/lib/action_controller/metal/redirector.rb +22 -0
- data/lib/action_controller/metal/render_options.rb +103 -0
- data/lib/action_controller/metal/rendering_controller.rb +57 -0
- data/lib/action_controller/metal/request_forgery_protection.rb +108 -0
- data/lib/action_controller/metal/rescuable.rb +13 -0
- data/lib/action_controller/metal/responder.rb +200 -0
- data/lib/action_controller/metal/session.rb +15 -0
- data/lib/action_controller/metal/session_management.rb +45 -0
- data/lib/action_controller/metal/streaming.rb +188 -0
- data/lib/action_controller/metal/testing.rb +39 -0
- data/lib/action_controller/metal/url_for.rb +41 -0
- data/lib/action_controller/metal/verification.rb +130 -0
- data/lib/action_controller/middleware.rb +38 -0
- data/lib/action_controller/notifications.rb +10 -0
- data/lib/action_controller/polymorphic_routes.rb +183 -0
- data/lib/action_controller/record_identifier.rb +91 -0
- data/lib/action_controller/testing/process.rb +111 -0
- data/lib/action_controller/testing/test_case.rb +345 -0
- data/lib/action_controller/translation.rb +13 -0
- data/lib/action_controller/url_rewriter.rb +204 -0
- data/lib/action_controller/vendor/html-scanner.rb +16 -0
- data/lib/action_controller/vendor/html-scanner/html/document.rb +68 -0
- data/lib/action_controller/vendor/html-scanner/html/node.rb +537 -0
- data/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +176 -0
- data/lib/action_controller/vendor/html-scanner/html/selector.rb +828 -0
- data/lib/action_controller/vendor/html-scanner/html/tokenizer.rb +105 -0
- data/lib/action_controller/vendor/html-scanner/html/version.rb +11 -0
- data/lib/action_dispatch.rb +70 -0
- data/lib/action_dispatch/http/headers.rb +33 -0
- data/lib/action_dispatch/http/mime_type.rb +231 -0
- data/lib/action_dispatch/http/mime_types.rb +23 -0
- data/lib/action_dispatch/http/request.rb +539 -0
- data/lib/action_dispatch/http/response.rb +290 -0
- data/lib/action_dispatch/http/status_codes.rb +42 -0
- data/lib/action_dispatch/http/utils.rb +20 -0
- data/lib/action_dispatch/middleware/callbacks.rb +50 -0
- data/lib/action_dispatch/middleware/params_parser.rb +79 -0
- data/lib/action_dispatch/middleware/rescue.rb +26 -0
- data/lib/action_dispatch/middleware/session/abstract_store.rb +208 -0
- data/lib/action_dispatch/middleware/session/cookie_store.rb +235 -0
- data/lib/action_dispatch/middleware/session/mem_cache_store.rb +47 -0
- data/lib/action_dispatch/middleware/show_exceptions.rb +143 -0
- data/lib/action_dispatch/middleware/stack.rb +116 -0
- data/lib/action_dispatch/middleware/static.rb +44 -0
- data/lib/action_dispatch/middleware/string_coercion.rb +29 -0
- data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb +24 -0
- data/lib/action_dispatch/middleware/templates/rescues/_trace.erb +26 -0
- data/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb +10 -0
- data/lib/action_dispatch/middleware/templates/rescues/layout.erb +29 -0
- data/lib/action_dispatch/middleware/templates/rescues/missing_template.erb +2 -0
- data/lib/action_dispatch/middleware/templates/rescues/routing_error.erb +10 -0
- data/lib/action_dispatch/middleware/templates/rescues/template_error.erb +21 -0
- data/lib/action_dispatch/middleware/templates/rescues/unknown_action.erb +2 -0
- data/lib/action_dispatch/routing.rb +381 -0
- data/lib/action_dispatch/routing/deprecated_mapper.rb +878 -0
- data/lib/action_dispatch/routing/mapper.rb +327 -0
- data/lib/action_dispatch/routing/route.rb +49 -0
- data/lib/action_dispatch/routing/route_set.rb +497 -0
- data/lib/action_dispatch/testing/assertions.rb +8 -0
- data/lib/action_dispatch/testing/assertions/dom.rb +35 -0
- data/lib/action_dispatch/testing/assertions/model.rb +19 -0
- data/lib/action_dispatch/testing/assertions/response.rb +145 -0
- data/lib/action_dispatch/testing/assertions/routing.rb +144 -0
- data/lib/action_dispatch/testing/assertions/selector.rb +639 -0
- data/lib/action_dispatch/testing/assertions/tag.rb +123 -0
- data/lib/action_dispatch/testing/integration.rb +504 -0
- data/lib/action_dispatch/testing/performance_test.rb +15 -0
- data/lib/action_dispatch/testing/test_request.rb +83 -0
- data/lib/action_dispatch/testing/test_response.rb +131 -0
- data/lib/action_pack.rb +24 -0
- data/lib/action_pack/version.rb +9 -0
- data/lib/action_view.rb +58 -0
- data/lib/action_view/base.rb +308 -0
- data/lib/action_view/context.rb +44 -0
- data/lib/action_view/erb/util.rb +48 -0
- data/lib/action_view/helpers.rb +62 -0
- data/lib/action_view/helpers/active_model_helper.rb +306 -0
- data/lib/action_view/helpers/ajax_helper.rb +68 -0
- data/lib/action_view/helpers/asset_tag_helper.rb +830 -0
- data/lib/action_view/helpers/atom_feed_helper.rb +198 -0
- data/lib/action_view/helpers/cache_helper.rb +39 -0
- data/lib/action_view/helpers/capture_helper.rb +168 -0
- data/lib/action_view/helpers/date_helper.rb +988 -0
- data/lib/action_view/helpers/debug_helper.rb +38 -0
- data/lib/action_view/helpers/form_helper.rb +1102 -0
- data/lib/action_view/helpers/form_options_helper.rb +600 -0
- data/lib/action_view/helpers/form_tag_helper.rb +495 -0
- data/lib/action_view/helpers/javascript_helper.rb +208 -0
- data/lib/action_view/helpers/number_helper.rb +311 -0
- data/lib/action_view/helpers/prototype_helper.rb +1309 -0
- data/lib/action_view/helpers/raw_output_helper.rb +9 -0
- data/lib/action_view/helpers/record_identification_helper.rb +20 -0
- data/lib/action_view/helpers/record_tag_helper.rb +58 -0
- data/lib/action_view/helpers/sanitize_helper.rb +259 -0
- data/lib/action_view/helpers/scriptaculous_helper.rb +226 -0
- data/lib/action_view/helpers/tag_helper.rb +151 -0
- data/lib/action_view/helpers/text_helper.rb +594 -0
- data/lib/action_view/helpers/translation_helper.rb +39 -0
- data/lib/action_view/helpers/url_helper.rb +639 -0
- data/lib/action_view/locale/en.yml +117 -0
- data/lib/action_view/paths.rb +80 -0
- data/lib/action_view/render/partials.rb +342 -0
- data/lib/action_view/render/rendering.rb +134 -0
- data/lib/action_view/safe_buffer.rb +28 -0
- data/lib/action_view/template/error.rb +101 -0
- data/lib/action_view/template/handler.rb +36 -0
- data/lib/action_view/template/handlers.rb +52 -0
- data/lib/action_view/template/handlers/builder.rb +17 -0
- data/lib/action_view/template/handlers/erb.rb +53 -0
- data/lib/action_view/template/handlers/rjs.rb +18 -0
- data/lib/action_view/template/resolver.rb +165 -0
- data/lib/action_view/template/template.rb +131 -0
- data/lib/action_view/template/text.rb +38 -0
- data/lib/action_view/test_case.rb +163 -0
- metadata +236 -0
@@ -0,0 +1,47 @@
|
|
1
|
+
module ActionDispatch
|
2
|
+
module Session
|
3
|
+
class MemCacheStore < AbstractStore
|
4
|
+
def initialize(app, options = {})
|
5
|
+
require 'memcache'
|
6
|
+
|
7
|
+
# Support old :expires option
|
8
|
+
options[:expire_after] ||= options[:expires]
|
9
|
+
|
10
|
+
super
|
11
|
+
|
12
|
+
@default_options = {
|
13
|
+
:namespace => 'rack:session',
|
14
|
+
:memcache_server => 'localhost:11211'
|
15
|
+
}.merge(@default_options)
|
16
|
+
|
17
|
+
@pool = options[:cache] || MemCache.new(@default_options[:memcache_server], @default_options)
|
18
|
+
unless @pool.servers.any? { |s| s.alive? }
|
19
|
+
raise "#{self} unable to find server during initialization."
|
20
|
+
end
|
21
|
+
@mutex = Mutex.new
|
22
|
+
|
23
|
+
super
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
def get_session(env, sid)
|
28
|
+
sid ||= generate_sid
|
29
|
+
begin
|
30
|
+
session = @pool.get(sid) || {}
|
31
|
+
rescue MemCache::MemCacheError, Errno::ECONNREFUSED
|
32
|
+
session = {}
|
33
|
+
end
|
34
|
+
[sid, session]
|
35
|
+
end
|
36
|
+
|
37
|
+
def set_session(env, sid, session_data)
|
38
|
+
options = env['rack.session.options']
|
39
|
+
expiry = options[:expire_after] || 0
|
40
|
+
@pool.set(sid, session_data, expiry)
|
41
|
+
return true
|
42
|
+
rescue MemCache::MemCacheError, Errno::ECONNREFUSED
|
43
|
+
return false
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,143 @@
|
|
1
|
+
require "active_support/core_ext/exception"
|
2
|
+
|
3
|
+
module ActionDispatch
|
4
|
+
class ShowExceptions
|
5
|
+
include StatusCodes
|
6
|
+
|
7
|
+
LOCALHOST = '127.0.0.1'.freeze
|
8
|
+
|
9
|
+
RESCUES_TEMPLATE_PATH = File.join(File.dirname(__FILE__), 'templates')
|
10
|
+
|
11
|
+
cattr_accessor :rescue_responses
|
12
|
+
@@rescue_responses = Hash.new(:internal_server_error)
|
13
|
+
@@rescue_responses.update({
|
14
|
+
'ActionController::RoutingError' => :not_found,
|
15
|
+
# TODO: Clean this up after the switch
|
16
|
+
ActionController::UnknownAction.name => :not_found,
|
17
|
+
'ActiveRecord::RecordNotFound' => :not_found,
|
18
|
+
'ActiveRecord::StaleObjectError' => :conflict,
|
19
|
+
'ActiveRecord::RecordInvalid' => :unprocessable_entity,
|
20
|
+
'ActiveRecord::RecordNotSaved' => :unprocessable_entity,
|
21
|
+
'ActionController::MethodNotAllowed' => :method_not_allowed,
|
22
|
+
'ActionController::NotImplemented' => :not_implemented,
|
23
|
+
'ActionController::InvalidAuthenticityToken' => :unprocessable_entity
|
24
|
+
})
|
25
|
+
|
26
|
+
cattr_accessor :rescue_templates
|
27
|
+
@@rescue_templates = Hash.new('diagnostics')
|
28
|
+
@@rescue_templates.update({
|
29
|
+
'ActionView::MissingTemplate' => 'missing_template',
|
30
|
+
'ActionController::RoutingError' => 'routing_error',
|
31
|
+
ActionController::UnknownAction.name => 'unknown_action',
|
32
|
+
'ActionView::TemplateError' => 'template_error'
|
33
|
+
})
|
34
|
+
|
35
|
+
FAILSAFE_RESPONSE = [500, {'Content-Type' => 'text/html'},
|
36
|
+
["<html><body><h1>500 Internal Server Error</h1>" <<
|
37
|
+
"If you are the administrator of this website, then please read this web " <<
|
38
|
+
"application's log file and/or the web server's log file to find out what " <<
|
39
|
+
"went wrong.</body></html>"]]
|
40
|
+
|
41
|
+
def initialize(app, consider_all_requests_local = false)
|
42
|
+
@app = app
|
43
|
+
@consider_all_requests_local = consider_all_requests_local
|
44
|
+
end
|
45
|
+
|
46
|
+
def call(env)
|
47
|
+
@app.call(env)
|
48
|
+
rescue Exception => exception
|
49
|
+
raise exception if env['action_dispatch.show_exceptions'] == false
|
50
|
+
render_exception(env, exception)
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
def render_exception(env, exception)
|
55
|
+
log_error(exception)
|
56
|
+
|
57
|
+
request = Request.new(env)
|
58
|
+
if @consider_all_requests_local || local_request?(request)
|
59
|
+
rescue_action_locally(request, exception)
|
60
|
+
else
|
61
|
+
rescue_action_in_public(exception)
|
62
|
+
end
|
63
|
+
rescue Exception => failsafe_error
|
64
|
+
$stderr.puts "Error during failsafe response: #{failsafe_error}"
|
65
|
+
FAILSAFE_RESPONSE
|
66
|
+
end
|
67
|
+
|
68
|
+
# Render detailed diagnostics for unhandled exceptions rescued from
|
69
|
+
# a controller action.
|
70
|
+
def rescue_action_locally(request, exception)
|
71
|
+
template = ActionView::Base.new([RESCUES_TEMPLATE_PATH],
|
72
|
+
:request => request,
|
73
|
+
:exception => exception
|
74
|
+
)
|
75
|
+
file = "rescues/#{@@rescue_templates[exception.class.name]}.erb"
|
76
|
+
body = template.render(:file => file, :layout => 'rescues/layout.erb')
|
77
|
+
render(status_code(exception), body)
|
78
|
+
end
|
79
|
+
|
80
|
+
# Attempts to render a static error page based on the
|
81
|
+
# <tt>status_code</tt> thrown, or just return headers if no such file
|
82
|
+
# exists. At first, it will try to render a localized static page.
|
83
|
+
# For example, if a 500 error is being handled Rails and locale is :da,
|
84
|
+
# it will first attempt to render the file at <tt>public/500.da.html</tt>
|
85
|
+
# then attempt to render <tt>public/500.html</tt>. If none of them exist,
|
86
|
+
# the body of the response will be left empty.
|
87
|
+
def rescue_action_in_public(exception)
|
88
|
+
status = status_code(exception)
|
89
|
+
locale_path = "#{public_path}/#{status}.#{I18n.locale}.html" if I18n.locale
|
90
|
+
path = "#{public_path}/#{status}.html"
|
91
|
+
|
92
|
+
if locale_path && File.exist?(locale_path)
|
93
|
+
render(status, File.read(locale_path))
|
94
|
+
elsif File.exist?(path)
|
95
|
+
render(status, File.read(path))
|
96
|
+
else
|
97
|
+
render(status, '')
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# True if the request came from localhost, 127.0.0.1.
|
102
|
+
def local_request?(request)
|
103
|
+
request.remote_addr == LOCALHOST && request.remote_ip == LOCALHOST
|
104
|
+
end
|
105
|
+
|
106
|
+
def status_code(exception)
|
107
|
+
interpret_status(@@rescue_responses[exception.class.name]).to_i
|
108
|
+
end
|
109
|
+
|
110
|
+
def render(status, body)
|
111
|
+
[status, {'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s}, [body]]
|
112
|
+
end
|
113
|
+
|
114
|
+
def public_path
|
115
|
+
defined?(Rails.public_path) ? Rails.public_path : 'public_path'
|
116
|
+
end
|
117
|
+
|
118
|
+
def log_error(exception)
|
119
|
+
return unless logger
|
120
|
+
|
121
|
+
ActiveSupport::Deprecation.silence do
|
122
|
+
if ActionView::TemplateError === exception
|
123
|
+
logger.fatal(exception.to_s)
|
124
|
+
else
|
125
|
+
logger.fatal(
|
126
|
+
"\n#{exception.class} (#{exception.message}):\n " +
|
127
|
+
clean_backtrace(exception).join("\n ") + "\n\n"
|
128
|
+
)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def clean_backtrace(exception)
|
134
|
+
defined?(Rails) && Rails.respond_to?(:backtrace_cleaner) ?
|
135
|
+
Rails.backtrace_cleaner.clean(exception.backtrace) :
|
136
|
+
exception.backtrace
|
137
|
+
end
|
138
|
+
|
139
|
+
def logger
|
140
|
+
defined?(Rails.logger) ? Rails.logger : Logger.new($stderr)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
module ActionDispatch
|
2
|
+
class MiddlewareStack < Array
|
3
|
+
class Middleware
|
4
|
+
def self.new(klass, *args, &block)
|
5
|
+
if klass.is_a?(self)
|
6
|
+
klass
|
7
|
+
else
|
8
|
+
super
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
attr_reader :args, :block
|
13
|
+
|
14
|
+
def initialize(klass, *args, &block)
|
15
|
+
@klass = klass
|
16
|
+
|
17
|
+
options = args.extract_options!
|
18
|
+
if options.has_key?(:if)
|
19
|
+
@conditional = options.delete(:if)
|
20
|
+
else
|
21
|
+
@conditional = true
|
22
|
+
end
|
23
|
+
args << options unless options.empty?
|
24
|
+
|
25
|
+
@args = args
|
26
|
+
@block = block
|
27
|
+
end
|
28
|
+
|
29
|
+
def klass
|
30
|
+
if @klass.respond_to?(:new)
|
31
|
+
@klass
|
32
|
+
elsif @klass.respond_to?(:call)
|
33
|
+
@klass.call
|
34
|
+
else
|
35
|
+
@klass.to_s.constantize
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def active?
|
40
|
+
return false unless klass
|
41
|
+
|
42
|
+
if @conditional.respond_to?(:call)
|
43
|
+
@conditional.call
|
44
|
+
else
|
45
|
+
@conditional
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def ==(middleware)
|
50
|
+
case middleware
|
51
|
+
when Middleware
|
52
|
+
klass == middleware.klass
|
53
|
+
when Class
|
54
|
+
klass == middleware
|
55
|
+
else
|
56
|
+
klass == middleware.to_s.constantize
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def inspect
|
61
|
+
str = klass.to_s
|
62
|
+
args.each { |arg| str += ", #{build_args.inspect}" }
|
63
|
+
str
|
64
|
+
end
|
65
|
+
|
66
|
+
def build(app)
|
67
|
+
if block
|
68
|
+
klass.new(app, *build_args, &block)
|
69
|
+
else
|
70
|
+
klass.new(app, *build_args)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
def build_args
|
76
|
+
Array(args).map { |arg| arg.respond_to?(:call) ? arg.call : arg }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def initialize(*args, &block)
|
81
|
+
super(*args)
|
82
|
+
block.call(self) if block_given?
|
83
|
+
end
|
84
|
+
|
85
|
+
def insert(index, *args, &block)
|
86
|
+
index = self.index(index) unless index.is_a?(Integer)
|
87
|
+
middleware = Middleware.new(*args, &block)
|
88
|
+
super(index, middleware)
|
89
|
+
end
|
90
|
+
|
91
|
+
alias_method :insert_before, :insert
|
92
|
+
|
93
|
+
def insert_after(index, *args, &block)
|
94
|
+
index = self.index(index) unless index.is_a?(Integer)
|
95
|
+
insert(index + 1, *args, &block)
|
96
|
+
end
|
97
|
+
|
98
|
+
def swap(target, *args, &block)
|
99
|
+
insert_before(target, *args, &block)
|
100
|
+
delete(target)
|
101
|
+
end
|
102
|
+
|
103
|
+
def use(*args, &block)
|
104
|
+
middleware = Middleware.new(*args, &block)
|
105
|
+
push(middleware)
|
106
|
+
end
|
107
|
+
|
108
|
+
def active
|
109
|
+
find_all { |middleware| middleware.active? }
|
110
|
+
end
|
111
|
+
|
112
|
+
def build(app)
|
113
|
+
active.reverse.inject(app) { |a, e| e.build(a) }
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'rack/utils'
|
2
|
+
|
3
|
+
module ActionDispatch
|
4
|
+
class Static
|
5
|
+
FILE_METHODS = %w(GET HEAD).freeze
|
6
|
+
|
7
|
+
def initialize(app, root)
|
8
|
+
@app = app
|
9
|
+
@file_server = ::Rack::File.new(root)
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
path = env['PATH_INFO'].chomp('/')
|
14
|
+
method = env['REQUEST_METHOD']
|
15
|
+
|
16
|
+
if FILE_METHODS.include?(method)
|
17
|
+
if file_exist?(path)
|
18
|
+
return @file_server.call(env)
|
19
|
+
else
|
20
|
+
cached_path = directory_exist?(path) ? "#{path}/index" : path
|
21
|
+
cached_path += ::ActionController::Base.page_cache_extension
|
22
|
+
|
23
|
+
if file_exist?(cached_path)
|
24
|
+
env['PATH_INFO'] = cached_path
|
25
|
+
return @file_server.call(env)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
@app.call(env)
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
def file_exist?(path)
|
35
|
+
full_path = File.join(@file_server.root, ::Rack::Utils.unescape(path))
|
36
|
+
File.file?(full_path) && File.readable?(full_path)
|
37
|
+
end
|
38
|
+
|
39
|
+
def directory_exist?(path)
|
40
|
+
full_path = File.join(@file_server.root, ::Rack::Utils.unescape(path))
|
41
|
+
File.directory?(full_path) && File.readable?(full_path)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module ActionDispatch
|
2
|
+
class StringCoercion
|
3
|
+
class UglyBody < ActiveSupport::BasicObject
|
4
|
+
def initialize(body)
|
5
|
+
@body = body
|
6
|
+
end
|
7
|
+
|
8
|
+
def each
|
9
|
+
@body.each do |part|
|
10
|
+
yield part.to_s
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
def method_missing(*args, &block)
|
16
|
+
@body.__send__(*args, &block)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize(app)
|
21
|
+
@app = app
|
22
|
+
end
|
23
|
+
|
24
|
+
def call(env)
|
25
|
+
status, headers, body = @app.call(env)
|
26
|
+
[status, headers, UglyBody.new(body)]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<% unless @exception.blamed_files.blank? %>
|
2
|
+
<% if (hide = @exception.blamed_files.length > 8) %>
|
3
|
+
<a href="#" onclick="document.getElementById('blame_trace').style.display='block'; return false;">Show blamed files</a>
|
4
|
+
<% end %>
|
5
|
+
<pre id="blame_trace" <%='style="display:none"' if hide %>><code><%=h @exception.describe_blame %></code></pre>
|
6
|
+
<% end %>
|
7
|
+
|
8
|
+
<%
|
9
|
+
clean_params = @request.parameters.clone
|
10
|
+
clean_params.delete("action")
|
11
|
+
clean_params.delete("controller")
|
12
|
+
|
13
|
+
request_dump = clean_params.empty? ? 'None' : clean_params.inspect.gsub(',', ",\n")
|
14
|
+
%>
|
15
|
+
|
16
|
+
<h2 style="margin-top: 30px">Request</h2>
|
17
|
+
<p><b>Parameters</b>: <pre><%=h request_dump %></pre></p>
|
18
|
+
|
19
|
+
<p><a href="#" onclick="document.getElementById('session_dump').style.display='block'; return false;">Show session dump</a></p>
|
20
|
+
<div id="session_dump" style="display:none"><%= debug(@request.session.instance_variable_get("@data")) %></div>
|
21
|
+
|
22
|
+
|
23
|
+
<h2 style="margin-top: 30px">Response</h2>
|
24
|
+
<p><b>Headers</b>: <pre><%=h @response ? @response.headers.inspect.gsub(',', ",\n") : 'None' %></pre></p>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<%
|
2
|
+
traces = [
|
3
|
+
["Application Trace", @exception.application_backtrace],
|
4
|
+
["Framework Trace", @exception.framework_backtrace],
|
5
|
+
["Full Trace", @exception.clean_backtrace]
|
6
|
+
]
|
7
|
+
names = traces.collect {|name, trace| name}
|
8
|
+
%>
|
9
|
+
|
10
|
+
<p><code>RAILS_ROOT: <%= defined?(RAILS_ROOT) ? RAILS_ROOT : "unset" %></code></p>
|
11
|
+
|
12
|
+
<div id="traces">
|
13
|
+
<% names.each do |name| %>
|
14
|
+
<%
|
15
|
+
show = "document.getElementById('#{name.gsub /\s/, '-'}').style.display='block';"
|
16
|
+
hide = (names - [name]).collect {|hide_name| "document.getElementById('#{hide_name.gsub /\s/, '-'}').style.display='none';"}
|
17
|
+
%>
|
18
|
+
<a href="#" onclick="<%= hide.join %><%= show %>; return false;"><%= name %></a> <%= '|' unless names.last == name %>
|
19
|
+
<% end %>
|
20
|
+
|
21
|
+
<% traces.each do |name, trace| %>
|
22
|
+
<div id="<%= name.gsub /\s/, '-' %>" style="display: <%= name == "Application Trace" ? 'block' : 'none' %>;">
|
23
|
+
<pre><code><%=h trace.join "\n" %></code></pre>
|
24
|
+
</div>
|
25
|
+
<% end %>
|
26
|
+
</div>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<h1>
|
2
|
+
<%=h @exception.class.to_s %>
|
3
|
+
<% if @request.parameters['controller'] %>
|
4
|
+
in <%=h @request.parameters['controller'].humanize %>Controller<% if @request.parameters['action'] %>#<%=h @request.parameters['action'] %><% end %>
|
5
|
+
<% end %>
|
6
|
+
</h1>
|
7
|
+
<pre><%=h @exception.clean_message %></pre>
|
8
|
+
|
9
|
+
<%= render :file => "rescues/_trace.erb" %>
|
10
|
+
<%= render :file => "rescues/_request_and_response.erb" %>
|