From 54756af35e64348bdbf92d158e9a693ca62a5aa5 Mon Sep 17 00:00:00 2001 From: Fotos Georgiadis Date: Mon, 26 Dec 2016 13:37:58 +0000 Subject: [PATCH] Use method to check idempotence in Net::HTTP::Persistent#idempotent? --- lib/net/http/persistent.rb | 7 +++---- test/test_net_http_persistent.rb | 9 +++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/net/http/persistent.rb b/lib/net/http/persistent.rb index e6a110c..ab39ee9 100644 --- a/lib/net/http/persistent.rb +++ b/lib/net/http/persistent.rb @@ -721,9 +721,8 @@ def http_version uri # Is +req+ idempotent according to RFC 2616? def idempotent? req - case req - when Net::HTTP::Delete, Net::HTTP::Get, Net::HTTP::Head, - Net::HTTP::Options, Net::HTTP::Put, Net::HTTP::Trace then + case req.method + when 'DELETE', 'GET', 'HEAD', 'OPTIONS', 'PUT', 'TRACE' then true end end @@ -911,7 +910,7 @@ def reset connection # If a block is passed #request behaves like Net::HTTP#request (the body of # the response will not have been read). # - # +req+ must be a Net::HTTPRequest subclass (see Net::HTTP for a list). + # +req+ must be a Net::HTTPGenericRequest subclass (see Net::HTTP for a list). # # If there is an error and the request is idempotent according to RFC 2616 # it will be retried automatically. diff --git a/test/test_net_http_persistent.rb b/test/test_net_http_persistent.rb index fa64570..4c223fc 100644 --- a/test/test_net_http_persistent.rb +++ b/test/test_net_http_persistent.rb @@ -728,7 +728,16 @@ def test_idempotent_eh assert @http.idempotent? Net::HTTP::Put.new '/' assert @http.idempotent? Net::HTTP::Trace.new '/' + assert @http.idempotent? Net::HTTPGenericRequest.new('DELETE', false, true, '/') + assert @http.idempotent? Net::HTTPGenericRequest.new('GET', false, true, '/') + assert @http.idempotent? Net::HTTPGenericRequest.new('HEAD', false, false, '/') + assert @http.idempotent? Net::HTTPGenericRequest.new('OPTIONS', false, false, '/') + assert @http.idempotent? Net::HTTPGenericRequest.new('PUT', true, true, '/') + assert @http.idempotent? Net::HTTPGenericRequest.new('TRACE', false, true, '/') + refute @http.idempotent? Net::HTTP::Post.new '/' + + refute @http.idempotent? Net::HTTPGenericRequest.new('POST', true, true, '/') end def test_normalize_uri