ruby/test/net/http/test_http_request.rb
naruse ddddf044b2 merge revision(s) 39232,39233,39238: [Backport #7831][Backport #7852]
* lib/net/http:  Do not handle Content-Encoding when the user sets
	  Accept-Encoding.  This allows users to handle Content-Encoding for
	  themselves.  This restores backwards-compatibility with Ruby 1.x.

	* lib/net/http/generic_request.rb:  ditto.

	* lib/net/http/response.rb:  ditto

	* test/net/http/test_http.rb:  Test for the above.

	* test/net/http/test_http_request.rb:  ditto.

	* test/net/http/test_httpresponse.rb:  ditto.
	  [ruby-trunk - Bug #7831]

	* lib/net/http.rb:  Removed OpenSSL dependency from Net::HTTP.

	* test/net/http/test_http.rb:  Remove Zlib dependency from tests.

	* test/net/http/test_http_request.rb:  ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@39244 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-02-14 15:51:45 +00:00

79 lines
1.8 KiB
Ruby

require 'net/http'
require 'test/unit'
require 'stringio'
class HTTPRequestTest < Test::Unit::TestCase
def test_initialize_GET
req = Net::HTTP::Get.new '/'
assert_equal 'GET', req.method
refute req.request_body_permitted?
assert req.response_body_permitted?
expected = {
'accept' => %w[*/*],
'user-agent' => %w[Ruby],
}
expected['accept-encoding'] = %w[gzip;q=1.0,deflate;q=0.6,identity;q=0.3] if
Net::HTTP::HAVE_ZLIB
assert_equal expected, req.to_hash
end
def test_initialize_GET_range
req = Net::HTTP::Get.new '/', 'Range' => 'bytes=0-9'
assert_equal 'GET', req.method
refute req.request_body_permitted?
assert req.response_body_permitted?
expected = {
'accept' => %w[*/*],
'user-agent' => %w[Ruby],
'range' => %w[bytes=0-9],
}
assert_equal expected, req.to_hash
end
def test_initialize_HEAD
req = Net::HTTP::Head.new '/'
assert_equal 'HEAD', req.method
refute req.request_body_permitted?
refute req.response_body_permitted?
expected = {
'accept' => %w[*/*],
'user-agent' => %w[Ruby],
}
assert_equal expected, req.to_hash
end
def test_initialize_accept_encoding
req1 = Net::HTTP::Get.new '/'
assert req1.decode_content, 'Bug #7831 - automatically decode content'
req2 = Net::HTTP::Get.new '/', 'accept-encoding' => 'identity'
refute req2.decode_content,
'Bug #7381 - do not decode content if the user overrides'
end if Net::HTTP::HAVE_ZLIB
def test_header_set
req = Net::HTTP::Get.new '/'
assert req.decode_content, 'Bug #7831 - automatically decode content'
req['accept-encoding'] = 'identity'
refute req.decode_content,
'Bug #7831 - do not decode content if the user overrides'
end if Net::HTTP::HAVE_ZLIB
end