Module: HTTPkit

Defined in:
lib/httpkit.rb,
lib/httpkit/body.rb,
lib/httpkit/client.rb,
lib/httpkit/server.rb,
lib/httpkit/version.rb,
lib/httpkit/promise.rb,
lib/httpkit/request.rb,
lib/httpkit/response.rb,
lib/httpkit/serializer.rb,
lib/httpkit/support/message.rb,
lib/httpkit/connection/status.rb,
lib/httpkit/server/body_handler.rb,
lib/httpkit/client/body_handler.rb,
lib/httpkit/server/block_handler.rb,
lib/httpkit/client/timeouts_handler.rb,
lib/httpkit/server/timeouts_handler.rb,
lib/httpkit/connection/eventmachine.rb,
lib/httpkit/support/handler_manager.rb,
lib/httpkit/server/mandatory_handler.rb,
lib/httpkit/client/mandatory_handler.rb,
lib/httpkit/server/keep_alive_handler.rb,
lib/httpkit/client/keep_alive_handler.rb

Defined Under Namespace

Modules: Connection, Support Classes: Body, Client, Promise, Request, Response, Serializer, Server

Constant Summary collapse

Error =
Class.new(StandardError)
VERSION =
'0.6.0'

Class Method Summary collapse

Class Method Details

.random_port(address) ⇒ Object


61
62
63
64
65
66
# File 'lib/httpkit.rb', line 61

def self.random_port(address)
  server = TCPServer.new(address, 0)
  server.addr[1]
ensure
  server.shutdown
end

.request(*args) ⇒ Object


76
77
78
79
80
81
82
# File 'lib/httpkit.rb', line 76

def self.request(*args)
  uri = URI(args[1])
  client = Client.start(address: uri.host, port: uri.port,
                        handlers: [Server::KeepAliveHandler.new,
                                   Server::TimeoutsHandler.new])
  client.request(*args)
end

.runObject


37
38
39
40
41
42
# File 'lib/httpkit.rb', line 37

def self.run
  start do
    yield
    stop
  end
end

.server(uri, &block) ⇒ Object


68
69
70
71
72
73
74
# File 'lib/httpkit.rb', line 68

def self.server(uri, &block)
  uri = URI(uri)
  Server.start(address: uri.host, port: uri.port,
               handlers: [Server::KeepAliveHandler.new,
                          Server::TimeoutsHandler.new,
                          Server::BlockHandler.new(block)])
end

.sleep(duration) ⇒ Object


55
56
57
58
59
# File 'lib/httpkit.rb', line 55

def self.sleep(duration)
  promise = Promise.new
  EM.add_timer(duration) { promise.fulfill }
  promise.sync
end

.startObject


44
45
46
47
48
# File 'lib/httpkit.rb', line 44

def self.start
  EM.run do
    Fiber.new { yield }.resume
  end
end

.stopObject


50
51
52
53
# File 'lib/httpkit.rb', line 50

def self.stop
  EM.stop
  EM.next_tick {}
end