rack 1.6.12 → 2.0.7
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rack might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/COPYING +1 -1
- data/HISTORY.md +138 -8
- data/README.rdoc +18 -28
- data/Rakefile +6 -14
- data/SPEC +10 -11
- data/contrib/rack_logo.svg +164 -111
- data/example/protectedlobster.rb +1 -1
- data/example/protectedlobster.ru +1 -1
- data/lib/rack.rb +70 -21
- data/lib/rack/auth/abstract/request.rb +5 -1
- data/lib/rack/auth/digest/params.rb +2 -3
- data/lib/rack/auth/digest/request.rb +1 -1
- data/lib/rack/body_proxy.rb +14 -9
- data/lib/rack/builder.rb +3 -3
- data/lib/rack/chunked.rb +5 -5
- data/lib/rack/{commonlogger.rb → common_logger.rb} +3 -3
- data/lib/rack/{conditionalget.rb → conditional_get.rb} +0 -0
- data/lib/rack/content_length.rb +2 -2
- data/lib/rack/deflater.rb +4 -39
- data/lib/rack/directory.rb +66 -54
- data/lib/rack/etag.rb +5 -4
- data/lib/rack/events.rb +154 -0
- data/lib/rack/file.rb +64 -40
- data/lib/rack/handler.rb +3 -25
- data/lib/rack/handler/cgi.rb +15 -16
- data/lib/rack/handler/fastcgi.rb +13 -14
- data/lib/rack/handler/lsws.rb +11 -11
- data/lib/rack/handler/scgi.rb +15 -15
- data/lib/rack/handler/thin.rb +3 -0
- data/lib/rack/handler/webrick.rb +24 -26
- data/lib/rack/head.rb +15 -17
- data/lib/rack/lint.rb +40 -40
- data/lib/rack/lobster.rb +1 -1
- data/lib/rack/lock.rb +15 -10
- data/lib/rack/logger.rb +2 -2
- data/lib/rack/media_type.rb +38 -0
- data/lib/rack/{methodoverride.rb → method_override.rb} +6 -6
- data/lib/rack/mime.rb +18 -5
- data/lib/rack/mock.rb +36 -54
- data/lib/rack/multipart.rb +35 -6
- data/lib/rack/multipart/generator.rb +5 -5
- data/lib/rack/multipart/parser.rb +270 -157
- data/lib/rack/multipart/uploaded_file.rb +1 -2
- data/lib/rack/{nulllogger.rb → null_logger.rb} +1 -1
- data/lib/rack/query_parser.rb +192 -0
- data/lib/rack/recursive.rb +8 -8
- data/lib/rack/request.rb +394 -305
- data/lib/rack/response.rb +130 -57
- data/lib/rack/rewindable_input.rb +1 -12
- data/lib/rack/runtime.rb +10 -18
- data/lib/rack/sendfile.rb +5 -7
- data/lib/rack/server.rb +30 -23
- data/lib/rack/session/abstract/id.rb +108 -138
- data/lib/rack/session/cookie.rb +26 -28
- data/lib/rack/session/memcache.rb +8 -14
- data/lib/rack/session/pool.rb +14 -21
- data/lib/rack/show_exceptions.rb +386 -0
- data/lib/rack/{showstatus.rb → show_status.rb} +3 -3
- data/lib/rack/static.rb +30 -5
- data/lib/rack/tempfile_reaper.rb +2 -2
- data/lib/rack/urlmap.rb +15 -14
- data/lib/rack/utils.rb +136 -211
- data/rack.gemspec +10 -9
- data/test/builder/an_underscore_app.rb +5 -0
- data/test/builder/options.ru +1 -1
- data/test/cgi/test.fcgi +1 -0
- data/test/cgi/test.gz +0 -0
- data/test/helper.rb +34 -0
- data/test/multipart/filename_with_encoded_words +7 -0
- data/test/multipart/filename_with_single_quote +7 -0
- data/test/multipart/quoted +15 -0
- data/test/multipart/rack-logo.png +0 -0
- data/test/multipart/unity3d_wwwform +11 -0
- data/test/registering_handler/rack/handler/registering_myself.rb +1 -1
- data/test/spec_auth_basic.rb +27 -19
- data/test/spec_auth_digest.rb +47 -46
- data/test/spec_body_proxy.rb +27 -27
- data/test/spec_builder.rb +51 -41
- data/test/spec_cascade.rb +24 -22
- data/test/spec_cgi.rb +49 -67
- data/test/spec_chunked.rb +37 -35
- data/test/{spec_commonlogger.rb → spec_common_logger.rb} +23 -21
- data/test/{spec_conditionalget.rb → spec_conditional_get.rb} +29 -28
- data/test/spec_config.rb +3 -2
- data/test/spec_content_length.rb +18 -17
- data/test/spec_content_type.rb +13 -12
- data/test/spec_deflater.rb +85 -49
- data/test/spec_directory.rb +87 -27
- data/test/spec_etag.rb +32 -31
- data/test/spec_events.rb +133 -0
- data/test/spec_fastcgi.rb +50 -72
- data/test/spec_file.rb +120 -77
- data/test/spec_handler.rb +19 -34
- data/test/spec_head.rb +15 -14
- data/test/spec_lint.rb +164 -199
- data/test/spec_lobster.rb +24 -23
- data/test/spec_lock.rb +79 -39
- data/test/spec_logger.rb +4 -3
- data/test/spec_media_type.rb +42 -0
- data/test/{spec_methodoverride.rb → spec_method_override.rb} +34 -35
- data/test/spec_mime.rb +19 -19
- data/test/spec_mock.rb +206 -144
- data/test/spec_multipart.rb +322 -200
- data/test/{spec_nulllogger.rb → spec_null_logger.rb} +5 -4
- data/test/spec_recursive.rb +17 -14
- data/test/spec_request.rb +780 -605
- data/test/spec_response.rb +215 -112
- data/test/spec_rewindable_input.rb +50 -40
- data/test/spec_runtime.rb +11 -10
- data/test/spec_sendfile.rb +30 -35
- data/test/spec_server.rb +78 -52
- data/test/spec_session_abstract_id.rb +11 -33
- data/test/spec_session_abstract_session_hash.rb +45 -0
- data/test/spec_session_cookie.rb +99 -67
- data/test/spec_session_memcache.rb +63 -101
- data/test/spec_session_pool.rb +48 -84
- data/test/{spec_showexceptions.rb → spec_show_exceptions.rb} +23 -28
- data/test/{spec_showstatus.rb → spec_show_status.rb} +36 -35
- data/test/spec_static.rb +71 -32
- data/test/spec_tempfile_reaper.rb +11 -10
- data/test/spec_thin.rb +55 -50
- data/test/spec_urlmap.rb +79 -78
- data/test/spec_utils.rb +441 -346
- data/test/spec_version.rb +2 -8
- data/test/spec_webrick.rb +93 -71
- data/test/static/foo.html +1 -0
- data/test/testrequest.rb +1 -1
- data/test/unregistered_handler/rack/handler/unregistered.rb +1 -1
- data/test/unregistered_handler/rack/handler/unregistered_long_one.rb +1 -1
- metadata +92 -70
- data/KNOWN-ISSUES +0 -44
- data/lib/rack/backports/uri/common_18.rb +0 -56
- data/lib/rack/backports/uri/common_192.rb +0 -52
- data/lib/rack/backports/uri/common_193.rb +0 -29
- data/lib/rack/handler/evented_mongrel.rb +0 -8
- data/lib/rack/handler/mongrel.rb +0 -106
- data/lib/rack/handler/swiftiplied_mongrel.rb +0 -8
- data/lib/rack/showexceptions.rb +0 -387
- data/lib/rack/utils/okjson.rb +0 -600
- data/test/spec_mongrel.rb +0 -182
data/KNOWN-ISSUES
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
= Known issues with Rack and ECMA-262
|
2
|
-
|
3
|
-
* Many users expect the escape() function defined in ECMA-262 to be compatible
|
4
|
-
with URI. Confusion is especially strong because the documentation for the
|
5
|
-
escape function includes a reference to the URI specifications. ECMA-262
|
6
|
-
escape is not however a URI escape function, it is a javascript escape
|
7
|
-
function, and is not fully compatible. Most notably, for characters outside of
|
8
|
-
the BMP. Users should use the more correct encodeURI functions.
|
9
|
-
|
10
|
-
= Known issues with Rack and Web servers
|
11
|
-
|
12
|
-
* Lighttpd sets wrong SCRIPT_NAME and PATH_INFO if you mount your
|
13
|
-
FastCGI app at "/". This can be fixed by using this middleware:
|
14
|
-
|
15
|
-
class LighttpdScriptNameFix
|
16
|
-
def initialize(app)
|
17
|
-
@app = app
|
18
|
-
end
|
19
|
-
|
20
|
-
def call(env)
|
21
|
-
env["PATH_INFO"] = env["SCRIPT_NAME"].to_s + env["PATH_INFO"].to_s
|
22
|
-
env["SCRIPT_NAME"] = ""
|
23
|
-
@app.call(env)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
Of course, use this only when your app runs at "/".
|
28
|
-
|
29
|
-
Since lighttpd 1.4.23, you also can use the "fix-root-scriptname" flag
|
30
|
-
in fastcgi.server.
|
31
|
-
|
32
|
-
= Known conflicts regarding parameter parsing
|
33
|
-
|
34
|
-
* Many users have differing opinions about parameter parsing. The current
|
35
|
-
parameter parsers in Rack are based on a combination of the HTTP and CGI
|
36
|
-
specs, and are intended to round-trip encoding and decoding. There are some
|
37
|
-
choices that may be viewed as deficiencies, specifically:
|
38
|
-
- Rack does not create implicit arrays for multiple instances of a parameter
|
39
|
-
- Rack returns nil when a value is not given
|
40
|
-
- Rack does not support multi-type keys in parameters
|
41
|
-
These issues or choices, will not be fixed before 2.0, if at all. They are
|
42
|
-
very major breaking changes. Users are free to write alternative parameter
|
43
|
-
parsers, and their own Request and Response wrappers. Moreover, users are
|
44
|
-
encouraged to do so.
|
@@ -1,56 +0,0 @@
|
|
1
|
-
# :stopdoc:
|
2
|
-
|
3
|
-
# Stolen from ruby core's uri/common.rb, with modifications to support 1.8.x
|
4
|
-
#
|
5
|
-
# https://github.com/ruby/ruby/blob/trunk/lib/uri/common.rb
|
6
|
-
#
|
7
|
-
#
|
8
|
-
|
9
|
-
module URI
|
10
|
-
TBLENCWWWCOMP_ = {} # :nodoc:
|
11
|
-
256.times do |i|
|
12
|
-
TBLENCWWWCOMP_[i.chr] = '%%%02X' % i
|
13
|
-
end
|
14
|
-
TBLENCWWWCOMP_[' '] = '+'
|
15
|
-
TBLENCWWWCOMP_.freeze
|
16
|
-
TBLDECWWWCOMP_ = {} # :nodoc:
|
17
|
-
256.times do |i|
|
18
|
-
h, l = i>>4, i&15
|
19
|
-
TBLDECWWWCOMP_['%%%X%X' % [h, l]] = i.chr
|
20
|
-
TBLDECWWWCOMP_['%%%x%X' % [h, l]] = i.chr
|
21
|
-
TBLDECWWWCOMP_['%%%X%x' % [h, l]] = i.chr
|
22
|
-
TBLDECWWWCOMP_['%%%x%x' % [h, l]] = i.chr
|
23
|
-
end
|
24
|
-
TBLDECWWWCOMP_['+'] = ' '
|
25
|
-
TBLDECWWWCOMP_.freeze
|
26
|
-
|
27
|
-
# Encode given +s+ to URL-encoded form data.
|
28
|
-
#
|
29
|
-
# This method doesn't convert *, -, ., 0-9, A-Z, _, a-z, but does convert SP
|
30
|
-
# (ASCII space) to + and converts others to %XX.
|
31
|
-
#
|
32
|
-
# This is an implementation of
|
33
|
-
# http://www.w3.org/TR/html5/forms.html#url-encoded-form-data
|
34
|
-
#
|
35
|
-
# See URI.decode_www_form_component, URI.encode_www_form
|
36
|
-
def self.encode_www_form_component(s)
|
37
|
-
str = s.to_s
|
38
|
-
if RUBY_VERSION < "1.9" && $KCODE =~ /u/i
|
39
|
-
str.gsub(/([^ a-zA-Z0-9_.-]+)/) do
|
40
|
-
'%' + $1.unpack('H2' * Rack::Utils.bytesize($1)).join('%').upcase
|
41
|
-
end.tr(' ', '+')
|
42
|
-
else
|
43
|
-
str.gsub(/[^*\-.0-9A-Z_a-z]/) {|m| TBLENCWWWCOMP_[m]}
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
# Decode given +str+ of URL-encoded form data.
|
48
|
-
#
|
49
|
-
# This decodes + to SP.
|
50
|
-
#
|
51
|
-
# See URI.encode_www_form_component, URI.decode_www_form
|
52
|
-
def self.decode_www_form_component(str, enc=nil)
|
53
|
-
raise ArgumentError, "invalid %-encoding (#{str})" unless /\A(?:%[0-9a-fA-F]{2}|[^%])*\z/ =~ str
|
54
|
-
str.gsub(/\+|%[0-9a-fA-F]{2}/) {|m| TBLDECWWWCOMP_[m]}
|
55
|
-
end
|
56
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
# :stopdoc:
|
2
|
-
|
3
|
-
# Stolen from ruby core's uri/common.rb @32618ba to fix DoS issues in 1.9.2
|
4
|
-
#
|
5
|
-
# https://github.com/ruby/ruby/blob/32618ba7438a2247042bba9b5d85b5d49070f5e5/lib/uri/common.rb
|
6
|
-
#
|
7
|
-
# Issue:
|
8
|
-
# http://redmine.ruby-lang.org/issues/5149
|
9
|
-
#
|
10
|
-
# Relevant Fixes:
|
11
|
-
# https://github.com/ruby/ruby/commit/b5f91deee04aa6ccbe07c23c8222b937c22a799b
|
12
|
-
# https://github.com/ruby/ruby/commit/93177c1e5c3906abf14472ae0b905d8b5c72ce1b
|
13
|
-
#
|
14
|
-
# This should probably be removed once there is a Ruby 1.9.2 patch level that
|
15
|
-
# includes this fix.
|
16
|
-
|
17
|
-
require 'uri/common'
|
18
|
-
|
19
|
-
module URI
|
20
|
-
TBLDECWWWCOMP_ = {} unless const_defined?(:TBLDECWWWCOMP_) #:nodoc:
|
21
|
-
if TBLDECWWWCOMP_.empty?
|
22
|
-
256.times do |i|
|
23
|
-
h, l = i>>4, i&15
|
24
|
-
TBLDECWWWCOMP_['%%%X%X' % [h, l]] = i.chr
|
25
|
-
TBLDECWWWCOMP_['%%%x%X' % [h, l]] = i.chr
|
26
|
-
TBLDECWWWCOMP_['%%%X%x' % [h, l]] = i.chr
|
27
|
-
TBLDECWWWCOMP_['%%%x%x' % [h, l]] = i.chr
|
28
|
-
end
|
29
|
-
TBLDECWWWCOMP_['+'] = ' '
|
30
|
-
TBLDECWWWCOMP_.freeze
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.decode_www_form(str, enc=Encoding::UTF_8)
|
34
|
-
return [] if str.empty?
|
35
|
-
unless /\A#{WFKV_}=#{WFKV_}(?:[;&]#{WFKV_}=#{WFKV_})*\z/o =~ str
|
36
|
-
raise ArgumentError, "invalid data of application/x-www-form-urlencoded (#{str})"
|
37
|
-
end
|
38
|
-
ary = []
|
39
|
-
$&.scan(/([^=;&]+)=([^;&]*)/) do
|
40
|
-
ary << [decode_www_form_component($1, enc), decode_www_form_component($2, enc)]
|
41
|
-
end
|
42
|
-
ary
|
43
|
-
end
|
44
|
-
|
45
|
-
def self.decode_www_form_component(str, enc=Encoding::UTF_8)
|
46
|
-
raise ArgumentError, "invalid %-encoding (#{str})" unless /\A[^%]*(?:%\h\h[^%]*)*\z/ =~ str
|
47
|
-
str.gsub(/\+|%\h\h/, TBLDECWWWCOMP_).force_encoding(enc)
|
48
|
-
end
|
49
|
-
|
50
|
-
remove_const :WFKV_ if const_defined?(:WFKV_)
|
51
|
-
WFKV_ = '(?:[^%#=;&]*(?:%\h\h[^%#=;&]*)*)' # :nodoc:
|
52
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
# :stopdoc:
|
2
|
-
|
3
|
-
require 'uri/common'
|
4
|
-
|
5
|
-
# Issue:
|
6
|
-
# http://bugs.ruby-lang.org/issues/5925
|
7
|
-
#
|
8
|
-
# Relevant commit:
|
9
|
-
# https://github.com/ruby/ruby/commit/edb7cdf1eabaff78dfa5ffedfbc2e91b29fa9ca1
|
10
|
-
|
11
|
-
module URI
|
12
|
-
256.times do |i|
|
13
|
-
TBLENCWWWCOMP_[i.chr] = '%%%02X' % i
|
14
|
-
end
|
15
|
-
TBLENCWWWCOMP_[' '] = '+'
|
16
|
-
TBLENCWWWCOMP_.freeze
|
17
|
-
|
18
|
-
256.times do |i|
|
19
|
-
h, l = i>>4, i&15
|
20
|
-
TBLDECWWWCOMP_['%%%X%X' % [h, l]] = i.chr
|
21
|
-
TBLDECWWWCOMP_['%%%x%X' % [h, l]] = i.chr
|
22
|
-
TBLDECWWWCOMP_['%%%X%x' % [h, l]] = i.chr
|
23
|
-
TBLDECWWWCOMP_['%%%x%x' % [h, l]] = i.chr
|
24
|
-
end
|
25
|
-
TBLDECWWWCOMP_['+'] = ' '
|
26
|
-
TBLDECWWWCOMP_.freeze
|
27
|
-
end
|
28
|
-
|
29
|
-
# :startdoc:
|
data/lib/rack/handler/mongrel.rb
DELETED
@@ -1,106 +0,0 @@
|
|
1
|
-
require 'mongrel'
|
2
|
-
require 'stringio'
|
3
|
-
require 'rack/content_length'
|
4
|
-
require 'rack/chunked'
|
5
|
-
|
6
|
-
module Rack
|
7
|
-
module Handler
|
8
|
-
class Mongrel < ::Mongrel::HttpHandler
|
9
|
-
def self.run(app, options={})
|
10
|
-
environment = ENV['RACK_ENV'] || 'development'
|
11
|
-
default_host = environment == 'development' ? 'localhost' : '0.0.0.0'
|
12
|
-
|
13
|
-
server = ::Mongrel::HttpServer.new(
|
14
|
-
options[:Host] || default_host,
|
15
|
-
options[:Port] || 8080,
|
16
|
-
options[:num_processors] || 950,
|
17
|
-
options[:throttle] || 0,
|
18
|
-
options[:timeout] || 60)
|
19
|
-
# Acts like Rack::URLMap, utilizing Mongrel's own path finding methods.
|
20
|
-
# Use is similar to #run, replacing the app argument with a hash of
|
21
|
-
# { path=>app, ... } or an instance of Rack::URLMap.
|
22
|
-
if options[:map]
|
23
|
-
if app.is_a? Hash
|
24
|
-
app.each do |path, appl|
|
25
|
-
path = '/'+path unless path[0] == ?/
|
26
|
-
server.register(path, Rack::Handler::Mongrel.new(appl))
|
27
|
-
end
|
28
|
-
elsif app.is_a? URLMap
|
29
|
-
app.instance_variable_get(:@mapping).each do |(host, path, appl)|
|
30
|
-
next if !host.nil? && !options[:Host].nil? && options[:Host] != host
|
31
|
-
path = '/'+path unless path[0] == ?/
|
32
|
-
server.register(path, Rack::Handler::Mongrel.new(appl))
|
33
|
-
end
|
34
|
-
else
|
35
|
-
raise ArgumentError, "first argument should be a Hash or URLMap"
|
36
|
-
end
|
37
|
-
else
|
38
|
-
server.register('/', Rack::Handler::Mongrel.new(app))
|
39
|
-
end
|
40
|
-
yield server if block_given?
|
41
|
-
server.run.join
|
42
|
-
end
|
43
|
-
|
44
|
-
def self.valid_options
|
45
|
-
environment = ENV['RACK_ENV'] || 'development'
|
46
|
-
default_host = environment == 'development' ? 'localhost' : '0.0.0.0'
|
47
|
-
|
48
|
-
{
|
49
|
-
"Host=HOST" => "Hostname to listen on (default: #{default_host})",
|
50
|
-
"Port=PORT" => "Port to listen on (default: 8080)",
|
51
|
-
"Processors=N" => "Number of concurrent processors to accept (default: 950)",
|
52
|
-
"Timeout=N" => "Time before a request is dropped for inactivity (default: 60)",
|
53
|
-
"Throttle=N" => "Throttle time between socket.accept calls in hundredths of a second (default: 0)",
|
54
|
-
}
|
55
|
-
end
|
56
|
-
|
57
|
-
def initialize(app)
|
58
|
-
@app = app
|
59
|
-
end
|
60
|
-
|
61
|
-
def process(request, response)
|
62
|
-
env = Hash[request.params]
|
63
|
-
env.delete "HTTP_CONTENT_TYPE"
|
64
|
-
env.delete "HTTP_CONTENT_LENGTH"
|
65
|
-
|
66
|
-
env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/"
|
67
|
-
|
68
|
-
rack_input = request.body || StringIO.new('')
|
69
|
-
rack_input.set_encoding(Encoding::BINARY) if rack_input.respond_to?(:set_encoding)
|
70
|
-
|
71
|
-
env.update({"rack.version" => Rack::VERSION,
|
72
|
-
"rack.input" => rack_input,
|
73
|
-
"rack.errors" => $stderr,
|
74
|
-
|
75
|
-
"rack.multithread" => true,
|
76
|
-
"rack.multiprocess" => false, # ???
|
77
|
-
"rack.run_once" => false,
|
78
|
-
|
79
|
-
"rack.url_scheme" => ["yes", "on", "1"].include?(env["HTTPS"]) ? "https" : "http"
|
80
|
-
})
|
81
|
-
env[QUERY_STRING] ||= ""
|
82
|
-
|
83
|
-
status, headers, body = @app.call(env)
|
84
|
-
|
85
|
-
begin
|
86
|
-
response.status = status.to_i
|
87
|
-
response.send_status(nil)
|
88
|
-
|
89
|
-
headers.each { |k, vs|
|
90
|
-
vs.split("\n").each { |v|
|
91
|
-
response.header[k] = v
|
92
|
-
}
|
93
|
-
}
|
94
|
-
response.send_header
|
95
|
-
|
96
|
-
body.each { |part|
|
97
|
-
response.write part
|
98
|
-
response.socket.flush
|
99
|
-
}
|
100
|
-
ensure
|
101
|
-
body.close if body.respond_to? :close
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
data/lib/rack/showexceptions.rb
DELETED
@@ -1,387 +0,0 @@
|
|
1
|
-
require 'ostruct'
|
2
|
-
require 'erb'
|
3
|
-
require 'rack/request'
|
4
|
-
require 'rack/utils'
|
5
|
-
|
6
|
-
module Rack
|
7
|
-
# Rack::ShowExceptions catches all exceptions raised from the app it
|
8
|
-
# wraps. It shows a useful backtrace with the sourcefile and
|
9
|
-
# clickable context, the whole Rack environment and the request
|
10
|
-
# data.
|
11
|
-
#
|
12
|
-
# Be careful when you use this on public-facing sites as it could
|
13
|
-
# reveal information helpful to attackers.
|
14
|
-
|
15
|
-
class ShowExceptions
|
16
|
-
CONTEXT = 7
|
17
|
-
|
18
|
-
def initialize(app)
|
19
|
-
@app = app
|
20
|
-
@template = ERB.new(TEMPLATE)
|
21
|
-
end
|
22
|
-
|
23
|
-
def call(env)
|
24
|
-
@app.call(env)
|
25
|
-
rescue StandardError, LoadError, SyntaxError => e
|
26
|
-
exception_string = dump_exception(e)
|
27
|
-
|
28
|
-
env["rack.errors"].puts(exception_string)
|
29
|
-
env["rack.errors"].flush
|
30
|
-
|
31
|
-
if accepts_html?(env)
|
32
|
-
content_type = "text/html"
|
33
|
-
body = pretty(env, e)
|
34
|
-
else
|
35
|
-
content_type = "text/plain"
|
36
|
-
body = exception_string
|
37
|
-
end
|
38
|
-
|
39
|
-
[
|
40
|
-
500,
|
41
|
-
{
|
42
|
-
CONTENT_TYPE => content_type,
|
43
|
-
CONTENT_LENGTH => Rack::Utils.bytesize(body).to_s,
|
44
|
-
},
|
45
|
-
[body],
|
46
|
-
]
|
47
|
-
end
|
48
|
-
|
49
|
-
def prefers_plaintext?(env)
|
50
|
-
!accepts_html?(env)
|
51
|
-
end
|
52
|
-
|
53
|
-
def accepts_html?(env)
|
54
|
-
Rack::Utils.best_q_match(env["HTTP_ACCEPT"], %w[text/html])
|
55
|
-
end
|
56
|
-
private :accepts_html?
|
57
|
-
|
58
|
-
def dump_exception(exception)
|
59
|
-
string = "#{exception.class}: #{exception.message}\n"
|
60
|
-
string << exception.backtrace.map { |l| "\t#{l}" }.join("\n")
|
61
|
-
string
|
62
|
-
end
|
63
|
-
|
64
|
-
def pretty(env, exception)
|
65
|
-
req = Rack::Request.new(env)
|
66
|
-
|
67
|
-
# This double assignment is to prevent an "unused variable" warning on
|
68
|
-
# Ruby 1.9.3. Yes, it is dumb, but I don't like Ruby yelling at me.
|
69
|
-
path = path = (req.script_name + req.path_info).squeeze("/")
|
70
|
-
|
71
|
-
# This double assignment is to prevent an "unused variable" warning on
|
72
|
-
# Ruby 1.9.3. Yes, it is dumb, but I don't like Ruby yelling at me.
|
73
|
-
frames = frames = exception.backtrace.map { |line|
|
74
|
-
frame = OpenStruct.new
|
75
|
-
if line =~ /(.*?):(\d+)(:in `(.*)')?/
|
76
|
-
frame.filename = $1
|
77
|
-
frame.lineno = $2.to_i
|
78
|
-
frame.function = $4
|
79
|
-
|
80
|
-
begin
|
81
|
-
lineno = frame.lineno-1
|
82
|
-
lines = ::File.readlines(frame.filename)
|
83
|
-
frame.pre_context_lineno = [lineno-CONTEXT, 0].max
|
84
|
-
frame.pre_context = lines[frame.pre_context_lineno...lineno]
|
85
|
-
frame.context_line = lines[lineno].chomp
|
86
|
-
frame.post_context_lineno = [lineno+CONTEXT, lines.size].min
|
87
|
-
frame.post_context = lines[lineno+1..frame.post_context_lineno]
|
88
|
-
rescue
|
89
|
-
end
|
90
|
-
|
91
|
-
frame
|
92
|
-
else
|
93
|
-
nil
|
94
|
-
end
|
95
|
-
}.compact
|
96
|
-
|
97
|
-
@template.result(binding)
|
98
|
-
end
|
99
|
-
|
100
|
-
def h(obj) # :nodoc:
|
101
|
-
case obj
|
102
|
-
when String
|
103
|
-
Utils.escape_html(obj)
|
104
|
-
else
|
105
|
-
Utils.escape_html(obj.inspect)
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
# :stopdoc:
|
110
|
-
|
111
|
-
# adapted from Django <djangoproject.com>
|
112
|
-
# Copyright (c) 2005, the Lawrence Journal-World
|
113
|
-
# Used under the modified BSD license:
|
114
|
-
# http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5
|
115
|
-
TEMPLATE = <<'HTML'
|
116
|
-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
117
|
-
<html lang="en">
|
118
|
-
<head>
|
119
|
-
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
120
|
-
<meta name="robots" content="NONE,NOARCHIVE" />
|
121
|
-
<title><%=h exception.class %> at <%=h path %></title>
|
122
|
-
<style type="text/css">
|
123
|
-
html * { padding:0; margin:0; }
|
124
|
-
body * { padding:10px 20px; }
|
125
|
-
body * * { padding:0; }
|
126
|
-
body { font:small sans-serif; }
|
127
|
-
body>div { border-bottom:1px solid #ddd; }
|
128
|
-
h1 { font-weight:normal; }
|
129
|
-
h2 { margin-bottom:.8em; }
|
130
|
-
h2 span { font-size:80%; color:#666; font-weight:normal; }
|
131
|
-
h3 { margin:1em 0 .5em 0; }
|
132
|
-
h4 { margin:0 0 .5em 0; font-weight: normal; }
|
133
|
-
table {
|
134
|
-
border:1px solid #ccc; border-collapse: collapse; background:white; }
|
135
|
-
tbody td, tbody th { vertical-align:top; padding:2px 3px; }
|
136
|
-
thead th {
|
137
|
-
padding:1px 6px 1px 3px; background:#fefefe; text-align:left;
|
138
|
-
font-weight:normal; font-size:11px; border:1px solid #ddd; }
|
139
|
-
tbody th { text-align:right; color:#666; padding-right:.5em; }
|
140
|
-
table.vars { margin:5px 0 2px 40px; }
|
141
|
-
table.vars td, table.req td { font-family:monospace; }
|
142
|
-
table td.code { width:100%;}
|
143
|
-
table td.code div { overflow:hidden; }
|
144
|
-
table.source th { color:#666; }
|
145
|
-
table.source td {
|
146
|
-
font-family:monospace; white-space:pre; border-bottom:1px solid #eee; }
|
147
|
-
ul.traceback { list-style-type:none; }
|
148
|
-
ul.traceback li.frame { margin-bottom:1em; }
|
149
|
-
div.context { margin: 10px 0; }
|
150
|
-
div.context ol {
|
151
|
-
padding-left:30px; margin:0 10px; list-style-position: inside; }
|
152
|
-
div.context ol li {
|
153
|
-
font-family:monospace; white-space:pre; color:#666; cursor:pointer; }
|
154
|
-
div.context ol.context-line li { color:black; background-color:#ccc; }
|
155
|
-
div.context ol.context-line li span { float: right; }
|
156
|
-
div.commands { margin-left: 40px; }
|
157
|
-
div.commands a { color:black; text-decoration:none; }
|
158
|
-
#summary { background: #ffc; }
|
159
|
-
#summary h2 { font-weight: normal; color: #666; }
|
160
|
-
#summary ul#quicklinks { list-style-type: none; margin-bottom: 2em; }
|
161
|
-
#summary ul#quicklinks li { float: left; padding: 0 1em; }
|
162
|
-
#summary ul#quicklinks>li+li { border-left: 1px #666 solid; }
|
163
|
-
#explanation { background:#eee; }
|
164
|
-
#template, #template-not-exist { background:#f6f6f6; }
|
165
|
-
#template-not-exist ul { margin: 0 0 0 20px; }
|
166
|
-
#traceback { background:#eee; }
|
167
|
-
#requestinfo { background:#f6f6f6; padding-left:120px; }
|
168
|
-
#summary table { border:none; background:transparent; }
|
169
|
-
#requestinfo h2, #requestinfo h3 { position:relative; margin-left:-100px; }
|
170
|
-
#requestinfo h3 { margin-bottom:-1em; }
|
171
|
-
.error { background: #ffc; }
|
172
|
-
.specific { color:#cc3300; font-weight:bold; }
|
173
|
-
</style>
|
174
|
-
<script type="text/javascript">
|
175
|
-
//<!--
|
176
|
-
function getElementsByClassName(oElm, strTagName, strClassName){
|
177
|
-
// Written by Jonathan Snook, http://www.snook.ca/jon;
|
178
|
-
// Add-ons by Robert Nyman, http://www.robertnyman.com
|
179
|
-
var arrElements = (strTagName == "*" && document.all)? document.all :
|
180
|
-
oElm.getElementsByTagName(strTagName);
|
181
|
-
var arrReturnElements = new Array();
|
182
|
-
strClassName = strClassName.replace(/\-/g, "\\-");
|
183
|
-
var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$$)");
|
184
|
-
var oElement;
|
185
|
-
for(var i=0; i<arrElements.length; i++){
|
186
|
-
oElement = arrElements[i];
|
187
|
-
if(oRegExp.test(oElement.className)){
|
188
|
-
arrReturnElements.push(oElement);
|
189
|
-
}
|
190
|
-
}
|
191
|
-
return (arrReturnElements)
|
192
|
-
}
|
193
|
-
function hideAll(elems) {
|
194
|
-
for (var e = 0; e < elems.length; e++) {
|
195
|
-
elems[e].style.display = 'none';
|
196
|
-
}
|
197
|
-
}
|
198
|
-
window.onload = function() {
|
199
|
-
hideAll(getElementsByClassName(document, 'table', 'vars'));
|
200
|
-
hideAll(getElementsByClassName(document, 'ol', 'pre-context'));
|
201
|
-
hideAll(getElementsByClassName(document, 'ol', 'post-context'));
|
202
|
-
}
|
203
|
-
function toggle() {
|
204
|
-
for (var i = 0; i < arguments.length; i++) {
|
205
|
-
var e = document.getElementById(arguments[i]);
|
206
|
-
if (e) {
|
207
|
-
e.style.display = e.style.display == 'none' ? 'block' : 'none';
|
208
|
-
}
|
209
|
-
}
|
210
|
-
return false;
|
211
|
-
}
|
212
|
-
function varToggle(link, id) {
|
213
|
-
toggle('v' + id);
|
214
|
-
var s = link.getElementsByTagName('span')[0];
|
215
|
-
var uarr = String.fromCharCode(0x25b6);
|
216
|
-
var darr = String.fromCharCode(0x25bc);
|
217
|
-
s.innerHTML = s.innerHTML == uarr ? darr : uarr;
|
218
|
-
return false;
|
219
|
-
}
|
220
|
-
//-->
|
221
|
-
</script>
|
222
|
-
</head>
|
223
|
-
<body>
|
224
|
-
|
225
|
-
<div id="summary">
|
226
|
-
<h1><%=h exception.class %> at <%=h path %></h1>
|
227
|
-
<h2><%=h exception.message %></h2>
|
228
|
-
<table><tr>
|
229
|
-
<th>Ruby</th>
|
230
|
-
<td>
|
231
|
-
<% if first = frames.first %>
|
232
|
-
<code><%=h first.filename %></code>: in <code><%=h first.function %></code>, line <%=h frames.first.lineno %>
|
233
|
-
<% else %>
|
234
|
-
unknown location
|
235
|
-
<% end %>
|
236
|
-
</td>
|
237
|
-
</tr><tr>
|
238
|
-
<th>Web</th>
|
239
|
-
<td><code><%=h req.request_method %> <%=h(req.host + path)%></code></td>
|
240
|
-
</tr></table>
|
241
|
-
|
242
|
-
<h3>Jump to:</h3>
|
243
|
-
<ul id="quicklinks">
|
244
|
-
<li><a href="#get-info">GET</a></li>
|
245
|
-
<li><a href="#post-info">POST</a></li>
|
246
|
-
<li><a href="#cookie-info">Cookies</a></li>
|
247
|
-
<li><a href="#env-info">ENV</a></li>
|
248
|
-
</ul>
|
249
|
-
</div>
|
250
|
-
|
251
|
-
<div id="traceback">
|
252
|
-
<h2>Traceback <span>(innermost first)</span></h2>
|
253
|
-
<ul class="traceback">
|
254
|
-
<% frames.each { |frame| %>
|
255
|
-
<li class="frame">
|
256
|
-
<code><%=h frame.filename %></code>: in <code><%=h frame.function %></code>
|
257
|
-
|
258
|
-
<% if frame.context_line %>
|
259
|
-
<div class="context" id="c<%=h frame.object_id %>">
|
260
|
-
<% if frame.pre_context %>
|
261
|
-
<ol start="<%=h frame.pre_context_lineno+1 %>" class="pre-context" id="pre<%=h frame.object_id %>">
|
262
|
-
<% frame.pre_context.each { |line| %>
|
263
|
-
<li onclick="toggle('pre<%=h frame.object_id %>', 'post<%=h frame.object_id %>')"><%=h line %></li>
|
264
|
-
<% } %>
|
265
|
-
</ol>
|
266
|
-
<% end %>
|
267
|
-
|
268
|
-
<ol start="<%=h frame.lineno %>" class="context-line">
|
269
|
-
<li onclick="toggle('pre<%=h frame.object_id %>', 'post<%=h frame.object_id %>')"><%=h frame.context_line %><span>...</span></li></ol>
|
270
|
-
|
271
|
-
<% if frame.post_context %>
|
272
|
-
<ol start='<%=h frame.lineno+1 %>' class="post-context" id="post<%=h frame.object_id %>">
|
273
|
-
<% frame.post_context.each { |line| %>
|
274
|
-
<li onclick="toggle('pre<%=h frame.object_id %>', 'post<%=h frame.object_id %>')"><%=h line %></li>
|
275
|
-
<% } %>
|
276
|
-
</ol>
|
277
|
-
<% end %>
|
278
|
-
</div>
|
279
|
-
<% end %>
|
280
|
-
</li>
|
281
|
-
<% } %>
|
282
|
-
</ul>
|
283
|
-
</div>
|
284
|
-
|
285
|
-
<div id="requestinfo">
|
286
|
-
<h2>Request information</h2>
|
287
|
-
|
288
|
-
<h3 id="get-info">GET</h3>
|
289
|
-
<% if req.GET and not req.GET.empty? %>
|
290
|
-
<table class="req">
|
291
|
-
<thead>
|
292
|
-
<tr>
|
293
|
-
<th>Variable</th>
|
294
|
-
<th>Value</th>
|
295
|
-
</tr>
|
296
|
-
</thead>
|
297
|
-
<tbody>
|
298
|
-
<% req.GET.sort_by { |k, v| k.to_s }.each { |key, val| %>
|
299
|
-
<tr>
|
300
|
-
<td><%=h key %></td>
|
301
|
-
<td class="code"><div><%=h val.inspect %></div></td>
|
302
|
-
</tr>
|
303
|
-
<% } %>
|
304
|
-
</tbody>
|
305
|
-
</table>
|
306
|
-
<% else %>
|
307
|
-
<p>No GET data.</p>
|
308
|
-
<% end %>
|
309
|
-
|
310
|
-
<h3 id="post-info">POST</h3>
|
311
|
-
<% if req.POST and not req.POST.empty? %>
|
312
|
-
<table class="req">
|
313
|
-
<thead>
|
314
|
-
<tr>
|
315
|
-
<th>Variable</th>
|
316
|
-
<th>Value</th>
|
317
|
-
</tr>
|
318
|
-
</thead>
|
319
|
-
<tbody>
|
320
|
-
<% req.POST.sort_by { |k, v| k.to_s }.each { |key, val| %>
|
321
|
-
<tr>
|
322
|
-
<td><%=h key %></td>
|
323
|
-
<td class="code"><div><%=h val.inspect %></div></td>
|
324
|
-
</tr>
|
325
|
-
<% } %>
|
326
|
-
</tbody>
|
327
|
-
</table>
|
328
|
-
<% else %>
|
329
|
-
<p>No POST data.</p>
|
330
|
-
<% end %>
|
331
|
-
|
332
|
-
|
333
|
-
<h3 id="cookie-info">COOKIES</h3>
|
334
|
-
<% unless req.cookies.empty? %>
|
335
|
-
<table class="req">
|
336
|
-
<thead>
|
337
|
-
<tr>
|
338
|
-
<th>Variable</th>
|
339
|
-
<th>Value</th>
|
340
|
-
</tr>
|
341
|
-
</thead>
|
342
|
-
<tbody>
|
343
|
-
<% req.cookies.each { |key, val| %>
|
344
|
-
<tr>
|
345
|
-
<td><%=h key %></td>
|
346
|
-
<td class="code"><div><%=h val.inspect %></div></td>
|
347
|
-
</tr>
|
348
|
-
<% } %>
|
349
|
-
</tbody>
|
350
|
-
</table>
|
351
|
-
<% else %>
|
352
|
-
<p>No cookie data.</p>
|
353
|
-
<% end %>
|
354
|
-
|
355
|
-
<h3 id="env-info">Rack ENV</h3>
|
356
|
-
<table class="req">
|
357
|
-
<thead>
|
358
|
-
<tr>
|
359
|
-
<th>Variable</th>
|
360
|
-
<th>Value</th>
|
361
|
-
</tr>
|
362
|
-
</thead>
|
363
|
-
<tbody>
|
364
|
-
<% env.sort_by { |k, v| k.to_s }.each { |key, val| %>
|
365
|
-
<tr>
|
366
|
-
<td><%=h key %></td>
|
367
|
-
<td class="code"><div><%=h val %></div></td>
|
368
|
-
</tr>
|
369
|
-
<% } %>
|
370
|
-
</tbody>
|
371
|
-
</table>
|
372
|
-
|
373
|
-
</div>
|
374
|
-
|
375
|
-
<div id="explanation">
|
376
|
-
<p>
|
377
|
-
You're seeing this error because you use <code>Rack::ShowExceptions</code>.
|
378
|
-
</p>
|
379
|
-
</div>
|
380
|
-
|
381
|
-
</body>
|
382
|
-
</html>
|
383
|
-
HTML
|
384
|
-
|
385
|
-
# :startdoc:
|
386
|
-
end
|
387
|
-
end
|