Included Modules

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
241:       def self.connect *args
242:         if args.length == 2
243:           args = {:host=>args[0], :port=>args[1]}
244:         else
245:           args = args.first
246:         end
247: 
248:         h,prt,ssl = args[:host], Integer(args[:port]), (args[:tls] || args[:ssl])
249:         conn = EM.connect( h, prt, self )
250:         conn.start_tls if ssl
251:         conn.set_default_host_header( h, prt, ssl )
252:         conn
253:       end
new() click to toggle source
    # File lib/em/protocols/httpclient2.rb, line 44
44:       def initialize
45:         @authorization = nil
46:         @closed = nil
47:         @requests = nil
48:       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
260:       def get args
261:         if args.is_a?(String)
262:           args = {:uri=>args}
263:         end
264:         args[:verb] = "GET"
265:         request args
266:       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
274:       def post args
275:         if args.is_a?(String)
276:           args = {:uri=>args}
277:         end
278:         args[:verb] = "POST"
279:         request args
280:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.