rack 2.0.9.3 → 3.0.0

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.

Files changed (201) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +808 -0
  3. data/CONTRIBUTING.md +142 -0
  4. data/{COPYING → MIT-LICENSE} +4 -2
  5. data/README.md +293 -0
  6. data/SPEC.rdoc +340 -0
  7. data/lib/rack/auth/abstract/handler.rb +6 -2
  8. data/lib/rack/auth/abstract/request.rb +4 -2
  9. data/lib/rack/auth/basic.rb +7 -4
  10. data/lib/rack/auth/digest/md5.rb +1 -129
  11. data/lib/rack/auth/digest/nonce.rb +1 -51
  12. data/lib/rack/auth/digest/params.rb +1 -52
  13. data/lib/rack/auth/digest/request.rb +1 -41
  14. data/lib/rack/auth/digest.rb +256 -0
  15. data/lib/rack/body_proxy.rb +18 -15
  16. data/lib/rack/builder.rb +151 -40
  17. data/lib/rack/cascade.rb +30 -12
  18. data/lib/rack/chunked.rb +74 -23
  19. data/lib/rack/common_logger.rb +49 -36
  20. data/lib/rack/conditional_get.rb +33 -26
  21. data/lib/rack/config.rb +2 -0
  22. data/lib/rack/constants.rb +63 -0
  23. data/lib/rack/content_length.rb +13 -16
  24. data/lib/rack/content_type.rb +12 -8
  25. data/lib/rack/deflater.rb +84 -45
  26. data/lib/rack/directory.rb +90 -64
  27. data/lib/rack/etag.rb +17 -23
  28. data/lib/rack/events.rb +23 -20
  29. data/lib/rack/file.rb +5 -172
  30. data/lib/rack/files.rb +216 -0
  31. data/lib/rack/head.rb +10 -9
  32. data/lib/rack/headers.rb +154 -0
  33. data/lib/rack/lint.rb +786 -645
  34. data/lib/rack/lock.rb +4 -6
  35. data/lib/rack/logger.rb +4 -0
  36. data/lib/rack/media_type.rb +10 -5
  37. data/lib/rack/method_override.rb +8 -2
  38. data/lib/rack/mime.rb +17 -1
  39. data/lib/rack/mock.rb +2 -195
  40. data/lib/rack/mock_request.rb +166 -0
  41. data/lib/rack/mock_response.rb +126 -0
  42. data/lib/rack/multipart/generator.rb +21 -15
  43. data/lib/rack/multipart/parser.rb +161 -118
  44. data/lib/rack/multipart/uploaded_file.rb +19 -7
  45. data/lib/rack/multipart.rb +23 -41
  46. data/lib/rack/null_logger.rb +11 -0
  47. data/lib/rack/query_parser.rb +126 -65
  48. data/lib/rack/recursive.rb +9 -5
  49. data/lib/rack/reloader.rb +6 -4
  50. data/lib/rack/request.rb +331 -74
  51. data/lib/rack/response.rb +223 -70
  52. data/lib/rack/rewindable_input.rb +28 -8
  53. data/lib/rack/runtime.rb +11 -8
  54. data/lib/rack/sendfile.rb +42 -33
  55. data/lib/rack/show_exceptions.rb +35 -18
  56. data/lib/rack/show_status.rb +25 -15
  57. data/lib/rack/static.rb +30 -18
  58. data/lib/rack/tempfile_reaper.rb +16 -5
  59. data/lib/rack/urlmap.rb +14 -6
  60. data/lib/rack/utils.rb +268 -260
  61. data/lib/rack/version.rb +34 -0
  62. data/lib/rack.rb +15 -92
  63. metadata +44 -207
  64. data/HISTORY.md +0 -520
  65. data/README.rdoc +0 -316
  66. data/Rakefile +0 -116
  67. data/SPEC +0 -263
  68. data/bin/rackup +0 -4
  69. data/contrib/rack.png +0 -0
  70. data/contrib/rack.svg +0 -150
  71. data/contrib/rack_logo.svg +0 -164
  72. data/contrib/rdoc.css +0 -412
  73. data/example/lobster.ru +0 -4
  74. data/example/protectedlobster.rb +0 -14
  75. data/example/protectedlobster.ru +0 -8
  76. data/lib/rack/handler/cgi.rb +0 -60
  77. data/lib/rack/handler/fastcgi.rb +0 -100
  78. data/lib/rack/handler/lsws.rb +0 -61
  79. data/lib/rack/handler/scgi.rb +0 -70
  80. data/lib/rack/handler/thin.rb +0 -36
  81. data/lib/rack/handler/webrick.rb +0 -120
  82. data/lib/rack/handler.rb +0 -99
  83. data/lib/rack/lobster.rb +0 -70
  84. data/lib/rack/server.rb +0 -395
  85. data/lib/rack/session/abstract/id.rb +0 -510
  86. data/lib/rack/session/cookie.rb +0 -204
  87. data/lib/rack/session/memcache.rb +0 -99
  88. data/lib/rack/session/pool.rb +0 -83
  89. data/rack.gemspec +0 -34
  90. data/test/builder/an_underscore_app.rb +0 -5
  91. data/test/builder/anything.rb +0 -5
  92. data/test/builder/comment.ru +0 -4
  93. data/test/builder/end.ru +0 -5
  94. data/test/builder/line.ru +0 -1
  95. data/test/builder/options.ru +0 -2
  96. data/test/cgi/assets/folder/test.js +0 -1
  97. data/test/cgi/assets/fonts/font.eot +0 -1
  98. data/test/cgi/assets/images/image.png +0 -1
  99. data/test/cgi/assets/index.html +0 -1
  100. data/test/cgi/assets/javascripts/app.js +0 -1
  101. data/test/cgi/assets/stylesheets/app.css +0 -1
  102. data/test/cgi/lighttpd.conf +0 -26
  103. data/test/cgi/rackup_stub.rb +0 -6
  104. data/test/cgi/sample_rackup.ru +0 -5
  105. data/test/cgi/test +0 -9
  106. data/test/cgi/test+directory/test+file +0 -1
  107. data/test/cgi/test.fcgi +0 -9
  108. data/test/cgi/test.gz +0 -0
  109. data/test/cgi/test.ru +0 -5
  110. data/test/gemloader.rb +0 -10
  111. data/test/helper.rb +0 -34
  112. data/test/multipart/bad_robots +0 -259
  113. data/test/multipart/binary +0 -0
  114. data/test/multipart/content_type_and_no_filename +0 -6
  115. data/test/multipart/empty +0 -10
  116. data/test/multipart/fail_16384_nofile +0 -814
  117. data/test/multipart/file1.txt +0 -1
  118. data/test/multipart/filename_and_modification_param +0 -7
  119. data/test/multipart/filename_and_no_name +0 -6
  120. data/test/multipart/filename_with_encoded_words +0 -7
  121. data/test/multipart/filename_with_escaped_quotes +0 -6
  122. data/test/multipart/filename_with_escaped_quotes_and_modification_param +0 -7
  123. data/test/multipart/filename_with_null_byte +0 -7
  124. data/test/multipart/filename_with_percent_escaped_quotes +0 -6
  125. data/test/multipart/filename_with_single_quote +0 -7
  126. data/test/multipart/filename_with_unescaped_percentages +0 -6
  127. data/test/multipart/filename_with_unescaped_percentages2 +0 -6
  128. data/test/multipart/filename_with_unescaped_percentages3 +0 -6
  129. data/test/multipart/filename_with_unescaped_quotes +0 -6
  130. data/test/multipart/ie +0 -6
  131. data/test/multipart/invalid_character +0 -6
  132. data/test/multipart/mixed_files +0 -21
  133. data/test/multipart/nested +0 -10
  134. data/test/multipart/none +0 -9
  135. data/test/multipart/quoted +0 -15
  136. data/test/multipart/rack-logo.png +0 -0
  137. data/test/multipart/semicolon +0 -6
  138. data/test/multipart/text +0 -15
  139. data/test/multipart/three_files_three_fields +0 -31
  140. data/test/multipart/unity3d_wwwform +0 -11
  141. data/test/multipart/webkit +0 -32
  142. data/test/rackup/config.ru +0 -31
  143. data/test/registering_handler/rack/handler/registering_myself.rb +0 -8
  144. data/test/spec_auth_basic.rb +0 -89
  145. data/test/spec_auth_digest.rb +0 -260
  146. data/test/spec_body_proxy.rb +0 -85
  147. data/test/spec_builder.rb +0 -233
  148. data/test/spec_cascade.rb +0 -63
  149. data/test/spec_cgi.rb +0 -84
  150. data/test/spec_chunked.rb +0 -103
  151. data/test/spec_common_logger.rb +0 -107
  152. data/test/spec_conditional_get.rb +0 -103
  153. data/test/spec_config.rb +0 -23
  154. data/test/spec_content_length.rb +0 -86
  155. data/test/spec_content_type.rb +0 -46
  156. data/test/spec_deflater.rb +0 -375
  157. data/test/spec_directory.rb +0 -148
  158. data/test/spec_etag.rb +0 -108
  159. data/test/spec_events.rb +0 -133
  160. data/test/spec_fastcgi.rb +0 -85
  161. data/test/spec_file.rb +0 -264
  162. data/test/spec_handler.rb +0 -57
  163. data/test/spec_head.rb +0 -46
  164. data/test/spec_lint.rb +0 -520
  165. data/test/spec_lobster.rb +0 -59
  166. data/test/spec_lock.rb +0 -204
  167. data/test/spec_logger.rb +0 -24
  168. data/test/spec_media_type.rb +0 -42
  169. data/test/spec_method_override.rb +0 -110
  170. data/test/spec_mime.rb +0 -51
  171. data/test/spec_mock.rb +0 -359
  172. data/test/spec_multipart.rb +0 -721
  173. data/test/spec_null_logger.rb +0 -21
  174. data/test/spec_recursive.rb +0 -75
  175. data/test/spec_request.rb +0 -1423
  176. data/test/spec_response.rb +0 -528
  177. data/test/spec_rewindable_input.rb +0 -128
  178. data/test/spec_runtime.rb +0 -50
  179. data/test/spec_sendfile.rb +0 -125
  180. data/test/spec_server.rb +0 -193
  181. data/test/spec_session_abstract_id.rb +0 -31
  182. data/test/spec_session_abstract_session_hash.rb +0 -45
  183. data/test/spec_session_cookie.rb +0 -442
  184. data/test/spec_session_memcache.rb +0 -357
  185. data/test/spec_session_persisted_secure_secure_session_hash.rb +0 -73
  186. data/test/spec_session_pool.rb +0 -247
  187. data/test/spec_show_exceptions.rb +0 -93
  188. data/test/spec_show_status.rb +0 -104
  189. data/test/spec_static.rb +0 -184
  190. data/test/spec_tempfile_reaper.rb +0 -64
  191. data/test/spec_thin.rb +0 -96
  192. data/test/spec_urlmap.rb +0 -237
  193. data/test/spec_utils.rb +0 -742
  194. data/test/spec_version.rb +0 -11
  195. data/test/spec_webrick.rb +0 -206
  196. data/test/static/another/index.html +0 -1
  197. data/test/static/foo.html +0 -1
  198. data/test/static/index.html +0 -1
  199. data/test/testrequest.rb +0 -78
  200. data/test/unregistered_handler/rack/handler/unregistered.rb +0 -7
  201. data/test/unregistered_handler/rack/handler/unregistered_long_one.rb +0 -7
data/test/spec_lock.rb DELETED
@@ -1,204 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'rack/lint'
3
- require 'rack/lock'
4
- require 'rack/mock'
5
-
6
- class Lock
7
- attr_reader :synchronized
8
-
9
- def initialize
10
- @synchronized = false
11
- end
12
-
13
- def lock
14
- @synchronized = true
15
- end
16
-
17
- def unlock
18
- @synchronized = false
19
- end
20
- end
21
-
22
- module LockHelpers
23
- def lock_app(app, lock = Lock.new)
24
- app = if lock
25
- Rack::Lock.new app, lock
26
- else
27
- Rack::Lock.new app
28
- end
29
- Rack::Lint.new app
30
- end
31
- end
32
-
33
- describe Rack::Lock do
34
- include LockHelpers
35
-
36
- describe 'Proxy' do
37
- include LockHelpers
38
-
39
- it 'delegate each' do
40
- env = Rack::MockRequest.env_for("/")
41
- response = Class.new {
42
- attr_accessor :close_called
43
- def initialize; @close_called = false; end
44
- def each; %w{ hi mom }.each { |x| yield x }; end
45
- }.new
46
-
47
- app = lock_app(lambda { |inner_env| [200, {"Content-Type" => "text/plain"}, response] })
48
- response = app.call(env)[2]
49
- list = []
50
- response.each { |x| list << x }
51
- list.must_equal %w{ hi mom }
52
- end
53
-
54
- it 'delegate to_path' do
55
- lock = Lock.new
56
- env = Rack::MockRequest.env_for("/")
57
-
58
- res = ['Hello World']
59
- def res.to_path ; "/tmp/hello.txt" ; end
60
-
61
- app = Rack::Lock.new(lambda { |inner_env| [200, {"Content-Type" => "text/plain"}, res] }, lock)
62
- body = app.call(env)[2]
63
-
64
- body.must_respond_to :to_path
65
- body.to_path.must_equal "/tmp/hello.txt"
66
- end
67
-
68
- it 'not delegate to_path if body does not implement it' do
69
- env = Rack::MockRequest.env_for("/")
70
-
71
- res = ['Hello World']
72
-
73
- app = lock_app(lambda { |inner_env| [200, {"Content-Type" => "text/plain"}, res] })
74
- body = app.call(env)[2]
75
-
76
- body.wont_respond_to :to_path
77
- end
78
- end
79
-
80
- it 'call super on close' do
81
- env = Rack::MockRequest.env_for("/")
82
- response = Class.new {
83
- attr_accessor :close_called
84
- def initialize; @close_called = false; end
85
- def close; @close_called = true; end
86
- }.new
87
-
88
- app = lock_app(lambda { |inner_env| [200, {"Content-Type" => "text/plain"}, response] })
89
- app.call(env)
90
- response.close_called.must_equal false
91
- response.close
92
- response.close_called.must_equal true
93
- end
94
-
95
- it "not unlock until body is closed" do
96
- lock = Lock.new
97
- env = Rack::MockRequest.env_for("/")
98
- response = Object.new
99
- app = lock_app(lambda { |inner_env| [200, {"Content-Type" => "text/plain"}, response] }, lock)
100
- lock.synchronized.must_equal false
101
- response = app.call(env)[2]
102
- lock.synchronized.must_equal true
103
- response.close
104
- lock.synchronized.must_equal false
105
- end
106
-
107
- it "return value from app" do
108
- env = Rack::MockRequest.env_for("/")
109
- body = [200, {"Content-Type" => "text/plain"}, %w{ hi mom }]
110
- app = lock_app(lambda { |inner_env| body })
111
-
112
- res = app.call(env)
113
- res[0].must_equal body[0]
114
- res[1].must_equal body[1]
115
- res[2].to_enum.to_a.must_equal ["hi", "mom"]
116
- end
117
-
118
- it "call synchronize on lock" do
119
- lock = Lock.new
120
- env = Rack::MockRequest.env_for("/")
121
- app = lock_app(lambda { |inner_env| [200, {"Content-Type" => "text/plain"}, %w{ a b c }] }, lock)
122
- lock.synchronized.must_equal false
123
- app.call(env)
124
- lock.synchronized.must_equal true
125
- end
126
-
127
- it "unlock if the app raises" do
128
- lock = Lock.new
129
- env = Rack::MockRequest.env_for("/")
130
- app = lock_app(lambda { raise Exception }, lock)
131
- lambda { app.call(env) }.must_raise Exception
132
- lock.synchronized.must_equal false
133
- end
134
-
135
- it "unlock if the app throws" do
136
- lock = Lock.new
137
- env = Rack::MockRequest.env_for("/")
138
- app = lock_app(lambda {|_| throw :bacon }, lock)
139
- lambda { app.call(env) }.must_throw :bacon
140
- lock.synchronized.must_equal false
141
- end
142
-
143
- it "set multithread flag to false" do
144
- app = lock_app(lambda { |env|
145
- env['rack.multithread'].must_equal false
146
- [200, {"Content-Type" => "text/plain"}, %w{ a b c }]
147
- }, false)
148
- env = Rack::MockRequest.env_for("/")
149
- env['rack.multithread'].must_equal true
150
- _, _, body = app.call(env)
151
- body.close
152
- env['rack.multithread'].must_equal true
153
- end
154
-
155
- it "reset original multithread flag when exiting lock" do
156
- app = Class.new(Rack::Lock) {
157
- def call(env)
158
- env['rack.multithread'].must_equal true
159
- super
160
- end
161
- }.new(lambda { |env| [200, {"Content-Type" => "text/plain"}, %w{ a b c }] })
162
- Rack::Lint.new(app).call(Rack::MockRequest.env_for("/"))
163
- end
164
-
165
- it 'not unlock if an error is raised before the mutex is locked' do
166
- lock = Class.new do
167
- def initialize() @unlocked = false end
168
- def unlocked?() @unlocked end
169
- def lock() raise Exception end
170
- def unlock() @unlocked = true end
171
- end.new
172
- env = Rack::MockRequest.env_for("/")
173
- app = lock_app(proc { [200, {"Content-Type" => "text/plain"}, []] }, lock)
174
- lambda { app.call(env) }.must_raise Exception
175
- lock.unlocked?.must_equal false
176
- end
177
-
178
- it "not reset the environment while the body is proxied" do
179
- proxy = Class.new do
180
- attr_reader :env
181
- def initialize(env) @env = env end
182
- end
183
- app = Rack::Lock.new lambda { |env| [200, {"Content-Type" => "text/plain"}, proxy.new(env)] }
184
- response = app.call(Rack::MockRequest.env_for("/"))[2]
185
- response.env['rack.multithread'].must_equal false
186
- end
187
-
188
- it "unlock if an exception occurs before returning" do
189
- lock = Lock.new
190
- env = Rack::MockRequest.env_for("/")
191
- app = lock_app(proc { [].freeze }, lock)
192
- lambda { app.call(env) }.must_raise Exception
193
- lock.synchronized.must_equal false
194
- end
195
-
196
- it "not replace the environment" do
197
- env = Rack::MockRequest.env_for("/")
198
- app = lock_app(lambda { |inner_env| [200, {"Content-Type" => "text/plain"}, [inner_env.object_id.to_s]] })
199
-
200
- _, _, body = app.call(env)
201
-
202
- body.to_enum.to_a.must_equal [env.object_id.to_s]
203
- end
204
- end
data/test/spec_logger.rb DELETED
@@ -1,24 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'stringio'
3
- require 'rack/lint'
4
- require 'rack/logger'
5
- require 'rack/mock'
6
-
7
- describe Rack::Logger do
8
- app = lambda { |env|
9
- log = env['rack.logger']
10
- log.debug("Created logger")
11
- log.info("Program started")
12
- log.warn("Nothing to do!")
13
-
14
- [200, {'Content-Type' => 'text/plain'}, ["Hello, World!"]]
15
- }
16
-
17
- it "conform to Rack::Lint" do
18
- errors = StringIO.new
19
- a = Rack::Lint.new(Rack::Logger.new(app))
20
- Rack::MockRequest.new(a).get('/', 'rack.errors' => errors)
21
- errors.string.must_match(/INFO -- : Program started/)
22
- errors.string.must_match(/WARN -- : Nothing to do/)
23
- end
24
- end
@@ -1,42 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'rack/media_type'
3
-
4
- describe Rack::MediaType do
5
- before { @empty_hash = {} }
6
-
7
- describe 'when content_type nil' do
8
- before { @content_type = nil }
9
-
10
- it '#type is nil' do
11
- Rack::MediaType.type(@content_type).must_be_nil
12
- end
13
-
14
- it '#params is empty' do
15
- Rack::MediaType.params(@content_type).must_equal @empty_hash
16
- end
17
- end
18
-
19
- describe 'when content_type contains only media_type' do
20
- before { @content_type = 'application/text' }
21
-
22
- it '#type is application/text' do
23
- Rack::MediaType.type(@content_type).must_equal 'application/text'
24
- end
25
-
26
- it '#params is empty' do
27
- Rack::MediaType.params(@content_type).must_equal @empty_hash
28
- end
29
- end
30
-
31
- describe 'when content_type contains media_type and params' do
32
- before { @content_type = 'application/text;CHARSET="utf-8"' }
33
-
34
- it '#type is application/text' do
35
- Rack::MediaType.type(@content_type).must_equal 'application/text'
36
- end
37
-
38
- it '#params has key "charset" with value "utf-8"' do
39
- Rack::MediaType.params(@content_type)['charset'].must_equal 'utf-8'
40
- end
41
- end
42
- end
@@ -1,110 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'stringio'
3
- require 'rack/method_override'
4
- require 'rack/mock'
5
-
6
- describe Rack::MethodOverride do
7
- def app
8
- Rack::Lint.new(Rack::MethodOverride.new(lambda {|e|
9
- [200, {"Content-Type" => "text/plain"}, []]
10
- }))
11
- end
12
-
13
- it "not affect GET requests" do
14
- env = Rack::MockRequest.env_for("/?_method=delete", :method => "GET")
15
- app.call env
16
-
17
- env["REQUEST_METHOD"].must_equal "GET"
18
- end
19
-
20
- it "sets rack.errors for invalid UTF8 _method values" do
21
- errors = StringIO.new
22
- env = Rack::MockRequest.env_for("/",
23
- :method => "POST",
24
- :input => "_method=\xBF".b,
25
- Rack::RACK_ERRORS => errors)
26
-
27
- app.call env
28
-
29
- errors.rewind
30
- errors.read.must_equal "Invalid string for method\n"
31
- env["REQUEST_METHOD"].must_equal "POST"
32
- end
33
-
34
- it "modify REQUEST_METHOD for POST requests when _method parameter is set" do
35
- env = Rack::MockRequest.env_for("/", :method => "POST", :input => "_method=put")
36
- app.call env
37
-
38
- env["REQUEST_METHOD"].must_equal "PUT"
39
- end
40
-
41
- it "modify REQUEST_METHOD for POST requests when X-HTTP-Method-Override is set" do
42
- env = Rack::MockRequest.env_for("/",
43
- :method => "POST",
44
- "HTTP_X_HTTP_METHOD_OVERRIDE" => "PATCH"
45
- )
46
- app.call env
47
-
48
- env["REQUEST_METHOD"].must_equal "PATCH"
49
- end
50
-
51
- it "not modify REQUEST_METHOD if the method is unknown" do
52
- env = Rack::MockRequest.env_for("/", :method => "POST", :input => "_method=foo")
53
- app.call env
54
-
55
- env["REQUEST_METHOD"].must_equal "POST"
56
- end
57
-
58
- it "not modify REQUEST_METHOD when _method is nil" do
59
- env = Rack::MockRequest.env_for("/", :method => "POST", :input => "foo=bar")
60
- app.call env
61
-
62
- env["REQUEST_METHOD"].must_equal "POST"
63
- end
64
-
65
- it "store the original REQUEST_METHOD prior to overriding" do
66
- env = Rack::MockRequest.env_for("/",
67
- :method => "POST",
68
- :input => "_method=options")
69
- app.call env
70
-
71
- env["rack.methodoverride.original_method"].must_equal "POST"
72
- end
73
-
74
- it "not modify REQUEST_METHOD when given invalid multipart form data" do
75
- input = <<EOF
76
- --AaB03x\r
77
- content-disposition: form-data; name="huge"; filename="huge"\r
78
- EOF
79
- env = Rack::MockRequest.env_for("/",
80
- "CONTENT_TYPE" => "multipart/form-data, boundary=AaB03x",
81
- "CONTENT_LENGTH" => input.size.to_s,
82
- :method => "POST", :input => input)
83
- app.call env
84
-
85
- env["REQUEST_METHOD"].must_equal "POST"
86
- end
87
-
88
- it "writes error to RACK_ERRORS when given invalid multipart form data" do
89
- input = <<EOF
90
- --AaB03x\r
91
- content-disposition: form-data; name="huge"; filename="huge"\r
92
- EOF
93
- env = Rack::MockRequest.env_for("/",
94
- "CONTENT_TYPE" => "multipart/form-data, boundary=AaB03x",
95
- "CONTENT_LENGTH" => input.size.to_s,
96
- Rack::RACK_ERRORS => StringIO.new,
97
- :method => "POST", :input => input)
98
- Rack::MethodOverride.new(proc { [200, {"Content-Type" => "text/plain"}, []] }).call env
99
-
100
- env[Rack::RACK_ERRORS].rewind
101
- env[Rack::RACK_ERRORS].read.must_match /Bad request content body/
102
- end
103
-
104
- it "not modify REQUEST_METHOD for POST requests when the params are unparseable" do
105
- env = Rack::MockRequest.env_for("/", :method => "POST", :input => "(%bad-params%)")
106
- app.call env
107
-
108
- env["REQUEST_METHOD"].must_equal "POST"
109
- end
110
- end
data/test/spec_mime.rb DELETED
@@ -1,51 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'rack/mime'
3
-
4
- describe Rack::Mime do
5
-
6
- it "should return the fallback mime-type for files with no extension" do
7
- fallback = 'image/jpg'
8
- Rack::Mime.mime_type(File.extname('no_ext'), fallback).must_equal fallback
9
- end
10
-
11
- it "should always return 'application/octet-stream' for unknown file extensions" do
12
- unknown_ext = File.extname('unknown_ext.abcdefg')
13
- Rack::Mime.mime_type(unknown_ext).must_equal 'application/octet-stream'
14
- end
15
-
16
- it "should return the mime-type for a given extension" do
17
- # sanity check. it would be infeasible test every single mime-type.
18
- Rack::Mime.mime_type(File.extname('image.jpg')).must_equal 'image/jpeg'
19
- end
20
-
21
- it "should support null fallbacks" do
22
- Rack::Mime.mime_type('.nothing', nil).must_be_nil
23
- end
24
-
25
- it "should match exact mimes" do
26
- Rack::Mime.match?('text/html', 'text/html').must_equal true
27
- Rack::Mime.match?('text/html', 'text/meme').must_equal false
28
- Rack::Mime.match?('text', 'text').must_equal true
29
- Rack::Mime.match?('text', 'binary').must_equal false
30
- end
31
-
32
- it "should match class wildcard mimes" do
33
- Rack::Mime.match?('text/html', 'text/*').must_equal true
34
- Rack::Mime.match?('text/plain', 'text/*').must_equal true
35
- Rack::Mime.match?('application/json', 'text/*').must_equal false
36
- Rack::Mime.match?('text/html', 'text').must_equal true
37
- end
38
-
39
- it "should match full wildcards" do
40
- Rack::Mime.match?('text/html', '*').must_equal true
41
- Rack::Mime.match?('text/plain', '*').must_equal true
42
- Rack::Mime.match?('text/html', '*/*').must_equal true
43
- Rack::Mime.match?('text/plain', '*/*').must_equal true
44
- end
45
-
46
- it "should match type wildcard mimes" do
47
- Rack::Mime.match?('text/html', '*/html').must_equal true
48
- Rack::Mime.match?('text/plain', '*/plain').must_equal true
49
- end
50
-
51
- end