Class: TestApp
- Inherits:
-
Object
- Object
- TestApp
- Defined in:
- ext/revdispatch/server.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize ⇒ TestApp
constructor
A new instance of TestApp.
Constructor Details
#initialize ⇒ TestApp
Returns a new instance of TestApp.
10 11 12 13 14 15 16 17 18 19 |
# File 'ext/revdispatch/server.rb', line 10 def initialize instance_eval do if $daemonized def log(msg) ; end else def log(msg) ; puts msg ; end end end log "Test server '#{__FILE__}', started" end |
Instance Method Details
#call(env) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'ext/revdispatch/server.rb', line 21 def call(env) commands = env['PATH_INFO'].split('/') extras = {} $req_count += 1 log "#{$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 log 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 |