Class: EventMachine::Protocols::HttpClient2 Deprecated
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Connection
|
|
Instance Chain:
self,
LineText2 ,
Connection
|
|
Inherits: |
EventMachine::Connection
|
Defined in: | lib/em/protocols/httpclient2.rb |
Overview
Constant Summary
LineText2
- Included
Class Method Summary
-
.connect(*args)
Make a connection to a remote HTTP server.
- .new ⇒ HttpClient2 constructor
Connection
- Inherited
.new | Override .new so subclasses don't have to call super and can ignore connection-specific arguments. |
Instance Attribute Summary
Connection
- Inherited
#comm_inactivity_timeout | comm_inactivity_timeout returns the current value (float in seconds) of the inactivity-timeout property of network-connection and datagram-socket objects. |
#comm_inactivity_timeout= | Allows you to set the inactivity-timeout property for a network connection or datagram socket. |
#error? | Returns true if the connection is in an error state, false otherwise. |
#notify_readable= | Watches connection for readability. |
#notify_readable?, | |
#notify_writable= | Watches connection for writeability. |
#notify_writable? | Returns true if the connection is being watched for writability. |
#paused?, | |
#pending_connect_timeout | The duration after which a TCP connection in the connecting state will fail. |
#pending_connect_timeout= | Sets the duration after which a TCP connection in a connecting state will fail. |
#signature, #watch_only? |
Instance Method Summary
- #connection_completed Internal use only Internal use only
-
#get(args)
Get a url.
- #pop_request
-
#post(args)
Post to a url.
- #post_init Internal use only Internal use only
- #receive_binary_data(text) Internal use only Internal use only
- #receive_line(ln) Internal use only Internal use only
- #request(args) Internal use only Internal use only
- #set_default_host_header(host, port, ssl)
- #unbind
LineText2
- Included
#receive_binary_data | Stub. |
#receive_data, | |
#receive_end_of_binary_data | Stub. |
#receive_line | Stub. |
#set_binary_mode | Alias for #set_text_mode, added for back-compatibility with |
#set_delimiter | The line delimiter may be a regular expression or a string. |
#set_line_mode | Called internally but also exposed to user code, for the case in which processing of binary data creates a need to transition back to line mode. |
#set_text_mode, | |
#unbind | In case of a dropped connection, we'll send a partial buffer to user code when in sized text mode. |
Connection
- Inherited
#associate_callback_target | conn_associate_callback_target. |
#close_connection | EventMachine::Connection#close_connection is called only by user code, and never by the event loop. |
#close_connection_after_writing | A variant of EventMachine#close_connection. |
#connection_completed | Called by the event loop when a remote TCP connection attempt completes successfully. |
#detach | Removes given connection from the event loop. |
#disable_keepalive | t_disable_keepalive. |
#enable_keepalive | t_enable_keepalive. |
#get_cipher_bits, #get_cipher_name, #get_cipher_protocol, | |
#get_idle_time | The number of seconds since the last send/receive activity on this connection. |
#get_outbound_data_size | conn_get_outbound_data_size. |
#get_peer_cert | If TLS is active on the connection, returns the remote X509 certificate as a string, in the popular PEM format. |
#get_peername | This method is used with stream-connections to obtain the identity of the remotely-connected peer. |
#get_pid | Returns the PID (kernel process identifier) of a subprocess associated with this |
#get_proxied_bytes | The number of bytes proxied to another connection. |
#get_sni_hostname, #get_sock_opt, | |
#get_sockname | Used with stream-connections to obtain the identity of the local side of the connection. |
#get_status | Returns a subprocess exit status. |
#initialize | Stubbed initialize so legacy superclasses can safely call super. |
#original_method, | |
#pause | Pause a connection so that EventMachine#send_data and |
#post_init | Called by the event loop immediately after the network connection has been established, and before resumption of the network loop. |
#proxy_completed | called when the reactor finished proxying all of the requested bytes. |
#proxy_incoming_to | EventMachine::Connection#proxy_incoming_to is called only by user code. |
#proxy_target_unbound | Called by the reactor after attempting to relay incoming data to a descriptor (set as a proxy target descriptor with EventMachine.enable_proxy) that has already been closed. |
#receive_data | Called by the event loop whenever data has been received by the network connection. |
#reconnect | Reconnect to a given host/port with the current instance. |
#resume | Resume a connection's EventMachine#send_data and |
#send_data | Call this method to send data to the remote end of the network connection. |
#send_datagram | Sends UDP messages. |
#send_file_data | Like Connection#send_data, this sends data to the remote end of the network connection. |
#set_sock_opt, | |
#ssl_handshake_completed | Called by |
#ssl_verify_peer | Called by |
#start_tls | Call EventMachine#start_tls at any point to initiate TLS encryption on connected streams. |
#stop_proxying | A helper method for EventMachine.disable_proxy |
#stream_file_data | Open a file on the filesystem and send it to the remote peer. |
#unbind | called by the framework whenever a connection (either a server or client connection) is closed. |
Constructor Details
.new ⇒ HttpClient2
# File 'lib/em/protocols/httpclient2.rb', line 49
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)
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 248
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
#connection_completed
# File 'lib/em/protocols/httpclient2.rb', line 311
def connection_completed super @connected.succeed end
#get(args)
Get a url
req = conn.get(:uri => '/') req.callback{|response| puts response.content }
# File 'lib/em/protocols/httpclient2.rb', line 267
def get args if args.is_a?(String) args = {:uri=>args} end args[:verb] = "GET" request args end
#pop_request
[ GitHub ]# File 'lib/em/protocols/httpclient2.rb', line 368
def pop_request @requests.pop end
#post(args)
Post to a url
req = conn.post('/data') req.callback{|response| puts response.content }
# File 'lib/em/protocols/httpclient2.rb', line 281
def post args if args.is_a?(String) args = {:uri=>args} end args[:verb] = "POST" request args end
#post_init
# File 'lib/em/protocols/httpclient2.rb', line 305
def post_init super @connected = EM::DefaultDeferrable.new end
#receive_binary_data(text)
# File 'lib/em/protocols/httpclient2.rb', line 360
def receive_binary_data text @requests.last.receive_text text end
#receive_line(ln)
# File 'lib/em/protocols/httpclient2.rb', line 350
def receive_line ln if req = @requests.last req.receive_line ln else p "??????????" p ln end end
#request(args)
# File 'lib/em/protocols/httpclient2.rb', line 336
def request args args[:host_header] = @host_header unless args.has_key?(:host_header) args[: ] = @authorization unless args.has_key?(: ) r = Request.new self, args if @closed r.fail else (@requests ||= []).unshift r @connected.callback {r.send_request} end r end
#set_default_host_header(host, port, ssl)
[ GitHub ]# File 'lib/em/protocols/httpclient2.rb', line 295
def set_default_host_header host, port, ssl if (ssl and port != 443) or (!ssl and port != 80) @host_header = "#{host}:#{port}" else @host_header = host end end
#unbind
[ GitHub ]# File 'lib/em/protocols/httpclient2.rb', line 329
def unbind super @closed = true (@requests || []).each {|r| r.fail} end