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/lib/rack/server.rb DELETED
@@ -1,395 +0,0 @@
1
- require 'optparse'
2
- require 'fileutils'
3
-
4
-
5
- module Rack
6
-
7
- class Server
8
-
9
- class Options
10
- def parse!(args)
11
- options = {}
12
- opt_parser = OptionParser.new("", 24, ' ') do |opts|
13
- opts.banner = "Usage: rackup [ruby options] [rack options] [rackup config]"
14
-
15
- opts.separator ""
16
- opts.separator "Ruby options:"
17
-
18
- lineno = 1
19
- opts.on("-e", "--eval LINE", "evaluate a LINE of code") { |line|
20
- eval line, TOPLEVEL_BINDING, "-e", lineno
21
- lineno += 1
22
- }
23
-
24
- opts.on("-b", "--builder BUILDER_LINE", "evaluate a BUILDER_LINE of code as a builder script") { |line|
25
- options[:builder] = line
26
- }
27
-
28
- opts.on("-d", "--debug", "set debugging flags (set $DEBUG to true)") {
29
- options[:debug] = true
30
- }
31
- opts.on("-w", "--warn", "turn warnings on for your script") {
32
- options[:warn] = true
33
- }
34
- opts.on("-q", "--quiet", "turn off logging") {
35
- options[:quiet] = true
36
- }
37
-
38
- opts.on("-I", "--include PATH",
39
- "specify $LOAD_PATH (may be used more than once)") { |path|
40
- (options[:include] ||= []).concat(path.split(":"))
41
- }
42
-
43
- opts.on("-r", "--require LIBRARY",
44
- "require the library, before executing your script") { |library|
45
- options[:require] = library
46
- }
47
-
48
- opts.separator ""
49
- opts.separator "Rack options:"
50
- opts.on("-s", "--server SERVER", "serve using SERVER (thin/puma/webrick/mongrel)") { |s|
51
- options[:server] = s
52
- }
53
-
54
- opts.on("-o", "--host HOST", "listen on HOST (default: localhost)") { |host|
55
- options[:Host] = host
56
- }
57
-
58
- opts.on("-p", "--port PORT", "use PORT (default: 9292)") { |port|
59
- options[:Port] = port
60
- }
61
-
62
- opts.on("-O", "--option NAME[=VALUE]", "pass VALUE to the server as option NAME. If no VALUE, sets it to true. Run '#{$0} -s SERVER -h' to get a list of options for SERVER") { |name|
63
- name, value = name.split('=', 2)
64
- value = true if value.nil?
65
- options[name.to_sym] = value
66
- }
67
-
68
- opts.on("-E", "--env ENVIRONMENT", "use ENVIRONMENT for defaults (default: development)") { |e|
69
- options[:environment] = e
70
- }
71
-
72
- opts.on("-D", "--daemonize", "run daemonized in the background") { |d|
73
- options[:daemonize] = d ? true : false
74
- }
75
-
76
- opts.on("-P", "--pid FILE", "file to store PID") { |f|
77
- options[:pid] = ::File.expand_path(f)
78
- }
79
-
80
- opts.separator ""
81
- opts.separator "Common options:"
82
-
83
- opts.on_tail("-h", "-?", "--help", "Show this message") do
84
- puts opts
85
- puts handler_opts(options)
86
-
87
- exit
88
- end
89
-
90
- opts.on_tail("--version", "Show version") do
91
- puts "Rack #{Rack.version} (Release: #{Rack.release})"
92
- exit
93
- end
94
- end
95
-
96
- begin
97
- opt_parser.parse! args
98
- rescue OptionParser::InvalidOption => e
99
- warn e.message
100
- abort opt_parser.to_s
101
- end
102
-
103
- options[:config] = args.last if args.last && !args.last.empty?
104
- options
105
- end
106
-
107
- def handler_opts(options)
108
- begin
109
- info = []
110
- server = Rack::Handler.get(options[:server]) || Rack::Handler.default
111
- if server && server.respond_to?(:valid_options)
112
- info << ""
113
- info << "Server-specific options for #{server.name}:"
114
-
115
- has_options = false
116
- server.valid_options.each do |name, description|
117
- next if name.to_s.match(/^(Host|Port)[^a-zA-Z]/) # ignore handler's host and port options, we do our own.
118
- info << " -O %-21s %s" % [name, description]
119
- has_options = true
120
- end
121
- return "" if !has_options
122
- end
123
- info.join("\n")
124
- rescue NameError
125
- return "Warning: Could not find handler specified (#{options[:server] || 'default'}) to determine handler-specific options"
126
- end
127
- end
128
- end
129
-
130
- # Start a new rack server (like running rackup). This will parse ARGV and
131
- # provide standard ARGV rackup options, defaulting to load 'config.ru'.
132
- #
133
- # Providing an options hash will prevent ARGV parsing and will not include
134
- # any default options.
135
- #
136
- # This method can be used to very easily launch a CGI application, for
137
- # example:
138
- #
139
- # Rack::Server.start(
140
- # :app => lambda do |e|
141
- # [200, {'Content-Type' => 'text/html'}, ['hello world']]
142
- # end,
143
- # :server => 'cgi'
144
- # )
145
- #
146
- # Further options available here are documented on Rack::Server#initialize
147
- def self.start(options = nil)
148
- new(options).start
149
- end
150
-
151
- attr_writer :options
152
-
153
- # Options may include:
154
- # * :app
155
- # a rack application to run (overrides :config)
156
- # * :config
157
- # a rackup configuration file path to load (.ru)
158
- # * :environment
159
- # this selects the middleware that will be wrapped around
160
- # your application. Default options available are:
161
- # - development: CommonLogger, ShowExceptions, and Lint
162
- # - deployment: CommonLogger
163
- # - none: no extra middleware
164
- # note: when the server is a cgi server, CommonLogger is not included.
165
- # * :server
166
- # choose a specific Rack::Handler, e.g. cgi, fcgi, webrick
167
- # * :daemonize
168
- # if true, the server will daemonize itself (fork, detach, etc)
169
- # * :pid
170
- # path to write a pid file after daemonize
171
- # * :Host
172
- # the host address to bind to (used by supporting Rack::Handler)
173
- # * :Port
174
- # the port to bind to (used by supporting Rack::Handler)
175
- # * :AccessLog
176
- # webrick access log options (or supporting Rack::Handler)
177
- # * :debug
178
- # turn on debug output ($DEBUG = true)
179
- # * :warn
180
- # turn on warnings ($-w = true)
181
- # * :include
182
- # add given paths to $LOAD_PATH
183
- # * :require
184
- # require the given libraries
185
- def initialize(options = nil)
186
- @ignore_options = []
187
-
188
- if options
189
- @use_default_options = false
190
- @options = options
191
- @app = options[:app] if options[:app]
192
- else
193
- argv = defined?(SPEC_ARGV) ? SPEC_ARGV : ARGV
194
- @use_default_options = true
195
- @options = parse_options(argv)
196
- end
197
- end
198
-
199
- def options
200
- merged_options = @use_default_options ? default_options.merge(@options) : @options
201
- merged_options.reject { |k, v| @ignore_options.include?(k) }
202
- end
203
-
204
- def default_options
205
- environment = ENV['RACK_ENV'] || 'development'
206
- default_host = environment == 'development' ? 'localhost' : '0.0.0.0'
207
-
208
- {
209
- :environment => environment,
210
- :pid => nil,
211
- :Port => 9292,
212
- :Host => default_host,
213
- :AccessLog => [],
214
- :config => "config.ru"
215
- }
216
- end
217
-
218
- def app
219
- @app ||= options[:builder] ? build_app_from_string : build_app_and_options_from_config
220
- end
221
-
222
- class << self
223
- def logging_middleware
224
- lambda { |server|
225
- server.server.name =~ /CGI/ || server.options[:quiet] ? nil : [Rack::CommonLogger, $stderr]
226
- }
227
- end
228
-
229
- def default_middleware_by_environment
230
- m = Hash.new {|h,k| h[k] = []}
231
- m["deployment"] = [
232
- [Rack::ContentLength],
233
- [Rack::Chunked],
234
- logging_middleware,
235
- [Rack::TempfileReaper]
236
- ]
237
- m["development"] = [
238
- [Rack::ContentLength],
239
- [Rack::Chunked],
240
- logging_middleware,
241
- [Rack::ShowExceptions],
242
- [Rack::Lint],
243
- [Rack::TempfileReaper]
244
- ]
245
-
246
- m
247
- end
248
-
249
- def middleware
250
- default_middleware_by_environment
251
- end
252
- end
253
-
254
- def middleware
255
- self.class.middleware
256
- end
257
-
258
- def start &blk
259
- if options[:warn]
260
- $-w = true
261
- end
262
-
263
- if includes = options[:include]
264
- $LOAD_PATH.unshift(*includes)
265
- end
266
-
267
- if library = options[:require]
268
- require library
269
- end
270
-
271
- if options[:debug]
272
- $DEBUG = true
273
- require 'pp'
274
- p options[:server]
275
- pp wrapped_app
276
- pp app
277
- end
278
-
279
- check_pid! if options[:pid]
280
-
281
- # Touch the wrapped app, so that the config.ru is loaded before
282
- # daemonization (i.e. before chdir, etc).
283
- wrapped_app
284
-
285
- daemonize_app if options[:daemonize]
286
-
287
- write_pid if options[:pid]
288
-
289
- trap(:INT) do
290
- if server.respond_to?(:shutdown)
291
- server.shutdown
292
- else
293
- exit
294
- end
295
- end
296
-
297
- server.run wrapped_app, options, &blk
298
- end
299
-
300
- def server
301
- @_server ||= Rack::Handler.get(options[:server])
302
-
303
- unless @_server
304
- @_server = Rack::Handler.default
305
-
306
- # We already speak FastCGI
307
- @ignore_options = [:File, :Port] if @_server.to_s == 'Rack::Handler::FastCGI'
308
- end
309
-
310
- @_server
311
- end
312
-
313
- private
314
- def build_app_and_options_from_config
315
- if !::File.exist? options[:config]
316
- abort "configuration #{options[:config]} not found"
317
- end
318
-
319
- app, options = Rack::Builder.parse_file(self.options[:config], opt_parser)
320
- @options.merge!(options) { |key, old, new| old }
321
- app
322
- end
323
-
324
- def build_app_from_string
325
- Rack::Builder.new_from_string(self.options[:builder])
326
- end
327
-
328
- def parse_options(args)
329
- # Don't evaluate CGI ISINDEX parameters.
330
- # http://www.meb.uni-bonn.de/docs/cgi/cl.html
331
- args.clear if ENV.include?(REQUEST_METHOD)
332
-
333
- @options = opt_parser.parse!(args)
334
- @options[:config] = ::File.expand_path(options[:config])
335
- ENV["RACK_ENV"] = options[:environment]
336
- @options
337
- end
338
-
339
- def opt_parser
340
- Options.new
341
- end
342
-
343
- def build_app(app)
344
- middleware[options[:environment]].reverse_each do |middleware|
345
- middleware = middleware.call(self) if middleware.respond_to?(:call)
346
- next unless middleware
347
- klass, *args = middleware
348
- app = klass.new(app, *args)
349
- end
350
- app
351
- end
352
-
353
- def wrapped_app
354
- @wrapped_app ||= build_app app
355
- end
356
-
357
- def daemonize_app
358
- Process.daemon
359
- end
360
-
361
- def write_pid
362
- ::File.open(options[:pid], ::File::CREAT | ::File::EXCL | ::File::WRONLY ){ |f| f.write("#{Process.pid}") }
363
- at_exit { ::FileUtils.rm_f(options[:pid]) }
364
- rescue Errno::EEXIST
365
- check_pid!
366
- retry
367
- end
368
-
369
- def check_pid!
370
- case pidfile_process_status
371
- when :running, :not_owned
372
- $stderr.puts "A server is already running. Check #{options[:pid]}."
373
- exit(1)
374
- when :dead
375
- ::File.delete(options[:pid])
376
- end
377
- end
378
-
379
- def pidfile_process_status
380
- return :exited unless ::File.exist?(options[:pid])
381
-
382
- pid = ::File.read(options[:pid]).to_i
383
- return :dead if pid == 0
384
-
385
- Process.kill(0, pid)
386
- :running
387
- rescue Errno::ESRCH
388
- :dead
389
- rescue Errno::EPERM
390
- :not_owned
391
- end
392
-
393
- end
394
-
395
- end