EventMachine::Protocols::HttpClient2

Usage

EM.run{
  conn = EM::Protocols::HttpClient2.connect 'google.com', 80

  req = conn.get('/')
  req.callback{ |response|
    p(response.status)
    p(response.headers)
    p(response.content)
  }
}

Public Class Methods

connect(*args) click to toggle source

Make a connection to a remote HTTP server. Can take either a pair of arguments (which will be interpreted as a hostname/ip-address and a port), or a hash. If the arguments are a hash, then supported values include:

:host => a hostname or ip-address
:port => a port number
:ssl => true to enable ssl
# File lib/em/protocols/httpclient2.rb, line 241
def self.connect *args
  if args.length == 2
    args = {:host=>args[0], :port=>args[1]}
  else
    args = args.first
  end

  h,prt,ssl = args[:host], Integer(args[:port]), (args[:tls] || args[:ssl])
  conn = EM.connect( h, prt, self )
  conn.start_tls if ssl
  conn.set_default_host_header( h, prt, ssl )
  conn
end
new() click to toggle source
# File lib/em/protocols/httpclient2.rb, line 44
def initialize
  @authorization = nil
  @closed = nil
  @requests = nil
end

Public Instance Methods

get(args) click to toggle source

Get a url

req = conn.get(:uri => '/')
req.callback{|response| puts response.content }
# File lib/em/protocols/httpclient2.rb, line 260
def get args
  if args.is_a?(String)
    args = {:uri=>args}
  end
  args[:verb] = "GET"
  request args
end
post(args) click to toggle source

Post to a url

req = conn.post('/data')
req.callback{|response| puts response.content }
# File lib/em/protocols/httpclient2.rb, line 274
def post args
  if args.is_a?(String)
    args = {:uri=>args}
  end
  args[:verb] = "POST"
  request args
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.