rack 1.4.7 → 1.5.0.beta.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.
- data/README.rdoc +2 -30
- data/Rakefile +1 -0
- data/SPEC +68 -4
- data/example/protectedlobster.rb +1 -1
- data/lib/rack.rb +2 -14
- data/lib/rack/auth/abstract/request.rb +1 -5
- data/lib/rack/builder.rb +8 -4
- data/lib/rack/cascade.rb +2 -2
- data/lib/rack/config.rb +5 -0
- data/lib/rack/deflater.rb +2 -1
- data/lib/rack/file.rb +25 -28
- data/lib/rack/handler.rb +18 -5
- data/lib/rack/handler/mongrel.rb +1 -1
- data/lib/rack/handler/scgi.rb +1 -1
- data/lib/rack/handler/thin.rb +6 -3
- data/lib/rack/handler/webrick.rb +1 -0
- data/lib/rack/head.rb +2 -0
- data/lib/rack/lint.rb +132 -7
- data/lib/rack/lobster.rb +3 -3
- data/lib/rack/lock.rb +2 -0
- data/lib/rack/methodoverride.rb +0 -2
- data/lib/rack/mime.rb +29 -0
- data/lib/rack/multipart/parser.rb +0 -9
- data/lib/rack/request.rb +66 -25
- data/lib/rack/response.rb +1 -2
- data/lib/rack/sendfile.rb +18 -4
- data/lib/rack/server.rb +20 -12
- data/lib/rack/session/abstract/id.rb +60 -59
- data/lib/rack/session/cookie.rb +11 -16
- data/lib/rack/utils.rb +97 -85
- data/rack.gemspec +1 -6
- data/test/spec_builder.rb +7 -0
- data/test/spec_cgi.rb +1 -1
- data/test/spec_chunked.rb +3 -5
- data/test/spec_content_length.rb +3 -6
- data/test/spec_deflater.rb +26 -9
- data/test/spec_fastcgi.rb +1 -1
- data/test/spec_file.rb +24 -11
- data/test/spec_head.rb +3 -8
- data/test/spec_lint.rb +6 -6
- data/test/spec_lock.rb +4 -7
- data/test/spec_methodoverride.rb +4 -1
- data/test/spec_mime.rb +51 -0
- data/test/spec_mongrel.rb +1 -1
- data/test/spec_multipart.rb +15 -49
- data/test/spec_nulllogger.rb +3 -6
- data/test/spec_request.rb +112 -18
- data/test/spec_response.rb +8 -8
- data/test/spec_sendfile.rb +52 -13
- data/test/spec_server.rb +6 -0
- data/test/spec_session_abstract_id.rb +11 -1
- data/test/spec_session_cookie.rb +140 -153
- data/test/spec_thin.rb +6 -1
- data/test/spec_utils.rb +23 -17
- data/test/spec_webrick.rb +1 -1
- metadata +37 -83
- checksums.yaml +0 -7
- data/test/cgi/lighttpd.errors +0 -1
- data/test/multipart/three_files_three_fields +0 -31
- data/test/spec_auth.rb +0 -57
data/rack.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "rack"
|
3
|
-
s.version = "1.
|
3
|
+
s.version = "1.5.0.beta.1"
|
4
4
|
s.platform = Gem::Platform::RUBY
|
5
5
|
s.summary = "a modular Ruby webserver interface"
|
6
6
|
|
@@ -29,9 +29,4 @@ EOF
|
|
29
29
|
|
30
30
|
s.add_development_dependency 'bacon'
|
31
31
|
s.add_development_dependency 'rake'
|
32
|
-
|
33
|
-
s.add_development_dependency 'ruby-fcgi'
|
34
|
-
s.add_development_dependency 'memcache-client'
|
35
|
-
s.add_development_dependency 'mongrel', '>= 1.2.0.pre2'
|
36
|
-
s.add_development_dependency 'thin'
|
37
32
|
end
|
data/test/spec_builder.rb
CHANGED
@@ -204,4 +204,11 @@ describe Rack::Builder do
|
|
204
204
|
Rack::MockRequest.new(app).get("/").body.to_s.should.equal '1'
|
205
205
|
end
|
206
206
|
end
|
207
|
+
|
208
|
+
describe 'new_from_string' do
|
209
|
+
it "builds a rack app from string" do
|
210
|
+
app, = Rack::Builder.new_from_string "run lambda{|env| [200, {'Content-Type' => 'text/plane'}, ['OK']] }"
|
211
|
+
Rack::MockRequest.new(app).get("/").body.to_s.should.equal 'OK'
|
212
|
+
end
|
213
|
+
end
|
207
214
|
end
|
data/test/spec_cgi.rb
CHANGED
@@ -43,7 +43,7 @@ describe Rack::Handler::CGI do
|
|
43
43
|
|
44
44
|
should "have rack headers" do
|
45
45
|
GET("/test")
|
46
|
-
response["rack.version"].should.equal([1,
|
46
|
+
response["rack.version"].should.equal([1,2])
|
47
47
|
response["rack.multithread"].should.be.false
|
48
48
|
response["rack.multiprocess"].should.be.true
|
49
49
|
response["rack.run_once"].should.be.true
|
data/test/spec_chunked.rb
CHANGED
@@ -3,18 +3,16 @@ require 'rack/lint'
|
|
3
3
|
require 'rack/mock'
|
4
4
|
|
5
5
|
describe Rack::Chunked do
|
6
|
-
::Enumerator = ::Enumerable::Enumerator unless Object.const_defined?(:Enumerator)
|
7
|
-
|
8
6
|
def chunked(app)
|
9
7
|
proc do |env|
|
10
8
|
app = Rack::Chunked.new(app)
|
11
9
|
response = Rack::Lint.new(app).call(env)
|
12
10
|
# we want to use body like an array, but it only has #each
|
13
|
-
response[2] =
|
11
|
+
response[2] = response[2].to_enum.to_a
|
14
12
|
response
|
15
13
|
end
|
16
14
|
end
|
17
|
-
|
15
|
+
|
18
16
|
before do
|
19
17
|
@env = Rack::MockRequest.
|
20
18
|
env_for('/', 'HTTP_VERSION' => '1.1', 'REQUEST_METHOD' => 'GET')
|
@@ -43,7 +41,7 @@ describe Rack::Chunked do
|
|
43
41
|
response.headers.should.not.include 'Content-Length'
|
44
42
|
response.headers['Transfer-Encoding'].should.equal 'chunked'
|
45
43
|
response.body.encoding.to_s.should.equal "ASCII-8BIT"
|
46
|
-
response.body.should.equal "c\r\n\xFE\xFFH\x00e\x00l\x00l\x00o\x00\r\n2\r\n \x00\r\na\r\nW\x00o\x00r\x00l\x00d\x00\r\n0\r\n\r\n"
|
44
|
+
response.body.should.equal "c\r\n\xFE\xFFH\x00e\x00l\x00l\x00o\x00\r\n2\r\n \x00\r\na\r\nW\x00o\x00r\x00l\x00d\x00\r\n0\r\n\r\n".force_encoding("BINARY")
|
47
45
|
end if RUBY_VERSION >= "1.9"
|
48
46
|
|
49
47
|
should 'not modify response when Content-Length header present' do
|
data/test/spec_content_length.rb
CHANGED
@@ -1,19 +1,16 @@
|
|
1
|
-
require 'enumerator'
|
2
1
|
require 'rack/content_length'
|
3
2
|
require 'rack/lint'
|
4
3
|
require 'rack/mock'
|
5
4
|
|
6
5
|
describe Rack::ContentLength do
|
7
|
-
::Enumerator = ::Enumerable::Enumerator unless Object.const_defined?(:Enumerator)
|
8
|
-
|
9
6
|
def content_length(app)
|
10
7
|
Rack::Lint.new Rack::ContentLength.new(app)
|
11
8
|
end
|
12
|
-
|
9
|
+
|
13
10
|
def request
|
14
11
|
Rack::MockRequest.env_for
|
15
12
|
end
|
16
|
-
|
13
|
+
|
17
14
|
should "set Content-Length on Array bodies if none is set" do
|
18
15
|
app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, ["Hello, World!"]] }
|
19
16
|
response = content_length(app).call(request)
|
@@ -81,6 +78,6 @@ describe Rack::ContentLength do
|
|
81
78
|
response = content_length(app).call(request)
|
82
79
|
expected = %w[one two three]
|
83
80
|
response[1]['Content-Length'].should.equal expected.join.size.to_s
|
84
|
-
|
81
|
+
response[2].to_enum.to_a.should.equal expected
|
85
82
|
end
|
86
83
|
end
|
data/test/spec_deflater.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'enumerator'
|
2
1
|
require 'stringio'
|
3
2
|
require 'time' # for Time#httpdate
|
4
3
|
require 'rack/deflater'
|
@@ -7,12 +6,10 @@ require 'rack/mock'
|
|
7
6
|
require 'zlib'
|
8
7
|
|
9
8
|
describe Rack::Deflater do
|
10
|
-
::Enumerator = ::Enumerable::Enumerator unless Object.const_defined?(:Enumerator)
|
11
|
-
|
12
9
|
def deflater(app)
|
13
10
|
Rack::Lint.new Rack::Deflater.new(app)
|
14
11
|
end
|
15
|
-
|
12
|
+
|
16
13
|
def build_response(status, body, accept_encoding, headers = {})
|
17
14
|
body = [body] if body.respond_to? :to_str
|
18
15
|
app = lambda do |env|
|
@@ -129,7 +126,7 @@ describe Rack::Deflater do
|
|
129
126
|
|
130
127
|
response[0].should.equal(200)
|
131
128
|
response[1].should.equal({ "Vary" => "Accept-Encoding", "Content-Type" => "text/plain" })
|
132
|
-
|
129
|
+
response[2].to_enum.to_a.should.equal(["Hello world!"])
|
133
130
|
end
|
134
131
|
|
135
132
|
should "be able to skip when there is no response entity body" do
|
@@ -137,19 +134,19 @@ describe Rack::Deflater do
|
|
137
134
|
|
138
135
|
response[0].should.equal(304)
|
139
136
|
response[1].should.equal({})
|
140
|
-
|
137
|
+
response[2].to_enum.to_a.should.equal([])
|
141
138
|
end
|
142
139
|
|
143
140
|
should "handle the lack of an acceptable encoding" do
|
144
141
|
response1 = build_response(200, "Hello world!", "identity;q=0", "PATH_INFO" => "/")
|
145
142
|
response1[0].should.equal(406)
|
146
143
|
response1[1].should.equal({"Content-Type" => "text/plain", "Content-Length" => "71"})
|
147
|
-
|
144
|
+
response1[2].to_enum.to_a.should.equal(["An acceptable encoding for the requested resource / could not be found."])
|
148
145
|
|
149
146
|
response2 = build_response(200, "Hello world!", "identity;q=0", "SCRIPT_NAME" => "/foo", "PATH_INFO" => "/bar")
|
150
147
|
response2[0].should.equal(406)
|
151
148
|
response2[1].should.equal({"Content-Type" => "text/plain", "Content-Length" => "78"})
|
152
|
-
|
149
|
+
response2[2].to_enum.to_a.should.equal(["An acceptable encoding for the requested resource /foo/bar could not be found."])
|
153
150
|
end
|
154
151
|
|
155
152
|
should "handle gzip response with Last-Modified header" do
|
@@ -182,6 +179,26 @@ describe Rack::Deflater do
|
|
182
179
|
|
183
180
|
response[0].should.equal(200)
|
184
181
|
response[1].should.not.include "Content-Encoding"
|
185
|
-
|
182
|
+
response[2].to_enum.to_a.join.should.equal("Hello World!")
|
183
|
+
end
|
184
|
+
|
185
|
+
should "do nothing when Content-Encoding already present" do
|
186
|
+
app = lambda { |env| [200, {'Content-Type' => 'text/plain', 'Content-Encoding' => 'gzip'}, ['Hello World!']] }
|
187
|
+
request = Rack::MockRequest.env_for("", "HTTP_ACCEPT_ENCODING" => "gzip")
|
188
|
+
response = deflater(app).call(request)
|
189
|
+
|
190
|
+
response[0].should.equal(200)
|
191
|
+
response[2].to_enum.to_a.join.should.equal("Hello World!")
|
192
|
+
end
|
193
|
+
|
194
|
+
should "deflate when Content-Encoding is identity" do
|
195
|
+
app = lambda { |env| [200, {'Content-Type' => 'text/plain', 'Content-Encoding' => 'identity'}, ['Hello World!']] }
|
196
|
+
request = Rack::MockRequest.env_for("", "HTTP_ACCEPT_ENCODING" => "deflate")
|
197
|
+
response = deflater(app).call(request)
|
198
|
+
|
199
|
+
response[0].should.equal(200)
|
200
|
+
buf = ''
|
201
|
+
response[2].each { |part| buf << part }
|
202
|
+
inflate(buf).should.equal("Hello World!")
|
186
203
|
end
|
187
204
|
end
|
data/test/spec_fastcgi.rb
CHANGED
@@ -48,7 +48,7 @@ describe Rack::Handler::FastCGI do
|
|
48
48
|
|
49
49
|
should "have rack headers" do
|
50
50
|
GET("/test.fcgi")
|
51
|
-
response["rack.version"].should.equal [1,
|
51
|
+
response["rack.version"].should.equal [1,2]
|
52
52
|
response["rack.multithread"].should.be.false
|
53
53
|
response["rack.multiprocess"].should.be.true
|
54
54
|
response["rack.run_once"].should.be.false
|
data/test/spec_file.rb
CHANGED
@@ -65,13 +65,13 @@ describe Rack::File do
|
|
65
65
|
should "not allow unsafe directory traversal" do
|
66
66
|
req = Rack::MockRequest.new(file(DOCROOT))
|
67
67
|
|
68
|
-
res = req.get("/../README")
|
68
|
+
res = req.get("/../README.rdoc")
|
69
69
|
res.should.be.client_error
|
70
70
|
|
71
|
-
res = req.get("../test")
|
71
|
+
res = req.get("../test/spec_file.rb")
|
72
72
|
res.should.be.client_error
|
73
73
|
|
74
|
-
res = req.get("
|
74
|
+
res = req.get("../README.rdoc")
|
75
75
|
res.should.be.client_error
|
76
76
|
|
77
77
|
res.should.be.not_found
|
@@ -145,14 +145,6 @@ describe Rack::File do
|
|
145
145
|
res["Content-Range"].should.equal "bytes */193"
|
146
146
|
end
|
147
147
|
|
148
|
-
should "support legacy cache control options provided as string" do
|
149
|
-
env = Rack::MockRequest.env_for("/cgi/test")
|
150
|
-
status, heads, _ = file(DOCROOT, 'public, max-age=38').call(env)
|
151
|
-
|
152
|
-
status.should.equal 200
|
153
|
-
heads['Cache-Control'].should.equal 'public, max-age=38'
|
154
|
-
end
|
155
|
-
|
156
148
|
should "support custom http headers" do
|
157
149
|
env = Rack::MockRequest.env_for("/cgi/test")
|
158
150
|
status, heads, _ = file(DOCROOT, 'Cache-Control' => 'public, max-age=38',
|
@@ -197,4 +189,25 @@ describe Rack::File do
|
|
197
189
|
res['Content-Length'].should.equal "193"
|
198
190
|
end
|
199
191
|
|
192
|
+
should "default to a mime type of text/plain" do
|
193
|
+
req = Rack::MockRequest.new(Rack::Lint.new(Rack::File.new(DOCROOT)))
|
194
|
+
res = req.get "/cgi/test"
|
195
|
+
res.should.be.successful
|
196
|
+
res['Content-Type'].should.equal "text/plain"
|
197
|
+
end
|
198
|
+
|
199
|
+
should "allow the default mime type to be set" do
|
200
|
+
req = Rack::MockRequest.new(Rack::Lint.new(Rack::File.new(DOCROOT, nil, 'application/octet-stream')))
|
201
|
+
res = req.get "/cgi/test"
|
202
|
+
res.should.be.successful
|
203
|
+
res['Content-Type'].should.equal "application/octet-stream"
|
204
|
+
end
|
205
|
+
|
206
|
+
should "not set Content-Type if the mime type is not set" do
|
207
|
+
req = Rack::MockRequest.new(Rack::Lint.new(Rack::File.new(DOCROOT, nil, nil)))
|
208
|
+
res = req.get "/cgi/test"
|
209
|
+
res.should.be.successful
|
210
|
+
res['Content-Type'].should.equal nil
|
211
|
+
end
|
212
|
+
|
200
213
|
end
|
data/test/spec_head.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'enumerator'
|
2
1
|
require 'rack/head'
|
3
2
|
require 'rack/lint'
|
4
3
|
require 'rack/mock'
|
@@ -16,17 +15,13 @@ describe Rack::Head do
|
|
16
15
|
return response, body
|
17
16
|
end
|
18
17
|
|
19
|
-
def enum
|
20
|
-
defined?(Enumerator) ? Enumerator : Enumerable::Enumerator
|
21
|
-
end
|
22
|
-
|
23
18
|
should "pass GET, POST, PUT, DELETE, OPTIONS, TRACE requests" do
|
24
19
|
%w[GET POST PUT DELETE OPTIONS TRACE].each do |type|
|
25
20
|
resp, _ = test_response("REQUEST_METHOD" => type)
|
26
21
|
|
27
22
|
resp[0].should.equal(200)
|
28
23
|
resp[1].should.equal({"Content-type" => "test/plain", "Content-length" => "3"})
|
29
|
-
|
24
|
+
resp[2].to_enum.to_a.should.equal(["foo"])
|
30
25
|
end
|
31
26
|
end
|
32
27
|
|
@@ -35,14 +30,14 @@ describe Rack::Head do
|
|
35
30
|
|
36
31
|
resp[0].should.equal(200)
|
37
32
|
resp[1].should.equal({"Content-type" => "test/plain", "Content-length" => "3"})
|
38
|
-
|
33
|
+
resp[2].to_enum.to_a.should.equal([])
|
39
34
|
end
|
40
35
|
|
41
36
|
should "close the body when it is removed" do
|
42
37
|
resp, body = test_response("REQUEST_METHOD" => "HEAD")
|
43
38
|
resp[0].should.equal(200)
|
44
39
|
resp[1].should.equal({"Content-type" => "test/plain", "Content-length" => "3"})
|
45
|
-
|
40
|
+
resp[2].to_enum.to_a.should.equal([])
|
46
41
|
body.should.be.closed
|
47
42
|
end
|
48
43
|
end
|
data/test/spec_lint.rb
CHANGED
@@ -234,12 +234,12 @@ describe Rack::Lint do
|
|
234
234
|
end
|
235
235
|
|
236
236
|
should "notice content-type errors" do
|
237
|
-
lambda {
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
}.should.raise(Rack::Lint::LintError).
|
242
|
-
|
237
|
+
# lambda {
|
238
|
+
# Rack::Lint.new(lambda { |env|
|
239
|
+
# [200, {"Content-length" => "0"}, []]
|
240
|
+
# }).call(env({}))
|
241
|
+
# }.should.raise(Rack::Lint::LintError).
|
242
|
+
# message.should.match(/No Content-Type/)
|
243
243
|
|
244
244
|
[100, 101, 204, 205, 304].each do |status|
|
245
245
|
lambda {
|
data/test/spec_lock.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'enumerator'
|
2
1
|
require 'rack/lint'
|
3
2
|
require 'rack/lock'
|
4
3
|
require 'rack/mock'
|
@@ -36,13 +35,11 @@ module LockHelpers
|
|
36
35
|
end
|
37
36
|
|
38
37
|
describe Rack::Lock do
|
39
|
-
::Enumerator = ::Enumerable::Enumerator unless Object.const_defined?(:Enumerator)
|
40
|
-
|
41
38
|
extend LockHelpers
|
42
|
-
|
39
|
+
|
43
40
|
describe 'Proxy' do
|
44
41
|
extend LockHelpers
|
45
|
-
|
42
|
+
|
46
43
|
should 'delegate each' do
|
47
44
|
env = Rack::MockRequest.env_for("/")
|
48
45
|
response = Class.new {
|
@@ -115,11 +112,11 @@ describe Rack::Lock do
|
|
115
112
|
env = Rack::MockRequest.env_for("/")
|
116
113
|
body = [200, {"Content-Type" => "text/plain"}, %w{ hi mom }]
|
117
114
|
app = lock_app(lambda { |inner_env| body })
|
118
|
-
|
115
|
+
|
119
116
|
res = app.call(env)
|
120
117
|
res[0].should.equal body[0]
|
121
118
|
res[1].should.equal body[1]
|
122
|
-
|
119
|
+
res[2].to_enum.to_a.should.equal ["hi", "mom"]
|
123
120
|
end
|
124
121
|
|
125
122
|
should "call synchronize on lock" do
|
data/test/spec_methodoverride.rb
CHANGED
@@ -65,7 +65,10 @@ EOF
|
|
65
65
|
"CONTENT_TYPE" => "multipart/form-data, boundary=AaB03x",
|
66
66
|
"CONTENT_LENGTH" => input.size.to_s,
|
67
67
|
:method => "POST", :input => input)
|
68
|
-
|
68
|
+
begin
|
69
|
+
app.call env
|
70
|
+
rescue EOFError
|
71
|
+
end
|
69
72
|
|
70
73
|
env["REQUEST_METHOD"].should.equal "POST"
|
71
74
|
end
|
data/test/spec_mime.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'rack/mime'
|
2
|
+
|
3
|
+
describe Rack::Mime do
|
4
|
+
|
5
|
+
it "should return the fallback mime-type for files with no extension" do
|
6
|
+
fallback = 'image/jpg'
|
7
|
+
Rack::Mime.mime_type(File.extname('no_ext'), fallback).should == fallback
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should always return 'application/octet-stream' for unknown file extensions" do
|
11
|
+
unknown_ext = File.extname('unknown_ext.abcdefg')
|
12
|
+
Rack::Mime.mime_type(unknown_ext).should == 'application/octet-stream'
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should return the mime-type for a given extension" do
|
16
|
+
# sanity check. it would be infeasible test every single mime-type.
|
17
|
+
Rack::Mime.mime_type(File.extname('image.jpg')).should == 'image/jpeg'
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should support null fallbacks" do
|
21
|
+
Rack::Mime.mime_type('.nothing', nil).should == nil
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should match exact mimes" do
|
25
|
+
Rack::Mime.match?('text/html', 'text/html').should == true
|
26
|
+
Rack::Mime.match?('text/html', 'text/meme').should == false
|
27
|
+
Rack::Mime.match?('text', 'text').should == true
|
28
|
+
Rack::Mime.match?('text', 'binary').should == false
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should match class wildcard mimes" do
|
32
|
+
Rack::Mime.match?('text/html', 'text/*').should == true
|
33
|
+
Rack::Mime.match?('text/plain', 'text/*').should == true
|
34
|
+
Rack::Mime.match?('application/json', 'text/*').should == false
|
35
|
+
Rack::Mime.match?('text/html', 'text').should == true
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should match full wildcards" do
|
39
|
+
Rack::Mime.match?('text/html', '*').should == true
|
40
|
+
Rack::Mime.match?('text/plain', '*').should == true
|
41
|
+
Rack::Mime.match?('text/html', '*/*').should == true
|
42
|
+
Rack::Mime.match?('text/plain', '*/*').should == true
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should match type wildcard mimes" do
|
46
|
+
Rack::Mime.match?('text/html', '*/html').should == true
|
47
|
+
Rack::Mime.match?('text/plain', '*/plain').should == true
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
data/test/spec_mongrel.rb
CHANGED
@@ -36,7 +36,7 @@ describe Rack::Handler::Mongrel do
|
|
36
36
|
|
37
37
|
should "have rack headers" do
|
38
38
|
GET("/test")
|
39
|
-
response["rack.version"].should.equal [1,
|
39
|
+
response["rack.version"].should.equal [1,2]
|
40
40
|
response["rack.multithread"].should.be.true
|
41
41
|
response["rack.multiprocess"].should.be.false
|
42
42
|
response["rack.run_once"].should.be.false
|
data/test/spec_multipart.rb
CHANGED
@@ -364,56 +364,22 @@ Content-Type: image/jpeg\r
|
|
364
364
|
end
|
365
365
|
|
366
366
|
it "builds complete params with the chunk size of 16384 slicing exactly on boundary" do
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
:input => StringIO.new(data)
|
376
|
-
}
|
377
|
-
env = Rack::MockRequest.env_for("/", options)
|
378
|
-
params = Rack::Multipart.parse_multipart(env)
|
379
|
-
|
380
|
-
params.should.not.equal nil
|
381
|
-
params.keys.should.include "AAAAAAAAAAAAAAAAAAA"
|
382
|
-
params["AAAAAAAAAAAAAAAAAAA"].keys.should.include "PLAPLAPLA_MEMMEMMEMM_ATTRATTRER"
|
383
|
-
params["AAAAAAAAAAAAAAAAAAA"]["PLAPLAPLA_MEMMEMMEMM_ATTRATTRER"].keys.should.include "new"
|
384
|
-
params["AAAAAAAAAAAAAAAAAAA"]["PLAPLAPLA_MEMMEMMEMM_ATTRATTRER"]["new"].keys.should.include "-2"
|
385
|
-
params["AAAAAAAAAAAAAAAAAAA"]["PLAPLAPLA_MEMMEMMEMM_ATTRATTRER"]["new"]["-2"].keys.should.include "ba_unit_id"
|
386
|
-
params["AAAAAAAAAAAAAAAAAAA"]["PLAPLAPLA_MEMMEMMEMM_ATTRATTRER"]["new"]["-2"]["ba_unit_id"].should.equal "1017"
|
387
|
-
ensure
|
388
|
-
Rack::Utils.multipart_part_limit = previous_limit
|
389
|
-
end
|
390
|
-
end
|
391
|
-
|
392
|
-
should "not reach a multi-part limit" do
|
393
|
-
begin
|
394
|
-
previous_limit = Rack::Utils.multipart_part_limit
|
395
|
-
Rack::Utils.multipart_part_limit = 4
|
396
|
-
|
397
|
-
env = Rack::MockRequest.env_for '/', multipart_fixture(:three_files_three_fields)
|
398
|
-
params = Rack::Multipart.parse_multipart(env)
|
399
|
-
params['reply'].should.equal 'yes'
|
400
|
-
params['to'].should.equal 'people'
|
401
|
-
params['from'].should.equal 'others'
|
402
|
-
ensure
|
403
|
-
Rack::Utils.multipart_part_limit = previous_limit
|
404
|
-
end
|
405
|
-
end
|
406
|
-
|
407
|
-
should "reach a multipart limit" do
|
408
|
-
begin
|
409
|
-
previous_limit = Rack::Utils.multipart_part_limit
|
410
|
-
Rack::Utils.multipart_part_limit = 3
|
367
|
+
data = File.open(multipart_file("fail_16384_nofile")) { |f| f.read }.gsub(/\n/, "\r\n")
|
368
|
+
options = {
|
369
|
+
"CONTENT_TYPE" => "multipart/form-data; boundary=----WebKitFormBoundaryWsY0GnpbI5U7ztzo",
|
370
|
+
"CONTENT_LENGTH" => data.length.to_s,
|
371
|
+
:input => StringIO.new(data)
|
372
|
+
}
|
373
|
+
env = Rack::MockRequest.env_for("/", options)
|
374
|
+
params = Rack::Multipart.parse_multipart(env)
|
411
375
|
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
376
|
+
params.should.not.equal nil
|
377
|
+
params.keys.should.include "AAAAAAAAAAAAAAAAAAA"
|
378
|
+
params["AAAAAAAAAAAAAAAAAAA"].keys.should.include "PLAPLAPLA_MEMMEMMEMM_ATTRATTRER"
|
379
|
+
params["AAAAAAAAAAAAAAAAAAA"]["PLAPLAPLA_MEMMEMMEMM_ATTRATTRER"].keys.should.include "new"
|
380
|
+
params["AAAAAAAAAAAAAAAAAAA"]["PLAPLAPLA_MEMMEMMEMM_ATTRATTRER"]["new"].keys.should.include "-2"
|
381
|
+
params["AAAAAAAAAAAAAAAAAAA"]["PLAPLAPLA_MEMMEMMEMM_ATTRATTRER"]["new"]["-2"].keys.should.include "ba_unit_id"
|
382
|
+
params["AAAAAAAAAAAAAAAAAAA"]["PLAPLAPLA_MEMMEMMEMM_ATTRATTRER"]["new"]["-2"]["ba_unit_id"].should.equal "1017"
|
417
383
|
end
|
418
384
|
|
419
385
|
should "return nil if no UploadedFiles were used" do
|