Skip to content

Commit fa4ed75

Browse files
committed
More verbose implementation.
1 parent 06d9813 commit fa4ed75

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

‎lib/protocol/http/request.rb‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,23 @@ def self.[](method, path = nil, _headers = nil, _body = nil, scheme: nil, author
134134

135135
# Whether the request can be replayed without side-effects.
136136
def idempotent?
137-
return true if @method == Methods::QUERY
137+
# QUERY requests are idempotent, even if they have a body:
138+
if @method == Methods::QUERY
139+
return true
140+
end
141+
142+
# POST requests are not idempotent, even if they have no body:
143+
if @method == Methods::POST
144+
return false
145+
end
146+
147+
# All other requests are idempotent if they have no body:
148+
if @body.nil? || @body.empty?
149+
return true
150+
end
138151

139-
@method != Methods::POST && (@body.nil? || @body.empty?)
152+
# Otherwise, we don't know if the request is idempotent or not, so we assume it is not:
153+
return false
140154
end
141155

142156
# Convert the request to a hash, suitable for serialization.

0 commit comments

Comments
 (0)