Skip to content

Instantly share code, notes, and snippets.

@andre
Created April 5, 2011 19:21
Show Gist options
  • Save andre/904320 to your computer and use it in GitHub Desktop.
Save andre/904320 to your computer and use it in GitHub Desktop.
# Multiple, concurrent HTTP (non-SSL) requests
#
# Works in macuruby
require 'net/http';
def do_https
http=Net::HTTP.new('www.yahoo.com', 80)
http.start() {|http|
req = Net::HTTP::Get.new('/')
response = http.request(req)
puts "done, got #{response.body.size} bytes"
}
end
t1=Thread.new {do_https};t2=Thread.new {do_https};t3=Thread.new {do_https}
t1.join; t2.join; t3.join
puts "done with all threads"
# Multiple, concurrent SSL requests
#
# works in Ruby 1.9.2, but Segfaults in Macruby 0.10
require 'net/http';require "net/https"
def do_https
http=Net::HTTP.new('www.paypal.com', 443)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.start() {|http|
req = Net::HTTP::Get.new('/')
response = http.request(req)
puts "done, got #{response.body.size} bytes"
}
end
t1=Thread.new {do_https};t2=Thread.new {do_https};t3=Thread.new {do_https}
t1.join; t2.join; t3.join
puts "done with all threads"
# sequential SSL requests
#
# works in MacRuby
require 'net/http';require "net/https"
def do_https
http=Net::HTTP.new('www.paypal.com', 443)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.start() {|http|
req = Net::HTTP::Get.new('/')
response = http.request(req)
puts "done, got #{response.body.size} bytes"
}
end
t1=Thread.new {do_https};
t1.join;
t2=Thread.new {do_https};
t2.join;
t3=Thread.new {do_https}
t3.join
puts "done with all threads"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment