rack 1.6.13 → 2.1.4.3
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/CHANGELOG.md +92 -0
- data/{COPYING → MIT-LICENSE} +4 -2
- data/README.rdoc +105 -141
- data/Rakefile +27 -28
- data/SPEC +6 -7
- data/bin/rackup +1 -0
- data/contrib/rack_logo.svg +164 -111
- data/example/lobster.ru +2 -0
- data/example/protectedlobster.rb +4 -2
- data/example/protectedlobster.ru +3 -1
- data/lib/rack/auth/abstract/handler.rb +3 -1
- data/lib/rack/auth/abstract/request.rb +7 -1
- data/lib/rack/auth/basic.rb +4 -1
- data/lib/rack/auth/digest/md5.rb +9 -7
- data/lib/rack/auth/digest/nonce.rb +6 -3
- data/lib/rack/auth/digest/params.rb +5 -4
- data/lib/rack/auth/digest/request.rb +3 -1
- data/lib/rack/body_proxy.rb +11 -9
- data/lib/rack/builder.rb +42 -18
- data/lib/rack/cascade.rb +6 -5
- data/lib/rack/chunked.rb +33 -10
- data/lib/rack/{commonlogger.rb → common_logger.rb} +14 -10
- data/lib/rack/{conditionalget.rb → conditional_get.rb} +3 -1
- data/lib/rack/config.rb +2 -0
- data/lib/rack/content_length.rb +5 -3
- data/lib/rack/content_type.rb +3 -1
- data/lib/rack/core_ext/regexp.rb +14 -0
- data/lib/rack/deflater.rb +33 -53
- data/lib/rack/directory.rb +75 -60
- data/lib/rack/etag.rb +8 -5
- data/lib/rack/events.rb +156 -0
- data/lib/rack/file.rb +4 -149
- data/lib/rack/files.rb +178 -0
- data/lib/rack/handler/cgi.rb +18 -17
- data/lib/rack/handler/fastcgi.rb +17 -16
- data/lib/rack/handler/lsws.rb +14 -12
- data/lib/rack/handler/scgi.rb +22 -19
- data/lib/rack/handler/thin.rb +6 -1
- data/lib/rack/handler/webrick.rb +28 -28
- data/lib/rack/handler.rb +9 -26
- data/lib/rack/head.rb +17 -17
- data/lib/rack/lint.rb +55 -52
- data/lib/rack/lobster.rb +8 -6
- data/lib/rack/lock.rb +17 -10
- data/lib/rack/logger.rb +4 -2
- data/lib/rack/media_type.rb +43 -0
- data/lib/rack/{methodoverride.rb → method_override.rb} +10 -8
- data/lib/rack/mime.rb +27 -6
- data/lib/rack/mock.rb +101 -60
- data/lib/rack/multipart/generator.rb +11 -12
- data/lib/rack/multipart/parser.rb +292 -161
- data/lib/rack/multipart/uploaded_file.rb +3 -2
- data/lib/rack/multipart.rb +38 -8
- data/lib/rack/{nulllogger.rb → null_logger.rb} +3 -1
- data/lib/rack/query_parser.rb +218 -0
- data/lib/rack/recursive.rb +11 -9
- data/lib/rack/reloader.rb +10 -4
- data/lib/rack/request.rb +447 -305
- data/lib/rack/response.rb +196 -83
- data/lib/rack/rewindable_input.rb +5 -14
- data/lib/rack/runtime.rb +12 -18
- data/lib/rack/sendfile.rb +19 -14
- data/lib/rack/server.rb +118 -41
- data/lib/rack/session/abstract/id.rb +139 -94
- data/lib/rack/session/cookie.rb +34 -26
- data/lib/rack/session/memcache.rb +4 -93
- data/lib/rack/session/pool.rb +12 -10
- data/lib/rack/show_exceptions.rb +392 -0
- data/lib/rack/{showstatus.rb → show_status.rb} +7 -5
- data/lib/rack/static.rb +41 -11
- data/lib/rack/tempfile_reaper.rb +4 -2
- data/lib/rack/urlmap.rb +25 -15
- data/lib/rack/utils.rb +203 -277
- data/lib/rack.rb +76 -24
- data/rack.gemspec +25 -14
- metadata +62 -183
- data/HISTORY.md +0 -375
- 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/builder/anything.rb +0 -5
- data/test/builder/comment.ru +0 -4
- data/test/builder/end.ru +0 -5
- data/test/builder/line.ru +0 -1
- data/test/builder/options.ru +0 -2
- data/test/cgi/assets/folder/test.js +0 -1
- data/test/cgi/assets/fonts/font.eot +0 -1
- data/test/cgi/assets/images/image.png +0 -1
- data/test/cgi/assets/index.html +0 -1
- data/test/cgi/assets/javascripts/app.js +0 -1
- data/test/cgi/assets/stylesheets/app.css +0 -1
- data/test/cgi/lighttpd.conf +0 -26
- data/test/cgi/rackup_stub.rb +0 -6
- data/test/cgi/sample_rackup.ru +0 -5
- data/test/cgi/test +0 -9
- data/test/cgi/test+directory/test+file +0 -1
- data/test/cgi/test.fcgi +0 -8
- data/test/cgi/test.ru +0 -5
- data/test/gemloader.rb +0 -10
- data/test/multipart/bad_robots +0 -259
- data/test/multipart/binary +0 -0
- data/test/multipart/content_type_and_no_filename +0 -6
- data/test/multipart/empty +0 -10
- data/test/multipart/fail_16384_nofile +0 -814
- data/test/multipart/file1.txt +0 -1
- data/test/multipart/filename_and_modification_param +0 -7
- data/test/multipart/filename_and_no_name +0 -6
- data/test/multipart/filename_with_escaped_quotes +0 -6
- data/test/multipart/filename_with_escaped_quotes_and_modification_param +0 -7
- data/test/multipart/filename_with_null_byte +0 -7
- data/test/multipart/filename_with_percent_escaped_quotes +0 -6
- data/test/multipart/filename_with_unescaped_percentages +0 -6
- data/test/multipart/filename_with_unescaped_percentages2 +0 -6
- data/test/multipart/filename_with_unescaped_percentages3 +0 -6
- data/test/multipart/filename_with_unescaped_quotes +0 -6
- data/test/multipart/ie +0 -6
- data/test/multipart/invalid_character +0 -6
- data/test/multipart/mixed_files +0 -21
- data/test/multipart/nested +0 -10
- data/test/multipart/none +0 -9
- data/test/multipart/semicolon +0 -6
- data/test/multipart/text +0 -15
- data/test/multipart/three_files_three_fields +0 -31
- data/test/multipart/webkit +0 -32
- data/test/rackup/config.ru +0 -31
- data/test/registering_handler/rack/handler/registering_myself.rb +0 -8
- data/test/spec_auth_basic.rb +0 -81
- data/test/spec_auth_digest.rb +0 -259
- data/test/spec_body_proxy.rb +0 -85
- data/test/spec_builder.rb +0 -223
- data/test/spec_cascade.rb +0 -61
- data/test/spec_cgi.rb +0 -102
- data/test/spec_chunked.rb +0 -101
- data/test/spec_commonlogger.rb +0 -93
- data/test/spec_conditionalget.rb +0 -102
- data/test/spec_config.rb +0 -22
- data/test/spec_content_length.rb +0 -85
- data/test/spec_content_type.rb +0 -45
- data/test/spec_deflater.rb +0 -339
- data/test/spec_directory.rb +0 -88
- data/test/spec_etag.rb +0 -107
- data/test/spec_fastcgi.rb +0 -107
- data/test/spec_file.rb +0 -221
- data/test/spec_handler.rb +0 -72
- data/test/spec_head.rb +0 -45
- data/test/spec_lint.rb +0 -550
- data/test/spec_lobster.rb +0 -58
- data/test/spec_lock.rb +0 -164
- data/test/spec_logger.rb +0 -23
- data/test/spec_methodoverride.rb +0 -111
- data/test/spec_mime.rb +0 -51
- data/test/spec_mock.rb +0 -297
- data/test/spec_mongrel.rb +0 -182
- data/test/spec_multipart.rb +0 -600
- data/test/spec_nulllogger.rb +0 -20
- data/test/spec_recursive.rb +0 -72
- data/test/spec_request.rb +0 -1232
- data/test/spec_response.rb +0 -407
- data/test/spec_rewindable_input.rb +0 -118
- data/test/spec_runtime.rb +0 -49
- data/test/spec_sendfile.rb +0 -130
- data/test/spec_server.rb +0 -167
- data/test/spec_session_abstract_id.rb +0 -53
- data/test/spec_session_cookie.rb +0 -410
- data/test/spec_session_memcache.rb +0 -358
- data/test/spec_session_persisted_secure_secure_session_hash.rb +0 -73
- data/test/spec_session_pool.rb +0 -246
- data/test/spec_showexceptions.rb +0 -98
- data/test/spec_showstatus.rb +0 -103
- data/test/spec_static.rb +0 -145
- data/test/spec_tempfile_reaper.rb +0 -63
- data/test/spec_thin.rb +0 -91
- data/test/spec_urlmap.rb +0 -236
- data/test/spec_utils.rb +0 -647
- data/test/spec_version.rb +0 -17
- data/test/spec_webrick.rb +0 -184
- data/test/static/another/index.html +0 -1
- data/test/static/index.html +0 -1
- data/test/testrequest.rb +0 -78
- data/test/unregistered_handler/rack/handler/unregistered.rb +0 -7
- data/test/unregistered_handler/rack/handler/unregistered_long_one.rb +0 -7
@@ -0,0 +1,218 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'core_ext/regexp'
|
4
|
+
|
5
|
+
module Rack
|
6
|
+
class QueryParser
|
7
|
+
using ::Rack::RegexpExtensions
|
8
|
+
|
9
|
+
DEFAULT_SEP = /[&;] */n
|
10
|
+
COMMON_SEP = { ";" => /[;] */n, ";," => /[;,] */n, "&" => /[&] */n }
|
11
|
+
|
12
|
+
# ParameterTypeError is the error that is raised when incoming structural
|
13
|
+
# parameters (parsed by parse_nested_query) contain conflicting types.
|
14
|
+
class ParameterTypeError < TypeError; end
|
15
|
+
|
16
|
+
# InvalidParameterError is the error that is raised when incoming structural
|
17
|
+
# parameters (parsed by parse_nested_query) contain invalid format or byte
|
18
|
+
# sequence.
|
19
|
+
class InvalidParameterError < ArgumentError; end
|
20
|
+
|
21
|
+
def self.make_default(key_space_limit, param_depth_limit)
|
22
|
+
new Params, key_space_limit, param_depth_limit
|
23
|
+
end
|
24
|
+
|
25
|
+
attr_reader :key_space_limit, :param_depth_limit
|
26
|
+
|
27
|
+
def initialize(params_class, key_space_limit, param_depth_limit)
|
28
|
+
@params_class = params_class
|
29
|
+
@key_space_limit = key_space_limit
|
30
|
+
@param_depth_limit = param_depth_limit
|
31
|
+
end
|
32
|
+
|
33
|
+
# Stolen from Mongrel, with some small modifications:
|
34
|
+
# Parses a query string by breaking it up at the '&'
|
35
|
+
# and ';' characters. You can also use this to parse
|
36
|
+
# cookies by changing the characters used in the second
|
37
|
+
# parameter (which defaults to '&;').
|
38
|
+
def parse_query(qs, d = nil, &unescaper)
|
39
|
+
unescaper ||= method(:unescape)
|
40
|
+
|
41
|
+
params = make_params
|
42
|
+
|
43
|
+
(qs || '').split(d ? (COMMON_SEP[d] || /[#{d}] */n) : DEFAULT_SEP).each do |p|
|
44
|
+
next if p.empty?
|
45
|
+
k, v = p.split('=', 2).map!(&unescaper)
|
46
|
+
|
47
|
+
if cur = params[k]
|
48
|
+
if cur.class == Array
|
49
|
+
params[k] << v
|
50
|
+
else
|
51
|
+
params[k] = [cur, v]
|
52
|
+
end
|
53
|
+
else
|
54
|
+
params[k] = v
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
return params.to_h
|
59
|
+
end
|
60
|
+
|
61
|
+
# parse_nested_query expands a query string into structural types. Supported
|
62
|
+
# types are Arrays, Hashes and basic value types. It is possible to supply
|
63
|
+
# query strings with parameters of conflicting types, in this case a
|
64
|
+
# ParameterTypeError is raised. Users are encouraged to return a 400 in this
|
65
|
+
# case.
|
66
|
+
def parse_nested_query(qs, d = nil)
|
67
|
+
return {} if qs.nil? || qs.empty?
|
68
|
+
params = make_params
|
69
|
+
|
70
|
+
qs.split(d ? (COMMON_SEP[d] || /[#{d}] */n) : DEFAULT_SEP).each do |p|
|
71
|
+
k, v = p.split('=', 2).map! { |s| unescape(s) }
|
72
|
+
|
73
|
+
normalize_params(params, k, v, param_depth_limit)
|
74
|
+
end
|
75
|
+
|
76
|
+
return params.to_h
|
77
|
+
rescue ArgumentError => e
|
78
|
+
raise InvalidParameterError, e.message
|
79
|
+
end
|
80
|
+
|
81
|
+
# normalize_params recursively expands parameters into structural types. If
|
82
|
+
# the structural types represented by two different parameter names are in
|
83
|
+
# conflict, a ParameterTypeError is raised.
|
84
|
+
def normalize_params(params, name, v, depth)
|
85
|
+
raise RangeError if depth <= 0
|
86
|
+
|
87
|
+
name =~ %r(\A[\[\]]*([^\[\]]+)\]*)
|
88
|
+
k = $1 || ''
|
89
|
+
after = $' || ''
|
90
|
+
|
91
|
+
if k.empty?
|
92
|
+
if !v.nil? && name == "[]"
|
93
|
+
return Array(v)
|
94
|
+
else
|
95
|
+
return
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
if after == ''
|
100
|
+
params[k] = v
|
101
|
+
elsif after == "["
|
102
|
+
params[name] = v
|
103
|
+
elsif after == "[]"
|
104
|
+
params[k] ||= []
|
105
|
+
raise ParameterTypeError, "expected Array (got #{params[k].class.name}) for param `#{k}'" unless params[k].is_a?(Array)
|
106
|
+
params[k] << v
|
107
|
+
elsif after =~ %r(^\[\]\[([^\[\]]+)\]$) || after =~ %r(^\[\](.+)$)
|
108
|
+
child_key = $1
|
109
|
+
params[k] ||= []
|
110
|
+
raise ParameterTypeError, "expected Array (got #{params[k].class.name}) for param `#{k}'" unless params[k].is_a?(Array)
|
111
|
+
if params_hash_type?(params[k].last) && !params_hash_has_key?(params[k].last, child_key)
|
112
|
+
normalize_params(params[k].last, child_key, v, depth - 1)
|
113
|
+
else
|
114
|
+
params[k] << normalize_params(make_params, child_key, v, depth - 1)
|
115
|
+
end
|
116
|
+
else
|
117
|
+
params[k] ||= make_params
|
118
|
+
raise ParameterTypeError, "expected Hash (got #{params[k].class.name}) for param `#{k}'" unless params_hash_type?(params[k])
|
119
|
+
params[k] = normalize_params(params[k], after, v, depth - 1)
|
120
|
+
end
|
121
|
+
|
122
|
+
params
|
123
|
+
end
|
124
|
+
|
125
|
+
def make_params
|
126
|
+
@params_class.new @key_space_limit
|
127
|
+
end
|
128
|
+
|
129
|
+
def new_space_limit(key_space_limit)
|
130
|
+
self.class.new @params_class, key_space_limit, param_depth_limit
|
131
|
+
end
|
132
|
+
|
133
|
+
def new_depth_limit(param_depth_limit)
|
134
|
+
self.class.new @params_class, key_space_limit, param_depth_limit
|
135
|
+
end
|
136
|
+
|
137
|
+
private
|
138
|
+
|
139
|
+
def params_hash_type?(obj)
|
140
|
+
obj.kind_of?(@params_class)
|
141
|
+
end
|
142
|
+
|
143
|
+
def params_hash_has_key?(hash, key)
|
144
|
+
return false if /\[\]/.match?(key)
|
145
|
+
|
146
|
+
key.split(/[\[\]]+/).inject(hash) do |h, part|
|
147
|
+
next h if part == ''
|
148
|
+
return false unless params_hash_type?(h) && h.key?(part)
|
149
|
+
h[part]
|
150
|
+
end
|
151
|
+
|
152
|
+
true
|
153
|
+
end
|
154
|
+
|
155
|
+
def unescape(s)
|
156
|
+
Utils.unescape(s)
|
157
|
+
end
|
158
|
+
|
159
|
+
class Params
|
160
|
+
def initialize(limit)
|
161
|
+
@limit = limit
|
162
|
+
@size = 0
|
163
|
+
@params = {}
|
164
|
+
end
|
165
|
+
|
166
|
+
def [](key)
|
167
|
+
@params[key]
|
168
|
+
end
|
169
|
+
|
170
|
+
def []=(key, value)
|
171
|
+
@size += key.size if key && !@params.key?(key)
|
172
|
+
raise RangeError, 'exceeded available parameter key space' if @size > @limit
|
173
|
+
@params[key] = value
|
174
|
+
end
|
175
|
+
|
176
|
+
def key?(key)
|
177
|
+
@params.key?(key)
|
178
|
+
end
|
179
|
+
|
180
|
+
# Recursively unwraps nested `Params` objects and constructs an object
|
181
|
+
# of the same shape, but using the objects' internal representations
|
182
|
+
# (Ruby hashes) in place of the objects. The result is a hash consisting
|
183
|
+
# purely of Ruby primitives.
|
184
|
+
#
|
185
|
+
# Mutation warning!
|
186
|
+
#
|
187
|
+
# 1. This method mutates the internal representation of the `Params`
|
188
|
+
# objects in order to save object allocations.
|
189
|
+
#
|
190
|
+
# 2. The value you get back is a reference to the internal hash
|
191
|
+
# representation, not a copy.
|
192
|
+
#
|
193
|
+
# 3. Because the `Params` object's internal representation is mutable
|
194
|
+
# through the `#[]=` method, it is not thread safe. The result of
|
195
|
+
# getting the hash representation while another thread is adding a
|
196
|
+
# key to it is non-deterministic.
|
197
|
+
#
|
198
|
+
def to_h
|
199
|
+
@params.each do |key, value|
|
200
|
+
case value
|
201
|
+
when self
|
202
|
+
# Handle circular references gracefully.
|
203
|
+
@params[key] = @params
|
204
|
+
when Params
|
205
|
+
@params[key] = value.to_h
|
206
|
+
when Array
|
207
|
+
value.map! { |v| v.kind_of?(Params) ? v.to_h : v }
|
208
|
+
else
|
209
|
+
# Ignore anything that is not a `Params` object or
|
210
|
+
# a collection that can contain one.
|
211
|
+
end
|
212
|
+
end
|
213
|
+
@params
|
214
|
+
end
|
215
|
+
alias_method :to_params_hash, :to_h
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
data/lib/rack/recursive.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'uri'
|
2
4
|
|
3
5
|
module Rack
|
@@ -10,15 +12,15 @@ module Rack
|
|
10
12
|
class ForwardRequest < Exception
|
11
13
|
attr_reader :url, :env
|
12
14
|
|
13
|
-
def initialize(url, env={})
|
15
|
+
def initialize(url, env = {})
|
14
16
|
@url = URI(url)
|
15
17
|
@env = env
|
16
18
|
|
17
|
-
@env[PATH_INFO]
|
18
|
-
@env[QUERY_STRING]
|
19
|
-
@env[
|
20
|
-
@env["HTTP_PORT"]
|
21
|
-
@env[
|
19
|
+
@env[PATH_INFO] = @url.path
|
20
|
+
@env[QUERY_STRING] = @url.query if @url.query
|
21
|
+
@env[HTTP_HOST] = @url.host if @url.host
|
22
|
+
@env["HTTP_PORT"] = @url.port if @url.port
|
23
|
+
@env[RACK_URL_SCHEME] = @url.scheme if @url.scheme
|
22
24
|
|
23
25
|
super "forwarding to #{url}"
|
24
26
|
end
|
@@ -40,7 +42,7 @@ module Rack
|
|
40
42
|
|
41
43
|
def _call(env)
|
42
44
|
@script_name = env[SCRIPT_NAME]
|
43
|
-
@app.call(env.merge(
|
45
|
+
@app.call(env.merge(RACK_RECURSIVE_INCLUDE => method(:include)))
|
44
46
|
rescue ForwardRequest => req
|
45
47
|
call(env.merge(req.env))
|
46
48
|
end
|
@@ -53,9 +55,9 @@ module Rack
|
|
53
55
|
|
54
56
|
env = env.merge(PATH_INFO => path,
|
55
57
|
SCRIPT_NAME => @script_name,
|
56
|
-
REQUEST_METHOD =>
|
58
|
+
REQUEST_METHOD => GET,
|
57
59
|
"CONTENT_LENGTH" => "0", "CONTENT_TYPE" => "",
|
58
|
-
|
60
|
+
RACK_INPUT => StringIO.new(""))
|
59
61
|
@app.call(env)
|
60
62
|
end
|
61
63
|
end
|
data/lib/rack/reloader.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (C) 2009-2018 Michael Fellinger <m.fellinger@gmail.com>
|
4
|
+
# Rack::Reloader is subject to the terms of an MIT-style license.
|
5
|
+
# See MIT-LICENSE or https://opensource.org/licenses/MIT.
|
4
6
|
|
5
7
|
require 'pathname'
|
6
8
|
|
9
|
+
require_relative 'core_ext/regexp'
|
10
|
+
|
7
11
|
module Rack
|
8
12
|
|
9
13
|
# High performant source reloader
|
@@ -20,6 +24,8 @@ module Rack
|
|
20
24
|
# It is performing a check/reload cycle at the start of every request, but
|
21
25
|
# also respects a cool down time, during which nothing will be done.
|
22
26
|
class Reloader
|
27
|
+
using ::Rack::RegexpExtensions
|
28
|
+
|
23
29
|
def initialize(app, cooldown = 10, backend = Stat)
|
24
30
|
@app = app
|
25
31
|
@cooldown = cooldown
|
@@ -69,7 +75,7 @@ module Rack
|
|
69
75
|
paths = ['./', *$LOAD_PATH].uniq
|
70
76
|
|
71
77
|
files.map{|file|
|
72
|
-
next if
|
78
|
+
next if /\.(so|bundle)$/.match?(file) # cannot reload compiled files
|
73
79
|
|
74
80
|
found, stat = figure_path(file, paths)
|
75
81
|
next unless found && stat && mtime = stat.mtime
|