summaryrefslogtreecommitdiff
path: root/test/net
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2020-03-11 14:26:22 +0900
committerGitHub <noreply@github.com>2020-03-10 22:26:22 -0700
commite0512b29aa47d4b79a27b0c0356bf47ec9b4e072 (patch)
tree2a2cf5d3a538c8c685cfc3312f65a8216bd8993e /test/net
parent12009fb3b984faf346250ee7723ecccf56622ce0 (diff)
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]
Notes
Notes: Merged-By: k0kubun <takashikkbn@gmail.com>
Diffstat (limited to 'test/net')
-rw-r--r--test/net/http/test_http.rb21
-rw-r--r--test/net/http/utils.rb6
2 files changed, 26 insertions, 1 deletions
diff --git a/test/net/http/test_http.rb b/test/net/http/test_http.rb
index 231aa48..c05c5f7 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 53f3be0..e343e16 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