From: Minero Aoki Date: 2001-02-26T21:37:42+09:00 Subject: [ruby-talk:11584] net/http is going to change Hi all, I'm going to make big change on net/http in Ruby 1.7 and later version. Changes are below: * HTTP#get, head, post never raise ProtocolError. * HTTP#get, head, post does return only ONE object, a HTTPResponse. * HTTPResponseReceiver is joined into HTTPResponse. * HTTP request object, HTTP::Get, Head, Post. The aim of these changes are for almost fixing design corruption. It's totally my fault. sigh. But this change will break many scripts, so I make a transitional period. To use current net/http features, insert this line before 'Net::HTTP.new': Net::HTTP.version_1_1 then existing applications (will) work without change on ruby 1.7 or later. Or if you want to use new features, insert this line instead: Net::HTTP.version_1_2 (call this method at your own lisk; new feature is still moving. If you want compatibility, use version_1_1.) For example: require 'net/http' Net::HTTP.version_1_1 http = Net::HTTP.new(addr, port) # not thread-safe :-( : http.start { response, body = http.get( path ) } response['content-type'] response.body another example: require 'net/http' Net::HTTP.version_1_1 http = Net::HTTP.new(addr, port) : http.start { response = http.get2( path ) {|r| # the TYPE of "r" is indefinite, but the methods which # the object can respond to are definite. r.response['content-length'] r.read_body r.body } response.body } An example of new features: require 'net/http' Net::HTTP.version_1_2 req = Net::HTTP::Get.new req.range = 0...500 # get first 500 bytes Net::HTTP.start( addr, port ) do |http| http.request( req ) do |response| p response['content-type'] p response['content-length] response.read_body end end At last, new net/http features are still moving. If you have any idea, feel free to request here (You can find new net/http code on main trunk of Ruby CVS). Minero Aoki