@@ -7,45 +7,45 @@ def fib(n)
77
88def wait ( seconds )
99 n = ( seconds / 0.01 ) . to_i
10- n . times do
10+ n . times do
1111 sleep ( 0.01 )
12- #File.read(DIR + '/yahoo.html')
12+ #File.read(DIR + '/yahoo.html')
1313 end
1414end
1515
1616class SimpleApp
1717 @@responses = { }
18-
18+
1919 def initialize
2020 @count = 0
2121 end
22-
22+
2323 def deferred? ( env )
2424 false
2525 end
26-
26+
2727 def call ( env )
2828 path = env [ 'PATH_INFO' ] || env [ 'REQUEST_URI' ]
2929 commands = path . split ( '/' )
30-
30+
3131 @count += 1
3232 if commands . include? ( 'periodical_activity' ) and @count % 10 != 1
3333 return [ 200 , { 'Content-Type' => 'text/plain' } , "quick response!\r \n " ]
3434 end
35-
35+
3636 if commands . include? ( 'fibonacci' )
3737 n = commands . last . to_i
3838 raise "fibonacci called with n <= 0" if n <= 0
3939 body = ( 1 ..n ) . to_a . map { |i | fib ( i ) . to_s } . join ( ' ' )
4040 status = 200
41-
41+
4242 elsif commands . include? ( 'wait' )
4343 n = commands . last . to_f
4444 raise "wait called with n <= 0" if n <= 0
4545 wait ( n )
4646 body = "waited about #{ n } seconds"
4747 status = 200
48-
48+
4949 elsif commands . include? ( 'bytes' )
5050 n = commands . last . to_i
5151 raise "bytes called with n <= 0" if n <= 0
@@ -56,17 +56,17 @@ def call(env)
5656 n = 20 * 1024 ;
5757 body = @@responses [ n ] || "C" *n
5858 status = 200
59-
59+
6060 elsif commands . include? ( 'test_post_length' )
6161 input_body = ""
6262 while chunk = env [ 'rack.input' ] . read ( 512 )
63- input_body << chunk
63+ input_body << chunk
6464 end
6565 if env [ 'CONTENT_LENGTH' ] . to_i == input_body . length
6666 body = "Content-Length matches input length"
6767 status = 200
6868 else
69- body = "Content-Length doesn't matches input length!
69+ body = "Content-Length doesn't matches input length!
7070 content_length = #{ env [ 'CONTENT_LENGTH' ] . to_i }
7171 input_body.length = #{ input_body . length } "
7272 status = 500
@@ -75,7 +75,7 @@ def call(env)
7575 status = 404
7676 body = "Undefined url"
7777 end
78-
78+
7979 body += "\r \n "
8080 headers = { 'Content-Type' => 'text/plain' , 'Content-Length' => body . length . to_s }
8181 [ status , headers , [ body ] ]
@@ -90,6 +90,6 @@ def call(env)
9090 require 'thin'
9191 require 'ebb'
9292# Rack::Handler::Mongrel.run(SimpleApp.new, :Port => 8000)
93- Thin ::Server . start ( "0.0.0.0" , 8000 , SimpleApp . new )
93+ Thin ::Server . start ( "0.0.0.0" , 8000 , SimpleApp . new )
9494# Ebb::start_server(SimpleApp.new, :port => 8000)
9595end
0 commit comments