diff options
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | lib/net/http.rb | 104 | ||||
-rw-r--r-- | test/net/http/test_http.rb | 59 |
3 files changed, 22 insertions, 145 deletions
@@ -1,3 +1,7 @@ +Fri Dec 10 10:07:59 2010 NARUSE, Yui <[email protected]> + + * lib/net/http.rb: remove version 1.1 features. + Fri Dec 10 02:18:02 2010 Aaron Patterson <[email protected]> * ext/openssl/ossl_x509store.c (ossl_x509stctx_cleanup): removing C diff --git a/lib/net/http.rb b/lib/net/http.rb index 4d475b14f7..05d82db12f 100644 --- a/lib/net/http.rb +++ b/lib/net/http.rb @@ -358,29 +358,11 @@ module Net #:nodoc: # There is also the Net::HTTPBadResponse exception which is raised when # there is a protocol error. # - # == Switching Net::HTTP versions - # - # You can use net/http.rb 1.1 features (bundled with Ruby 1.6) by calling - # HTTP.version_1_1. Calling Net::HTTP.version_1_2 allows you to use 1.2 - # features again. Do not confuse this with HTTP protocol features. - # - # # example - # Net::HTTP.start {|http1| ...(http1 has 1.2 features)... } - # - # Net::HTTP.version_1_1 - # Net::HTTP.start {|http2| ...(http2 has 1.1 features)... } - # - # Net::HTTP.version_1_2 - # Net::HTTP.start {|http3| ...(http3 has 1.2 features)... } - # - # Switching versions is NOT thread-safe. - # class HTTP < Protocol # :stopdoc: Revision = %q$Revision$.split[1] HTTPVersion = '1.1' - @newimpl = true begin require 'zlib' require 'stringio' #for our purposes (unpacking gzip) lump these together @@ -393,25 +375,18 @@ module Net #:nodoc: # Turns on net/http 1.2 (ruby 1.8) features. # Defaults to ON in ruby 1.8 or later. def HTTP.version_1_2 - @newimpl = true - end - - # Turns on net/http 1.1 (ruby 1.6) features. - # Defaults to OFF in ruby 1.8. - def HTTP.version_1_1 - @newimpl = false + true end # Returns true if net/http is in version 1.2 mode. # Defaults to true. def HTTP.version_1_2? - @newimpl + true end - # Returns true if net/http is in version 1.1 compatible mode. - # Defaults to true. + # :nodoc: def HTTP.version_1_1? - not @newimpl + false end class << HTTP @@ -588,11 +563,7 @@ module Net #:nodoc: # The +address+ should be a DNS hostname or IP address. # If +p_addr+ is given, creates a Net::HTTP object with proxy support. def HTTP.new(address, port = nil, p_addr = nil, p_port = nil, p_user = nil, p_pass = nil) - h = Proxy(p_addr, p_port, p_user, p_pass).newobj(address, port) - h.instance_eval { - @newimpl = ::Net::HTTP.version_1_2? - } - h + Proxy(p_addr, p_port, p_user, p_pass).newobj(address, port) end # Creates a new Net::HTTP object for the specified server address, @@ -988,10 +959,7 @@ module Net #:nodoc: # the header as well to prevent confusion. Otherwise # it leaves the body as it found it. # - # In version 1.1 (ruby 1.6), this method returns a pair of objects, - # a Net::HTTPResponse object and the entity body string. - # In version 1.2 (ruby 1.8), this method returns a Net::HTTPResponse - # object. + # This method returns a Net::HTTPResponse object. # # If called with a block, yields each fragment of the # entity body in turn as a string as it is read from @@ -1001,16 +969,8 @@ module Net #:nodoc: # +dest+ argument is obsolete. # It still works but you must not use it. # - # In version 1.1, this method might raise an exception for - # 3xx (redirect). In this case you can get a HTTPResponse object - # from "anException.response". - # - # In version 1.2, this method never raises an exception. - # - # # version 1.1 (bundled with Ruby 1.6) - # response, body = http.get('/index.html') + # This method never raises an exception. # - # # version 1.2 (bundled with Ruby 1.8 or later) # response = http.get('/index.html') # # # using block @@ -1049,11 +1009,6 @@ module Net #:nodoc: end res = r } - unless @newimpl - res.value - return res, res.body - end - res end @@ -1062,11 +1017,7 @@ module Net #:nodoc: # # This method returns a Net::HTTPResponse object. # - # In version 1.1, this method might raise an exception for - # 3xx (redirect). On the case you can get a HTTPResponse object - # as "anException.response". - # - # In version 1.2, this method never raises an exception. + # This method never raises an exception. # # response = nil # Net::HTTP.start('some.www.server', 80) {|http| @@ -1075,17 +1026,13 @@ module Net #:nodoc: # p response['content-type'] # def head(path, initheader = nil) - res = request(Head.new(path, initheader)) - res.value unless @newimpl - res + request(Head.new(path, initheader)) end # Posts +data+ (must be a String) to +path+. +header+ must be a Hash # like { 'Accept' => '*/*', ... }. # - # In version 1.1 (ruby 1.6), this method returns a pair of objects, a - # Net::HTTPResponse object and an entity body string. - # In version 1.2 (ruby 1.8), this method returns a Net::HTTPResponse object. + # This method returns a Net::HTTPResponse object. # # If called with a block, yields each fragment of the # entity body in turn as a string as it is read from @@ -1095,15 +1042,8 @@ module Net #:nodoc: # +dest+ argument is obsolete. # It still works but you must not use it. # - # In version 1.1, this method might raise an exception for - # 3xx (redirect). In this case you can get an HTTPResponse object - # by "anException.response". - # In version 1.2, this method never raises exception. - # - # # version 1.1 - # response, body = http.post('/cgi-bin/search.rb', 'query=foo') + # This method never raises exception. # - # # version 1.2 # response = http.post('/cgi-bin/search.rb', 'query=foo') # # # using block @@ -1128,9 +1068,7 @@ module Net #:nodoc: end def put(path, data, initheader = nil) #:nodoc: - res = request(Put.new(path, initheader), data) - res.value unless @newimpl - res + request(Put.new(path, initheader), data) end # Sends a PROPPATCH request to the +path+ and gets a response, @@ -1335,10 +1273,6 @@ module Net #:nodoc: r.read_body dest, &block res = r } - unless @newimpl - res.value - return res, res.body - end res end @@ -2493,20 +2427,6 @@ module Net #:nodoc: "#<#{self.class} #{@code} #{@message} readbody=#{@read}>" end - # For backward compatibility. - # To allow Net::HTTP 1.1 style assignment - # e.g. - # response, body = Net::HTTP.get(....) - # - def to_ary - warn "net/http.rb: warning: Net::HTTP v1.1 style assignment found at #{caller(1)[0]}; use `response = http.get(...)' instead." if $VERBOSE - res = self.dup - class << res - undef to_ary - end - [res, res.body] - end - # # response <-> exception relationship # diff --git a/test/net/http/test_http.rb b/test/net/http/test_http.rb index 76280ad168..586cce59bc 100644 --- a/test/net/http/test_http.rb +++ b/test/net/http/test_http.rb @@ -32,27 +32,23 @@ module TestNetHTTP_version_1_1_methods end def _test_get__get(http) - res, body = http.get('/') + res = http.get('/') assert_kind_of Net::HTTPResponse, res assert_kind_of String, res.body - assert_kind_of String, body unless self.is_a?(TestNetHTTP_v1_2_chunked) assert_not_nil res['content-length'] assert_equal $test_net_http_data.size, res['content-length'].to_i end assert_equal $test_net_http_data_type, res['Content-Type'] - assert_equal $test_net_http_data.size, body.size - assert_equal $test_net_http_data, body assert_equal $test_net_http_data.size, res.body.size assert_equal $test_net_http_data, res.body end def _test_get__iter(http) buf = '' - res, body = http.get('/') {|s| buf << s } + res = http.get('/') {|s| buf << s } assert_kind_of Net::HTTPResponse, res # assert_kind_of String, res.body - # assert_kind_of String, body unless self.is_a?(TestNetHTTP_v1_2_chunked) assert_not_nil res['content-length'] assert_equal $test_net_http_data.size, res['content-length'].to_i @@ -66,10 +62,9 @@ module TestNetHTTP_version_1_1_methods def _test_get__chunked(http) buf = '' - res, body = http.get('/') {|s| buf << s } + res = http.get('/') {|s| buf << s } assert_kind_of Net::HTTPResponse, res # assert_kind_of String, res.body - # assert_kind_of String, body unless self.is_a?(TestNetHTTP_v1_2_chunked) assert_not_nil res['content-length'] assert_equal $test_net_http_data.size, res['content-length'].to_i @@ -93,9 +88,8 @@ module TestNetHTTP_version_1_1_methods end def test_get__implicit_start - res, body = new().get('/') + res = new().get('/') assert_kind_of Net::HTTPResponse, res - assert_kind_of String, body assert_kind_of String, res.body unless self.is_a?(TestNetHTTP_v1_2_chunked) assert_not_nil res['content-length'] @@ -134,11 +128,9 @@ module TestNetHTTP_version_1_1_methods uheader = {} uheader['Accept'] = 'application/octet-stream' data = 'post data' - res, body = http.post('/', data) + res = http.post('/', data) assert_kind_of Net::HTTPResponse, res - assert_kind_of String, body assert_kind_of String, res.body - assert_equal data, body assert_equal data, res.body assert_equal data, res.entity end @@ -179,11 +171,9 @@ module TestNetHTTP_version_1_1_methods uheader = {} uheader['Accept'] = 'application/octet-stream' data = 'patch data' - res, body = http.patch('/', data) + res = http.patch('/', data) assert_kind_of Net::HTTPResponse, res - assert_kind_of String, body assert_kind_of String, res.body - assert_equal data, body assert_equal data, res.body assert_equal data, res.entity end @@ -305,23 +295,6 @@ module TestNetHTTP_version_1_2_methods end end -class TestNetHTTP_version_1_1 < Test::Unit::TestCase - CONFIG = { - 'host' => '127.0.0.1', - 'port' => 10081, - 'proxy_host' => nil, - 'proxy_port' => nil, - } - - include TestNetHTTPUtils - include TestNetHTTP_version_1_1_methods - - def new - Net::HTTP.version_1_1 - super - end -end - class TestNetHTTP_v1_2 < Test::Unit::TestCase CONFIG = { 'host' => '127.0.0.1', @@ -371,23 +344,3 @@ class TestNetHTTP_v1_2_chunked < Test::Unit::TestCase } end end - -=begin -class TestNetHTTP_proxy < Test::Unit::TestCase - CONFIG = { - 'host' => '127.0.0.1', - 'port' => 10081, - 'proxy_host' => '127.0.0.1', - 'proxy_port' => 10082, - } - - include TestNetHTTPUtils - include TestNetHTTP_version_1_1_methods - include TestNetHTTP_version_1_2_methods - - def new - Net::HTTP.version_1_2 - super - end -end -=end |