Created
November 4, 2011 08:00
-
-
Save macks/1338880 to your computer and use it in GitHub Desktop.
https client for Rev (libev)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rev' | |
require 'rev/ssl' | |
class MyHttpClient < Rev::HttpClient | |
attr_reader :response_header, :response_body | |
def on_connect | |
@response_body = [] | |
super | |
end | |
def on_response_header(header) | |
@response_header = header | |
end | |
def on_body_data(data) | |
@response_body << data | |
end | |
end | |
class MyHttpsClient < MyHttpClient | |
include Rev::SSL | |
alias on_ssl_connect on_connect | |
alias on_connect ssl_client_start | |
end | |
evloop = Rev::Loop.new | |
conn = MyHttpsClient.connect('www.google.com', 443) | |
conn.request(:get, '/') | |
conn.on_close do | |
puts "Status=#{@response_header.status}" | |
@response_header.each do |key, value| | |
puts "#{key}=#{value.inspect}" | |
end | |
puts | |
puts @response_body.join | |
end | |
conn.attach(evloop) | |
evloop.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment