rack 1.6.13 → 2.0.0.alpha

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.

Files changed (138) hide show
  1. checksums.yaml +5 -5
  2. data/HISTORY.md +139 -18
  3. data/README.rdoc +17 -25
  4. data/Rakefile +6 -14
  5. data/SPEC +8 -9
  6. data/contrib/rack_logo.svg +164 -111
  7. data/lib/rack.rb +70 -21
  8. data/lib/rack/auth/digest/request.rb +1 -1
  9. data/lib/rack/body_proxy.rb +14 -9
  10. data/lib/rack/builder.rb +3 -3
  11. data/lib/rack/chunked.rb +5 -5
  12. data/lib/rack/{commonlogger.rb → common_logger.rb} +2 -2
  13. data/lib/rack/{conditionalget.rb → conditional_get.rb} +0 -0
  14. data/lib/rack/content_length.rb +2 -2
  15. data/lib/rack/deflater.rb +4 -4
  16. data/lib/rack/directory.rb +49 -55
  17. data/lib/rack/etag.rb +2 -1
  18. data/lib/rack/events.rb +154 -0
  19. data/lib/rack/file.rb +55 -40
  20. data/lib/rack/handler.rb +2 -24
  21. data/lib/rack/handler/cgi.rb +15 -16
  22. data/lib/rack/handler/fastcgi.rb +13 -14
  23. data/lib/rack/handler/lsws.rb +11 -11
  24. data/lib/rack/handler/scgi.rb +15 -15
  25. data/lib/rack/handler/thin.rb +3 -0
  26. data/lib/rack/handler/webrick.rb +22 -24
  27. data/lib/rack/head.rb +15 -17
  28. data/lib/rack/lint.rb +38 -38
  29. data/lib/rack/lobster.rb +1 -1
  30. data/lib/rack/lock.rb +6 -10
  31. data/lib/rack/logger.rb +2 -2
  32. data/lib/rack/media_type.rb +38 -0
  33. data/lib/rack/{methodoverride.rb → method_override.rb} +4 -11
  34. data/lib/rack/mime.rb +18 -5
  35. data/lib/rack/mock.rb +35 -52
  36. data/lib/rack/multipart.rb +35 -6
  37. data/lib/rack/multipart/generator.rb +4 -4
  38. data/lib/rack/multipart/parser.rb +273 -158
  39. data/lib/rack/multipart/uploaded_file.rb +1 -2
  40. data/lib/rack/{nulllogger.rb → null_logger.rb} +1 -1
  41. data/lib/rack/query_parser.rb +174 -0
  42. data/lib/rack/recursive.rb +8 -8
  43. data/lib/rack/reloader.rb +1 -2
  44. data/lib/rack/request.rb +370 -304
  45. data/lib/rack/response.rb +129 -56
  46. data/lib/rack/rewindable_input.rb +1 -12
  47. data/lib/rack/runtime.rb +10 -18
  48. data/lib/rack/sendfile.rb +5 -7
  49. data/lib/rack/server.rb +31 -25
  50. data/lib/rack/session/abstract/id.rb +93 -135
  51. data/lib/rack/session/cookie.rb +26 -28
  52. data/lib/rack/session/memcache.rb +8 -14
  53. data/lib/rack/session/pool.rb +14 -21
  54. data/lib/rack/show_exceptions.rb +386 -0
  55. data/lib/rack/{showstatus.rb → show_status.rb} +3 -3
  56. data/lib/rack/static.rb +30 -5
  57. data/lib/rack/tempfile_reaper.rb +2 -2
  58. data/lib/rack/urlmap.rb +13 -14
  59. data/lib/rack/utils.rb +128 -221
  60. data/rack.gemspec +9 -5
  61. data/test/builder/an_underscore_app.rb +5 -0
  62. data/test/builder/options.ru +1 -1
  63. data/test/cgi/test.fcgi +1 -0
  64. data/test/cgi/test.gz +0 -0
  65. data/test/helper.rb +31 -0
  66. data/test/multipart/filename_with_encoded_words +7 -0
  67. data/test/multipart/{filename_with_null_byte → filename_with_single_quote} +1 -1
  68. data/test/multipart/quoted +15 -0
  69. data/test/multipart/rack-logo.png +0 -0
  70. data/test/registering_handler/rack/handler/registering_myself.rb +1 -1
  71. data/test/spec_auth_basic.rb +20 -19
  72. data/test/spec_auth_digest.rb +47 -46
  73. data/test/spec_body_proxy.rb +27 -27
  74. data/test/spec_builder.rb +51 -41
  75. data/test/spec_cascade.rb +24 -22
  76. data/test/spec_cgi.rb +49 -67
  77. data/test/spec_chunked.rb +36 -34
  78. data/test/{spec_commonlogger.rb → spec_common_logger.rb} +23 -21
  79. data/test/{spec_conditionalget.rb → spec_conditional_get.rb} +29 -28
  80. data/test/spec_config.rb +3 -2
  81. data/test/spec_content_length.rb +18 -17
  82. data/test/spec_content_type.rb +13 -12
  83. data/test/spec_deflater.rb +66 -40
  84. data/test/spec_directory.rb +72 -27
  85. data/test/spec_etag.rb +32 -31
  86. data/test/spec_events.rb +133 -0
  87. data/test/spec_fastcgi.rb +50 -72
  88. data/test/spec_file.rb +96 -77
  89. data/test/spec_handler.rb +19 -34
  90. data/test/spec_head.rb +15 -14
  91. data/test/spec_lint.rb +162 -197
  92. data/test/spec_lobster.rb +24 -23
  93. data/test/spec_lock.rb +69 -39
  94. data/test/spec_logger.rb +4 -3
  95. data/test/spec_media_type.rb +42 -0
  96. data/test/spec_method_override.rb +83 -0
  97. data/test/spec_mime.rb +19 -19
  98. data/test/spec_mock.rb +196 -151
  99. data/test/spec_multipart.rb +310 -202
  100. data/test/{spec_nulllogger.rb → spec_null_logger.rb} +5 -4
  101. data/test/spec_recursive.rb +17 -14
  102. data/test/spec_request.rb +763 -607
  103. data/test/spec_response.rb +209 -156
  104. data/test/spec_rewindable_input.rb +50 -40
  105. data/test/spec_runtime.rb +11 -10
  106. data/test/spec_sendfile.rb +30 -35
  107. data/test/spec_server.rb +78 -52
  108. data/test/spec_session_abstract_id.rb +11 -33
  109. data/test/spec_session_cookie.rb +97 -65
  110. data/test/spec_session_memcache.rb +63 -101
  111. data/test/spec_session_pool.rb +48 -84
  112. data/test/spec_show_exceptions.rb +80 -0
  113. data/test/{spec_showstatus.rb → spec_show_status.rb} +36 -35
  114. data/test/spec_static.rb +71 -32
  115. data/test/spec_tempfile_reaper.rb +11 -10
  116. data/test/spec_thin.rb +55 -50
  117. data/test/spec_urlmap.rb +79 -78
  118. data/test/spec_utils.rb +417 -345
  119. data/test/spec_version.rb +2 -8
  120. data/test/spec_webrick.rb +77 -67
  121. data/test/static/foo.html +1 -0
  122. data/test/testrequest.rb +1 -1
  123. data/test/unregistered_handler/rack/handler/unregistered.rb +1 -1
  124. data/test/unregistered_handler/rack/handler/unregistered_long_one.rb +1 -1
  125. metadata +116 -71
  126. data/KNOWN-ISSUES +0 -44
  127. data/lib/rack/backports/uri/common_18.rb +0 -56
  128. data/lib/rack/backports/uri/common_192.rb +0 -52
  129. data/lib/rack/backports/uri/common_193.rb +0 -29
  130. data/lib/rack/handler/evented_mongrel.rb +0 -8
  131. data/lib/rack/handler/mongrel.rb +0 -106
  132. data/lib/rack/handler/swiftiplied_mongrel.rb +0 -8
  133. data/lib/rack/showexceptions.rb +0 -387
  134. data/lib/rack/utils/okjson.rb +0 -600
  135. data/test/spec_methodoverride.rb +0 -111
  136. data/test/spec_mongrel.rb +0 -182
  137. data/test/spec_session_persisted_secure_secure_session_hash.rb +0 -73
  138. data/test/spec_showexceptions.rb +0 -98
@@ -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:
@@ -1,8 +0,0 @@
1
- require 'swiftcore/evented_mongrel'
2
-
3
- module Rack
4
- module Handler
5
- class EventedMongrel < Handler::Mongrel
6
- end
7
- end
8
- end
@@ -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
@@ -1,8 +0,0 @@
1
- require 'swiftcore/swiftiplied_mongrel'
2
-
3
- module Rack
4
- module Handler
5
- class SwiftipliedMongrel < Handler::Mongrel
6
- end
7
- end
8
- end
@@ -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