Skip to content

Commit

Permalink
Merge pull request rack#596 from SamSaffron/master
Browse files Browse the repository at this point in the history
Conditional get is causing exceptions during regular usage
  • Loading branch information
rkh committed Sep 3, 2013
2 parents 210167f + 94790b7 commit 0adc7ce
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/rack/conditionalget.rb
Expand Up @@ -61,7 +61,16 @@ def modified_since?(modified_since, headers)
end

def to_rfc2822(since)
Time.rfc2822(since) rescue nil
# shortest possible valid date is the obsolete: 1 Nov 97 09:55 A
# anything shorter is invalid, this avoids exceptions for common cases
# most common being the empty string
if since && since.length >= 16
# NOTE: there is no trivial way to write this in a non execption way
# _rfc2822 returns a hash but is not that usable
Time.rfc2822(since) rescue nil
else
nil
end
end
end
end

0 comments on commit 0adc7ce

Please sign in to comment.