homura-runtime 0.3.3 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/homura/runtime/version.rb +1 -1
- data/vendor/rack/auth/abstract/handler.rb +41 -0
- data/vendor/rack/auth/abstract/request.rb +51 -0
- data/vendor/rack/auth/basic.rb +58 -0
- data/vendor/rack/bad_request.rb +8 -0
- data/vendor/rack/body_proxy.rb +63 -0
- data/vendor/rack/builder.rb +315 -0
- data/vendor/rack/cascade.rb +67 -0
- data/vendor/rack/common_logger.rb +94 -0
- data/vendor/rack/conditional_get.rb +87 -0
- data/vendor/rack/config.rb +22 -0
- data/vendor/rack/constants.rb +68 -0
- data/vendor/rack/content_length.rb +34 -0
- data/vendor/rack/content_type.rb +33 -0
- data/vendor/rack/deflater.rb +159 -0
- data/vendor/rack/directory.rb +210 -0
- data/vendor/rack/etag.rb +71 -0
- data/vendor/rack/events.rb +172 -0
- data/vendor/rack/files.rb +224 -0
- data/vendor/rack/head.rb +25 -0
- data/vendor/rack/headers.rb +238 -0
- data/vendor/rack/lint.rb +1000 -0
- data/vendor/rack/lock.rb +29 -0
- data/vendor/rack/media_type.rb +42 -0
- data/vendor/rack/method_override.rb +56 -0
- data/vendor/rack/mime.rb +694 -0
- data/vendor/rack/mock.rb +3 -0
- data/vendor/rack/mock_request.rb +161 -0
- data/vendor/rack/mock_response.rb +147 -0
- data/vendor/rack/multipart/generator.rb +99 -0
- data/vendor/rack/multipart/parser.rb +586 -0
- data/vendor/rack/multipart/uploaded_file.rb +82 -0
- data/vendor/rack/multipart.rb +77 -0
- data/vendor/rack/null_logger.rb +48 -0
- data/vendor/rack/protection/authenticity_token.rb +256 -0
- data/vendor/rack/protection/base.rb +140 -0
- data/vendor/rack/protection/content_security_policy.rb +80 -0
- data/vendor/rack/protection/cookie_tossing.rb +77 -0
- data/vendor/rack/protection/escaped_params.rb +93 -0
- data/vendor/rack/protection/form_token.rb +25 -0
- data/vendor/rack/protection/frame_options.rb +39 -0
- data/vendor/rack/protection/http_origin.rb +43 -0
- data/vendor/rack/protection/ip_spoofing.rb +27 -0
- data/vendor/rack/protection/json_csrf.rb +60 -0
- data/vendor/rack/protection/path_traversal.rb +45 -0
- data/vendor/rack/protection/referrer_policy.rb +27 -0
- data/vendor/rack/protection/remote_referrer.rb +22 -0
- data/vendor/rack/protection/remote_token.rb +24 -0
- data/vendor/rack/protection/session_hijacking.rb +37 -0
- data/vendor/rack/protection/strict_transport.rb +41 -0
- data/vendor/rack/protection/version.rb +7 -0
- data/vendor/rack/protection/xss_header.rb +27 -0
- data/vendor/rack/protection.rb +58 -0
- data/vendor/rack/query_parser.rb +261 -0
- data/vendor/rack/recursive.rb +66 -0
- data/vendor/rack/reloader.rb +112 -0
- data/vendor/rack/request.rb +818 -0
- data/vendor/rack/response.rb +403 -0
- data/vendor/rack/rewindable_input.rb +116 -0
- data/vendor/rack/runtime.rb +35 -0
- data/vendor/rack/sendfile.rb +197 -0
- data/vendor/rack/session/abstract/id.rb +533 -0
- data/vendor/rack/session/constants.rb +13 -0
- data/vendor/rack/session/cookie.rb +292 -0
- data/vendor/rack/session/encryptor.rb +415 -0
- data/vendor/rack/session/pool.rb +76 -0
- data/vendor/rack/session/version.rb +10 -0
- data/vendor/rack/session.rb +12 -0
- data/vendor/rack/show_exceptions.rb +433 -0
- data/vendor/rack/show_status.rb +121 -0
- data/vendor/rack/static.rb +188 -0
- data/vendor/rack/tempfile_reaper.rb +44 -0
- data/vendor/rack/urlmap.rb +99 -0
- data/vendor/rack/utils.rb +631 -0
- data/vendor/rack/version.rb +17 -0
- data/vendor/rack.rb +66 -0
- metadata +76 -1
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Released under the MIT License.
|
|
4
|
+
# Copyright, 2022-2023, by Samuel Williams.
|
|
5
|
+
|
|
6
|
+
require_relative 'abstract/id'
|
|
7
|
+
|
|
8
|
+
module Rack
|
|
9
|
+
module Session
|
|
10
|
+
# Rack::Session::Pool provides simple cookie based session management.
|
|
11
|
+
# Session data is stored in a hash held by @pool.
|
|
12
|
+
# In the context of a multithreaded environment, sessions being
|
|
13
|
+
# committed to the pool is done in a merging manner.
|
|
14
|
+
#
|
|
15
|
+
# The :drop option is available in rack.session.options if you wish to
|
|
16
|
+
# explicitly remove the session from the session cache.
|
|
17
|
+
#
|
|
18
|
+
# Example:
|
|
19
|
+
# myapp = MyRackApp.new
|
|
20
|
+
# sessioned = Rack::Session::Pool.new(myapp,
|
|
21
|
+
# :domain => 'foo.com',
|
|
22
|
+
# :expire_after => 2592000
|
|
23
|
+
# )
|
|
24
|
+
# Rack::Handler::WEBrick.run sessioned
|
|
25
|
+
|
|
26
|
+
class Pool < Abstract::PersistedSecure
|
|
27
|
+
attr_reader :mutex, :pool
|
|
28
|
+
DEFAULT_OPTIONS = Abstract::ID::DEFAULT_OPTIONS.merge(drop: false, allow_fallback: true)
|
|
29
|
+
|
|
30
|
+
def initialize(app, options = {})
|
|
31
|
+
super
|
|
32
|
+
@pool = Hash.new
|
|
33
|
+
@mutex = Mutex.new
|
|
34
|
+
@allow_fallback = @default_options.delete(:allow_fallback)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def generate_sid(*args, use_mutex: true)
|
|
38
|
+
loop do
|
|
39
|
+
sid = super(*args)
|
|
40
|
+
break sid unless use_mutex ? @mutex.synchronize { @pool.key? sid.private_id } : @pool.key?(sid.private_id)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def find_session(req, sid)
|
|
45
|
+
@mutex.synchronize do
|
|
46
|
+
unless sid and session = get_session_with_fallback(sid)
|
|
47
|
+
sid, session = generate_sid(use_mutex: false), {}
|
|
48
|
+
@pool.store sid.private_id, session
|
|
49
|
+
end
|
|
50
|
+
[sid, session]
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def write_session(req, session_id, new_session, options)
|
|
55
|
+
@mutex.synchronize do
|
|
56
|
+
@pool.store session_id.private_id, new_session
|
|
57
|
+
session_id
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def delete_session(req, session_id, options)
|
|
62
|
+
@mutex.synchronize do
|
|
63
|
+
@pool.delete(session_id.public_id)
|
|
64
|
+
@pool.delete(session_id.private_id)
|
|
65
|
+
generate_sid(use_mutex: false) unless options[:drop]
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
private
|
|
70
|
+
|
|
71
|
+
def get_session_with_fallback(sid)
|
|
72
|
+
@pool[sid.private_id] || (@pool[sid.public_id] if @allow_fallback)
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Released under the MIT License.
|
|
4
|
+
# Copyright, 2022-2023, by Samuel Williams.
|
|
5
|
+
# Copyright, 2022, by Jeremy Evans.
|
|
6
|
+
|
|
7
|
+
module Rack
|
|
8
|
+
module Session
|
|
9
|
+
autoload :Cookie, "rack/session/cookie"
|
|
10
|
+
autoload :Pool, "rack/session/pool"
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'erb'
|
|
4
|
+
|
|
5
|
+
require_relative 'constants'
|
|
6
|
+
require_relative 'utils'
|
|
7
|
+
require_relative 'request'
|
|
8
|
+
|
|
9
|
+
module Rack
|
|
10
|
+
# Rack::ShowExceptions catches all exceptions raised from the app it
|
|
11
|
+
# wraps. It shows a useful backtrace with the sourcefile and
|
|
12
|
+
# clickable context, the whole Rack environment and the request
|
|
13
|
+
# data.
|
|
14
|
+
#
|
|
15
|
+
# Be careful when you use this on public-facing sites as it could
|
|
16
|
+
# reveal information helpful to attackers.
|
|
17
|
+
|
|
18
|
+
class ShowExceptions
|
|
19
|
+
CONTEXT = 7
|
|
20
|
+
|
|
21
|
+
Frame = Struct.new(:filename, :lineno, :function,
|
|
22
|
+
:pre_context_lineno, :pre_context,
|
|
23
|
+
:context_line, :post_context_lineno,
|
|
24
|
+
:post_context)
|
|
25
|
+
|
|
26
|
+
def initialize(app)
|
|
27
|
+
@app = app
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def call(env)
|
|
31
|
+
@app.call(env)
|
|
32
|
+
rescue StandardError, LoadError, SyntaxError => e
|
|
33
|
+
exception_string = dump_exception(e)
|
|
34
|
+
|
|
35
|
+
env[RACK_ERRORS].puts(exception_string)
|
|
36
|
+
env[RACK_ERRORS].flush
|
|
37
|
+
|
|
38
|
+
if accepts_html?(env)
|
|
39
|
+
content_type = "text/html"
|
|
40
|
+
body = pretty(env, e)
|
|
41
|
+
else
|
|
42
|
+
content_type = "text/plain"
|
|
43
|
+
body = exception_string
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
[
|
|
47
|
+
500,
|
|
48
|
+
{
|
|
49
|
+
CONTENT_TYPE => content_type,
|
|
50
|
+
CONTENT_LENGTH => body.bytesize.to_s,
|
|
51
|
+
},
|
|
52
|
+
[body],
|
|
53
|
+
]
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def prefers_plaintext?(env)
|
|
57
|
+
!accepts_html?(env)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def accepts_html?(env)
|
|
61
|
+
Rack::Utils.best_q_match(env["HTTP_ACCEPT"], %w[text/html])
|
|
62
|
+
end
|
|
63
|
+
private :accepts_html?
|
|
64
|
+
|
|
65
|
+
def dump_exception(exception)
|
|
66
|
+
if exception.respond_to?(:detailed_message)
|
|
67
|
+
message = exception.detailed_message(highlight: false)
|
|
68
|
+
# :nocov:
|
|
69
|
+
# Ruby 3.2 added Exception#detailed_message, so the else
|
|
70
|
+
# branch cannot be hit on the current Ruby version.
|
|
71
|
+
else
|
|
72
|
+
message = exception.message
|
|
73
|
+
# :nocov:
|
|
74
|
+
end
|
|
75
|
+
# homura patch: Opal strings are immutable.
|
|
76
|
+
string = "#{exception.class}: #{message}\n".dup
|
|
77
|
+
string += exception.backtrace.map { |l| "\t#{l}" }.join("\n") if exception.backtrace
|
|
78
|
+
string
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# homura patch: the upstream implementation uses
|
|
82
|
+
# `template.result(binding)`, and the ERB template compiles at render
|
|
83
|
+
# time to a Ruby fragment that Opal in turn hands off to
|
|
84
|
+
# `Opal.Binding.$new(function($code) { return eval($code); }, ...)`.
|
|
85
|
+
# Cloudflare Workers rejects that with "Code generation from strings
|
|
86
|
+
# disallowed" on the first dispatch through ShowExceptions. We rebuild
|
|
87
|
+
# the same rescue page as a plain Ruby string builder so the entire
|
|
88
|
+
# pretty-printing path stays inside the Workers sandbox.
|
|
89
|
+
def pretty(env, exception)
|
|
90
|
+
req = Rack::Request.new(env)
|
|
91
|
+
path = (req.script_name + req.path_info).squeeze('/')
|
|
92
|
+
frames = (exception.backtrace || []).map { |line|
|
|
93
|
+
if line =~ /(.*?):(\d+)(:in `(.*)')?/
|
|
94
|
+
frame = Frame.new
|
|
95
|
+
frame.filename = $1
|
|
96
|
+
frame.lineno = $2.to_i
|
|
97
|
+
frame.function = $4
|
|
98
|
+
frame
|
|
99
|
+
end
|
|
100
|
+
}.compact
|
|
101
|
+
|
|
102
|
+
buffer = +'<!DOCTYPE html><html lang="en"><head>'
|
|
103
|
+
buffer += '<meta http-equiv="content-type" content="text/html; charset=utf-8"/>'
|
|
104
|
+
buffer += "<title>#{h(exception.class)} at #{h(path)}</title>"
|
|
105
|
+
buffer += '<style>body{font:14px -apple-system,sans-serif;margin:20px;color:#222}'
|
|
106
|
+
buffer += 'h1{font-weight:normal;color:#900}'
|
|
107
|
+
buffer += 'h2{margin-top:1.2em;font-size:1em;color:#555}'
|
|
108
|
+
buffer += 'pre{background:#f5f5f5;padding:10px;overflow:auto;white-space:pre-wrap}'
|
|
109
|
+
buffer += 'ol.traceback{font-family:monospace}'
|
|
110
|
+
buffer += 'ol.traceback li{margin-bottom:.3em}</style></head><body>'
|
|
111
|
+
buffer += "<h1>#{h(exception.class)} at #{h(path)}</h1>"
|
|
112
|
+
buffer += "<h2>#{h(exception.message)}</h2>"
|
|
113
|
+
buffer += '<h3>Traceback</h3>'
|
|
114
|
+
buffer += '<ol class="traceback">'
|
|
115
|
+
frames.each do |frame|
|
|
116
|
+
buffer += '<li>'
|
|
117
|
+
buffer += "<code>#{h(frame.filename)}:#{frame.lineno}</code>"
|
|
118
|
+
buffer += " in <code>#{h(frame.function)}</code>" if frame.function
|
|
119
|
+
buffer += '</li>'
|
|
120
|
+
end
|
|
121
|
+
buffer += '</ol>'
|
|
122
|
+
buffer += '<h3>Request</h3>'
|
|
123
|
+
buffer += '<pre>'
|
|
124
|
+
buffer += "#{h(req.request_method)} #{h(req.fullpath)}\n"
|
|
125
|
+
buffer += "Host: #{h(req.host_with_port)}\n"
|
|
126
|
+
buffer += '</pre>'
|
|
127
|
+
buffer += '<h3>Environment</h3>'
|
|
128
|
+
buffer += '<pre>'
|
|
129
|
+
env.sort_by { |k, _| k.to_s }.each do |k, v|
|
|
130
|
+
next unless k.is_a?(String)
|
|
131
|
+
next if k.start_with?('rack.')
|
|
132
|
+
next if k == 'cloudflare.env' || k == 'cloudflare.ctx'
|
|
133
|
+
buffer += "#{h(k)} = #{h(v.inspect)}\n"
|
|
134
|
+
end
|
|
135
|
+
buffer += '</pre>'
|
|
136
|
+
buffer += '</body></html>'
|
|
137
|
+
buffer
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def template
|
|
141
|
+
TEMPLATE
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def h(obj) # :nodoc:
|
|
145
|
+
case obj
|
|
146
|
+
when String
|
|
147
|
+
Utils.escape_html(obj)
|
|
148
|
+
else
|
|
149
|
+
Utils.escape_html(obj.inspect)
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
# :stopdoc:
|
|
154
|
+
|
|
155
|
+
# adapted from Django <www.djangoproject.com>
|
|
156
|
+
# Copyright (c) Django Software Foundation and individual contributors.
|
|
157
|
+
# Used under the modified BSD license:
|
|
158
|
+
# http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5
|
|
159
|
+
TEMPLATE = ERB.new(<<-'HTML'.gsub(/^ /, ''))
|
|
160
|
+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
161
|
+
<html lang="en">
|
|
162
|
+
<head>
|
|
163
|
+
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
|
164
|
+
<meta name="robots" content="NONE,NOARCHIVE" />
|
|
165
|
+
<title><%=h exception.class %> at <%=h path %></title>
|
|
166
|
+
<style type="text/css">
|
|
167
|
+
html * { padding:0; margin:0; }
|
|
168
|
+
body * { padding:10px 20px; }
|
|
169
|
+
body * * { padding:0; }
|
|
170
|
+
body { font:small sans-serif; }
|
|
171
|
+
body>div { border-bottom:1px solid #ddd; }
|
|
172
|
+
h1 { font-weight:normal; }
|
|
173
|
+
h2 { margin-bottom:.8em; }
|
|
174
|
+
h2 span { font-size:80%; color:#666; font-weight:normal; }
|
|
175
|
+
h3 { margin:1em 0 .5em 0; }
|
|
176
|
+
h4 { margin:0 0 .5em 0; font-weight: normal; }
|
|
177
|
+
table {
|
|
178
|
+
border:1px solid #ccc; border-collapse: collapse; background:white; }
|
|
179
|
+
tbody td, tbody th { vertical-align:top; padding:2px 3px; }
|
|
180
|
+
thead th {
|
|
181
|
+
padding:1px 6px 1px 3px; background:#fefefe; text-align:left;
|
|
182
|
+
font-weight:normal; font-size:11px; border:1px solid #ddd; }
|
|
183
|
+
tbody th { text-align:right; color:#666; padding-right:.5em; }
|
|
184
|
+
table.vars { margin:5px 0 2px 40px; }
|
|
185
|
+
table.vars td, table.req td { font-family:monospace; }
|
|
186
|
+
table td.code { width:100%;}
|
|
187
|
+
table td.code div { overflow:hidden; }
|
|
188
|
+
table.source th { color:#666; }
|
|
189
|
+
table.source td {
|
|
190
|
+
font-family:monospace; white-space:pre; border-bottom:1px solid #eee; }
|
|
191
|
+
ul.traceback { list-style-type:none; }
|
|
192
|
+
ul.traceback li.frame { margin-bottom:1em; }
|
|
193
|
+
div.context { margin: 10px 0; }
|
|
194
|
+
div.context ol {
|
|
195
|
+
padding-left:30px; margin:0 10px; list-style-position: inside; }
|
|
196
|
+
div.context ol li {
|
|
197
|
+
font-family:monospace; white-space:pre; color:#666; cursor:pointer; }
|
|
198
|
+
div.context ol.context-line li { color:black; background-color:#ccc; }
|
|
199
|
+
div.context ol.context-line li span { float: right; }
|
|
200
|
+
div.commands { margin-left: 40px; }
|
|
201
|
+
div.commands a { color:black; text-decoration:none; }
|
|
202
|
+
#summary { background: #ffc; }
|
|
203
|
+
#summary h2 { font-family: monospace; font-weight: normal; color: #666; white-space: pre-wrap; }
|
|
204
|
+
#summary ul#quicklinks { list-style-type: none; margin-bottom: 2em; }
|
|
205
|
+
#summary ul#quicklinks li { float: left; padding: 0 1em; }
|
|
206
|
+
#summary ul#quicklinks>li+li { border-left: 1px #666 solid; }
|
|
207
|
+
#explanation { background:#eee; }
|
|
208
|
+
#template, #template-not-exist { background:#f6f6f6; }
|
|
209
|
+
#template-not-exist ul { margin: 0 0 0 20px; }
|
|
210
|
+
#traceback { background:#eee; }
|
|
211
|
+
#requestinfo { background:#f6f6f6; padding-left:120px; }
|
|
212
|
+
#summary table { border:none; background:transparent; }
|
|
213
|
+
#requestinfo h2, #requestinfo h3 { position:relative; margin-left:-100px; }
|
|
214
|
+
#requestinfo h3 { margin-bottom:-1em; }
|
|
215
|
+
.error { background: #ffc; }
|
|
216
|
+
.specific { color:#cc3300; font-weight:bold; }
|
|
217
|
+
</style>
|
|
218
|
+
<script type="text/javascript">
|
|
219
|
+
//<!--
|
|
220
|
+
function getElementsByClassName(oElm, strTagName, strClassName){
|
|
221
|
+
// Written by Jonathan Snook, http://www.snook.ca/jon;
|
|
222
|
+
// Add-ons by Robert Nyman, http://www.robertnyman.com
|
|
223
|
+
var arrElements = (strTagName == "*" && document.all)? document.all :
|
|
224
|
+
oElm.getElementsByTagName(strTagName);
|
|
225
|
+
var arrReturnElements = new Array();
|
|
226
|
+
strClassName = strClassName.replace(/\-/g, "\\-");
|
|
227
|
+
var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$$)");
|
|
228
|
+
var oElement;
|
|
229
|
+
for(var i=0; i<arrElements.length; i++){
|
|
230
|
+
oElement = arrElements[i];
|
|
231
|
+
if(oRegExp.test(oElement.className)){
|
|
232
|
+
arrReturnElements.push(oElement);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return (arrReturnElements)
|
|
236
|
+
}
|
|
237
|
+
function hideAll(elems) {
|
|
238
|
+
for (var e = 0; e < elems.length; e++) {
|
|
239
|
+
elems[e].style.display = 'none';
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
window.onload = function() {
|
|
243
|
+
hideAll(getElementsByClassName(document, 'table', 'vars'));
|
|
244
|
+
hideAll(getElementsByClassName(document, 'ol', 'pre-context'));
|
|
245
|
+
hideAll(getElementsByClassName(document, 'ol', 'post-context'));
|
|
246
|
+
}
|
|
247
|
+
function toggle() {
|
|
248
|
+
for (var i = 0; i < arguments.length; i++) {
|
|
249
|
+
var e = document.getElementById(arguments[i]);
|
|
250
|
+
if (e) {
|
|
251
|
+
e.style.display = e.style.display == 'none' ? 'block' : 'none';
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
256
|
+
function varToggle(link, id) {
|
|
257
|
+
toggle('v' + id);
|
|
258
|
+
var s = link.getElementsByTagName('span')[0];
|
|
259
|
+
var uarr = String.fromCharCode(0x25b6);
|
|
260
|
+
var darr = String.fromCharCode(0x25bc);
|
|
261
|
+
s.innerHTML = s.innerHTML == uarr ? darr : uarr;
|
|
262
|
+
return false;
|
|
263
|
+
}
|
|
264
|
+
//-->
|
|
265
|
+
</script>
|
|
266
|
+
</head>
|
|
267
|
+
<body>
|
|
268
|
+
|
|
269
|
+
<div id="summary">
|
|
270
|
+
<h1><%=h exception.class %> at <%=h path %></h1>
|
|
271
|
+
<% if exception.respond_to?(:detailed_message) %>
|
|
272
|
+
<h2><%=h exception.detailed_message(highlight: false) %></h2>
|
|
273
|
+
<% else %>
|
|
274
|
+
<h2><%=h exception.message %></h2>
|
|
275
|
+
<% end %>
|
|
276
|
+
<table><tr>
|
|
277
|
+
<th>Ruby</th>
|
|
278
|
+
<td>
|
|
279
|
+
<% if first = frames.first %>
|
|
280
|
+
<code><%=h first.filename %></code>: in <code><%=h first.function %></code>, line <%=h frames.first.lineno %>
|
|
281
|
+
<% else %>
|
|
282
|
+
unknown location
|
|
283
|
+
<% end %>
|
|
284
|
+
</td>
|
|
285
|
+
</tr><tr>
|
|
286
|
+
<th>Web</th>
|
|
287
|
+
<td><code><%=h req.request_method %> <%=h(req.host + path)%></code></td>
|
|
288
|
+
</tr></table>
|
|
289
|
+
|
|
290
|
+
<h3>Jump to:</h3>
|
|
291
|
+
<ul id="quicklinks">
|
|
292
|
+
<li><a href="#get-info">GET</a></li>
|
|
293
|
+
<li><a href="#post-info">POST</a></li>
|
|
294
|
+
<li><a href="#cookie-info">Cookies</a></li>
|
|
295
|
+
<li><a href="#env-info">ENV</a></li>
|
|
296
|
+
</ul>
|
|
297
|
+
</div>
|
|
298
|
+
|
|
299
|
+
<div id="traceback">
|
|
300
|
+
<h2>Traceback <span>(innermost first)</span></h2>
|
|
301
|
+
<ul class="traceback">
|
|
302
|
+
<% frames.each { |frame| %>
|
|
303
|
+
<li class="frame">
|
|
304
|
+
<code><%=h frame.filename %></code>: in <code><%=h frame.function %></code>
|
|
305
|
+
|
|
306
|
+
<% if frame.context_line %>
|
|
307
|
+
<div class="context" id="c<%=h frame.object_id %>">
|
|
308
|
+
<% if frame.pre_context %>
|
|
309
|
+
<ol start="<%=h frame.pre_context_lineno+1 %>" class="pre-context" id="pre<%=h frame.object_id %>">
|
|
310
|
+
<% frame.pre_context.each { |line| %>
|
|
311
|
+
<li onclick="toggle('pre<%=h frame.object_id %>', 'post<%=h frame.object_id %>')"><%=h line %></li>
|
|
312
|
+
<% } %>
|
|
313
|
+
</ol>
|
|
314
|
+
<% end %>
|
|
315
|
+
|
|
316
|
+
<ol start="<%=h frame.lineno %>" class="context-line">
|
|
317
|
+
<li onclick="toggle('pre<%=h frame.object_id %>', 'post<%=h frame.object_id %>')"><%=h frame.context_line %><span>...</span></li></ol>
|
|
318
|
+
|
|
319
|
+
<% if frame.post_context %>
|
|
320
|
+
<ol start='<%=h frame.lineno+1 %>' class="post-context" id="post<%=h frame.object_id %>">
|
|
321
|
+
<% frame.post_context.each { |line| %>
|
|
322
|
+
<li onclick="toggle('pre<%=h frame.object_id %>', 'post<%=h frame.object_id %>')"><%=h line %></li>
|
|
323
|
+
<% } %>
|
|
324
|
+
</ol>
|
|
325
|
+
<% end %>
|
|
326
|
+
</div>
|
|
327
|
+
<% end %>
|
|
328
|
+
</li>
|
|
329
|
+
<% } %>
|
|
330
|
+
</ul>
|
|
331
|
+
</div>
|
|
332
|
+
|
|
333
|
+
<div id="requestinfo">
|
|
334
|
+
<h2>Request information</h2>
|
|
335
|
+
|
|
336
|
+
<h3 id="get-info">GET</h3>
|
|
337
|
+
<% if req.GET and not req.GET.empty? %>
|
|
338
|
+
<table class="req">
|
|
339
|
+
<thead>
|
|
340
|
+
<tr>
|
|
341
|
+
<th>Variable</th>
|
|
342
|
+
<th>Value</th>
|
|
343
|
+
</tr>
|
|
344
|
+
</thead>
|
|
345
|
+
<tbody>
|
|
346
|
+
<% req.GET.sort_by { |k, v| k.to_s }.each { |key, val| %>
|
|
347
|
+
<tr>
|
|
348
|
+
<td><%=h key %></td>
|
|
349
|
+
<td class="code"><div><%=h val.inspect %></div></td>
|
|
350
|
+
</tr>
|
|
351
|
+
<% } %>
|
|
352
|
+
</tbody>
|
|
353
|
+
</table>
|
|
354
|
+
<% else %>
|
|
355
|
+
<p>No GET data.</p>
|
|
356
|
+
<% end %>
|
|
357
|
+
|
|
358
|
+
<h3 id="post-info">POST</h3>
|
|
359
|
+
<% if ((req.POST and not req.POST.empty?) rescue (no_post_data = "Invalid POST data"; nil)) %>
|
|
360
|
+
<table class="req">
|
|
361
|
+
<thead>
|
|
362
|
+
<tr>
|
|
363
|
+
<th>Variable</th>
|
|
364
|
+
<th>Value</th>
|
|
365
|
+
</tr>
|
|
366
|
+
</thead>
|
|
367
|
+
<tbody>
|
|
368
|
+
<% req.POST.sort_by { |k, v| k.to_s }.each { |key, val| %>
|
|
369
|
+
<tr>
|
|
370
|
+
<td><%=h key %></td>
|
|
371
|
+
<td class="code"><div><%=h val.inspect %></div></td>
|
|
372
|
+
</tr>
|
|
373
|
+
<% } %>
|
|
374
|
+
</tbody>
|
|
375
|
+
</table>
|
|
376
|
+
<% else %>
|
|
377
|
+
<p><%= no_post_data || "No POST data" %>.</p>
|
|
378
|
+
<% end %>
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
<h3 id="cookie-info">COOKIES</h3>
|
|
382
|
+
<% unless req.cookies.empty? %>
|
|
383
|
+
<table class="req">
|
|
384
|
+
<thead>
|
|
385
|
+
<tr>
|
|
386
|
+
<th>Variable</th>
|
|
387
|
+
<th>Value</th>
|
|
388
|
+
</tr>
|
|
389
|
+
</thead>
|
|
390
|
+
<tbody>
|
|
391
|
+
<% req.cookies.each { |key, val| %>
|
|
392
|
+
<tr>
|
|
393
|
+
<td><%=h key %></td>
|
|
394
|
+
<td class="code"><div><%=h val.inspect %></div></td>
|
|
395
|
+
</tr>
|
|
396
|
+
<% } %>
|
|
397
|
+
</tbody>
|
|
398
|
+
</table>
|
|
399
|
+
<% else %>
|
|
400
|
+
<p>No cookie data.</p>
|
|
401
|
+
<% end %>
|
|
402
|
+
|
|
403
|
+
<h3 id="env-info">Rack ENV</h3>
|
|
404
|
+
<table class="req">
|
|
405
|
+
<thead>
|
|
406
|
+
<tr>
|
|
407
|
+
<th>Variable</th>
|
|
408
|
+
<th>Value</th>
|
|
409
|
+
</tr>
|
|
410
|
+
</thead>
|
|
411
|
+
<tbody>
|
|
412
|
+
<% env.sort_by { |k, v| k.to_s }.each { |key, val| %>
|
|
413
|
+
<tr>
|
|
414
|
+
<td><%=h key %></td>
|
|
415
|
+
<td class="code"><div><%=h val.inspect %></div></td>
|
|
416
|
+
</tr>
|
|
417
|
+
<% } %>
|
|
418
|
+
</tbody>
|
|
419
|
+
</table>
|
|
420
|
+
|
|
421
|
+
</div>
|
|
422
|
+
|
|
423
|
+
<div id="explanation">
|
|
424
|
+
<p>
|
|
425
|
+
You're seeing this error because you use <code>Rack::ShowExceptions</code>.
|
|
426
|
+
</p>
|
|
427
|
+
</div>
|
|
428
|
+
|
|
429
|
+
</body>
|
|
430
|
+
</html>
|
|
431
|
+
HTML
|
|
432
|
+
end
|
|
433
|
+
end
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'erb'
|
|
4
|
+
|
|
5
|
+
require_relative 'constants'
|
|
6
|
+
require_relative 'utils'
|
|
7
|
+
require_relative 'request'
|
|
8
|
+
require_relative 'body_proxy'
|
|
9
|
+
|
|
10
|
+
module Rack
|
|
11
|
+
# Rack::ShowStatus catches all empty responses and replaces them
|
|
12
|
+
# with a site explaining the error.
|
|
13
|
+
#
|
|
14
|
+
# Additional details can be put into <tt>rack.showstatus.detail</tt>
|
|
15
|
+
# and will be shown as HTML. If such details exist, the error page
|
|
16
|
+
# is always rendered, even if the reply was not empty.
|
|
17
|
+
|
|
18
|
+
class ShowStatus
|
|
19
|
+
def initialize(app)
|
|
20
|
+
@app = app
|
|
21
|
+
@template = ERB.new(TEMPLATE)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def call(env)
|
|
25
|
+
status, headers, body = response = @app.call(env)
|
|
26
|
+
empty = headers[CONTENT_LENGTH].to_i <= 0
|
|
27
|
+
|
|
28
|
+
# client or server error, or explicit message
|
|
29
|
+
if (status.to_i >= 400 && empty) || env[RACK_SHOWSTATUS_DETAIL]
|
|
30
|
+
# This double assignment is to prevent an "unused variable" warning.
|
|
31
|
+
# Yes, it is dumb, but I don't like Ruby yelling at me.
|
|
32
|
+
req = req = Rack::Request.new(env)
|
|
33
|
+
|
|
34
|
+
message = Rack::Utils::HTTP_STATUS_CODES[status.to_i] || status.to_s
|
|
35
|
+
|
|
36
|
+
# This double assignment is to prevent an "unused variable" warning.
|
|
37
|
+
# Yes, it is dumb, but I don't like Ruby yelling at me.
|
|
38
|
+
detail = detail = env[RACK_SHOWSTATUS_DETAIL] || message
|
|
39
|
+
|
|
40
|
+
html = @template.result(binding)
|
|
41
|
+
size = html.bytesize
|
|
42
|
+
|
|
43
|
+
response[2] = Rack::BodyProxy.new([html]) do
|
|
44
|
+
body.close if body.respond_to?(:close)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
headers[CONTENT_TYPE] = "text/html"
|
|
48
|
+
headers[CONTENT_LENGTH] = size.to_s
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
response
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def h(obj) # :nodoc:
|
|
55
|
+
case obj
|
|
56
|
+
when String
|
|
57
|
+
Utils.escape_html(obj)
|
|
58
|
+
else
|
|
59
|
+
Utils.escape_html(obj.inspect)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# :stopdoc:
|
|
64
|
+
|
|
65
|
+
# adapted from Django <www.djangoproject.com>
|
|
66
|
+
# Copyright (c) Django Software Foundation and individual contributors.
|
|
67
|
+
# Used under the modified BSD license:
|
|
68
|
+
# http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5
|
|
69
|
+
TEMPLATE = <<'HTML'
|
|
70
|
+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
71
|
+
<html lang="en">
|
|
72
|
+
<head>
|
|
73
|
+
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
|
74
|
+
<title><%=h message %> at <%=h req.script_name + req.path_info %></title>
|
|
75
|
+
<meta name="robots" content="NONE,NOARCHIVE" />
|
|
76
|
+
<style type="text/css">
|
|
77
|
+
html * { padding:0; margin:0; }
|
|
78
|
+
body * { padding:10px 20px; }
|
|
79
|
+
body * * { padding:0; }
|
|
80
|
+
body { font:small sans-serif; background:#eee; }
|
|
81
|
+
body>div { border-bottom:1px solid #ddd; }
|
|
82
|
+
h1 { font-weight:normal; margin-bottom:.4em; }
|
|
83
|
+
h1 span { font-size:60%; color:#666; font-weight:normal; }
|
|
84
|
+
table { border:none; border-collapse: collapse; width:100%; }
|
|
85
|
+
td, th { vertical-align:top; padding:2px 3px; }
|
|
86
|
+
th { width:12em; text-align:right; color:#666; padding-right:.5em; }
|
|
87
|
+
#info { background:#f6f6f6; }
|
|
88
|
+
#info ol { margin: 0.5em 4em; }
|
|
89
|
+
#info ol li { font-family: monospace; }
|
|
90
|
+
#summary { background: #ffc; }
|
|
91
|
+
#explanation { background:#eee; border-bottom: 0px none; }
|
|
92
|
+
</style>
|
|
93
|
+
</head>
|
|
94
|
+
<body>
|
|
95
|
+
<div id="summary">
|
|
96
|
+
<h1><%=h message %> <span>(<%= status.to_i %>)</span></h1>
|
|
97
|
+
<table class="meta">
|
|
98
|
+
<tr>
|
|
99
|
+
<th>Request Method:</th>
|
|
100
|
+
<td><%=h req.request_method %></td>
|
|
101
|
+
</tr>
|
|
102
|
+
<tr>
|
|
103
|
+
<th>Request URL:</th>
|
|
104
|
+
<td><%=h req.url %></td>
|
|
105
|
+
</tr>
|
|
106
|
+
</table>
|
|
107
|
+
</div>
|
|
108
|
+
<div id="info">
|
|
109
|
+
<p><%=h detail %></p>
|
|
110
|
+
</div>
|
|
111
|
+
|
|
112
|
+
<div id="explanation">
|
|
113
|
+
<p>
|
|
114
|
+
You're seeing this error because you use <code>Rack::ShowStatus</code>.
|
|
115
|
+
</p>
|
|
116
|
+
</div>
|
|
117
|
+
</body>
|
|
118
|
+
</html>
|
|
119
|
+
HTML
|
|
120
|
+
end
|
|
121
|
+
end
|