Created
April 5, 2011 19:21
-
-
Save andre/904320 to your computer and use it in GitHub Desktop.
This file contains 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
# 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" |
This file contains 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
# 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" |
This file contains 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
# 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