Sha256: e173e25281aa804982a4933054255b197f41c8f7f4bf60430085e0b66911c204

Contents?: true

Size: 1.39 KB

Versions: 1

Compression:

Stored size: 1.39 KB

Contents

require 'rubygems'
require 'ebb'

Ebb.log = File.open('/dev/null','w')

TEST_PORT = 4044


class HelperApp
  def call(env)
    commands = env['PATH_INFO'].split('/')

    if commands.include?('delay')
      n = commands.last.to_i
      raise "delay called with n <= 0" if n < 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?('test_post_length')
      input_body = env['rack.input'].read
      
      content_length_header = env['HTTP_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'}, body]
  end
end

def start_test_server
  puts "starting up ebb";
  Thread.start{ Ebb.start_server(HelperApp.new, :port => TEST_PORT) }
  sleep 0.1 until Ebb.running?

  Signal.trap( "HUP" ){
    Ebb.stop_server
    sleep 0.1 while Ebb.running?
  }

  # keep process alive
  sleep 0.5 while Ebb.running?
end
if( ARGV[0] == "start" )
  start_test_server
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
evdispatch-0.1.5 ext/revdispatch/server.rb