rack 2.0.1 → 2.2.17
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 +5 -5
- data/CHANGELOG.md +795 -0
- data/CONTRIBUTING.md +136 -0
- data/{COPYING → MIT-LICENSE} +4 -2
- data/README.rdoc +188 -145
- data/Rakefile +37 -23
- data/{SPEC → SPEC.rdoc} +46 -17
- data/bin/rackup +1 -0
- data/example/lobster.ru +2 -0
- data/example/protectedlobster.rb +3 -1
- data/example/protectedlobster.ru +2 -0
- data/lib/rack/auth/abstract/handler.rb +3 -1
- data/lib/rack/auth/abstract/request.rb +1 -1
- data/lib/rack/auth/basic.rb +6 -4
- data/lib/rack/auth/digest/md5.rb +13 -11
- data/lib/rack/auth/digest/nonce.rb +5 -3
- data/lib/rack/auth/digest/params.rb +4 -2
- data/lib/rack/auth/digest/request.rb +5 -3
- data/lib/rack/body_proxy.rb +15 -14
- data/lib/rack/builder.rb +116 -23
- data/lib/rack/cascade.rb +28 -12
- data/lib/rack/chunked.rb +68 -20
- data/lib/rack/common_logger.rb +37 -25
- data/lib/rack/conditional_get.rb +20 -16
- data/lib/rack/config.rb +2 -0
- data/lib/rack/content_length.rb +8 -7
- data/lib/rack/content_type.rb +5 -4
- data/lib/rack/core_ext/regexp.rb +14 -0
- data/lib/rack/deflater.rb +60 -70
- data/lib/rack/directory.rb +84 -64
- data/lib/rack/etag.rb +8 -5
- data/lib/rack/events.rb +19 -20
- data/lib/rack/file.rb +4 -173
- data/lib/rack/files.rb +218 -0
- data/lib/rack/handler/cgi.rb +2 -3
- data/lib/rack/handler/fastcgi.rb +4 -4
- data/lib/rack/handler/lsws.rb +3 -3
- data/lib/rack/handler/scgi.rb +9 -8
- data/lib/rack/handler/thin.rb +3 -3
- data/lib/rack/handler/webrick.rb +19 -10
- data/lib/rack/handler.rb +7 -2
- data/lib/rack/head.rb +1 -1
- data/lib/rack/lint.rb +221 -186
- data/lib/rack/lobster.rb +10 -10
- data/lib/rack/lock.rb +14 -4
- data/lib/rack/logger.rb +2 -0
- data/lib/rack/media_type.rb +23 -8
- data/lib/rack/method_override.rb +13 -4
- data/lib/rack/mime.rb +9 -1
- data/lib/rack/mock.rb +135 -29
- data/lib/rack/multipart/generator.rb +17 -13
- data/lib/rack/multipart/parser.rb +85 -68
- data/lib/rack/multipart/uploaded_file.rb +15 -7
- data/lib/rack/multipart.rb +6 -5
- data/lib/rack/null_logger.rb +2 -0
- data/lib/rack/query_parser.rb +108 -36
- data/lib/rack/recursive.rb +7 -5
- data/lib/rack/reloader.rb +8 -4
- data/lib/rack/request.rb +232 -60
- data/lib/rack/response.rb +127 -44
- data/lib/rack/rewindable_input.rb +4 -3
- data/lib/rack/runtime.rb +6 -4
- data/lib/rack/sendfile.rb +14 -10
- data/lib/rack/server.rb +97 -25
- data/lib/rack/session/abstract/id.rb +113 -25
- data/lib/rack/session/cookie.rb +22 -14
- data/lib/rack/session/memcache.rb +4 -87
- data/lib/rack/session/pool.rb +24 -10
- data/lib/rack/show_exceptions.rb +22 -18
- data/lib/rack/show_status.rb +9 -9
- data/lib/rack/static.rb +25 -12
- data/lib/rack/tempfile_reaper.rb +1 -1
- data/lib/rack/urlmap.rb +13 -7
- data/lib/rack/utils.rb +135 -123
- data/lib/rack/version.rb +29 -0
- data/lib/rack.rb +67 -73
- data/rack.gemspec +40 -29
- metadata +25 -184
- data/HISTORY.md +0 -505
- data/test/builder/an_underscore_app.rb +0 -5
- 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 -9
- data/test/cgi/test.gz +0 -0
- data/test/cgi/test.ru +0 -5
- data/test/gemloader.rb +0 -10
- data/test/helper.rb +0 -34
- 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_encoded_words +0 -7
- 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_percent_escaped_quotes +0 -6
- data/test/multipart/filename_with_single_quote +0 -7
- 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/quoted +0 -15
- data/test/multipart/rack-logo.png +0 -0
- data/test/multipart/semicolon +0 -6
- data/test/multipart/text +0 -15
- data/test/multipart/three_files_three_fields +0 -31
- data/test/multipart/unity3d_wwwform +0 -11
- 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 -89
- data/test/spec_auth_digest.rb +0 -260
- data/test/spec_body_proxy.rb +0 -85
- data/test/spec_builder.rb +0 -233
- data/test/spec_cascade.rb +0 -63
- data/test/spec_cgi.rb +0 -84
- data/test/spec_chunked.rb +0 -103
- data/test/spec_common_logger.rb +0 -95
- data/test/spec_conditional_get.rb +0 -103
- data/test/spec_config.rb +0 -23
- data/test/spec_content_length.rb +0 -86
- data/test/spec_content_type.rb +0 -46
- data/test/spec_deflater.rb +0 -365
- data/test/spec_directory.rb +0 -148
- data/test/spec_etag.rb +0 -108
- data/test/spec_events.rb +0 -133
- data/test/spec_fastcgi.rb +0 -85
- data/test/spec_file.rb +0 -251
- data/test/spec_handler.rb +0 -57
- data/test/spec_head.rb +0 -46
- data/test/spec_lint.rb +0 -515
- data/test/spec_lobster.rb +0 -59
- data/test/spec_lock.rb +0 -194
- data/test/spec_logger.rb +0 -24
- data/test/spec_media_type.rb +0 -42
- data/test/spec_method_override.rb +0 -83
- data/test/spec_mime.rb +0 -51
- data/test/spec_mock.rb +0 -342
- data/test/spec_multipart.rb +0 -716
- data/test/spec_null_logger.rb +0 -21
- data/test/spec_recursive.rb +0 -75
- data/test/spec_request.rb +0 -1393
- data/test/spec_response.rb +0 -510
- data/test/spec_rewindable_input.rb +0 -128
- data/test/spec_runtime.rb +0 -50
- data/test/spec_sendfile.rb +0 -125
- data/test/spec_server.rb +0 -193
- data/test/spec_session_abstract_id.rb +0 -31
- data/test/spec_session_abstract_session_hash.rb +0 -28
- data/test/spec_session_cookie.rb +0 -442
- data/test/spec_session_memcache.rb +0 -320
- data/test/spec_session_pool.rb +0 -210
- data/test/spec_show_exceptions.rb +0 -80
- data/test/spec_show_status.rb +0 -104
- data/test/spec_static.rb +0 -184
- data/test/spec_tempfile_reaper.rb +0 -64
- data/test/spec_thin.rb +0 -96
- data/test/spec_urlmap.rb +0 -237
- data/test/spec_utils.rb +0 -742
- data/test/spec_version.rb +0 -11
- data/test/spec_webrick.rb +0 -208
- data/test/static/another/index.html +0 -1
- data/test/static/foo.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
data/lib/rack/static.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
|
-
|
2
|
-
require "rack/utils"
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
3
|
module Rack
|
5
4
|
|
6
5
|
# The Rack::Static middleware intercepts requests for static files
|
7
6
|
# (javascript files, images, stylesheets, etc) based on the url prefixes or
|
8
|
-
# route mappings passed in the options, and serves them using a Rack::
|
7
|
+
# route mappings passed in the options, and serves them using a Rack::Files
|
9
8
|
# object. This allows a Rack stack to serve both static and dynamic content.
|
10
9
|
#
|
11
10
|
# Examples:
|
@@ -15,6 +14,11 @@ module Rack
|
|
15
14
|
#
|
16
15
|
# use Rack::Static, :urls => ["/media"]
|
17
16
|
#
|
17
|
+
# Same as previous, but instead of returning 404 for missing files under
|
18
|
+
# /media, call the next middleware:
|
19
|
+
#
|
20
|
+
# use Rack::Static, :urls => ["/media"], :cascade => true
|
21
|
+
#
|
18
22
|
# Serve all requests beginning with /css or /images from the folder "public"
|
19
23
|
# in the current directory (ie public/css/* and public/images/*):
|
20
24
|
#
|
@@ -82,24 +86,26 @@ module Rack
|
|
82
86
|
# ]
|
83
87
|
#
|
84
88
|
class Static
|
89
|
+
(require_relative 'core_ext/regexp'; using ::Rack::RegexpExtensions) if RUBY_VERSION < '2.4'
|
85
90
|
|
86
|
-
def initialize(app, options={})
|
91
|
+
def initialize(app, options = {})
|
87
92
|
@app = app
|
88
93
|
@urls = options[:urls] || ["/favicon.ico"]
|
89
94
|
@index = options[:index]
|
90
95
|
@gzip = options[:gzip]
|
96
|
+
@cascade = options[:cascade]
|
91
97
|
root = options[:root] || Dir.pwd
|
92
98
|
|
93
99
|
# HTTP Headers
|
94
100
|
@header_rules = options[:header_rules] || []
|
95
101
|
# Allow for legacy :cache_control option while prioritizing global header_rules setting
|
96
|
-
@header_rules.unshift([:all, {CACHE_CONTROL => options[:cache_control]}]) if options[:cache_control]
|
102
|
+
@header_rules.unshift([:all, { CACHE_CONTROL => options[:cache_control] }]) if options[:cache_control]
|
97
103
|
|
98
|
-
@file_server = Rack::
|
104
|
+
@file_server = Rack::Files.new(root)
|
99
105
|
end
|
100
106
|
|
101
107
|
def add_index_root?(path)
|
102
|
-
@index && path
|
108
|
+
@index && route_file(path) && path.end_with?('/')
|
103
109
|
end
|
104
110
|
|
105
111
|
def overwrite_file_path(path)
|
@@ -116,11 +122,12 @@ module Rack
|
|
116
122
|
|
117
123
|
def call(env)
|
118
124
|
path = env[PATH_INFO]
|
125
|
+
actual_path = Utils.clean_path_info(Utils.unescape_path(path))
|
119
126
|
|
120
|
-
if can_serve(
|
127
|
+
if can_serve(actual_path)
|
121
128
|
if overwrite_file_path(path)
|
122
129
|
env[PATH_INFO] = (add_index_root?(path) ? path + @index : @urls[path])
|
123
|
-
elsif @gzip && env['HTTP_ACCEPT_ENCODING']
|
130
|
+
elsif @gzip && env['HTTP_ACCEPT_ENCODING'] && /\bgzip\b/.match?(env['HTTP_ACCEPT_ENCODING'])
|
124
131
|
path = env[PATH_INFO]
|
125
132
|
env[PATH_INFO] += '.gz'
|
126
133
|
response = @file_server.call(env)
|
@@ -128,6 +135,8 @@ module Rack
|
|
128
135
|
|
129
136
|
if response[0] == 404
|
130
137
|
response = nil
|
138
|
+
elsif response[0] == 304
|
139
|
+
# Do nothing, leave headers as is
|
131
140
|
else
|
132
141
|
if mime_type = Mime.mime_type(::File.extname(path), 'text/plain')
|
133
142
|
response[1][CONTENT_TYPE] = mime_type
|
@@ -139,6 +148,10 @@ module Rack
|
|
139
148
|
path = env[PATH_INFO]
|
140
149
|
response ||= @file_server.call(env)
|
141
150
|
|
151
|
+
if @cascade && response[0] == 404
|
152
|
+
return @app.call(env)
|
153
|
+
end
|
154
|
+
|
142
155
|
headers = response[1]
|
143
156
|
applicable_rules(path).each do |rule, new_headers|
|
144
157
|
new_headers.each { |field, content| headers[field] = content }
|
@@ -157,14 +170,14 @@ module Rack
|
|
157
170
|
when :all
|
158
171
|
true
|
159
172
|
when :fonts
|
160
|
-
|
173
|
+
/\.(?:ttf|otf|eot|woff2|woff|svg)\z/.match?(path)
|
161
174
|
when String
|
162
175
|
path = ::Rack::Utils.unescape(path)
|
163
176
|
path.start_with?(rule) || path.start_with?('/' + rule)
|
164
177
|
when Array
|
165
|
-
|
178
|
+
/\.(#{rule.join('|')})\z/.match?(path)
|
166
179
|
when Regexp
|
167
|
-
path
|
180
|
+
rule.match?(path)
|
168
181
|
else
|
169
182
|
false
|
170
183
|
end
|
data/lib/rack/tempfile_reaper.rb
CHANGED
data/lib/rack/urlmap.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'set'
|
4
|
+
|
1
5
|
module Rack
|
2
6
|
# Rack::URLMap takes a hash mapping urls or paths to apps, and
|
3
7
|
# dispatches accordingly. Support for HTTP/1.1 host names exists if
|
@@ -12,17 +16,16 @@ module Rack
|
|
12
16
|
# first, since they are most specific.
|
13
17
|
|
14
18
|
class URLMap
|
15
|
-
NEGATIVE_INFINITY = -1.0 / 0.0
|
16
|
-
INFINITY = 1.0 / 0.0
|
17
|
-
|
18
19
|
def initialize(map = {})
|
19
20
|
remap(map)
|
20
21
|
end
|
21
22
|
|
22
23
|
def remap(map)
|
24
|
+
@known_hosts = Set[]
|
23
25
|
@mapping = map.map { |location, app|
|
24
26
|
if location =~ %r{\Ahttps?://(.*?)(/.*)}
|
25
27
|
host, location = $1, $2
|
28
|
+
@known_hosts << host
|
26
29
|
else
|
27
30
|
host = nil
|
28
31
|
end
|
@@ -32,11 +35,11 @@ module Rack
|
|
32
35
|
end
|
33
36
|
|
34
37
|
location = location.chomp('/')
|
35
|
-
match = Regexp.new("^#{Regexp.quote(location).gsub('/', '/+')}(.*)",
|
38
|
+
match = Regexp.new("^#{Regexp.quote(location).gsub('/', '/+')}(.*)", Regexp::NOENCODING)
|
36
39
|
|
37
40
|
[host, location, match, app]
|
38
41
|
}.sort_by do |(host, location, _, _)|
|
39
|
-
[host ? -host.size : INFINITY, -location.size]
|
42
|
+
[host ? -host.size : Float::INFINITY, -location.size]
|
40
43
|
end
|
41
44
|
end
|
42
45
|
|
@@ -50,10 +53,13 @@ module Rack
|
|
50
53
|
is_same_server = casecmp?(http_host, server_name) ||
|
51
54
|
casecmp?(http_host, "#{server_name}:#{server_port}")
|
52
55
|
|
56
|
+
is_host_known = @known_hosts.include? http_host
|
57
|
+
|
53
58
|
@mapping.each do |host, location, match, app|
|
54
59
|
unless casecmp?(http_host, host) \
|
55
60
|
|| casecmp?(server_name, host) \
|
56
|
-
|| (!host && is_same_server)
|
61
|
+
|| (!host && is_same_server) \
|
62
|
+
|| (!host && !is_host_known) # If we don't have a matching host, default to the first without a specified host
|
57
63
|
next
|
58
64
|
end
|
59
65
|
|
@@ -68,7 +74,7 @@ module Rack
|
|
68
74
|
return app.call(env)
|
69
75
|
end
|
70
76
|
|
71
|
-
[404, {CONTENT_TYPE => "text/plain", "X-Cascade" => "pass"}, ["Not Found: #{path}"]]
|
77
|
+
[404, { CONTENT_TYPE => "text/plain", "X-Cascade" => "pass" }, ["Not Found: #{path}"]]
|
72
78
|
|
73
79
|
ensure
|
74
80
|
env[PATH_INFO] = path
|