1 DIR = File.dirname(__FILE__)
9 n = (seconds / 0.01).to_i
12 #File.read(DIR + '/yahoo.html')
28 path = env['PATH_INFO'] || env['REQUEST_URI']
29 commands = path.split('/')
32 if commands.include?('periodical_activity') and @count % 10 != 1
33 return [200, {'Content-Type'=>'text/plain'}, "quick response!\r\n"]
36 if commands.include?('fibonacci')
37 n = commands.last.to_i
38 raise "fibonacci called with n <= 0" if n <= 0
39 body = (1..n).to_a.map { |i| fib(i).to_s }.join(' ')
42 elsif commands.include?('wait')
43 n = commands.last.to_f
44 raise "wait called with n <= 0" if n <= 0
46 body = "waited about #{n} seconds"
49 elsif commands.include?('bytes')
50 n = commands.last.to_i
51 raise "bytes called with n <= 0" if n <= 0
52 body = @@responses[n] || "C"*n
55 elsif commands.include?('fixed')
57 body = @@responses[n] || "C"*n
60 elsif commands.include?('test_post_length')
62 while chunk = env['rack.input'].read(512)
65 if env['CONTENT_LENGTH'].to_i == input_body.length
66 body = "Content-Length matches input length"
69 body = "Content-Length doesn't matches input length!
70 content_length = #{env['CONTENT_LENGTH'].to_i}
71 input_body.length = #{input_body.length}"
76 body = "Undefined url"
80 headers = {'Content-Type' => 'text/plain', 'Content-Length' => body.length.to_s }
81 [status, headers, [body]]
87 #require DIR + '/../lib/ebb'
92 # Rack::Handler::Mongrel.run(SimpleApp.new, :Port => 8000)
93 Thin::Server.start("0.0.0.0", 8000, SimpleApp.new)
94 # Ebb::start_server(SimpleApp.new, :port => 8000)