From: Tony Arcieri Date: 2008-02-12T11:42:55+09:00 Subject: Re: Rev/actor TCP monkey patching ------=_Part_24738_6873291.1202784181681 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On Feb 11, 2008 4:26 PM, fedzor wrote: > Short and sweet - > > How exactly does one monkey patch Rev's TCP over Net::HTTP-s? > Check out the SVN trunk: svn checkout http://rev.rubyforge.org/svn/ There's now a Rev::SSL module you can extend any subclass of Rev::TCPSocket with (this includes Revactor::TCP::Socket). To use it with Rev::HttpClient, just: require 'rev/ssl' and subclass HttpClient, defining the following callbacks: def on_connect super extend(Rev::SSL) ssl_client_start end You'll also need to: def on_ssl_connect request(...) # Make the HTTP request after the SSL handshake completes end ...to initiate the HTTP request after the SSL handshake is complete. There's a cooresponding #on_ssl_error(ex) method you can define to capture any errors which occur during the SSL handshake (or any attempts to negotiate a new session). You can also: def ssl_context OpenSSL::SSL::SSLContext.new(...) end ...to create an OpenSSL context to use for the SSL session. By default no certificate verification takes place, so if you'd like to do any add the appropriate certificates to the SSL context object. If you're having any trouble, you might take a look at the Revactor SVN trunk: svn checkout http://revactor.rubyforge.org/svn/ Revactor's HttpClient is already configured for SSL support, and wraps everything up a lot better, e.g.: response = Revactor::HttpClient.get("https://your.ssl.server.here/") This also takes care of some of the other annoyances of HTTP, like following redirects. If you don't want to use Revactor directly, you can at least use it as a reference for using Rev::HttpClient in conjunction with SSL. Just have a look at lib/revactor/http_client.rb I'd like to wrap up SSL support in Rev's HttpClient a bit more nicely, but for now my real priority was getting it working in Revactor. -- Tony Arcieri ClickCaster, Inc. tony@clickcaster.com ------=_Part_24738_6873291.1202784181681--