Sha256: 33499da4445423aab6e4744d56fff967c42e5e6f0742a6085b6d4f935d19bd2d

Contents?: true

Size: 1.29 KB

Versions: 25

Compression:

Stored size: 1.29 KB

Contents

# this server simply is for testing out the different http methods. it echoes back the passed in info
require 'rubygems'
require 'eventmachine'
require 'evma_httpserver'
 
class MethodServer  < EventMachine::Connection
  include EventMachine::HttpServer
 
  def process_http_request
    EventMachine.stop if ENV["PATH_INFO"] == "/die"
    
    resp = EventMachine::DelegatedHttpResponse.new( self )
    
    # Block which fulfills the request
    operation = proc do
      sleep MethodServer.sleep_time
      resp.status = 200
      resp.content = request_params + "\n#{@http_post_content}"
    end

    # Callback block to execute once the request is fulfilled
    callback = proc do |res|
      resp.send_response
    end

    # Let the thread pool (20 Ruby threads) handle request
    EM.defer(operation, callback)
  end
  
  def request_params
    %w( PATH_INFO QUERY_STRING HTTP_COOKIE IF_NONE_MATCH CONTENT_TYPE REQUEST_METHOD REQUEST_URI ).collect do |param|
      "#{param}=#{ENV[param]}"
    end.join("\n")
  end
  
  def self.sleep_time=(val)
    @sleep_time = val
  end
  
  def self.sleep_time
    @sleep_time || 0
  end
end
# 
# port = (ARGV[0] || 3000).to_i
# #Process.fork do
#   EventMachine::run {
#     EventMachine.epoll
#     EventMachine::start_server("0.0.0.0", port, MethodServer)
#   }
# #end

Version data entries

25 entries across 25 versions & 5 rubygems

Version Path
abhay-typhoeus-0.0.22 spec/servers/method_server.rb
dbalatero-typhoeus-0.0.20 spec/servers/method_server.rb
dbalatero-typhoeus-0.0.21 spec/servers/method_server.rb
dbalatero-typhoeus-0.0.22 spec/servers/method_server.rb
pauldix-typhoeus-0.0.10 spec/servers/method_server.rb
pauldix-typhoeus-0.0.11 spec/servers/method_server.rb
pauldix-typhoeus-0.0.12 spec/servers/method_server.rb
pauldix-typhoeus-0.0.13 spec/servers/method_server.rb
pauldix-typhoeus-0.0.14 spec/servers/method_server.rb
pauldix-typhoeus-0.0.15 spec/servers/method_server.rb
pauldix-typhoeus-0.0.16 spec/servers/method_server.rb
pauldix-typhoeus-0.0.17 spec/servers/method_server.rb
pauldix-typhoeus-0.0.18 spec/servers/method_server.rb
pauldix-typhoeus-0.0.19 spec/servers/method_server.rb
pauldix-typhoeus-0.0.20 spec/servers/method_server.rb
pauldix-typhoeus-0.0.22 spec/servers/method_server.rb
pauldix-typhoeus-0.0.23 spec/servers/method_server.rb
pauldix-typhoeus-0.0.24 spec/servers/method_server.rb
pauldix-typhoeus-0.0.8 spec/servers/method_server.rb
pauldix-typhoeus-0.1.0 spec/servers/method_server.rb