Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use method to check idempotence in Net::HTTP::Persistent#idempotent? #83

Merged
merged 1 commit into from
Jul 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions lib/net/http/persistent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions test/test_net_http_persistent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down