Permalink
Browse files

Fix a few small issues:

- retry_after may equal the limit
- someone (net/http?) lowercases header names?!
- better short circuit for integer Retry-After
  • Loading branch information...
1 parent 6b39612 commit 3787e8a1f014f1c71b55c77a0af15096911c1ef0 @nz committed Apr 8, 2012
Showing with 5 additions and 3 deletions.
  1. +5 −3 lib/rsolr/client.rb
View
8 lib/rsolr/client.rb
@@ -183,15 +183,17 @@ def retry_503?(request_context, response)
return false unless retry_503 && retry_503 > 0
retry_after_limit = request_context[:retry_after_limit] || 1
retry_after = retry_after(response)
- return false unless retry_after && retry_after < retry_after_limit
+ return false unless retry_after && retry_after <= retry_after_limit
true
end
# Retry-After can be a relative number of seconds from now, or an RFC 1123 Date.
# If the latter, attempt to convert it to a relative time in seconds.
def retry_after(response)
- retry_after = response[:headers]['Retry-After']
- if retry_after.is_a?(String)
+ retry_after = Array(response[:headers]['Retry-After'] || response[:headers]['retry-after']).flatten.first
+ if retry_after =~ /\A[0-9]+\Z/
+ retry_after = retry_after.to_i
+ else
begin
retry_after_date = DateTime.parse(retry_after)
retry_after = retry_after_date.to_time - Time.now

0 comments on commit 3787e8a

Please sign in to comment.