Sha256: 6f68b67346fb0fc133bfe6bfe8105ce01ff43723bb14f4fd9d049d48b8c99f18
Contents?: true
Size: 1.58 KB
Versions: 4
Compression:
Stored size: 1.58 KB
Contents
require 'rubygems' require 'rack' TEST_PORT = 4044 $req_count = 0 class TestApp def initialize puts "Test server '#{__FILE__}', started" end def call(env) commands = env['PATH_INFO'].split('/') extras = {} $req_count += 1 puts "#{$req_count} requests" if commands.include?('delay') n = commands.last.to_f raise "delay called with n <= 0" if n < 0.0 sleep n body = "delayed #{n} seconds" status = 200 elsif commands.include?('bytes') n = commands.last.to_i raise "bytes called with n <= 0" if n <= 0 body = "C"*n status = 200 elsif commands.include?('redir') n = commands.last.to_i if n <= 0 extras = {'Location' => '/bytes/10'} body = "redirect to bytes" else extras = {'Location' => "/redir/#{n-1}"} body = "redirect to redir #{n-1}" end puts body status = 302 elsif commands.include?('test_post_length') input_body = env['rack.input'].read content_length_header = env['CONTENT_LENGTH'].to_i if content_length_header == input_body.length body = "Content-Length matches input length" status = 200 else body = "Content-Length header is #{content_length_header} but body length is #{input_body.length}" status = 500 end else status = 404 body = "Undefined url" end [status, {'Content-Type' => 'text/json'}.merge(extras), body] end end Rack::Handler::Mongrel.run( Rack::ShowExceptions.new(Rack::Lint.new(TestApp.new)), :Port => TEST_PORT )
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
evdispatch-0.2.6 | ext/revdispatch/server.rb |
evdispatch-0.3.0 | ext/revdispatch/server.rb |
evdispatch-0.3.1 | ext/revdispatch/server.rb |
evdispatch-0.4.0 | ext/revdispatch/server.rb |