rack 1.6.13 → 2.0.1
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 +5 -5
- data/COPYING +1 -1
- data/HISTORY.md +138 -8
- data/README.rdoc +17 -25
- data/Rakefile +6 -14
- data/SPEC +8 -9
- 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/{conditionalget.rb → conditional_get.rb} +0 -0
- data/lib/rack/content_length.rb +2 -2
- data/lib/rack/deflater.rb +4 -4
- data/lib/rack/directory.rb +66 -54
- data/lib/rack/etag.rb +4 -3
- data/lib/rack/events.rb +154 -0
- data/lib/rack/file.rb +63 -39
- 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 +22 -24
- data/lib/rack/handler.rb +3 -25
- data/lib/rack/head.rb +15 -17
- data/lib/rack/lint.rb +38 -38
- data/lib/rack/lobster.rb +1 -1
- data/lib/rack/lock.rb +6 -10
- data/lib/rack/logger.rb +2 -2
- data/lib/rack/media_type.rb +38 -0
- data/lib/rack/{methodoverride.rb → method_override.rb} +4 -11
- data/lib/rack/mime.rb +18 -5
- data/lib/rack/mock.rb +35 -53
- data/lib/rack/multipart/generator.rb +5 -5
- data/lib/rack/multipart/parser.rb +272 -158
- 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 +383 -307
- data/lib/rack/response.rb +129 -56
- 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 +31 -25
- data/lib/rack/session/abstract/id.rb +95 -135
- data/lib/rack/session/cookie.rb +26 -28
- data/lib/rack/session/memcache.rb +8 -14
- data/lib/rack/session/pool.rb +14 -21
- 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 +135 -210
- data/lib/rack.rb +70 -21
- data/rack.gemspec +7 -5
- 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_null_byte → filename_with_single_quote} +1 -1
- 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 +36 -34
- 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 +66 -40
- 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 +107 -77
- data/test/spec_handler.rb +19 -34
- data/test/spec_head.rb +15 -14
- data/test/spec_lint.rb +162 -197
- data/test/spec_lobster.rb +24 -23
- data/test/spec_lock.rb +69 -39
- data/test/spec_logger.rb +4 -3
- data/test/spec_media_type.rb +42 -0
- data/test/spec_method_override.rb +83 -0
- data/test/spec_mime.rb +19 -19
- data/test/spec_mock.rb +196 -151
- data/test/spec_multipart.rb +317 -201
- data/test/{spec_nulllogger.rb → spec_null_logger.rb} +5 -4
- data/test/spec_recursive.rb +17 -14
- data/test/spec_request.rb +768 -607
- data/test/spec_response.rb +214 -111
- 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 +28 -0
- data/test/spec_session_cookie.rb +97 -65
- data/test/spec_session_memcache.rb +63 -101
- data/test/spec_session_pool.rb +48 -84
- data/test/spec_show_exceptions.rb +80 -0
- 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 +91 -67
- 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 +103 -69
- 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_methodoverride.rb +0 -111
- data/test/spec_mongrel.rb +0 -182
- data/test/spec_session_persisted_secure_secure_session_hash.rb +0 -73
- data/test/spec_showexceptions.rb +0 -98
data/lib/rack/mock.rb
CHANGED
@@ -41,27 +41,27 @@ module Rack
|
|
41
41
|
end
|
42
42
|
|
43
43
|
DEFAULT_ENV = {
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
}
|
44
|
+
RACK_VERSION => Rack::VERSION,
|
45
|
+
RACK_INPUT => StringIO.new,
|
46
|
+
RACK_ERRORS => StringIO.new,
|
47
|
+
RACK_MULTITHREAD => true,
|
48
|
+
RACK_MULTIPROCESS => true,
|
49
|
+
RACK_RUNONCE => false,
|
50
|
+
}.freeze
|
51
51
|
|
52
52
|
def initialize(app)
|
53
53
|
@app = app
|
54
54
|
end
|
55
55
|
|
56
|
-
def get(uri, opts={}) request(
|
57
|
-
def post(uri, opts={}) request(
|
58
|
-
def put(uri, opts={}) request(
|
59
|
-
def patch(uri, opts={}) request(
|
60
|
-
def delete(uri, opts={}) request(
|
61
|
-
def head(uri, opts={}) request(
|
62
|
-
def options(uri, opts={}) request(
|
56
|
+
def get(uri, opts={}) request(GET, uri, opts) end
|
57
|
+
def post(uri, opts={}) request(POST, uri, opts) end
|
58
|
+
def put(uri, opts={}) request(PUT, uri, opts) end
|
59
|
+
def patch(uri, opts={}) request(PATCH, uri, opts) end
|
60
|
+
def delete(uri, opts={}) request(DELETE, uri, opts) end
|
61
|
+
def head(uri, opts={}) request(HEAD, uri, opts) end
|
62
|
+
def options(uri, opts={}) request(OPTIONS, uri, opts) end
|
63
63
|
|
64
|
-
def request(method=
|
64
|
+
def request(method=GET, uri="", opts={})
|
65
65
|
env = self.class.env_for(uri, opts.merge(:method => method))
|
66
66
|
|
67
67
|
if opts[:lint]
|
@@ -70,17 +70,17 @@ module Rack
|
|
70
70
|
app = @app
|
71
71
|
end
|
72
72
|
|
73
|
-
errors = env[
|
73
|
+
errors = env[RACK_ERRORS]
|
74
74
|
status, headers, body = app.call(env)
|
75
75
|
MockResponse.new(status, headers, body, errors)
|
76
76
|
ensure
|
77
77
|
body.close if body.respond_to?(:close)
|
78
78
|
end
|
79
79
|
|
80
|
-
# For historical reasons, we're pinning to RFC 2396.
|
81
|
-
#
|
80
|
+
# For historical reasons, we're pinning to RFC 2396.
|
81
|
+
# URI::Parser = URI::RFC2396_Parser
|
82
82
|
def self.parse_uri_rfc2396(uri)
|
83
|
-
@parser ||=
|
83
|
+
@parser ||= URI::Parser.new
|
84
84
|
@parser.parse(uri)
|
85
85
|
end
|
86
86
|
|
@@ -91,28 +91,34 @@ module Rack
|
|
91
91
|
|
92
92
|
env = DEFAULT_ENV.dup
|
93
93
|
|
94
|
-
|
94
|
+
env[REQUEST_METHOD] = opts[:method] ? opts[:method].to_s.upcase : GET
|
95
|
+
env[SERVER_NAME] = uri.host || "example.org"
|
96
|
+
env[SERVER_PORT] = uri.port ? uri.port.to_s : "80"
|
97
|
+
env[QUERY_STRING] = uri.query.to_s
|
98
|
+
env[PATH_INFO] = (!uri.path || uri.path.empty?) ? "/" : uri.path
|
99
|
+
env[RACK_URL_SCHEME] = uri.scheme || "http"
|
100
|
+
env[HTTPS] = env[RACK_URL_SCHEME] == "https" ? "on" : "off"
|
95
101
|
|
96
102
|
env[SCRIPT_NAME] = opts[:script_name] || ""
|
97
103
|
|
98
104
|
if opts[:fatal]
|
99
|
-
env[
|
105
|
+
env[RACK_ERRORS] = FatalWarner.new
|
100
106
|
else
|
101
|
-
env[
|
107
|
+
env[RACK_ERRORS] = StringIO.new
|
102
108
|
end
|
103
109
|
|
104
110
|
if params = opts[:params]
|
105
|
-
if env[REQUEST_METHOD] ==
|
111
|
+
if env[REQUEST_METHOD] == GET
|
106
112
|
params = Utils.parse_nested_query(params) if params.is_a?(String)
|
107
113
|
params.update(Utils.parse_nested_query(env[QUERY_STRING]))
|
108
114
|
env[QUERY_STRING] = Utils.build_nested_query(params)
|
109
115
|
elsif !opts.has_key?(:input)
|
110
116
|
opts["CONTENT_TYPE"] = "application/x-www-form-urlencoded"
|
111
117
|
if params.is_a?(Hash)
|
112
|
-
if data =
|
118
|
+
if data = Rack::Multipart.build_multipart(params)
|
113
119
|
opts[:input] = data
|
114
120
|
opts["CONTENT_LENGTH"] ||= data.length.to_s
|
115
|
-
opts["CONTENT_TYPE"] = "multipart/form-data; boundary=#{
|
121
|
+
opts["CONTENT_TYPE"] = "multipart/form-data; boundary=#{Rack::Multipart::MULTIPART_BOUNDARY}"
|
116
122
|
else
|
117
123
|
opts[:input] = Utils.build_nested_query(params)
|
118
124
|
end
|
@@ -122,8 +128,7 @@ module Rack
|
|
122
128
|
end
|
123
129
|
end
|
124
130
|
|
125
|
-
empty_str =
|
126
|
-
empty_str.force_encoding("ASCII-8BIT") if empty_str.respond_to? :force_encoding
|
131
|
+
empty_str = String.new.force_encoding(Encoding::ASCII_8BIT)
|
127
132
|
opts[:input] ||= empty_str
|
128
133
|
if String === opts[:input]
|
129
134
|
rack_input = StringIO.new(opts[:input])
|
@@ -131,10 +136,10 @@ module Rack
|
|
131
136
|
rack_input = opts[:input]
|
132
137
|
end
|
133
138
|
|
134
|
-
rack_input.set_encoding(Encoding::BINARY)
|
135
|
-
env[
|
139
|
+
rack_input.set_encoding(Encoding::BINARY)
|
140
|
+
env[RACK_INPUT] = rack_input
|
136
141
|
|
137
|
-
env["CONTENT_LENGTH"] ||= env[
|
142
|
+
env["CONTENT_LENGTH"] ||= env[RACK_INPUT].length.to_s
|
138
143
|
|
139
144
|
opts.each { |field, value|
|
140
145
|
env[field] = value if String === field
|
@@ -142,28 +147,6 @@ module Rack
|
|
142
147
|
|
143
148
|
env
|
144
149
|
end
|
145
|
-
|
146
|
-
if "<3".respond_to? :b
|
147
|
-
def self.env_with_encoding(env, opts, uri)
|
148
|
-
env[REQUEST_METHOD] = (opts[:method] ? opts[:method].to_s.upcase : "GET").b
|
149
|
-
env["SERVER_NAME"] = (uri.host || "example.org").b
|
150
|
-
env["SERVER_PORT"] = (uri.port ? uri.port.to_s : "80").b
|
151
|
-
env[QUERY_STRING] = (uri.query.to_s).b
|
152
|
-
env[PATH_INFO] = ((!uri.path || uri.path.empty?) ? "/" : uri.path).b
|
153
|
-
env["rack.url_scheme"] = (uri.scheme || "http").b
|
154
|
-
env["HTTPS"] = (env["rack.url_scheme"] == "https" ? "on" : "off").b
|
155
|
-
end
|
156
|
-
else
|
157
|
-
def self.env_with_encoding(env, opts, uri)
|
158
|
-
env[REQUEST_METHOD] = opts[:method] ? opts[:method].to_s.upcase : "GET"
|
159
|
-
env["SERVER_NAME"] = uri.host || "example.org"
|
160
|
-
env["SERVER_PORT"] = uri.port ? uri.port.to_s : "80"
|
161
|
-
env[QUERY_STRING] = uri.query.to_s
|
162
|
-
env[PATH_INFO] = (!uri.path || uri.path.empty?) ? "/" : uri.path
|
163
|
-
env["rack.url_scheme"] = uri.scheme || "http"
|
164
|
-
env["HTTPS"] = env["rack.url_scheme"] == "https" ? "on" : "off"
|
165
|
-
end
|
166
|
-
end
|
167
150
|
end
|
168
151
|
|
169
152
|
# Rack::MockResponse provides useful helpers for testing your apps.
|
@@ -180,7 +163,6 @@ module Rack
|
|
180
163
|
def initialize(status, headers, body, errors=StringIO.new(""))
|
181
164
|
@original_headers = headers
|
182
165
|
@errors = errors.string if errors.respond_to?(:string)
|
183
|
-
@body_string = nil
|
184
166
|
|
185
167
|
super(body, status, headers)
|
186
168
|
end
|
@@ -11,18 +11,18 @@ module Rack
|
|
11
11
|
|
12
12
|
def dump
|
13
13
|
return nil if @first && !multipart?
|
14
|
-
return flattened_params
|
14
|
+
return flattened_params unless @first
|
15
15
|
|
16
16
|
flattened_params.map do |name, file|
|
17
17
|
if file.respond_to?(:original_filename)
|
18
|
-
::File.open(file.path,
|
19
|
-
f.set_encoding(Encoding::BINARY)
|
18
|
+
::File.open(file.path, 'rb') do |f|
|
19
|
+
f.set_encoding(Encoding::BINARY)
|
20
20
|
content_for_tempfile(f, file, name)
|
21
21
|
end
|
22
22
|
else
|
23
23
|
content_for_other(file, name)
|
24
24
|
end
|
25
|
-
end.join
|
25
|
+
end.join << "--#{MULTIPART_BOUNDARY}--\r"
|
26
26
|
end
|
27
27
|
|
28
28
|
private
|
@@ -90,4 +90,4 @@ EOF
|
|
90
90
|
end
|
91
91
|
end
|
92
92
|
end
|
93
|
-
end
|
93
|
+
end
|