From e0512b29aa47d4b79a27b0c0356bf47ec9b4e072 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Wed, 11 Mar 2020 14:26:22 +0900 Subject: Let Net::HTTP.get take request headers (#2957) * Let Net::HTTP.get take request headers * Add more test cases for no header usages * Add examples with request headers * Add a NEWS entry [ci skip] [Feature #16686] --- test/net/http/test_http.rb | 21 +++++++++++++++++++++ test/net/http/utils.rb | 6 +++++- 2 files changed, 26 insertions(+), 1 deletion(-) (limited to 'test/net') diff --git a/test/net/http/test_http.rb b/test/net/http/test_http.rb index 231aa48557..c05c5f79c6 100644 --- a/test/net/http/test_http.rb +++ b/test/net/http/test_http.rb @@ -283,6 +283,27 @@ module TestNetHTTP_version_1_1_methods def test_s_get assert_equal $test_net_http_data, Net::HTTP.get(config('host'), '/', config('port')) + + assert_equal $test_net_http_data, Net::HTTP.get( + URI.parse("http://#{config('host')}:#{config('port')}") + ) + assert_equal $test_net_http_data, Net::HTTP.get( + URI.parse("http://#{config('host')}:#{config('port')}"), "Accept" => "text/plain" + ) + end + + def test_s_get_response + res = Net::HTTP.get_response( + URI.parse("http://#{config('host')}:#{config('port')}") + ) + assert_equal "application/octet-stream", res["Content-Type"] + assert_equal $test_net_http_data, res.body + + res = Net::HTTP.get_response( + URI.parse("http://#{config('host')}:#{config('port')}"), "Accept" => "text/plain" + ) + assert_equal "text/plain", res["Content-Type"] + assert_equal $test_net_http_data, res.body end def test_head diff --git a/test/net/http/utils.rb b/test/net/http/utils.rb index 53f3be0b88..e343e16712 100644 --- a/test/net/http/utils.rb +++ b/test/net/http/utils.rb @@ -81,7 +81,11 @@ module TestNetHTTPUtils end def do_GET(req, res) - res['Content-Type'] = $test_net_http_data_type + if req['Accept'] != '*/*' + res['Content-Type'] = req['Accept'] + else + res['Content-Type'] = $test_net_http_data_type + end res.body = $test_net_http_data res.chunked = @chunked end -- cgit v1.2.3