rack 1.6.13 → 2.0.9
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 +4 -4
- data/COPYING +1 -1
- data/HISTORY.md +138 -8
- data/README.rdoc +18 -28
- data/Rakefile +6 -14
- data/SPEC +3 -3
- data/contrib/rack_logo.svg +164 -111
- data/example/protectedlobster.rb +1 -1
- data/example/protectedlobster.ru +1 -1
- 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/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/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/handler.rb +3 -25
- 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/generator.rb +5 -5
- data/lib/rack/multipart/parser.rb +270 -157
- data/lib/rack/multipart/uploaded_file.rb +1 -2
- data/lib/rack/multipart.rb +35 -6
- 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 +110 -75
- data/lib/rack/session/cookie.rb +24 -17
- data/lib/rack/session/memcache.rb +9 -9
- data/lib/rack/session/pool.rb +8 -8
- 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 +138 -211
- data/lib/rack.rb +70 -21
- 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 +233 -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 +67 -68
- data/test/spec_session_pool.rb +52 -51
- 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 +57 -36
- 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/lib/rack/{conditionalget.rb → conditional_get.rb} +0 -0
@@ -0,0 +1,386 @@
|
|
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
|
+
end
|
21
|
+
|
22
|
+
def call(env)
|
23
|
+
@app.call(env)
|
24
|
+
rescue StandardError, LoadError, SyntaxError => e
|
25
|
+
exception_string = dump_exception(e)
|
26
|
+
|
27
|
+
env[RACK_ERRORS].puts(exception_string)
|
28
|
+
env[RACK_ERRORS].flush
|
29
|
+
|
30
|
+
if accepts_html?(env)
|
31
|
+
content_type = "text/html"
|
32
|
+
body = pretty(env, e)
|
33
|
+
else
|
34
|
+
content_type = "text/plain"
|
35
|
+
body = exception_string
|
36
|
+
end
|
37
|
+
|
38
|
+
[
|
39
|
+
500,
|
40
|
+
{
|
41
|
+
CONTENT_TYPE => content_type,
|
42
|
+
CONTENT_LENGTH => body.bytesize.to_s,
|
43
|
+
},
|
44
|
+
[body],
|
45
|
+
]
|
46
|
+
end
|
47
|
+
|
48
|
+
def prefers_plaintext?(env)
|
49
|
+
!accepts_html?(env)
|
50
|
+
end
|
51
|
+
|
52
|
+
def accepts_html?(env)
|
53
|
+
Rack::Utils.best_q_match(env["HTTP_ACCEPT"], %w[text/html])
|
54
|
+
end
|
55
|
+
private :accepts_html?
|
56
|
+
|
57
|
+
def dump_exception(exception)
|
58
|
+
string = "#{exception.class}: #{exception.message}\n"
|
59
|
+
string << exception.backtrace.map { |l| "\t#{l}" }.join("\n")
|
60
|
+
string
|
61
|
+
end
|
62
|
+
|
63
|
+
def pretty(env, exception)
|
64
|
+
req = Rack::Request.new(env)
|
65
|
+
|
66
|
+
# This double assignment is to prevent an "unused variable" warning on
|
67
|
+
# Ruby 1.9.3. Yes, it is dumb, but I don't like Ruby yelling at me.
|
68
|
+
path = path = (req.script_name + req.path_info).squeeze("/")
|
69
|
+
|
70
|
+
# This double assignment is to prevent an "unused variable" warning on
|
71
|
+
# Ruby 1.9.3. Yes, it is dumb, but I don't like Ruby yelling at me.
|
72
|
+
frames = frames = exception.backtrace.map { |line|
|
73
|
+
frame = OpenStruct.new
|
74
|
+
if line =~ /(.*?):(\d+)(:in `(.*)')?/
|
75
|
+
frame.filename = $1
|
76
|
+
frame.lineno = $2.to_i
|
77
|
+
frame.function = $4
|
78
|
+
|
79
|
+
begin
|
80
|
+
lineno = frame.lineno-1
|
81
|
+
lines = ::File.readlines(frame.filename)
|
82
|
+
frame.pre_context_lineno = [lineno-CONTEXT, 0].max
|
83
|
+
frame.pre_context = lines[frame.pre_context_lineno...lineno]
|
84
|
+
frame.context_line = lines[lineno].chomp
|
85
|
+
frame.post_context_lineno = [lineno+CONTEXT, lines.size].min
|
86
|
+
frame.post_context = lines[lineno+1..frame.post_context_lineno]
|
87
|
+
rescue
|
88
|
+
end
|
89
|
+
|
90
|
+
frame
|
91
|
+
else
|
92
|
+
nil
|
93
|
+
end
|
94
|
+
}.compact
|
95
|
+
|
96
|
+
TEMPLATE.result(binding)
|
97
|
+
end
|
98
|
+
|
99
|
+
def h(obj) # :nodoc:
|
100
|
+
case obj
|
101
|
+
when String
|
102
|
+
Utils.escape_html(obj)
|
103
|
+
else
|
104
|
+
Utils.escape_html(obj.inspect)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
# :stopdoc:
|
109
|
+
|
110
|
+
# adapted from Django <djangoproject.com>
|
111
|
+
# Copyright (c) 2005, the Lawrence Journal-World
|
112
|
+
# Used under the modified BSD license:
|
113
|
+
# http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5
|
114
|
+
TEMPLATE = ERB.new(<<-'HTML'.gsub(/^ /, ''))
|
115
|
+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
116
|
+
<html lang="en">
|
117
|
+
<head>
|
118
|
+
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
119
|
+
<meta name="robots" content="NONE,NOARCHIVE" />
|
120
|
+
<title><%=h exception.class %> at <%=h path %></title>
|
121
|
+
<style type="text/css">
|
122
|
+
html * { padding:0; margin:0; }
|
123
|
+
body * { padding:10px 20px; }
|
124
|
+
body * * { padding:0; }
|
125
|
+
body { font:small sans-serif; }
|
126
|
+
body>div { border-bottom:1px solid #ddd; }
|
127
|
+
h1 { font-weight:normal; }
|
128
|
+
h2 { margin-bottom:.8em; }
|
129
|
+
h2 span { font-size:80%; color:#666; font-weight:normal; }
|
130
|
+
h3 { margin:1em 0 .5em 0; }
|
131
|
+
h4 { margin:0 0 .5em 0; font-weight: normal; }
|
132
|
+
table {
|
133
|
+
border:1px solid #ccc; border-collapse: collapse; background:white; }
|
134
|
+
tbody td, tbody th { vertical-align:top; padding:2px 3px; }
|
135
|
+
thead th {
|
136
|
+
padding:1px 6px 1px 3px; background:#fefefe; text-align:left;
|
137
|
+
font-weight:normal; font-size:11px; border:1px solid #ddd; }
|
138
|
+
tbody th { text-align:right; color:#666; padding-right:.5em; }
|
139
|
+
table.vars { margin:5px 0 2px 40px; }
|
140
|
+
table.vars td, table.req td { font-family:monospace; }
|
141
|
+
table td.code { width:100%;}
|
142
|
+
table td.code div { overflow:hidden; }
|
143
|
+
table.source th { color:#666; }
|
144
|
+
table.source td {
|
145
|
+
font-family:monospace; white-space:pre; border-bottom:1px solid #eee; }
|
146
|
+
ul.traceback { list-style-type:none; }
|
147
|
+
ul.traceback li.frame { margin-bottom:1em; }
|
148
|
+
div.context { margin: 10px 0; }
|
149
|
+
div.context ol {
|
150
|
+
padding-left:30px; margin:0 10px; list-style-position: inside; }
|
151
|
+
div.context ol li {
|
152
|
+
font-family:monospace; white-space:pre; color:#666; cursor:pointer; }
|
153
|
+
div.context ol.context-line li { color:black; background-color:#ccc; }
|
154
|
+
div.context ol.context-line li span { float: right; }
|
155
|
+
div.commands { margin-left: 40px; }
|
156
|
+
div.commands a { color:black; text-decoration:none; }
|
157
|
+
#summary { background: #ffc; }
|
158
|
+
#summary h2 { font-weight: normal; color: #666; }
|
159
|
+
#summary ul#quicklinks { list-style-type: none; margin-bottom: 2em; }
|
160
|
+
#summary ul#quicklinks li { float: left; padding: 0 1em; }
|
161
|
+
#summary ul#quicklinks>li+li { border-left: 1px #666 solid; }
|
162
|
+
#explanation { background:#eee; }
|
163
|
+
#template, #template-not-exist { background:#f6f6f6; }
|
164
|
+
#template-not-exist ul { margin: 0 0 0 20px; }
|
165
|
+
#traceback { background:#eee; }
|
166
|
+
#requestinfo { background:#f6f6f6; padding-left:120px; }
|
167
|
+
#summary table { border:none; background:transparent; }
|
168
|
+
#requestinfo h2, #requestinfo h3 { position:relative; margin-left:-100px; }
|
169
|
+
#requestinfo h3 { margin-bottom:-1em; }
|
170
|
+
.error { background: #ffc; }
|
171
|
+
.specific { color:#cc3300; font-weight:bold; }
|
172
|
+
</style>
|
173
|
+
<script type="text/javascript">
|
174
|
+
//<!--
|
175
|
+
function getElementsByClassName(oElm, strTagName, strClassName){
|
176
|
+
// Written by Jonathan Snook, http://www.snook.ca/jon;
|
177
|
+
// Add-ons by Robert Nyman, http://www.robertnyman.com
|
178
|
+
var arrElements = (strTagName == "*" && document.all)? document.all :
|
179
|
+
oElm.getElementsByTagName(strTagName);
|
180
|
+
var arrReturnElements = new Array();
|
181
|
+
strClassName = strClassName.replace(/\-/g, "\\-");
|
182
|
+
var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$$)");
|
183
|
+
var oElement;
|
184
|
+
for(var i=0; i<arrElements.length; i++){
|
185
|
+
oElement = arrElements[i];
|
186
|
+
if(oRegExp.test(oElement.className)){
|
187
|
+
arrReturnElements.push(oElement);
|
188
|
+
}
|
189
|
+
}
|
190
|
+
return (arrReturnElements)
|
191
|
+
}
|
192
|
+
function hideAll(elems) {
|
193
|
+
for (var e = 0; e < elems.length; e++) {
|
194
|
+
elems[e].style.display = 'none';
|
195
|
+
}
|
196
|
+
}
|
197
|
+
window.onload = function() {
|
198
|
+
hideAll(getElementsByClassName(document, 'table', 'vars'));
|
199
|
+
hideAll(getElementsByClassName(document, 'ol', 'pre-context'));
|
200
|
+
hideAll(getElementsByClassName(document, 'ol', 'post-context'));
|
201
|
+
}
|
202
|
+
function toggle() {
|
203
|
+
for (var i = 0; i < arguments.length; i++) {
|
204
|
+
var e = document.getElementById(arguments[i]);
|
205
|
+
if (e) {
|
206
|
+
e.style.display = e.style.display == 'none' ? 'block' : 'none';
|
207
|
+
}
|
208
|
+
}
|
209
|
+
return false;
|
210
|
+
}
|
211
|
+
function varToggle(link, id) {
|
212
|
+
toggle('v' + id);
|
213
|
+
var s = link.getElementsByTagName('span')[0];
|
214
|
+
var uarr = String.fromCharCode(0x25b6);
|
215
|
+
var darr = String.fromCharCode(0x25bc);
|
216
|
+
s.innerHTML = s.innerHTML == uarr ? darr : uarr;
|
217
|
+
return false;
|
218
|
+
}
|
219
|
+
//-->
|
220
|
+
</script>
|
221
|
+
</head>
|
222
|
+
<body>
|
223
|
+
|
224
|
+
<div id="summary">
|
225
|
+
<h1><%=h exception.class %> at <%=h path %></h1>
|
226
|
+
<h2><%=h exception.message %></h2>
|
227
|
+
<table><tr>
|
228
|
+
<th>Ruby</th>
|
229
|
+
<td>
|
230
|
+
<% if first = frames.first %>
|
231
|
+
<code><%=h first.filename %></code>: in <code><%=h first.function %></code>, line <%=h frames.first.lineno %>
|
232
|
+
<% else %>
|
233
|
+
unknown location
|
234
|
+
<% end %>
|
235
|
+
</td>
|
236
|
+
</tr><tr>
|
237
|
+
<th>Web</th>
|
238
|
+
<td><code><%=h req.request_method %> <%=h(req.host + path)%></code></td>
|
239
|
+
</tr></table>
|
240
|
+
|
241
|
+
<h3>Jump to:</h3>
|
242
|
+
<ul id="quicklinks">
|
243
|
+
<li><a href="#get-info">GET</a></li>
|
244
|
+
<li><a href="#post-info">POST</a></li>
|
245
|
+
<li><a href="#cookie-info">Cookies</a></li>
|
246
|
+
<li><a href="#env-info">ENV</a></li>
|
247
|
+
</ul>
|
248
|
+
</div>
|
249
|
+
|
250
|
+
<div id="traceback">
|
251
|
+
<h2>Traceback <span>(innermost first)</span></h2>
|
252
|
+
<ul class="traceback">
|
253
|
+
<% frames.each { |frame| %>
|
254
|
+
<li class="frame">
|
255
|
+
<code><%=h frame.filename %></code>: in <code><%=h frame.function %></code>
|
256
|
+
|
257
|
+
<% if frame.context_line %>
|
258
|
+
<div class="context" id="c<%=h frame.object_id %>">
|
259
|
+
<% if frame.pre_context %>
|
260
|
+
<ol start="<%=h frame.pre_context_lineno+1 %>" class="pre-context" id="pre<%=h frame.object_id %>">
|
261
|
+
<% frame.pre_context.each { |line| %>
|
262
|
+
<li onclick="toggle('pre<%=h frame.object_id %>', 'post<%=h frame.object_id %>')"><%=h line %></li>
|
263
|
+
<% } %>
|
264
|
+
</ol>
|
265
|
+
<% end %>
|
266
|
+
|
267
|
+
<ol start="<%=h frame.lineno %>" class="context-line">
|
268
|
+
<li onclick="toggle('pre<%=h frame.object_id %>', 'post<%=h frame.object_id %>')"><%=h frame.context_line %><span>...</span></li></ol>
|
269
|
+
|
270
|
+
<% if frame.post_context %>
|
271
|
+
<ol start='<%=h frame.lineno+1 %>' class="post-context" id="post<%=h frame.object_id %>">
|
272
|
+
<% frame.post_context.each { |line| %>
|
273
|
+
<li onclick="toggle('pre<%=h frame.object_id %>', 'post<%=h frame.object_id %>')"><%=h line %></li>
|
274
|
+
<% } %>
|
275
|
+
</ol>
|
276
|
+
<% end %>
|
277
|
+
</div>
|
278
|
+
<% end %>
|
279
|
+
</li>
|
280
|
+
<% } %>
|
281
|
+
</ul>
|
282
|
+
</div>
|
283
|
+
|
284
|
+
<div id="requestinfo">
|
285
|
+
<h2>Request information</h2>
|
286
|
+
|
287
|
+
<h3 id="get-info">GET</h3>
|
288
|
+
<% if req.GET and not req.GET.empty? %>
|
289
|
+
<table class="req">
|
290
|
+
<thead>
|
291
|
+
<tr>
|
292
|
+
<th>Variable</th>
|
293
|
+
<th>Value</th>
|
294
|
+
</tr>
|
295
|
+
</thead>
|
296
|
+
<tbody>
|
297
|
+
<% req.GET.sort_by { |k, v| k.to_s }.each { |key, val| %>
|
298
|
+
<tr>
|
299
|
+
<td><%=h key %></td>
|
300
|
+
<td class="code"><div><%=h val.inspect %></div></td>
|
301
|
+
</tr>
|
302
|
+
<% } %>
|
303
|
+
</tbody>
|
304
|
+
</table>
|
305
|
+
<% else %>
|
306
|
+
<p>No GET data.</p>
|
307
|
+
<% end %>
|
308
|
+
|
309
|
+
<h3 id="post-info">POST</h3>
|
310
|
+
<% if req.POST and not req.POST.empty? %>
|
311
|
+
<table class="req">
|
312
|
+
<thead>
|
313
|
+
<tr>
|
314
|
+
<th>Variable</th>
|
315
|
+
<th>Value</th>
|
316
|
+
</tr>
|
317
|
+
</thead>
|
318
|
+
<tbody>
|
319
|
+
<% req.POST.sort_by { |k, v| k.to_s }.each { |key, val| %>
|
320
|
+
<tr>
|
321
|
+
<td><%=h key %></td>
|
322
|
+
<td class="code"><div><%=h val.inspect %></div></td>
|
323
|
+
</tr>
|
324
|
+
<% } %>
|
325
|
+
</tbody>
|
326
|
+
</table>
|
327
|
+
<% else %>
|
328
|
+
<p>No POST data.</p>
|
329
|
+
<% end %>
|
330
|
+
|
331
|
+
|
332
|
+
<h3 id="cookie-info">COOKIES</h3>
|
333
|
+
<% unless req.cookies.empty? %>
|
334
|
+
<table class="req">
|
335
|
+
<thead>
|
336
|
+
<tr>
|
337
|
+
<th>Variable</th>
|
338
|
+
<th>Value</th>
|
339
|
+
</tr>
|
340
|
+
</thead>
|
341
|
+
<tbody>
|
342
|
+
<% req.cookies.each { |key, val| %>
|
343
|
+
<tr>
|
344
|
+
<td><%=h key %></td>
|
345
|
+
<td class="code"><div><%=h val.inspect %></div></td>
|
346
|
+
</tr>
|
347
|
+
<% } %>
|
348
|
+
</tbody>
|
349
|
+
</table>
|
350
|
+
<% else %>
|
351
|
+
<p>No cookie data.</p>
|
352
|
+
<% end %>
|
353
|
+
|
354
|
+
<h3 id="env-info">Rack ENV</h3>
|
355
|
+
<table class="req">
|
356
|
+
<thead>
|
357
|
+
<tr>
|
358
|
+
<th>Variable</th>
|
359
|
+
<th>Value</th>
|
360
|
+
</tr>
|
361
|
+
</thead>
|
362
|
+
<tbody>
|
363
|
+
<% env.sort_by { |k, v| k.to_s }.each { |key, val| %>
|
364
|
+
<tr>
|
365
|
+
<td><%=h key %></td>
|
366
|
+
<td class="code"><div><%=h val %></div></td>
|
367
|
+
</tr>
|
368
|
+
<% } %>
|
369
|
+
</tbody>
|
370
|
+
</table>
|
371
|
+
|
372
|
+
</div>
|
373
|
+
|
374
|
+
<div id="explanation">
|
375
|
+
<p>
|
376
|
+
You're seeing this error because you use <code>Rack::ShowExceptions</code>.
|
377
|
+
</p>
|
378
|
+
</div>
|
379
|
+
|
380
|
+
</body>
|
381
|
+
</html>
|
382
|
+
HTML
|
383
|
+
|
384
|
+
# :startdoc:
|
385
|
+
end
|
386
|
+
end
|
@@ -22,7 +22,7 @@ module Rack
|
|
22
22
|
empty = headers[CONTENT_LENGTH].to_i <= 0
|
23
23
|
|
24
24
|
# client or server error, or explicit message
|
25
|
-
if (status.to_i >= 400 && empty) || env[
|
25
|
+
if (status.to_i >= 400 && empty) || env[RACK_SHOWSTATUS_DETAIL]
|
26
26
|
# This double assignment is to prevent an "unused variable" warning on
|
27
27
|
# Ruby 1.9.3. Yes, it is dumb, but I don't like Ruby yelling at me.
|
28
28
|
req = req = Rack::Request.new(env)
|
@@ -31,10 +31,10 @@ module Rack
|
|
31
31
|
|
32
32
|
# This double assignment is to prevent an "unused variable" warning on
|
33
33
|
# Ruby 1.9.3. Yes, it is dumb, but I don't like Ruby yelling at me.
|
34
|
-
detail = detail = env[
|
34
|
+
detail = detail = env[RACK_SHOWSTATUS_DETAIL] || message
|
35
35
|
|
36
36
|
body = @template.result(binding)
|
37
|
-
size =
|
37
|
+
size = body.bytesize
|
38
38
|
[status, headers.merge(CONTENT_TYPE => "text/html", CONTENT_LENGTH => size.to_s), [body]]
|
39
39
|
else
|
40
40
|
[status, headers, body]
|
data/lib/rack/static.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require "rack/file"
|
2
|
+
require "rack/utils"
|
3
|
+
|
1
4
|
module Rack
|
2
5
|
|
3
6
|
# The Rack::Static middleware intercepts requests for static files
|
@@ -84,18 +87,23 @@ module Rack
|
|
84
87
|
@app = app
|
85
88
|
@urls = options[:urls] || ["/favicon.ico"]
|
86
89
|
@index = options[:index]
|
90
|
+
@gzip = options[:gzip]
|
87
91
|
root = options[:root] || Dir.pwd
|
88
92
|
|
89
93
|
# HTTP Headers
|
90
94
|
@header_rules = options[:header_rules] || []
|
91
95
|
# Allow for legacy :cache_control option while prioritizing global header_rules setting
|
92
|
-
@header_rules.
|
96
|
+
@header_rules.unshift([:all, {CACHE_CONTROL => options[:cache_control]}]) if options[:cache_control]
|
93
97
|
|
94
98
|
@file_server = Rack::File.new(root)
|
95
99
|
end
|
96
100
|
|
101
|
+
def add_index_root?(path)
|
102
|
+
@index && path =~ /\/$/
|
103
|
+
end
|
104
|
+
|
97
105
|
def overwrite_file_path(path)
|
98
|
-
@urls.kind_of?(Hash) && @urls.key?(path) ||
|
106
|
+
@urls.kind_of?(Hash) && @urls.key?(path) || add_index_root?(path)
|
99
107
|
end
|
100
108
|
|
101
109
|
def route_file(path)
|
@@ -110,9 +118,26 @@ module Rack
|
|
110
118
|
path = env[PATH_INFO]
|
111
119
|
|
112
120
|
if can_serve(path)
|
113
|
-
|
114
|
-
|
115
|
-
|
121
|
+
if overwrite_file_path(path)
|
122
|
+
env[PATH_INFO] = (add_index_root?(path) ? path + @index : @urls[path])
|
123
|
+
elsif @gzip && env['HTTP_ACCEPT_ENCODING'] =~ /\bgzip\b/
|
124
|
+
path = env[PATH_INFO]
|
125
|
+
env[PATH_INFO] += '.gz'
|
126
|
+
response = @file_server.call(env)
|
127
|
+
env[PATH_INFO] = path
|
128
|
+
|
129
|
+
if response[0] == 404
|
130
|
+
response = nil
|
131
|
+
else
|
132
|
+
if mime_type = Mime.mime_type(::File.extname(path), 'text/plain')
|
133
|
+
response[1][CONTENT_TYPE] = mime_type
|
134
|
+
end
|
135
|
+
response[1]['Content-Encoding'] = 'gzip'
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
path = env[PATH_INFO]
|
140
|
+
response ||= @file_server.call(env)
|
116
141
|
|
117
142
|
headers = response[1]
|
118
143
|
applicable_rules(path).each do |rule, new_headers|
|
data/lib/rack/tempfile_reaper.rb
CHANGED
@@ -11,10 +11,10 @@ module Rack
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def call(env)
|
14
|
-
env[
|
14
|
+
env[RACK_TEMPFILES] ||= []
|
15
15
|
status, headers, body = @app.call(env)
|
16
16
|
body_proxy = BodyProxy.new(body) do
|
17
|
-
env[
|
17
|
+
env[RACK_TEMPFILES].each(&:close!) unless env[RACK_TEMPFILES].nil?
|
18
18
|
end
|
19
19
|
[status, headers, body_proxy]
|
20
20
|
end
|
data/lib/rack/urlmap.rb
CHANGED
@@ -41,17 +41,19 @@ module Rack
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def call(env)
|
44
|
-
path
|
45
|
-
script_name = env[
|
46
|
-
|
47
|
-
|
48
|
-
|
44
|
+
path = env[PATH_INFO]
|
45
|
+
script_name = env[SCRIPT_NAME]
|
46
|
+
http_host = env[HTTP_HOST]
|
47
|
+
server_name = env[SERVER_NAME]
|
48
|
+
server_port = env[SERVER_PORT]
|
49
|
+
|
50
|
+
is_same_server = casecmp?(http_host, server_name) ||
|
51
|
+
casecmp?(http_host, "#{server_name}:#{server_port}")
|
49
52
|
|
50
53
|
@mapping.each do |host, location, match, app|
|
51
|
-
unless casecmp?(
|
52
|
-
|| casecmp?(
|
53
|
-
|| (!host &&
|
54
|
-
casecmp?(hHost, sName+':'+sPort)))
|
54
|
+
unless casecmp?(http_host, host) \
|
55
|
+
|| casecmp?(server_name, host) \
|
56
|
+
|| (!host && is_same_server)
|
55
57
|
next
|
56
58
|
end
|
57
59
|
|
@@ -60,8 +62,8 @@ module Rack
|
|
60
62
|
rest = m[1]
|
61
63
|
next unless !rest || rest.empty? || rest[0] == ?/
|
62
64
|
|
63
|
-
env[
|
64
|
-
env[
|
65
|
+
env[SCRIPT_NAME] = (script_name + location)
|
66
|
+
env[PATH_INFO] = rest
|
65
67
|
|
66
68
|
return app.call(env)
|
67
69
|
end
|
@@ -69,8 +71,8 @@ module Rack
|
|
69
71
|
[404, {CONTENT_TYPE => "text/plain", "X-Cascade" => "pass"}, ["Not Found: #{path}"]]
|
70
72
|
|
71
73
|
ensure
|
72
|
-
env[
|
73
|
-
env[
|
74
|
+
env[PATH_INFO] = path
|
75
|
+
env[SCRIPT_NAME] = script_name
|
74
76
|
end
|
75
77
|
|
76
78
|
private
|
@@ -87,4 +89,3 @@ module Rack
|
|
87
89
|
end
|
88
90
|
end
|
89
91
|
end
|
90
|
-
|