Class: EventMachine::Protocols::HttpClient2

Inherits:
Connection
  • Object
show all
Includes:
LineText2
Defined in:
lib/em/protocols/httpclient2.rb

Overview

Note: This class is deprecated and will be removed. Please use EM-HTTP-Request instead.

=== 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) } }

Constant Summary

Constants included from LineText2

LineText2::MaxBinaryLength

Class Method Summary collapse

Instance Method Summary collapse

Methods included from LineText2

#receive_data, #receive_end_of_binary_data, #set_binary_mode, #set_delimiter, #set_line_mode, #set_text_mode

Methods inherited from Connection

#close_connection, #close_connection_after_writing, #comm_inactivity_timeout, #comm_inactivity_timeout=, #detach, #error?, #get_idle_time, #get_peer_cert, #get_peername, #get_pid, #get_proxied_bytes, #get_sock_opt, #get_sockname, #get_status, #notify_readable=, #notify_readable?, #notify_writable=, #notify_writable?, #pause, #paused?, #pending_connect_timeout, #pending_connect_timeout=, #proxy_completed, #proxy_incoming_to, #proxy_target_unbound, #receive_data, #reconnect, #resume, #send_data, #send_datagram, #send_file_data, #set_sock_opt, #ssl_handshake_completed, #ssl_verify_peer, #start_tls, #stop_proxying, #stream_file_data

Constructor Details

#initializeHttpClient2

Returns a new instance of HttpClient2.



46
47
48
49
50
51
52
# File 'lib/em/protocols/httpclient2.rb', line 46

def initialize
  warn "HttpClient2 is deprecated and will be removed. EM-Http-Request should be used instead."

  @authorization = nil
  @closed = nil
  @requests = nil
end

Class Method Details

.connect(*args) ⇒ Object

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



246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'lib/em/protocols/httpclient2.rb', line 246

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

Instance Method Details

#get(args) ⇒ Object

Get a url

req = conn.get(:uri => '/') req.callback{|response| puts response.content }



265
266
267
268
269
270
271
# File 'lib/em/protocols/httpclient2.rb', line 265

def get args
  if args.is_a?(String)
    args = {:uri=>args}
  end
  args[:verb] = "GET"
  request args
end

#post(args) ⇒ Object

Post to a url

req = conn.post('/data')

req.callback{|response| puts response.content }

XXX there's no way to supply a POST body.. wtf?



279
280
281
282
283
284
285
# File 'lib/em/protocols/httpclient2.rb', line 279

def post args
  if args.is_a?(String)
    args = {:uri=>args}
  end
  args[:verb] = "POST"
  request args
end